From 847e2ef8551bc8dab4dac182ea6bb59ef31408a2 Mon Sep 17 00:00:00 2001 From: morizon Date: Mon, 3 Jul 2023 10:38:13 +0800 Subject: [PATCH] fix: walletconnect v2 deeplink for android OK-20872 (#3176) * fix: wc v2 deeplink handle for android * fix: lint --- .../engine/src/vaults/impl/stc/keyring/KeyringHd.test.ts | 5 ++++- packages/engine/src/vaults/impl/stc/keyring/index.ts | 2 +- .../ProviderApiWalletConnect/ProviderApiWalletConnect.ts | 7 +++++-- packages/kit/src/routes/deepLink.ts | 9 ++++++++- packages/kit/src/views/ManageNetworks/Listing/index.tsx | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/engine/src/vaults/impl/stc/keyring/KeyringHd.test.ts b/packages/engine/src/vaults/impl/stc/keyring/KeyringHd.test.ts index 9fe8a7aab84..8484d0bcc79 100644 --- a/packages/engine/src/vaults/impl/stc/keyring/KeyringHd.test.ts +++ b/packages/engine/src/vaults/impl/stc/keyring/KeyringHd.test.ts @@ -1,5 +1,8 @@ import { hdAccount1, network } from '../@tests/stcMockData'; -import { testPrepareAccounts, testSignTransaction } from '../@tests/stcPresetCase'; +import { + testPrepareAccounts, + testSignTransaction, +} from '../@tests/stcPresetCase'; import { KeyringHd } from './KeyringHd'; diff --git a/packages/engine/src/vaults/impl/stc/keyring/index.ts b/packages/engine/src/vaults/impl/stc/keyring/index.ts index 32dd07c13d4..2e1cab13039 100644 --- a/packages/engine/src/vaults/impl/stc/keyring/index.ts +++ b/packages/engine/src/vaults/impl/stc/keyring/index.ts @@ -1,4 +1,4 @@ export * from './KeyringHardware'; export * from './KeyringHd'; export * from './KeyringImported'; -export * from './KeyringWatching'; \ No newline at end of file +export * from './KeyringWatching'; diff --git a/packages/kit-bg/src/providers/ProviderApiWalletConnect/ProviderApiWalletConnect.ts b/packages/kit-bg/src/providers/ProviderApiWalletConnect/ProviderApiWalletConnect.ts index 013e1ac2eda..3117e0a6e74 100644 --- a/packages/kit-bg/src/providers/ProviderApiWalletConnect/ProviderApiWalletConnect.ts +++ b/packages/kit-bg/src/providers/ProviderApiWalletConnect/ProviderApiWalletConnect.ts @@ -461,8 +461,10 @@ class ProviderApiWalletConnect extends WalletConnectClientForWallet { // TODO save to DB? console.log('WalletConnectV2 session_proposal APPROVE: ', session); - // TODO - // this.redirectToDapp({ }) + if (session) { + // TODO redirectToDapp for V2 handler + // this.redirectToDapp({ }) + } } catch (error) { const session = await this.web3walletV2?.rejectSession({ id: proposal.id, @@ -529,6 +531,7 @@ class ProviderApiWalletConnect extends WalletConnectClientForWallet { // TODO sessionV2 accounts and peer accounts matched check + // handleSessionRequest will call this.redirectToDapp() const result = await this.handleSessionRequest({ networkImpl, payload: params.request, diff --git a/packages/kit/src/routes/deepLink.ts b/packages/kit/src/routes/deepLink.ts index 04ab1f13a9c..bbf120ddd3a 100644 --- a/packages/kit/src/routes/deepLink.ts +++ b/packages/kit/src/routes/deepLink.ts @@ -50,7 +50,7 @@ const processDeepLinkUrl = memoizee( // - packages/app/app.json // ** ios UniversalLink - // https://app.onekey.so/wc/connect/wc?uri=wc%3Aeb16df1f-1d3b-4018-9d18-28ef610cc1a4%401%3Fbridge%3Dhttps%253A%252F%252Fj.bridge.walletconnect.org%26key%3D0037246aefb211f98a8386d4bf7fd2a5344960bf98cb39c57fb312a098f2eb77 + // https://app.onekey.so/wc/connect/wc?uri=wc%3Aeb16df1f-1d3b-4018-9d18-28ef610cc1a4%401%3Fbridge%3Dhttps%253A%252F%252Fj.bridge.walletconnect.org%26key%3D0037246aefb211f98a8386d4bf7fd2a5344960bf98cb39c57fb312a098f2eb77 if ( hostname === 'app.onekey.so' && path === WalletConnectUniversalLinkPath @@ -61,6 +61,7 @@ const processDeepLinkUrl = memoizee( } // ** ios/android/desktop DeepLink + // onekey-wallet://wc // onekey-wallet://wc?uri=wc%3Afa75a793-a3fb-48e4-8629-8f1f034ec6eb%401%3Fbridge%3Dhttps%253A%252F%252Fy.bridge.walletconnect.org%26key%3D9e97f71a32b4e629cb60106295dca54d733d124da480b4031d0d848b678fd610/ if ( scheme === ONEKEY_APP_DEEP_LINK || @@ -77,14 +78,20 @@ const processDeepLinkUrl = memoizee( } // ** WalletConnect uri DeepLink + // wc: // wc:c157eb01-8262-40e4-963e-7ebee47d0eac@1?bridge=https%3A%2F%2F7.bridge.walletconnect.org&key=881d859aa3ae028e284dd03e3be1d09c486329a400509a39c85246813808956b if ( scheme === WALLET_CONNECT_DEEP_LINK || scheme === WALLET_CONNECT_DEEP_LINK_NAME ) { + // V1 if (queryParams?.bridge && queryParams?.key) { wcUri = url; } + // V2 + if (queryParams?.['relay-protocol'] && queryParams?.symKey) { + wcUri = url; + } } if (wcUri) { diff --git a/packages/kit/src/views/ManageNetworks/Listing/index.tsx b/packages/kit/src/views/ManageNetworks/Listing/index.tsx index 8dcaced1366..0711c8bd2e1 100644 --- a/packages/kit/src/views/ManageNetworks/Listing/index.tsx +++ b/packages/kit/src/views/ManageNetworks/Listing/index.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */ -import { FC, useEffect } from 'react'; -import { useCallback, useMemo, useRef, useState } from 'react'; +import type { FC } from 'react'; +import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useNavigation } from '@react-navigation/core'; import { useFocusEffect } from '@react-navigation/native';