-
Notifications
You must be signed in to change notification settings - Fork 986
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 WalletConnect sessions disappearing #21350
Conversation
Jenkins BuildsClick to see older builds (8)
|
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.
Looking good, left a couple of comments 📓
My main overall question is to understand a little bit more about how wallet connect events/effects are working now. For example, how do the changes resolve the issue, I think it's because of the way we structuring the effects to avoid some kind of inconsistent state, but I'm not sure.
Really like that we're defining re-usable effects too ♻️
[:effects.wallet-connect/approve-session | ||
{:web3-wallet web3-wallet | ||
:proposal current-proposal | ||
:networks session-networks | ||
:accounts accounts | ||
:on-success (fn [approved-session] | ||
(log/info "Wallet Connect session approved") | ||
(rf/dispatch [:wallet-connect/reset-current-session-proposal]) | ||
(rf/dispatch [:wallet-connect/persist-session | ||
approved-session])) | ||
:on-fail (fn [error] | ||
(log/error "Wallet Connect session approval failed" | ||
{:error error | ||
:event :wallet-connect/approve-session}) | ||
(rf/dispatch | ||
[:wallet-connect/reset-current-session-proposal]))}]) | ||
{:web3-wallet web3-wallet | ||
:proposal-request current-proposal | ||
:session-networks session-networks | ||
:address current-address | ||
:on-success #(rf/dispatch [:wallet-connect/approve-session-success %]) | ||
:on-fail #(rf/dispatch [:wallet-connect/approve-session-error %])}]) |
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.
Can we use rf/call-continuation
inside the definition for :effects.wallet-connect/approve-session
?
If we do that then we can define :on-success
and :on-failure
with vectors:
[:effects.wallet-connect/approve-session
{:web3-wallet web3-wallet
:proposal-request current-proposal
:session-networks session-networks
:address current-address
:on-success [:wallet-connect/approve-session-success]
:on-fail [:wallet-connect/approve-session-error]}]
For reference, here's an example of how the effect would use rf/call-continuation
to work promesa: https://github.com/status-im/status-mobile/blob/seanstrom/chore-refactor-screens-definitions/src/status_im/contexts/wallet/effects.cljs#L63-L68
{:fx [[:effects.wallet-connect/get-sessions | ||
{:online? (-> db :network/status (= :online)) | ||
:web3-wallet (get db :wallet-connect/web3-wallet) | ||
:addresses addresses | ||
:on-success #(rf/dispatch [:wallet-connect/get-sessions-success %]) | ||
:on-error #(rf/dispatch [:wallet-connect/get-sessions-error %])}]]}))) |
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.
Similar suggestion about using rf/call-continuation
for this effect too 🙏
@clauxx thank you for the PR. Unfortunately I am still facing issue on IOS. ISSUE 1 'Failed to get dapps connection' error and empty dapp list on relogin (IOS)Reproducing on iPhone 15, IOS 17.6.1
Actual result: 'Failed to get dapps connection' error. Dapps list is empty. |
:wallet-connect/delete-session | ||
(fn [{:keys [db]} [topic]] | ||
(log/info "Removing session from persistance and state" topic) | ||
{:db (update db | ||
:wallet-connect/sessions | ||
(fn [sessions] | ||
(->> sessions | ||
(remove #(= (:topic %) topic)) | ||
(into [])))) | ||
:fx [[:json-rpc/call | ||
[{:method "wallet_disconnectWalletConnectSession" | ||
:params [topic] | ||
:on-success #(log/info "Wallet Connect session disconnected") | ||
:on-error #(log/info "Wallet Connect session persistence failed" %)}]]]})) | ||
(into []))))})) |
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.
@seanstrom so here is the cause of the bug. This event was called when disconnecting a dapp and when syncing persisted dapps. We shouldn't be removing active sessions from the db when syncing the persisted dapps. The faulty "sync" was likely caused by the expiry date check, but hard to tell the cause since it's difficult to reproduce.
@pavloburykh could you try again please? I think I found the root cause for this issue, being that the wallet was finalizing its initialization and loading the accounts after we attempt to fetch the sessions, leading to the empty list, but it's hard to tell since it's very hard to reproduce for me. EDIT: if possible, even if the bug is fixed, could you please attach the logs? |
Thanks @clauxx, ISSUE 1 is fixed now. I will proceed with the rest of testing. Here are the logs from my IOS |
100% of end-end tests have passed
Passed tests (7)Click to expandClass TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestWalletOneDevice:
Class TestCommunityOneDeviceMerged:
Class TestWalletMultipleDevice:
Class TestCommunityMultipleDeviceMerged:
|
@clauxx thank you again for the fixes. No issues from my side. PR is ready for merge. |
fixes #21275
Summary
The sessions were disappearing due to a bug in the session fetching logic, which was unnecessarily convoluted with multiple events. Here, the bug was fixed and the session logic was simplified into functions, which minimized the number of events we use.
Changes:
Testing notes
Since there are changes in session management, we should test the following flows:
status: ready