Skip to content

Commit 7353fb9

Browse files
authored
fix: refreshes session list when /sessions route is loaded (#657)
1 parent dcb6ac5 commit 7353fb9

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

advanced/wallets/react-wallet-v2/src/hooks/useWalletConnectEventsManager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { approveEIP5792Request } from '@/utils/EIP5792RequestHandlerUtils'
2020
import EIP155Lib from '@/lib/EIP155Lib'
2121
import { getWallet } from '@/utils/EIP155WalletUtil'
2222
import { EIP7715_METHOD } from '@/data/EIP7715Data'
23+
import { refreshSessionsList } from '@/pages/wc'
2324

2425
export default function useWalletConnectEventsManager(initialized: boolean) {
2526
/******************************************************************************
@@ -173,11 +174,11 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
173174
web3wallet.engine.signClient.events.on('session_ping', data => console.log('ping', data))
174175
web3wallet.on('session_delete', data => {
175176
console.log('session_delete event received', data)
176-
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
177+
refreshSessionsList()
177178
})
178179
web3wallet.on('session_authenticate', onSessionAuthenticate)
179180
// load sessions on init
180-
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
181+
refreshSessionsList()
181182
}
182-
}, [initialized, onAuthRequest, onSessionProposal, onSessionRequest])
183+
}, [initialized, onAuthRequest, onSessionAuthenticate, onSessionProposal, onSessionRequest])
183184
}

advanced/wallets/react-wallet-v2/src/pages/sessions.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import PageHeader from '@/components/PageHeader'
22
import SessionCard from '@/components/SessionCard'
33
import SettingsStore from '@/store/SettingsStore'
44
import { Text } from '@nextui-org/react'
5-
import { Fragment } from 'react'
5+
import { Fragment, useEffect } from 'react'
66
import { useSnapshot } from 'valtio'
7+
import { refreshSessionsList } from './wc'
78

89
export default function SessionsPage() {
910
const { sessions } = useSnapshot(SettingsStore.state)
10-
11+
useEffect(() => refreshSessionsList(), [])
1112
if (!sessions.length) {
1213
return (
1314
<Fragment>

advanced/wallets/react-wallet-v2/src/pages/wc.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useRouter } from 'next/router'
44
import WalletConnectPage from './walletconnect'
55
import ModalStore from '@/store/ModalStore'
66
import { useSnapshot } from 'valtio'
7+
import SettingsStore from '@/store/SettingsStore'
8+
import { web3wallet } from '@/utils/WalletConnectUtil'
79

810
export default function DeepLinkPairingPage() {
911
const state = useSnapshot(ModalStore.state)
@@ -54,3 +56,8 @@ export default function DeepLinkPairingPage() {
5456

5557
return <WalletConnectPage deepLink={uri} />
5658
}
59+
60+
export function refreshSessionsList() {
61+
if (!web3wallet) return
62+
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
63+
}

0 commit comments

Comments
 (0)