From 0c26ce8f154296ffb900060dab7603728ab4a3da Mon Sep 17 00:00:00 2001 From: aelf-lxy Date: Mon, 21 Oct 2024 10:31:27 +0800 Subject: [PATCH 1/2] feat: support aelf wallet --- README.md | 1 - packages/base/package.json | 2 +- packages/base/src/types.ts | 2 +- packages/bridge/package.json | 2 +- packages/bridge/src/ui.tsx | 1 + packages/react/package.json | 2 +- packages/utils/package.json | 2 +- packages/wallets/night-elf/package.json | 2 +- .../wallets/night-elf/src/AelfBridgeCheck.ts | 31 ++++++++++++------- packages/wallets/night-elf/src/index.ts | 4 +-- packages/wallets/night-elf/src/utils.ts | 8 +++++ packages/wallets/portkey-aa/package.json | 2 +- packages/wallets/portkey-aa/src/index.ts | 4 +++ .../wallets/portkey-discover/package.json | 2 +- .../wallets/portkey-discover/src/index.ts | 2 +- 15 files changed, 43 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 650f46b3..6ba59b1b 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,6 @@ const baseConfig = { // cancelAutoLoginInTelegram: false, enableAcceleration: true, networkType: NETWORK_TYPE, - chainId: CHAIN_ID, showVconsole: false, chainId: CHAIN_ID, keyboard: true, diff --git a/packages/base/package.json b/packages/base/package.json index 79076640..d77fa042 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-base", - "version": "0.1.15", + "version": "0.1.17-alpha.6", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/base/src/types.ts b/packages/base/src/types.ts index 8d5f8215..99a96d71 100644 --- a/packages/base/src/types.ts +++ b/packages/base/src/types.ts @@ -20,7 +20,7 @@ export enum LoginStateEnum { export type TWalletInfo = | { name?: string; - address?: string; + address: string; extraInfo?: { [key: string]: any; }; diff --git a/packages/bridge/package.json b/packages/bridge/package.json index 2acf0b2e..e0ec1c68 100755 --- a/packages/bridge/package.json +++ b/packages/bridge/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-bridge", - "version": "0.1.15", + "version": "0.1.17-alpha.6", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/bridge/src/ui.tsx b/packages/bridge/src/ui.tsx index 0ff3a515..e723ba0a 100644 --- a/packages/bridge/src/ui.tsx +++ b/packages/bridge/src/ui.tsx @@ -268,6 +268,7 @@ const SignInModal: React.FC = (props: ISignInModalProps) => { isToggleAccountRef.current = true; await bridgeInstance.onPortkeyAAUnLock(defaultPin); await bridgeInstance.doubleCheckDisconnect(); + TelegramPlatform.close(); }; TelegramPlatform.initializeTelegramWebApp({ handleLogout }); }; diff --git a/packages/react/package.json b/packages/react/package.json index ebdbd0a4..b35925ed 100755 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-react", - "version": "0.1.15", + "version": "0.1.17-alpha.6", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/utils/package.json b/packages/utils/package.json index a33ec136..f0321b7f 100755 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/utils", - "version": "0.1.15", + "version": "0.1.17-alpha.6", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/wallets/night-elf/package.json b/packages/wallets/night-elf/package.json index 8e8d39d0..070fa58b 100755 --- a/packages/wallets/night-elf/package.json +++ b/packages/wallets/night-elf/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-night-elf", - "version": "0.1.15", + "version": "0.1.17-alpha.6", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/wallets/night-elf/src/AelfBridgeCheck.ts b/packages/wallets/night-elf/src/AelfBridgeCheck.ts index 4cb1d6b2..f516bbfd 100644 --- a/packages/wallets/night-elf/src/AelfBridgeCheck.ts +++ b/packages/wallets/night-elf/src/AelfBridgeCheck.ts @@ -13,17 +13,24 @@ export default class AelfBridgeCheck { const bridgeInstance = new AElfBridge({ timeout: 3000, }); - bridgeInstance.connect().then((isConnected: boolean) => { - if (timeout) return; - if (isConnected) { - resolve(true); - } else { - reject({ - error: 200001, - message: 'timeout, please use AELF Wallet APP or open the page in PC', - }); - } - }); + console.log('bridgeInstance', bridgeInstance); + bridgeInstance + .connect() + .then((isConnected: boolean) => { + console.log('bridgeInstance isConnected', isConnected); + if (timeout) return; + if (isConnected) { + resolve(true); + } else { + reject({ + error: 200001, + message: 'timeout, please use AELF Wallet APP or open the page in PC', + }); + } + }) + .catch((e: any) => { + console.log('error in catch:', e); + }); setTimeout(() => { timeout = true; reject({ @@ -57,7 +64,7 @@ export default class AelfBridgeCheck { }; aelfInstanceByBridge.logout = (_: any, callback: () => void) => { accountInfo = null; - callback(); + callback?.(); }; return aelfInstanceByBridge; } diff --git a/packages/wallets/night-elf/src/index.ts b/packages/wallets/night-elf/src/index.ts index 4f610473..24686bfc 100644 --- a/packages/wallets/night-elf/src/index.ts +++ b/packages/wallets/night-elf/src/index.ts @@ -151,7 +151,7 @@ export class NightElfWallet extends BaseWalletAdapter { } const result = await defaultAElfBridge.logout({ address }); - if (result.error) throw result; + if (result?.error) throw result; this._wallet = null; this._loginState = LoginStateEnum.INITIAL; @@ -277,7 +277,7 @@ export class NightElfWallet extends BaseWalletAdapter { contractAddress: contractAddress, aelfInstance: bridge, account: { - address: this._wallet.address!, + address: this._wallet.address, }, }); } diff --git a/packages/wallets/night-elf/src/utils.ts b/packages/wallets/night-elf/src/utils.ts index b8091daa..e0fa8997 100644 --- a/packages/wallets/night-elf/src/utils.ts +++ b/packages/wallets/night-elf/src/utils.ts @@ -8,14 +8,21 @@ export const getBridges = async (nodes: INightElfWalletAdapterConfig['nodes'], a const { isMobile } = utils; try { const isAElfBridge = isMobile() && !(window as any)?.NightElf; + console.log('aelf-wallet-debug----------1'); + console.log(`isMobile(): ${isMobile()}`); + console.log(`(window as any)?.NightElf: ${(window as any)?.NightElf}`); + const connector = ( await (isAElfBridge ? import('./AelfBridgeCheck') : import('./NightElfCheck')) ).default; + console.log('connector', connector); // check connector await connector.getInstance().check(); + console.log('aelf-wallet-debug----------2'); let firstKey = ''; const bridges: { [key: string]: AElfDappBridge } = {}; + console.log('nodes:', nodes); if (!nodes || Object.keys(nodes).length === 0) { throw makeError(ERR_CODE.INIT_BRIDGE_ERROR); } @@ -23,6 +30,7 @@ export const getBridges = async (nodes: INightElfWalletAdapterConfig['nodes'], a if (!firstKey) firstKey = k; bridges[k] = connector.initAelfInstanceByExtension(v.rpcUrl, appName); }); + console.log('aelf-wallet-debug----------3'); const node = nodes[firstKey]; const bridge = bridges[firstKey]; return { bridge, node, bridges }; diff --git a/packages/wallets/portkey-aa/package.json b/packages/wallets/portkey-aa/package.json index ce66edb2..f54d5487 100755 --- a/packages/wallets/portkey-aa/package.json +++ b/packages/wallets/portkey-aa/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-portkey-aa", - "version": "0.1.15", + "version": "0.1.17-alpha.6", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/wallets/portkey-aa/src/index.ts b/packages/wallets/portkey-aa/src/index.ts index ca9eb086..eddfe852 100644 --- a/packages/wallets/portkey-aa/src/index.ts +++ b/packages/wallets/portkey-aa/src/index.ts @@ -60,6 +60,10 @@ export class PortkeyAAWallet extends BaseWalletAdapter { this.autoRequestAccountHandler(); } + setChainId(chainId: TChainId) { + this._config.chainId = chainId; + } + get loginState() { return this._loginState; } diff --git a/packages/wallets/portkey-discover/package.json b/packages/wallets/portkey-discover/package.json index ad93705f..088dc066 100755 --- a/packages/wallets/portkey-discover/package.json +++ b/packages/wallets/portkey-discover/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-portkey-discover", - "version": "0.1.15", + "version": "0.1.17-alpha.6", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/wallets/portkey-discover/src/index.ts b/packages/wallets/portkey-discover/src/index.ts index 4ff8de4f..08b2a121 100644 --- a/packages/wallets/portkey-discover/src/index.ts +++ b/packages/wallets/portkey-discover/src/index.ts @@ -404,7 +404,7 @@ export class PortkeyDiscoverWallet extends BaseWalletAdapter { } const finalChainId = chainId || this._chainId; const contract = await this.getContract(finalChainId, contractAddress); - const rs = contract.callSendMethod(methodName, this._wallet.address!, args, sendOptions); + const rs = contract.callSendMethod(methodName, this._wallet.address, args, sendOptions); return rs as R; } From 7196729bea20768c8f10eb4da3055b1626afd8bb Mon Sep 17 00:00:00 2001 From: aelf-lxy Date: Mon, 21 Oct 2024 10:31:51 +0800 Subject: [PATCH 2/2] feat: support aelf wallet --- packages/base/package.json | 2 +- packages/bridge/package.json | 2 +- packages/react/package.json | 2 +- packages/utils/package.json | 2 +- packages/wallets/night-elf/package.json | 2 +- packages/wallets/portkey-aa/package.json | 2 +- packages/wallets/portkey-discover/package.json | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/base/package.json b/packages/base/package.json index d77fa042..54d19dde 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-base", - "version": "0.1.17-alpha.6", + "version": "0.1.17", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/bridge/package.json b/packages/bridge/package.json index e0ec1c68..e2edf4e4 100755 --- a/packages/bridge/package.json +++ b/packages/bridge/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-bridge", - "version": "0.1.17-alpha.6", + "version": "0.1.17", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/react/package.json b/packages/react/package.json index b35925ed..781d2baf 100755 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-react", - "version": "0.1.17-alpha.6", + "version": "0.1.17", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/utils/package.json b/packages/utils/package.json index f0321b7f..3b5b70cf 100755 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/utils", - "version": "0.1.17-alpha.6", + "version": "0.1.17", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/wallets/night-elf/package.json b/packages/wallets/night-elf/package.json index 070fa58b..df7f6445 100755 --- a/packages/wallets/night-elf/package.json +++ b/packages/wallets/night-elf/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-night-elf", - "version": "0.1.17-alpha.6", + "version": "0.1.17", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/wallets/portkey-aa/package.json b/packages/wallets/portkey-aa/package.json index f54d5487..db286efa 100755 --- a/packages/wallets/portkey-aa/package.json +++ b/packages/wallets/portkey-aa/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-portkey-aa", - "version": "0.1.17-alpha.6", + "version": "0.1.17", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js", diff --git a/packages/wallets/portkey-discover/package.json b/packages/wallets/portkey-discover/package.json index 088dc066..8a17b172 100755 --- a/packages/wallets/portkey-discover/package.json +++ b/packages/wallets/portkey-discover/package.json @@ -1,6 +1,6 @@ { "name": "@aelf-web-login/wallet-adapter-portkey-discover", - "version": "0.1.17-alpha.6", + "version": "0.1.17", "type": "module", "main": "dist/esm/index.js", "module": "dist/esm/index.js",