Skip to content

Commit

Permalink
listen for local storage wallet changes
Browse files Browse the repository at this point in the history
  • Loading branch information
huumn committed Nov 7, 2024
1 parent d117549 commit 2c88bd3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions wallets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ function useLocalWallets () {
}, [wallets, setWallets, me?.id])

useEffect(() => {
// listen for changes to any wallet config in local storage
// from any window with the same origin
const handleStorage = (event) => {
if (event.key.startsWith(getStorageKey(''))) {
loadWallets()
}
}
window.addEventListener('storage', handleStorage)

loadWallets()
return () => window.removeEventListener('storage', handleStorage)
}, [loadWallets])

return { wallets, reloadLocalWallets: loadWallets, removeLocalWallets: removeWallets }
Expand Down

0 comments on commit 2c88bd3

Please sign in to comment.