Skip to content

Commit

Permalink
chore: 🤖 lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Portkey-David committed Jan 21, 2025
1 parent 6966fe6 commit 667a5d6
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 133 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"@portkey/did": "2.19.0-alpha.7",
"@portkey/did-ui-react": "2.19.0-alpha.7",
"@portkey/iframe-provider": "^2.4.0-alpha.6",
"@portkey/onboarding": "2.19.0-alpha.7",
"@portkey/provider-types": "^2.4.0-alpha.6",
"@portkey/did": "2.19.0-alpha.9",
"@portkey/did-ui-react": "2.19.0-alpha.9",
"@portkey/iframe-provider": "^2.4.0-alpha.8",
"@portkey/onboarding": "2.19.0-alpha.9",
"@portkey/provider-types": "^2.4.0-alpha.8",
"@types/qs": "^6.9.18",
"aelf-sdk": "^3.4.7",
"antd": "4.24.14",
Expand Down
21 changes: 20 additions & 1 deletion src/controllers/AELFMethodController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const aelfMethodList = [
MethodsWallet.GET_WALLET_CURRENT_MANAGER_ADDRESS,
MethodsWallet.GET_WALLET_MANAGER_SYNC_STATUS,
MethodsWallet.GET_WALLET_TRANSACTION_SIGNATURE,
MethodsWallet.WALLET_LOCK,
];
interface AELFMethodControllerProps {
approvalController: ApprovalController;
Expand Down Expand Up @@ -216,6 +217,7 @@ export default class AELFMethodController {
case MethodsBase.WALLET_INFO:
this.getWalletInfo(sendResponse, message.payload);
break;

case MethodsWallet.GET_WALLET_SIGNATURE: {
const isCipherText = checkIsCipherText(message.payload.payload.data);
message.payload.payload.isCipherText = isCipherText;
Expand Down Expand Up @@ -252,6 +254,9 @@ export default class AELFMethodController {
case MethodsWallet.GET_WALLET_MANAGER_SYNC_STATUS:
this.getWalletManagerSyncStatus(sendResponse, message.payload);
break;
case MethodsWallet.WALLET_LOCK:
this.lockWallet(sendResponse, message.payload);
break;
default:
sendResponse(
errorHandler(
Expand Down Expand Up @@ -359,7 +364,6 @@ export default class AELFMethodController {
getWalletState: RequestCommonHandler = async (sendResponse: SendResponseFun, message) => {
try {
let data: any = {
isUnlocked: !this.dappManager.isLocked(),
isConnected: !this.dappManager.isLocked(),
isLogged: this.dappManager.isLogged(),
};
Expand Down Expand Up @@ -801,6 +805,21 @@ export default class AELFMethodController {
}
};

lockWallet: RequestCommonHandler = async sendResponse => {
try {
const result = await this.dappManager.lockWallet();
sendResponse({ ...errorHandler(0), data: result });
} catch (error) {
console.log('getCAHash===', error);
sendResponse({
...errorHandler(100001),
data: {
code: ResponseCode.INTERNAL_ERROR,
},
});
}
};

async getCaContract(chainInfo: ChainInfo) {
const manager = await this.getManager();
return await getContract({
Expand Down
6 changes: 5 additions & 1 deletion src/service/ServiceWorkerInstantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import SWEventController from '../controllers/EventController/SWEventController'
import OpenPageService from './OpenPageService';

const permissionWhitelist = [
MethodsWallet.GET_WALLET_STATE,
// The method that requires the dapp not to trigger the lock call
MethodsBase.ACCOUNTS,
MethodsBase.CHAIN_ID,
MethodsBase.CHAIN_IDS,
MethodsBase.CHAINS_INFO,
MethodsBase.WALLET_INFO,
MethodsWallet.GET_WALLET_STATE,
MethodsWallet.WALLET_LOCK,
];

// This is the script that runs in the extension's serviceWorker ( singleton )
Expand Down Expand Up @@ -62,9 +63,12 @@ export default class ServiceWorkerInstantiate {
// }

const registerRes = await this.permissionController.checkRegister(request.method, request?.payload);

console.log(registerRes, 'registerRes===');
if (registerRes.error !== 0) return sendResponse(registerRes);

const isLocked = await this.permissionController.checkIsLockOtherwiseUnlock(request.method);
console.log('isLocked', isLocked);
if (isLocked.error !== 0) return sendResponse(isLocked);

this.dispenseMessage(sendResponse, request);
Expand Down
21 changes: 12 additions & 9 deletions src/utils/dappManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IBaseDappManagerProps {

export abstract class DappManager implements IDappManager {
protected appId: string;

constructor({ appId }: { appId: string }) {
this.appId = appId;
}
Expand All @@ -24,11 +25,21 @@ export abstract class DappManager implements IDappManager {
getDid() {
return did;
}
isActive(): boolean {
return true;
}

async lockWallet() {
return this.getDid().reset();
}
isLocked(): boolean {
console.log('=====isLocked', !did?.didWallet?.aaInfo?.accountInfo?.caHash);
return Boolean(!did?.didWallet?.aaInfo?.accountInfo?.caHash);
}

isLogged() {
return Boolean(localStorage.getItem(getWebWalletStorageKey(this.appId)));
}

getWallet() {
return this.getDid()?.didWallet as unknown as DIDWallet<portkey.WalletAccount>;
}
Expand All @@ -52,10 +63,6 @@ export abstract class DappManager implements IDappManager {
return getChain(chainId);
}

isActive() {
return true;
}

// async updateManagerSyncState(chainId: ChainId) {
// const { currentNetwork } = await this.getWallet();
// this.store.dispatch(updateCASyncState({ networkType: currentNetwork, chainId }));
Expand Down Expand Up @@ -103,10 +110,6 @@ export abstract class DappManager implements IDappManager {
return originChainId;
}

isLogged() {
return Boolean(localStorage.getItem(getWebWalletStorageKey(this.appId)));
}

async accounts() {
console.log(did.didWallet, 'accounts==');
const chains = await this.chainIds();
Expand Down
Loading

0 comments on commit 667a5d6

Please sign in to comment.