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: re-connecting a locked wallet #2341

Merged
merged 2 commits into from
Aug 16, 2023
Merged

Fix: re-connecting a locked wallet #2341

merged 2 commits into from
Aug 16, 2023

Conversation

katspaugh
Copy link
Member

@katspaugh katspaugh commented Aug 1, 2023

What it solves

Resolves #2306

How this PR fixes it

The cause of the bug was that

  • window.ethereum.isConnected() returns true even if MetaMask is locked
  • We didn't await the promise from _metamask.isUnlocked and it always returning false

I've removed isConnected and made it wait for the promise. Also added custom logic for WC v2 and tests for it.

@katspaugh katspaugh requested a review from iamacook August 1, 2023 10:56
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

Branch preview

✅ Deploy successful!

https://fix_mm--walletweb.review-wallet-web.5afe.dev

@github-actions
Copy link

github-actions bot commented Aug 1, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action


// WalletConnect v2
if (walletName === WalletNames.WALLET_CONNECT_V2) {
const wcSession = window.localStorage.getItem('wc@2:client:0.3//session')
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the 0.3 is versioning.

You can call storageKey (and maybe even get) from WC here to avoid outdated session data.

Copy link
Member Author

@katspaugh katspaugh Aug 1, 2023

Choose a reason for hiding this comment

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

I'm aware of the trade-offs here and would sooner check local storage directly rather than call some internal WC method. This can be made more robust by searching for a key named wc@2:client:*//session perhaps.

Copy link
Member

Choose a reason for hiding this comment

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

I'm aware of the trade-offs here and would sooner check local storage directly rather than call some internal WC method.

storageKey would return the key with which you could check the localStorage directly.

This can be made more robust by searching for a key named wc@2:client:*//session perhaps.

I'd personally prefer this.

@katspaugh
Copy link
Member Author

I've made another PR that also fixes this issue: #2343

@katspaugh
Copy link
Member Author

I'll close this PR to focus on the onboard's auto-connect solution.

@katspaugh katspaugh closed this Aug 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2023
@katspaugh katspaugh reopened this Aug 16, 2023
@katspaugh katspaugh changed the base branch from dev to revert-autoconnect August 16, 2023 10:30
@katspaugh katspaugh merged commit fe6cbfe into revert-autoconnect Aug 16, 2023
6 of 8 checks passed
@katspaugh katspaugh deleted the fix-mm branch August 16, 2023 10:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MM] Reconnecting to last wallet fails and onboard will not show up
2 participants