diff --git a/package.json b/package.json index ce9d96b2667..144808a3857 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@rabby-wallet/eth-lattice-keyring": "^1.0.5", "@rabby-wallet/eth-simple-keyring": "^4.2.1", "@rabby-wallet/eth-trezor-keyring": "^2.2.0", - "@rabby-wallet/eth-walletconnect-keyring": "^2.0.0-beta.3", + "@rabby-wallet/eth-walletconnect-keyring": "2.0.0-beta.4", "@rabby-wallet/eth-watch-keyring": "^1.0.0", "@rabby-wallet/gnosis-sdk": "^1.3.5", "@rabby-wallet/page-provider": "^0.1.20", diff --git a/src/background/controller/wallet.ts b/src/background/controller/wallet.ts index d02a74923e6..114a723c455 100644 --- a/src/background/controller/wallet.ts +++ b/src/background/controller/wallet.ts @@ -1710,7 +1710,11 @@ export class WalletController extends BaseController { return null; }; - initWalletConnect = async (brandName: string, curStashId?: number | null) => { + initWalletConnect = async ( + brandName: string, + curStashId?: number | null, + chainId = 1 + ) => { let keyring: WalletConnectKeyring, isNewKey; const keyringType = KEYRING_CLASS.WALLETCONNECT; try { @@ -1725,14 +1729,14 @@ export class WalletController extends BaseController { keyring = new WalletConnect(GET_WALLETCONNECT_CONFIG()); isNewKey = true; } - const { uri } = await keyring.initConnector(brandName, 1); + const { uri } = await keyring.initConnector(brandName, chainId); let stashId = curStashId; if (isNewKey) { stashId = this.addKeyringToStash(keyring); eventBus.addEventListener( EVENTS.WALLETCONNECT.INIT, - ({ address, brandName }) => { - (keyring as WalletConnectKeyring).init(address, brandName); + ({ address, brandName, chainId }) => { + (keyring as WalletConnectKeyring).init(address, brandName, chainId); } ); (keyring as WalletConnectKeyring).on('inited', (uri) => { diff --git a/src/background/service/keyring/index.ts b/src/background/service/keyring/index.ts index 3f2ad4adf19..511481882e4 100644 --- a/src/background/service/keyring/index.ts +++ b/src/background/service/keyring/index.ts @@ -872,8 +872,8 @@ export class KeyringService extends EventEmitter { if (keyring.type === KEYRING_CLASS.WALLETCONNECT) { eventBus.addEventListener( EVENTS.WALLETCONNECT.INIT, - ({ address, brandName }) => { - (keyring as WalletConnectKeyring).init(address, brandName); + ({ address, brandName, chainId }) => { + (keyring as WalletConnectKeyring).init(address, brandName, chainId); } ); (keyring as WalletConnectKeyring).on('inited', (uri) => { diff --git a/src/ui/utils/WalletContext.tsx b/src/ui/utils/WalletContext.tsx index 64915ef9364..181bb470cb1 100644 --- a/src/ui/utils/WalletContext.tsx +++ b/src/ui/utils/WalletContext.tsx @@ -40,6 +40,7 @@ const useCommonPopupViewState = () => { address: string; brandName: string; realBrandName?: string; + chainId?: number; }>(); const [data, setData] = useState(); diff --git a/src/ui/views/Approval/components/FooterBar/WalletConnectAccount.tsx b/src/ui/views/Approval/components/FooterBar/WalletConnectAccount.tsx index 39b08951ce4..79c573c2fdc 100644 --- a/src/ui/views/Approval/components/FooterBar/WalletConnectAccount.tsx +++ b/src/ui/views/Approval/components/FooterBar/WalletConnectAccount.tsx @@ -117,6 +117,7 @@ export const WalletConnectAccount: React.FC = ({ account, chain }) => { address, brandName, realBrandName, + chainId: chain?.id, }); if (tipStatus === 'DISCONNECTED') { activePopup('WalletConnect'); diff --git a/src/ui/views/WalletConnect/index.tsx b/src/ui/views/WalletConnect/index.tsx index 7c8cc3d19a8..13565075456 100644 --- a/src/ui/views/WalletConnect/index.tsx +++ b/src/ui/views/WalletConnect/index.tsx @@ -19,6 +19,7 @@ import { useSessionStatus } from '@/ui/component/WalletConnect/useSessionStatus' import { useBrandNameHasWallet } from '@/ui/component/WalletConnect/useBrandNameHasWallet'; import { getOriginFromUrl } from '@/utils'; import { ConnectedSite } from '@/background/service/permission'; +import { findChainByEnum } from '@/utils/chain'; const WalletConnectName = WALLET_BRAND_CONTENT['WALLETCONNECT']?.name; @@ -38,14 +39,14 @@ const WalletConnectTemplate = () => { Parameters | undefined >(); const [curStashId, setCurStashId] = useState(); - const [site, setSite] = useState(null); + const siteRef = React.useRef(null); const getCurrentSite = useCallback(async () => { const tab = await getCurrentTab(); if (!tab.id || !tab.url) return; const domain = getOriginFromUrl(tab.url); const current = await wallet.getCurrentSite(tab.id, domain); - setSite(current); + siteRef.current = current; }, []); const [run, loading] = useWalletRequest(wallet.importWalletConnect, { @@ -89,9 +90,11 @@ const WalletConnectTemplate = () => { }; const handleImportByWalletconnect = async () => { + const chain = findChainByEnum(siteRef.current?.chain); const { uri, stashId } = await wallet.initWalletConnect( brand.brand, - curStashId + curStashId, + chain?.id ); setCurStashId(stashId); setWalletconnectUri(uri!); @@ -178,28 +181,7 @@ const WalletConnectTemplate = () => { }, [sessionStatus]); const init = async () => { - // const cache = await wallet.getPageStateCache(); - // if (cache && cache.path === history.location.pathname) { - // const { states } = cache; - // if (states.uri) setWalletconnectUri(states.uri); - // if (states.brand) { - // setBrand(states.brand); - // } - // if (states.data) { - // setRunParams([ - // states.data.payload, - // states.brand.brand, - // states.bridgeURL, - // states.stashId, - // ]); - // } - // if (states.bridgeURL && states.bridgeURL !== bridgeURL) { - // setBridgeURL(states.bridgeURL); - // } - // } else { - // handleImportByWalletconnect(); - // } - + await getCurrentSite(); handleImportByWalletconnect(); setReady(true); }; diff --git a/yarn.lock b/yarn.lock index d1c8d8605cb..e3493bb82b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3452,10 +3452,10 @@ ethereumjs-util "^7.1.5" hdkey "0.8.0" -"@rabby-wallet/eth-walletconnect-keyring@^2.0.0-beta.3": - version "2.0.0-beta.3" - resolved "https://registry.yarnpkg.com/@rabby-wallet/eth-walletconnect-keyring/-/eth-walletconnect-keyring-2.0.0-beta.3.tgz#12f15db257ff069b5bf4627ce1c71b5a7f895b18" - integrity sha512-kZdYY0lzWpuKskcQCmte4iEHJPXLRnpgr3xJTA6JsWYjEJ/ldAtFostCYVsxTpHv7+VuPhkMibRWfoxdZLoXBg== +"@rabby-wallet/eth-walletconnect-keyring@2.0.0-beta.4": + version "2.0.0-beta.4" + resolved "https://registry.yarnpkg.com/@rabby-wallet/eth-walletconnect-keyring/-/eth-walletconnect-keyring-2.0.0-beta.4.tgz#c8ed76c031396534c0eeb62ad7df9de65271cde8" + integrity sha512-L3+DvLAarJoiSr2DaOVvZQM6gM7j7Xu7ao6ZeHafo5HFSBQ9Ruj8UDip80LMsGaGcfvHDq3G4BU8V2lutiH/uA== dependencies: "@ethereumjs/tx" "^3.5.2" "@walletconnect/sign-client" "^2.10.0"