0

I have a wallet connection setup where I eagerly connect to the wallet using provider.connect({ onlyIfTrusted: true }). When a user clicks disconnect I call provider.disconnect().

Now when they refresh the page, I do not want Phantom to eagerly reconnect! they just disconnected so it should not reconnect!

I can fix this by removing eagerly reconnect but having to reconnect the wallet everytime after reloading the page is a bad UX. I can see places like Jupiter etc have this UX so I know its possible.

Thank you,

2 Answers 2

0

If you do not wish the user to reconnect after reloading you should not eagerly connect. Connecting the user after reloading is the purpose of an eager connection.

The only way for the user to not reconnect after reloading with an eager connection is for them to remove the dapp connection from their settings.

0

You get this for free if you use wallet-adapter instead of directly calling Phantom's provider API. https://github.com/anza-xyz/wallet-adapter

We do it by storing the wallet name (eg Phantom) in local storage. If there's a wallet name there and autoconnect is being used, then we eagerly connect to that wallet. On disconnect we clear the stored wallet name, so that reloading will require the user to select a wallet again.

You can see an example of that UX in our example app: https://anza-xyz.github.io/wallet-adapter/example/

If you open your browser dev tools and enter localStorage.walletName after connecting/disconnecting you'll be able to see how it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.