Skip to content
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

[Fix] wagmi switch chain claim error #41

Merged
merged 5 commits into from
Dec 18, 2024

Conversation

BrettCleary
Copy link
Contributor

@BrettCleary BrettCleary commented Dec 8, 2024

see HyperPlay-Gaming/hyperplay-desktop-client#1185 and https://github.com/HyperPlay-Gaming/product-management/issues/801

Something about our client implemenation or a wagmi bug is causing the address to be set but no connection is established. It is stuck in reconnecting status, so perhaps it connects, get the address, and then loses the connection object but keeps the address on the config object.

We can just make the same check that wagmi does in switch chain and call connectAsync if it fails to ensure the connection is made to wagmi

Copy link

vercel bot commented Dec 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quests-ui ✅ Ready (Inspect) Visit Preview Dec 18, 2024 7:33am

connectionHasSwitchChain = !!currentConnection?.connector.switchChain
}

if (account.address && connectionHasSwitchChain) {
address = account.address
} else {
onShowMetaMaskPopup?.()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed, but didn't want to slow down this PR. If MM ext sends a notification, the appropriate window will already be shown in the UI.

Comment on lines +228 to 238
*/
let connectionHasSwitchChain = false
if (config.state.current) {
const currentConnection = config.state.connections.get(
config.state.current
)
connectionHasSwitchChain = !!currentConnection?.connector.switchChain
}

if (account.address && connectionHasSwitchChain) {
address = account.address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at their code, it looks like switchChain is not supported by all the connectors https://github.com/wevm/wagmi/blob/main/packages/core/src/connectors/createConnector.ts#L64

if that's the case, then we'd never enter this if clause

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it would always throw on line 249 then since we need switch chain to be present to proceed.

await switchChainAsync({ chainId: reward.chain_id })

If the connector didn't have switch chain, then another connect call would be performed to try and connect to the injected provider which does have switchChain. This is our intended UX for now I believe.

@BrettCleary BrettCleary merged commit 65a44e8 into main Dec 18, 2024
2 checks passed
@BrettCleary BrettCleary deleted the fix/wagmi_switch_chain_claim_error branch December 18, 2024 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants