Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implements dynamic session list #413

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
web3wallet.on('auth_request', onAuthRequest)
// TODOs
web3wallet.engine.signClient.events.on('session_ping', data => console.log('ping', data))
web3wallet.on('session_delete', data => console.log('delete', data))
web3wallet.on('session_delete', data => {
console.log('session_delete event received', data)
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
})
// load sessions on init
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
}
}, [initialized, onAuthRequest, onSessionProposal, onSessionRequest])
}
7 changes: 4 additions & 3 deletions advanced/wallets/react-wallet-v2/src/pages/sessions.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import PageHeader from '@/components/PageHeader'
import SessionCard from '@/components/SessionCard'
import { web3wallet } from '@/utils/WalletConnectUtil'
import SettingsStore from '@/store/SettingsStore'
import { Text } from '@nextui-org/react'
import { Fragment, useState } from 'react'
import { Fragment } from 'react'
import { useSnapshot } from 'valtio'

export default function SessionsPage() {
const [sessions] = useState(Object.values(web3wallet.getActiveSessions()))
const { sessions } = useSnapshot(SettingsStore.state)

if (!sessions.length) {
return (
Expand Down
11 changes: 8 additions & 3 deletions advanced/wallets/react-wallet-v2/src/store/SettingsStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Verify } from '@walletconnect/types'
import { Verify, SessionTypes } from '@walletconnect/types'
import { proxy } from 'valtio'

/**
Expand All @@ -19,6 +19,7 @@ interface State {
relayerRegionURL: string
activeChainId: string
currentRequestVerifyContext?: Verify.Context
sessions: SessionTypes.Struct[]
}

/**
Expand All @@ -37,7 +38,8 @@ const state = proxy<State>({
tronAddress: '',
tezosAddress: '',
kadenaAddress: '',
relayerRegionURL: ''
relayerRegionURL: '',
sessions: []
})

/**
Expand Down Expand Up @@ -94,6 +96,9 @@ const SettingsStore = {
setCurrentRequestVerifyContext(context: Verify.Context) {
state.currentRequestVerifyContext = context
},
setSessions(sessions: SessionTypes.Struct[]) {
state.sessions = sessions
},

toggleTestNets() {
state.testNets = !state.testNets
Expand All @@ -102,7 +107,7 @@ const SettingsStore = {
} else {
localStorage.removeItem('TEST_NETS')
}
},
}
}

export default SettingsStore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import ChainAddressMini from '@/components/ChainAddressMini'
import { getChainData } from '@/data/chainsUtil'
import RequestModal from './RequestModal'
import { useSnapshot } from 'valtio'
import SettingsStore from '@/store/SettingsStore'

const StyledText = styled(Text, {
fontWeight: 400
Expand Down Expand Up @@ -232,6 +233,7 @@ export default function SessionProposalModal() {
id: proposal.id,
namespaces
})
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
} catch (e) {
setIsLoadingApprove(false)
styledToast((e as Error).message, 'error')
Expand Down
Loading