Skip to content

Commit 6e69499

Browse files
committed
Modify WalletConnect to disconnect properly
1 parent 2d5f6a8 commit 6e69499

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/modules/select/wallets/wallet-connect.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { WalletConnectOptions, WalletModule } from '../../../interfaces'
1+
import {
2+
WalletConnectOptions,
3+
WalletModule,
4+
Helpers
5+
} from '../../../interfaces'
26

37
import walletConnectIcon from '../wallet-icons/icon-wallet-connect'
48

@@ -9,7 +13,9 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
913
name: label || 'WalletConnect',
1014
svg: svg || walletConnectIcon,
1115
iconSrc,
12-
wallet: async () => {
16+
wallet: async (helpers: Helpers) => {
17+
const { resetWalletState } = helpers
18+
1319
const { default: WalletConnectProvider } = await import(
1420
'@walletconnect/web3-provider'
1521
)
@@ -20,6 +26,10 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
2026

2127
provider.autoRefreshOnNetworkChange = false
2228

29+
provider.wc.on('disconnect', () => {
30+
resetWalletState(true)
31+
})
32+
2333
return {
2434
provider,
2535
interface: {
@@ -40,7 +50,7 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
4050
onChange: func => {
4151
provider
4252
.send('eth_accounts')
43-
.then((accounts: string[]) => func(accounts[0]))
53+
.then((accounts: string[]) => accounts[0] && func(accounts[0]))
4454
provider.on('accountsChanged', (accounts: string[]) =>
4555
func(accounts[0])
4656
)
@@ -65,7 +75,8 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
6575
'latest'
6676
])
6777
})
68-
}
78+
},
79+
disconnect: () => provider.close()
6980
}
7081
}
7182
},

0 commit comments

Comments
 (0)