Skip to content

Commit ee3caae

Browse files
authored
feat: close wallet tab after request modal is closed (#829)
1 parent f937e2f commit ee3caae

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ export default function DeepLinkPairingPage() {
3535
}, [state.view])
3636

3737
useEffect(() => {
38-
if (requestId) {
39-
ModalStore.open('LoadingModal', { loadingMessage })
40-
}
41-
42-
if (uri) {
43-
ModalStore.open('LoadingModal', { loadingMessage })
38+
if (uri || requestId) {
39+
ModalStore.open('LoadingModal', { loadingMessage }, () => {
40+
console.log('Modal closed')
41+
window.close()
42+
})
4443
}
4544
}, [uri, requestId, loadingMessage])
4645

advanced/wallets/react-wallet-v2/src/store/ModalStore.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { SessionTypes, SignClientTypes } from '@walletconnect/types'
2-
import { WalletKitTypes } from '@reown/walletkit'
3-
import { proxy } from 'valtio'
2+
import { proxy, subscribe } from 'valtio'
43

54
/**
65
* Types
@@ -52,10 +51,18 @@ const state = proxy<State>({
5251
const ModalStore = {
5352
state,
5453

55-
open(view: State['view'], data: State['data']) {
54+
open(view: State['view'], data: State['data'], onClose?: () => void) {
5655
state.view = view
5756
state.data = data
5857
state.open = true
58+
if (!onClose) return
59+
const unsubscribe = subscribe(state, () => {
60+
if (!state.open) {
61+
console.log('ModalStore: Closing modal')
62+
unsubscribe()
63+
onClose?.()
64+
}
65+
})
5966
},
6067

6168
close() {

0 commit comments

Comments
 (0)