-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add a way to react on network and wallet changes #30
Comments
@alexsteixeira, @gsmachado please comment if my description is unclear. |
I think that's fine. 👍 Basically, we need that a way to pass through the events from the specific wallet to the NWA SDK users. 😸 |
Yep, at the moment it disconnects everytime to act like walletconnect. |
hey @mfbz! |
Heyy @gsmachado Case 1No changes needed on the codebase. You implement directly the hooks needed. walletChanged ...
const [currentWalletName, setCurrentWalletName] = useState<string | null>(null);
useEffect(()=> {
if (wallet?.name !== currentWalletName) {
setCurrentWalletName(wallet.name);
onWalletChanged(currentWalletName);
}
}, [wallet, currentWalletName]); networkChanged ...
const [walletNetwork, setWalletNetwork] = useState<string | null>(null);
const fetchWalletNetwork = useCallback(async () => {
try {
const result = await getNetworks();
if (result?.status === 'success') {
setWalletNetwork(result.data?.defaultNetwork || null);
}
} catch (error) {
console.error(error);
}
}, [getNetworks]);
useEffect(() => {
if (connected) {
fetchWalletNetwork();
} else {
setWalletNetwork(null);
}
}, [connected, fetchWalletNetwork]); Case 2:Basically the same but in the library. Maybe with custom hooks separated from useWallet one to avoid having wallet network fetching happening also when not needed. Thoughts about this? If you need them in a hurry I think it's better to go with Case 1. |
We need a functionality that allows the user of the wallet-adapt to react on network changes (e.g., changing from mainnet to testnet) and wallet changes. Currently the adapter simply disconnects the wallet on such changes.
It would be nice if the WALLET_CHANGED/NETWORK_CHANGED events would bubble up to the library user or the
useWallet()
method would return variables that hold such state. Something like:The text was updated successfully, but these errors were encountered: