You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @pellyadolfo can you help me understand why an app would need to reload after wallet state change? Usually specific components would reload and not the whole app.
Uhm, this is what I understood as the best practice because probably everything populated in the UI is corresponding to the specific wallet/chain configuration. So, if the wallet account changes, user disconnects, or chain is switched, probably nothing on the UI would apply after the change, and doing a selective maintenance is very error prone and multiplies the development effort.
Can you figure out any non-default data in a dApp persisting a chain / wallet / account switch?
@pellyadolfo best practices are not to reload the app. Global state should reflect the chain and specific components of the page should reflect state changes. Reloading the app will reload all libraries and loose any state which is why apps dont reload when a chain is changed or wallet is disconnected/connected. If you are set on reloading there is a browser api to reload but I dont recommend usage in this case (or most cases) for both UX and state management reasons.
I can agree that today is not the best practice......... if you have plenty of resources to do it better ($$$$$$)..... which is not my case and this is why I think there is still a use case (e.g. a MVP). Not everybody has the google's cash available.
Is your request related to a problem?
Not really. Missing a discussion board for best practices so I am opening here to get guidance on where to post usage questions.
Feature Description
What is the recommended way to reload the app after chain / wallet switches / disconnect ?
Alternative Solutions
window.ethereum.on('accountsChanged', (accounts: any) => { console.log('accountsChanged. Reloading') window.location.reload(); }); window.ethereum.on('chainChanged', (chainId: any) => { console.log('chainChanged. Reloading') window.location.reload(); }); window.ethereum.on('disconnect', (accounts: any) => { console.log('disconnect. Reloading') window.location.reload(); });
subscride to wallet updates adding a flag to prevent infinite loop of first rendering (React)
const wallets2 = web3Onboard.state.select('wallets')
wallets.subscribe(wallet => { ... ))
Anything else?
A discussions board would help adopters. Github has a discussions tab itself. Stackoverflow has only one ticket open https://stackoverflow.com/questions/tagged/web3-onboard
The text was updated successfully, but these errors were encountered: