Skip to content

Commit

Permalink
Merge pull request #228 from Portkey-Wallet/feature/did-dev1.2.8
Browse files Browse the repository at this point in the history
Feature/did dev1.2.8
  • Loading branch information
Ian-potter authored May 29, 2023
2 parents 7603f0a + 9f0070d commit 78cc10d
Show file tree
Hide file tree
Showing 339 changed files with 18,808 additions and 2,935 deletions.
70 changes: 70 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
displayName: 'did',
preset: 'ts-jest',
testEnvironment: 'jsdom',
coverageDirectory: 'coverage',
collectCoverageFrom: [
'**/packages/hooks/hooks-ca/*.{ts,tsx}',
'**/packages/store/store-ca/**/slice.{ts,tsx}',
'**/packages/utils/wallet/index.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}',
'!**/node_modules/**',
'!**/*.test.{ts,tsx}',
],
coverageReporters: ['json-summary'],
moduleNameMapper: {
'\\.(css|less)$': 'identity-obj-proxy',
},
projects: [
{
displayName: 'hooks',
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/hooks/hooks-ca/*.test.{ts,tsx}'],
testEnvironment: 'jsdom',
},
{
displayName: 'store',
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/store/store-ca/**/*.test.{ts,tsx}'],
testEnvironment: 'jsdom',
},
{
displayName: 'utils',
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/utils/**/*.test.{ts,tsx}'],
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',
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/web-extension-did/app/web/hooks/*.test.{ts,tsx}'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|tsx)$': [
`ts-jest`,
{ isolatedModules: true, tsconfig: './packages/web-extension-did/tsconfig.json' },
],
},
roots: ['<rootDir>/packages/web-extension-did'],
moduleNameMapper: {
'^react$': '<rootDir>/node_modules/react',
'^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',
},
coveragePathIgnorePatterns: ['/node_modules/', '/store/', '/hooks-ca/', '/utils/'],
},
],
};
37 changes: 35 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,50 @@
"extension:did": "yarn workspace web-extension-did run",
"extension-did:dev": "yarn extension:did dev:watch",
"graphql": "yarn workspace @portkey-wallet/graphql run",
"page": "yarn workspace web-page run"
"page": "yarn workspace web-page run",
"test": "jest",
"test-cov": "jest --coverage",
"test-badges": "jest --coverage && istanbul-badges-readme"
},
"devDependencies": {
"@babel/core": "^7.19.1",
"@babel/plugin-proposal-decorators": "^7.19.1",
"@babel/plugin-transform-modules-commonjs": "^7.21.2",
"@babel/plugin-transform-runtime": "^7.19.1",
"@babel/preset-env": "^7.19.1",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.2.5",
"babel-jest": "^29.5.0",
"babel-loader": "^8.2.5",
"babel-plugin-import": "^1.13.5",
"babel-plugin-module-resolver": "^4.1.0",
"babel-preset-es2015": "^6.24.1",
"eslint": "^8.23.1",
"eslint-plugin-react": "^7.31.8",
"husky": "^8.0.1",
"identity-obj-proxy": "^3.0.0",
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"lerna": "^5.5.2",
"lint-staged": ">=13"
"lint-staged": ">=13",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"ts-jest": "^29.0.4"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --cache --fix"
},
"husky": {
"hooks": {
"pre-commit": "yarn run test && istanbul-badges-readme && git add 'README.md'"
}
},
"version": "1.0.0"
}
1 change: 1 addition & 0 deletions packages/api/api-did/activity/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
activityList: '/api/app/user/activities/activities',
activity: '/api/app/user/activities/activity',
activityListWithAddress: '/api/app/user/activities/transactions',
} as const;
7 changes: 6 additions & 1 deletion packages/api/api-did/payment/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export const getOrderQuote = async (params: GetOrderQuoteParamsType) => {
return rst.data as OrderQuoteType;
};

export const getCryptoInfo = async (params: { fiat: string }, symbol: string, chainId: string) => {
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',
);

const rst = await request.payment.getCryptoList({
params,
});
Expand Down
33 changes: 33 additions & 0 deletions packages/api/api-did/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ServiceInit } from '../server/config';
import { customFetch } from '@portkey-wallet/utils/fetch';
import { IExceptionManager, Severity } from '@portkey-wallet/utils/ExceptionManager';
import { BaseConfig, RequestConfig } from '../types';
import { getRequestConfig, spliceUrl } from '../utils';
import { isValidRefreshTokenConfig, queryAuthorization, RefreshTokenConfig } from './utils/index';
Expand All @@ -8,6 +9,7 @@ export class DidService extends ServiceInit {
protected refreshTokenConfig?: RefreshTokenConfig;
protected onLockApp?: (expired?: boolean) => void;
locked?: boolean;
exceptionManager?: IExceptionManager;
constructor() {
super();
}
Expand Down Expand Up @@ -49,9 +51,27 @@ export class DidService extends ServiceInit {
this.refreshTokenConfig = config;
};
send = async (base: BaseConfig, config?: RequestConfig, reCount = 0): Promise<any> => {
try {
return await this.sendOrigin(base, config, reCount);
} catch (errResult: any) {
const { URL, fetchConfig } = this.getConfig(base, config);
this.errorReport(URL, fetchConfig, errResult);
throw errResult;
}
};

getConfig = (base: BaseConfig, config?: RequestConfig) => {
const { method = 'POST', url, baseURL, ...fetchConfig } = getRequestConfig(base, config, this.defaultConfig) || {};
const _url = url || (typeof base === 'string' ? base : base.target);
const URL = spliceUrl(baseURL || '', _url);
return {
URL,
method,
fetchConfig,
};
};
sendOrigin = async (base: BaseConfig, config?: RequestConfig, reCount = 0): Promise<any> => {
const { URL, fetchConfig, method } = this.getConfig(base, config);
const fetchResult = await customFetch(URL, {
...fetchConfig,
method,
Expand All @@ -75,6 +95,19 @@ export class DidService extends ServiceInit {
setLockCallBack = (callBack: (expired?: boolean) => void) => {
this.onLockApp = callBack;
};

setExceptionManager = (exceptionManager: IExceptionManager) => {
this.exceptionManager = exceptionManager;
};
errorReport = (url: string, fetchConfig: any, fetchResult: any) => {
this.exceptionManager?.reportErrorMessage?.(`${URL} request error`, Severity.Fatal, {
req: {
url,
config: fetchConfig,
},
rep: fetchResult,
});
};
}

export default new DidService();
43 changes: 0 additions & 43 deletions packages/api/api-did/utils/verification.ts

This file was deleted.

16 changes: 13 additions & 3 deletions packages/api/api-did/verification/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ export class Verification extends StorageBaseLoader {
public async save() {
this._store.setItem(this._defaultKeyName, JSON.stringify(this.verifierMap));
}
public get(key: string) {
public get(key: string): void | VerifierInfo {
const info = this.verifierMap[key];
if (!info) return;
const endTime = info.time + this._expirationTime;
if (endTime > Date.now()) {
return info;
} else {
delete this.verifierMap[key];
this.save();
this.delete(key);
}
}
public delete(key: string) {
delete this.verifierMap[key];
this.save();
}
public async set(key: string, value: VerifierInfo) {
this.verifierMap[key] = value;
await this.save();
Expand All @@ -70,4 +73,11 @@ export class Verification extends StorageBaseLoader {
throw error;
}
}
public async checkVerificationCode(config: RequestConfig) {
const { guardianIdentifier, verifierId } = config.params || {};
const key = (guardianIdentifier || '') + (verifierId || '');
const req = await request.verify.checkVerificationCode(config);
this.delete(key);
return req;
}
}
4 changes: 4 additions & 0 deletions packages/api/api-did/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export default {
config: { method: 'PUT' },
},
pullNotify: 'api/app/notify/pullNotify',
getPhoneCountryCode: {
target: '/api/app/phone/info',
config: { method: 'GET' },
},
} as const;
64 changes: 6 additions & 58 deletions packages/constants/constants-ca/activity.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,9 @@
export enum TransactionTypes {
TRANSFER = 'Transfer',
CROSS_CHAIN_TRANSFER = 'CrossChainTransfer',
CROSS_CHAIN_RECEIVE_TOKEN = 'CrossChainReceiveToken',
SOCIAL_RECOVERY = 'SocialRecovery',
REMOVE_MANAGER = 'RemoveManagerInfo',
ADD_MANAGER = 'AddManagerInfo',
CROSS_CHAIN_TRANSFER = 'CrossChainTransfer', // CrossChain Transfer
CLAIM_TOKEN = 'ClaimToken', // faucet receive transfer
}

export const transactionTypes = [
TransactionTypes.TRANSFER,
TransactionTypes.CROSS_CHAIN_TRANSFER,
TransactionTypes.CROSS_CHAIN_RECEIVE_TOKEN,
TransactionTypes.SOCIAL_RECOVERY,
TransactionTypes.ADD_MANAGER,
TransactionTypes.REMOVE_MANAGER,
];

export const transactionTypesForActivityList = [
TransactionTypes.TRANSFER,
TransactionTypes.CROSS_CHAIN_TRANSFER,
// 'CrossChainReceiveToken', // activityListPage do not need this type
TransactionTypes.SOCIAL_RECOVERY,
TransactionTypes.ADD_MANAGER,
TransactionTypes.REMOVE_MANAGER,
];

/**
* According to the TransactionTypes, it is converted into a text for page display.
* @used ActivityListPage and ActivityDetailPage
*/
export const transactionTypesMap = (type?: TransactionTypes, nftId?: string): string => {
if (!type) return '';
let newType: string = TransactionTypes.TRANSFER;
switch (type) {
case TransactionTypes.TRANSFER:
newType = TransactionTypes.TRANSFER + (nftId ? ' NFT' : '');
break;

case TransactionTypes.CROSS_CHAIN_TRANSFER:
newType = 'CrossChain Transfer' + (nftId ? ' NFT' : '');
break;

case TransactionTypes.SOCIAL_RECOVERY:
newType = 'Social Recovery';
break;

case TransactionTypes.ADD_MANAGER:
newType = 'Scan code login';
break;

case TransactionTypes.REMOVE_MANAGER:
newType = 'Exit Wallet';
break;
}
return newType;
};

export const DEFAULT_AMOUNT = 0;
export const DEFAULT_DECIMAL = 8;
export const DEFAULT_DIGITS = 4;
Expand All @@ -68,8 +16,8 @@ export const SIDE_CHAIN = 'SideChain';
export const TESTNET = 'TESTNET';
export const TEST_NET = 'Testnet';

export const HIDDEN_TRANSACTION_TYPES = [
TransactionTypes.SOCIAL_RECOVERY,
TransactionTypes.ADD_MANAGER,
TransactionTypes.REMOVE_MANAGER,
export const SHOW_FROM_TRANSACTION_TYPES = [
TransactionTypes.TRANSFER,
TransactionTypes.CROSS_CHAIN_TRANSFER,
TransactionTypes.CLAIM_TOKEN,
];
6 changes: 6 additions & 0 deletions packages/constants/constants-ca/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ export const ELF_SYMBOL = 'ELF';
export const NFT_SMALL_SIZE = 144;
export const NFT_MIDDLE_SIZE = 294;
export const NFT_LARGE_SIZE = 1008;

export enum BalanceTab {
TOKEN = 'token',
NFT = 'nft',
ACTIVITY = 'activity',
}
Loading

0 comments on commit 78cc10d

Please sign in to comment.