Skip to content

WalletConnect session hooks

Usage

connect() must be called and WalletConnect session must be initiated before account balance will be returned.

Want more control over your WalletConnect session? You can use these hooks to listen for wallet-originated events or for session changes.

import { useOnSessionDelete, useOnSessionEvent, useOnSessionExpire, useOnSessionUpdate, useSession } from '@puzzlehq/sdk';
const session = useSession()
useOnSessionDelete(({ topic }) => {
console.log(`session topic deleted: ${topic}`);
})
useOnSessionEvent(({ params, topic }) => {
const eventName = params.event.name;
if (eventName === 'accountselected') {
console.log('new account selected!');
} else if (eventName === 'selectedAccountSynced') {
console.log('selected account state has been synced');
} else if (eventName === 'sharedAccountSynced') {
console.log('a shared account state has been synced');
}
})
useOnSessionExpire(({ topic }) => {
console.log(`session topic expired: ${topic}`)l
})
useOnSessionUpdate(({ params, topic }) => {
console.log(`session topic updated: ${topic}`);
console.log(`new params are: ${params}`);
})