Skip to content

Commit

Permalink
Fix wallet disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Feb 22, 2024
1 parent 8914ed0 commit 00c04b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 4 additions & 5 deletions packages/ui/src/accounts/model/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,15 @@ export class WalletConnect extends BaseDotsamaWallet {
}

protected _handleDisconnection(provider: Provider): void {
const appDisconnectHandler = () => {
const appDisconnectHandler = async () => {
if (!this._provider?.session) return

reset()

// `client.disconnect` doesn't work (it keeps the connection opened).
provider.client.disconnect({
await provider.client.disconnect({
topic: this._provider.session.topic,
reason: { code: -1, message: 'Disconnected by client!' },
})

reset()
}
const disconnectSubscription = this._disconnection$.subscribe(appDisconnectHandler)

Expand Down
5 changes: 3 additions & 2 deletions packages/ui/src/accounts/providers/accounts/useWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ const useSelectedWallet = (allWallets: Wallet[]) => {
const [recentWallet, setRecentWallet] = useLocalStorage<string | undefined>('recentWallet')
const [walletState, setWalletState] = useState<WalletState>()

const setWallet = useCallback(async (wallet: Wallet | undefined) => {
const setWallet = useCallback(async (wallet: Wallet | undefined): Promise<void> => {
if (!wallet) {
WalletDisconnection$.next()
_setWallet(undefined)
setWalletState(undefined)
setRecentWallet(undefined)
Expand All @@ -98,7 +99,7 @@ const useSelectedWallet = (allWallets: Wallet[]) => {
_setWallet(wallet)
setWalletState('READY')
setRecentWallet(wallet.extensionName)
return () => WalletDisconnection$.next()
return
} catch (error) {
const message: string = error?.message?.toLowerCase()
if (message.includes('not allowed to interact') || message.includes('rejected')) {
Expand Down

0 comments on commit 00c04b0

Please sign in to comment.