-
Notifications
You must be signed in to change notification settings - Fork 673
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
feat: optimistic disconnect #1871
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@magiziz For that WalletConnect scenario, I think what might work better is an "optimistic disconnect". When the user taps disconnect, we put the RainbowKit modal into the disconnected state and then trigger the |
isDisconnecting
is truede8e6ec
to
f8e3806
Compare
@@ -19,6 +19,7 @@ export const YourApp = () => { | |||
<ConnectButton.Custom> | |||
{({ | |||
account, | |||
disconnecting, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technically won't be a breaking change. If we were to merge this the only thing that would impact is if disconnecting
is true, then openConnectModal
with just return a noop
function. Here is an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For injected wallets it should happen super fast, but for WalletConnect in some scenarios might take time. Of course depending on their socket server.
I started to look into a refactor here:
|
32f9168
to
b90d73e
Compare
chore: remove unnecessary code chore: remove unnecessary code
b90d73e
to
a69fe5c
Compare
const { isConnected } = useAccount(); | ||
const { isDisconnecting } = useRainbowKitWagmiState(); | ||
|
||
if (!isConnected) { | ||
if (!isConnected || isDisconnecting) { | ||
return 'disconnected'; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most important part out of all which makes this work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is not ideal especially in the long term, but wagmi's useDisconnect
hook doesn't provide a global scope state support. It only supports at a component level since they use TanStack react query mutation directly.
Maybe we can look at having isDisconnecting
state in useAccount
hook in the future, but for now this approach works.
As long as we mark isDisconnecting
to disconnected
mode in useConnectionStatus
that'd work for now 🙏
// may mark it as 'disconnected', we don't want the user to open the modal as the wagmi state | ||
// still considers it 'connected' | ||
!isDisconnecting && | ||
(connectionStatus === 'disconnected' || | ||
connectionStatus === 'unauthenticated') | ||
? openConnectModal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You technically can still open the connect modal if your connectionStatus
is returning disconnected
.
If we allow users to open the connect modal by the time WalletConnect takes time to disconnect, they'll face the issue with shim disconnection which is a known issue in wagmi rn. Ofc only if they start connecting different wallets at once, but we'll make sure to disable it.
Changes
isDisconnecting
inRainbowKitWagmiStateProvider
. IfisDisconnecting
istrue
, theuseConnectionStatus
hook is set to thedisconnected
state.Screen recordings / screenshots
optimistic_disconnect.mov