Skip to content

Commit

Permalink
feat(core): export onDisconnect, onAccountsChanged, and onChainChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson86tw committed Apr 30, 2024
1 parent c3929aa commit f521865
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/core/src/services/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function useConnect(pinia?: any) {
})

walletStore.wallet.connector.onAccountsChanged(async (accounts: string[]) => {
console.log('accounts changed:', accounts)
walletStore.onAccountsChangedCallback && walletStore.onAccountsChangedCallback(accounts)

if (!accounts.length) {
Expand Down Expand Up @@ -138,6 +139,18 @@ export function useConnect(pinia?: any) {
}
}

function onDisconnect(callback: (...args: any[]) => void) {
walletStore.onDisconnectCallback = callback
}

function onAccountsChanged(callback: (accounts: string[]) => void) {
walletStore.onAccountsChangedCallback = callback
}

function onChainChanged(callback: (chainId: number) => void) {
walletStore.onChainChangedCallback = callback
}

return {
isWindowEthereumAvailable,

Expand All @@ -158,5 +171,9 @@ export function useConnect(pinia?: any) {
connectTo,
disconnect,
autoConnect,

onDisconnect,
onAccountsChanged,
onChainChanged,
}
}

0 comments on commit f521865

Please sign in to comment.