From 615241f9eb31027e7167ff02528027956b8b00f8 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Thu, 21 Nov 2024 22:34:18 +0800 Subject: [PATCH] fix: Fix an issue where solana is disconnected when trust evm wallet is disconnected --- .changeset/happy-jobs-hope.md | 5 +++ .../walletkit/src/evm/wallets/injected.ts | 33 +++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 .changeset/happy-jobs-hope.md diff --git a/.changeset/happy-jobs-hope.md b/.changeset/happy-jobs-hope.md new file mode 100644 index 00000000..362d9f1c --- /dev/null +++ b/.changeset/happy-jobs-hope.md @@ -0,0 +1,5 @@ +--- +'@node-real/walletkit': patch +--- + +Fix an issue where solana is disconnected when trust evm wallet is disconnected diff --git a/packages/walletkit/src/evm/wallets/injected.ts b/packages/walletkit/src/evm/wallets/injected.ts index c50196e9..2de0a597 100644 --- a/packages/walletkit/src/evm/wallets/injected.ts +++ b/packages/walletkit/src/evm/wallets/injected.ts @@ -35,6 +35,8 @@ export type InjectedParameters = { // Regex of wallets/providers that can accurately simulate contract calls & display contract revert reasons. const supportsSimulationIdRegex = /(rabby|trustwallet)/; +const notRevokePermissionWallets = ['trust']; + const targetMap = { coinbaseWallet: { id: 'coinbaseWallet', @@ -264,20 +266,23 @@ export function injected(parameters: InjectedParameters = {}) { try { // Adding timeout as not all wallets support this method and can hang // https://github.com/wevm/wagmi/issues/4064 - await withTimeout( - () => - // TODO: Remove explicit type for viem@3 - provider.request<{ - Method: 'wallet_revokePermissions'; - Parameters: [permissions: { eth_accounts: Record }]; - ReturnType: null; - }>({ - // `'wallet_revokePermissions'` added in `viem@2.10.3` - method: 'wallet_revokePermissions', - params: [{ eth_accounts: {} }], - }), - { timeout: 100 }, - ); + + if (!notRevokePermissionWallets.includes(this.id)) { + await withTimeout( + () => + // TODO: Remove explicit type for viem@3 + provider.request<{ + Method: 'wallet_revokePermissions'; + Parameters: [permissions: { eth_accounts: Record }]; + ReturnType: null; + }>({ + // `'wallet_revokePermissions'` added in `viem@2.10.3` + method: 'wallet_revokePermissions', + params: [{ eth_accounts: {} }], + }), + { timeout: 100 }, + ); + } } catch {} // Add shim signalling connector is disconnected