Skip to content

Commit

Permalink
Merge pull request #1185 from Portkey-Wallet/release/did-v1.4.6
Browse files Browse the repository at this point in the history
Release/did v1.4.6
  • Loading branch information
portkey-yellow authored Oct 30, 2023
2 parents 78cc10d + 3af1ed2 commit 880ab41
Show file tree
Hide file tree
Showing 1,243 changed files with 73,324 additions and 10,653 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ ignore/
**/*.zip

coverage

# network
packages/constants/constants-ca/network.ts
74 changes: 60 additions & 14 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@ module.exports = {
'**/packages/hooks/hooks-ca/*.{ts,tsx}',
'**/packages/store/store-ca/**/slice.{ts,tsx}',
'**/packages/utils/wallet/index.ts',
'**/packages/utils/activity.ts',
'**/packages/web-extension-did/app/web/store/reducers/**/*.{ts,tsx}',
'**/packages/web-extension-did/app/web/hooks/useActiveLockStatus.ts',
'**/packages/web-extension-did/app/web/hooks/useCaInfoOnChain.ts',
'**/packages/web-extension-did/app/web/hooks/useNetwork.ts',
'!**/packages/hooks/hooks-ca/contact.{ts,tsx}',
'**/packages/web-extension-did/app/web/controllers/approval/*.ts',
'**/packages/web-extension-did/app/web/controllers/methodController/*.ts',
'**/packages/web-extension-did/app/web/utils/device.ts',
'**/packages/web-extension-did/app/web/utils/errorHandler.ts',
// '**/packages/web-extension-did/app/web/hooks/useActiveLockStatus.ts',
// '**/packages/web-extension-did/app/web/hooks/useCaInfoOnChain.ts',
// '**/packages/web-extension-did/app/web/hooks/useNetwork.ts',
'!**/packages/store/store-ca/{cms,dapp,discover,misc,txFee}/*.{ts,tsx}',
'!**/packages/hooks/hooks-ca/{contact,useTxFee,wallet}.{ts,tsx}',
'!**/node_modules/**',
'!**/*.test.{ts,tsx}',
],
coverageReporters: ['json-summary'],
coverageReporters: ['text', 'json-summary', 'json', 'lcov'],
coverageThreshold: {
global: {
branches: 95,
functions: 95,
lines: 95,
statements: 95,
},
},
moduleNameMapper: {
'\\.(css|less)$': 'identity-obj-proxy',
},
Expand All @@ -25,6 +39,7 @@ module.exports = {
displayName: 'hooks',
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/hooks/hooks-ca/*.test.{ts,tsx}'],
testPathIgnorePatterns: ['<rootDir>/packages/hooks/hooks-ca/wallet.test.ts'],
testEnvironment: 'jsdom',
},
{
Expand All @@ -40,15 +55,15 @@ module.exports = {
testEnvironment: 'jsdom',
},
{
displayName: 'web-extension-did-store',
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/web-extension-did/app/web/store/**/*.test.{ts,tsx}'],
testEnvironment: 'jsdom',
},
{
displayName: 'web-extension-did-hooks',
displayName: 'web-extension-did',
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/web-extension-did/app/web/hooks/*.test.{ts,tsx}'],
testMatch: [
// '<rootDir>/packages/web-extension-did/app/web/hooks/*.test.{ts,tsx}',
'<rootDir>/packages/web-extension-did/app/web/store/**/*.test.{ts,tsx}',
'<rootDir>/packages/web-extension-did/app/web/controllers/approval/*.test.ts',
'<rootDir>/packages/web-extension-did/app/web/controllers/methodController/*.test.ts',
'<rootDir>/packages/web-extension-did/app/web/utils/*.test.ts',
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|tsx)$': [
Expand All @@ -59,12 +74,43 @@ module.exports = {
roots: ['<rootDir>/packages/web-extension-did'],
moduleNameMapper: {
'^react$': '<rootDir>/node_modules/react',
'^utils$': '<rootDir>/packages/web-extension-did/app/web/utils',
'^utils/(.*)$': '<rootDir>/packages/web-extension-did/app/web/utils/$1',
'^store/(.*)$': '<rootDir>/packages/web-extension-did/app/web/store/$1',
'^constants/(.*)$': '<rootDir>/packages/web-extension-did/app/web/constants/$1',
'^messages/(.*)$': '<rootDir>/packages/web-extension-did/app/web/messages/$1',
'^service/(.*)$': '<rootDir>/packages/web-extension-did/app/web/service/$1',
'^controllers/(.*)$': '<rootDir>/packages/web-extension-did/app/web/controllers/$1',
},
coveragePathIgnorePatterns: ['/node_modules/', '/store/', '/hooks-ca/', '/utils/'],
coveragePathIgnorePatterns: [
'/node_modules/',
'/packages/store/store-ca/',
'/packages/hooks/hooks-ca/',
'/packages/utils/',
],
},
// {
// displayName: 'mobile-app-did',
// roots: ['<rootDir>/packages/mobile-app-did'],
// preset: 'react-native',
// transform: {
// '^.+\\.(ts|tsx)$': [`ts-jest`, { isolatedModules: true, tsconfig: './packages/mobile-app-did/tsconfig.json' }],
// },
// transformIgnorePatterns: ['<rootDir>/node_modules/(?!((jest-)?react-native|@react-native(-community)?)/)'],
// testEnvironment: 'react-native',
// globals: {
// __DEV__: true,
// },
// setupFilesAfterEnv: ['./packages/mobile-app-did/jest-setup/mockAsyncStorage.ts'],
// moduleNameMapper: {
// '^react$': '<rootDir>/node_modules/react',
// '^utils/(.*)$': '<rootDir>/packages/mobile-app-did/js/utils/$1',
// '^store/(.*)$': '<rootDir>/packages/mobile-app-did/js/store/$1',
// '^@portkey-wallet/store/(.*)$': '<rootDir>/packages/store/$1',
// store: '<rootDir>/packages/mobile-app-did/js/store/index',
// '^dapp/(.*)$': '<rootDir>/packages/mobile-app-did/js/dapp/$1',
// },
// coveragePathIgnorePatterns: ['/node_modules/', '/store/', '/Test/', '/utils/'],
// },
],
};
10 changes: 8 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "0.0.0",
"version": "1.3.0",
"packages": ["packages/*"],
"npmClient": "yarn"
"npmClient": "yarn",
"command": {
"publish": {
"allowBranch": ["release/*"],
"message": "chore: 🤖 release %s"
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
]
},
"scripts": {
"prepare": "husky install",
"bootstrap": "lerna bootstrap",
"build": "lerna run build",
"clean": "lerna clean --yes",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"prepare": "husky install",
"tag:did": "lerna version --tag-version-prefix=did-v",
"reset-modules": "rm -rf node_modules/ yarn.lock packages/*/node_modules",
"common-package:extension": "npx lerna add @portkey-wallet/utils --scope=web-extension && npx lerna add @portkey-wallet/hooks --scope=web-extension && npx lerna add @portkey-wallet/store --scope=web-extension && npx lerna add @portkey-wallet/constants --scope=web-extension",
"app:did": "yarn workspace mobile-did run",
Expand Down
22 changes: 21 additions & 1 deletion packages/api/api-did/contact/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { BaseConfig } from '../../types';

const BASE_URL = `/api/app/contacts`;
const KeyList = ['addContact', 'editContact', 'deleteContact', 'checkContactName'] as const;
const KeyList = [
'addContact',
'editContact',
'deleteContact',
'checkContactName',
'readImputation',
'contactPrivacyList',
'updateContactPrivacy',
] as const;

const ApiObject: Record<typeof KeyList[number], BaseConfig> = {
addContact: {
Expand All @@ -20,6 +28,18 @@ const ApiObject: Record<typeof KeyList[number], BaseConfig> = {
target: `${BASE_URL}/exist`,
config: { method: 'GET' },
},
readImputation: {
target: `${BASE_URL}/read`,
config: { method: 'POST' },
},
contactPrivacyList: {
target: `/api/app/privacyPermission`,
config: { method: 'GET' },
},
updateContactPrivacy: {
target: `/api/app/privacyPermission`,
config: { method: 'POST' },
},
};

export default ApiObject;
12 changes: 12 additions & 0 deletions packages/api/api-did/discover/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
addBookmark: '/api/app/bookmarks',
deleteAllBookmark: {
target: '/api/app/bookmarks',
config: { method: 'DELETE' },
},
deleteBookmark: '/api/app/bookmarks/modify',
getBookmarks: {
target: '/api/app/bookmarks',
config: { method: 'GET' },
},
} as const;
14 changes: 7 additions & 7 deletions packages/api/api-did/es/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ESBaseConfig } from './type';

const Method = 'GET';
const BaseESUrl = `/api/app/search/`;
const BaseESUrl = `/api/app/`;

const KeyList = [
'getUserTokenList',
Expand All @@ -14,27 +14,27 @@ const KeyList = [

const ApiObject: Record<typeof KeyList[number], ESBaseConfig> = {
getUserTokenList: {
target: `${BaseESUrl}usertokenindex`,
target: `${BaseESUrl}search/usertokenindex`,
config: { method: Method },
},
getChainsInfo: {
target: `${BaseESUrl}chainsinfoindex`,
target: `${BaseESUrl}search/chainsinfoindex`,
config: { method: Method, params: { sort: 'chainId' } },
},
getRegisterResult: {
target: `${BaseESUrl}accountregisterindex`,
target: `${BaseESUrl}search/accountregisterindex`,
config: { method: Method },
},
getRecoverResult: {
target: `${BaseESUrl}accountrecoverindex`,
target: `${BaseESUrl}search/accountrecoverindex`,
config: { method: Method },
},
getContactList: {
target: `${BaseESUrl}contactindex`,
target: `${BaseESUrl}contacts/list`,
config: { method: Method },
},
getCaHolder: {
target: `${BaseESUrl}caholderindex`,
target: `${BaseESUrl}search/caholderindex`,
config: { method: Method },
},
};
Expand Down
7 changes: 7 additions & 0 deletions packages/api/api-did/es/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ export type ESBaseConfig = BaseConfig & {
};

export type ES_API_REQ_FUNCTION = (config?: RequestConfig & ESConfig) => Promise<{ type: 'timeout' } | any>;

export interface IGetContactListParams {
page: number;
size: number;
modificationTime: string;
keyword?: string;
}
12 changes: 5 additions & 7 deletions packages/api/api-did/es/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { request } from '@portkey-wallet/api/api-did';
import { GetContractListApiType } from '@portkey-wallet/types/types-ca/contact';
import { IGetContactListParams } from '../type';

export const getContactList = (
baseURL: string,
{ page, size, modificationTime }: { page: number; size: number; modificationTime: string },
{ page, size, modificationTime, keyword }: IGetContactListParams,
): Promise<GetContractListApiType> => {
return request.es.getContactList({
baseURL,
Expand All @@ -13,18 +14,14 @@ export const getContactList = (
sortType: 0,
skipCount: (page - 1) * size,
maxResultCount: size,
keyword,
},
});
};

export const getContactEventList = (
baseURL: string,
{
page,
size,
modificationTime,
fetchTime,
}: { page: number; size: number; modificationTime: string; fetchTime: string },
{ page, size, modificationTime, fetchTime, keyword }: IGetContactListParams & { fetchTime: string },
): Promise<GetContractListApiType> => {
return request.es.getContactList({
baseURL,
Expand All @@ -34,6 +31,7 @@ export const getContactEventList = (
sortType: 0,
skipCount: (page - 1) * size,
maxResultCount: size,
keyword,
},
});
};
Expand Down
6 changes: 6 additions & 0 deletions packages/api/api-did/im/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
getImageThumb: {
target: '/api/app/image/getThumbnail',
config: { method: 'GET' },
},
} as const;
6 changes: 6 additions & 0 deletions packages/api/api-did/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import paymentApi from './payment';
import deviceApi from './device';
import messageApi from './message';
import switchApi from './switch';
import discoverApi from './discover';
import txFeeApi from './txFee';
import imApi from './im';

import esApi from './es';
import myServer, { DidService } from './server';
Expand Down Expand Up @@ -48,6 +51,9 @@ export const EXPAND_APIS = {
device: deviceApi,
message: messageApi,
switch: switchApi,
discover: discoverApi,
txFee: txFeeApi,
im: imApi,
};

export type BASE_REQ_TYPES = {
Expand Down
2 changes: 2 additions & 0 deletions packages/api/api-did/message/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
sendScanLoginSuccess: '/api/app/message/scanLoginSuccess',
sendScanLogin: '/api/app/message/scanLogin',
checkQRCodeExist: '/api/app/qrcode',
};
4 changes: 4 additions & 0 deletions packages/api/api-did/message/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ type sendScanLoginSuccessParams = {
export async function sendScanLoginSuccess({ targetClientId }: sendScanLoginSuccessParams) {
return request.message.sendScanLoginSuccess({ params: { targetClientId } });
}

export const checkQRCodeExist = (id: string): Promise<boolean> => {
return request.message.checkQRCodeExist({ params: { id } });
};
2 changes: 2 additions & 0 deletions packages/api/api-did/payment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export default {
config: { method: 'GET' },
},
updateAchOrder: '/api/app/thirdPart/order/alchemy',
updateAlchemyOrderTxHash: '/api/app/thirdPart/alchemy/txHash',
sendSellTransaction: '/api/app/thirdPart/alchemy/transaction',
} as const;
4 changes: 2 additions & 2 deletions packages/api/api-did/payment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export interface OrderQuoteType {
export interface CryptoInfoType {
crypto: string;
network: string;
buyEnable: number;
sellEnable: number;
buyEnable: string;
sellEnable: string;
minPurchaseAmount: number | null;
maxPurchaseAmount: number | null;
address: null;
Expand Down
20 changes: 13 additions & 7 deletions packages/api/api-did/payment/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { request } from '@portkey-wallet/api/api-did';
import { CryptoInfoType, GetAchTokenDataType, OrderQuoteType } from '../type';
import { TransDirectEnum } from '@portkey-wallet/constants/constants-ca/payment';
import { PaymentTypeEnum } from '@portkey-wallet/types/types-ca/payment';

export interface GetOrderQuoteParamsType {
crypto: string;
Expand All @@ -23,19 +24,24 @@ export const getOrderQuote = async (params: GetOrderQuoteParamsType) => {
return rst.data as OrderQuoteType;
};

export const getCryptoInfo = async (params: { fiat: string }, symbol: string, _chainId: string) => {
// FIXME _chainId to chainId
console.log(
'At present, only the main network is connected to legal currency, and the test is the faucet. If the test network is connected to legal currency, chainId will be used',
);

export const getCryptoInfo = async (
params: { fiat: string },
symbol: string,
network: string,
side: PaymentTypeEnum,
) => {
const rst = await request.payment.getCryptoList({
params,
});
if (rst.returnCode !== '0000') {
throw new Error(rst.returnMsg);
}
return (rst.data as CryptoInfoType[]).find((item: any) => item.crypto === symbol && item.network === symbol);
return (rst.data as CryptoInfoType[]).find(
(item: any) =>
item.crypto === symbol &&
item.network === network &&
(side === PaymentTypeEnum.BUY ? Number(item.buyEnable) === 1 : Number(item.sellEnable) === 1),
);
};

export const getCryptoList = async (params: { fiat: string }) => {
Expand Down
Loading

0 comments on commit 880ab41

Please sign in to comment.