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

chore: call getPermissions on accountsChanged when using extension #1185

Merged

Conversation

christopherferreira9
Copy link
Collaborator

@christopherferreira9 christopherferreira9 commented Jan 8, 2025

Explanation

Historically, we used to call sdk.terminate() when receiving an accountsChanged=[] event thinking that permissions had been revoked from the extension.

The problem with this is that EIP-1193 requires the extension to send accountsChanged=[] when locking the extension (to be changed) meaning that the accounts are no longer available and that it needs to e unlocked for them to be available again.

It is scheduled for extension to stop emitting this event but because we need to keep backward compatibility until most users have the new extension version, we need to implement a workaround for this specific case. Upon discussing with wallet-api members it was decided that SDK would call getPermissions when receiving accountsChanged=[] since this call returns permissions even when the wallet is locked.

The flow should then be:

  1. Catch accountsChanged=[]
  2. Call wallet_getPermissions
    a) if no permissions are returned → Terminate
    b) If permissions are received do nothing

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@christopherferreira9 christopherferreira9 requested a review from a team as a code owner January 8, 2025 12:31
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.40%. Comparing base (d647181) to head (8d1b9b3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...DK/InitializerManager/setupExtensionPreferences.ts 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1185      +/-   ##
==========================================
+ Coverage   74.13%   74.40%   +0.26%     
==========================================
  Files         181      181              
  Lines        4300     4306       +6     
  Branches     1054     1057       +3     
==========================================
+ Hits         3188     3204      +16     
+ Misses       1112     1102      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@christopherferreira9 christopherferreira9 marked this pull request as draft January 8, 2025 12:47
Copy link

sonarqubecloud bot commented Jan 8, 2025

@christopherferreira9 christopherferreira9 marked this pull request as ready for review January 8, 2025 16:13
@christopherferreira9 christopherferreira9 merged commit 4151089 into main Jan 9, 2025
36 checks passed
@christopherferreira9 christopherferreira9 deleted the chore/extension-call-getPermissions-accountsChanged branch January 9, 2025 10:28
@christopherferreira9 christopherferreira9 mentioned this pull request Jan 14, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants