listen for local storage wallet changes (#1552)

This commit is contained in:
Keyan 2024-11-07 13:15:39 -06:00 committed by GitHub
parent d117549348
commit a67ef43f6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions

View File

@ -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 }