fix(WalletConnect): dApp connection state presented in the UI is out-of sync

1. The DAppsListProvider needs to receive all the user accounts so that it can process all dapps the user is connected to (the dapps filtering based on selected account is an internal impl. detail)
2. Call `revokeSession` on disconnect only if the dapp cannot be found in the WC active sessions. There is some overlapping between Browser connector and Wallet connect because both operate on the same data stored in the DB. If Browser connector controller removes WC data, the WC disconnect flows cannot be successfully completed.
3. Reuse the same notification flow for Browser connector as it's used for WC
4. Fix dapp filtering when processing the dapps that will be displayed in the UI.
This commit is contained in:
Alex Jbanca 2024-08-08 22:38:32 +03:00 committed by Anthony Laibe
parent 6edabc3c8e
commit 21227893c2
3 changed files with 16 additions and 25 deletions

View File

@ -60,19 +60,15 @@ QObject {
let dappsList = JSON.parse(dappsJson); let dappsList = JSON.parse(dappsJson);
for (let i = 0; i < dappsList.length; i++) { for (let i = 0; i < dappsList.length; i++) {
const cachedEntry = dappsList[i]; const cachedEntry = dappsList[i];
let accountAddresses = cachedEntry.accountAddresses // TODO #15075: on SDK dApps refresh update the model that has data source from persistence instead of using reset
if (!accountAddresses) {
accountAddresses = [{address: ''}];
}
const dappEntryWithRequiredRoles = { const dappEntryWithRequiredRoles = {
description: cachedEntry.description, description: "",
url: cachedEntry.url, url: cachedEntry.url,
name: cachedEntry.name, name: cachedEntry.name,
iconUrl: cachedEntry.url, iconUrl: cachedEntry.iconUrl,
accountAddresses: cachedEntry.accountAddresses accountAddresses: [{address: ''}]
} }
dapps.append(dappsList[i]); dapps.append(dappEntryWithRequiredRoles);
} }
} }
root.store.dappsListReceived.connect(dappsListReceivedFn); root.store.dappsListReceived.connect(dappsListReceivedFn);
@ -103,7 +99,7 @@ QObject {
if (existingDApp) { if (existingDApp) {
// In Qt5.15.2 this is the way to make a "union" of two arrays // In Qt5.15.2 this is the way to make a "union" of two arrays
// more modern syntax (ES-6) is not available yet // more modern syntax (ES-6) is not available yet
const combinedAddresses = new Set(existingDApp.accountAddresses.concat(dapp.accountAddresses)); const combinedAddresses = new Set(existingDApp.accountAddresses.concat(accounts));
existingDApp.accountAddresses = Array.from(combinedAddresses); existingDApp.accountAddresses = Array.from(combinedAddresses);
} else { } else {
dapp.accountAddresses = accounts dapp.accountAddresses = accounts

View File

@ -482,7 +482,6 @@ WalletConnectSDKBase {
controller.recallDAppPermission(dAppUrl) controller.recallDAppPermission(dAppUrl)
const session = { url: dAppUrl, name: "", icon: "" } const session = { url: dAppUrl, name: "", icon: "" }
root.wcService.connectorDAppsProvider.revokeSession(JSON.stringify(session)) root.wcService.connectorDAppsProvider.revokeSession(JSON.stringify(session))
root.wcService.displayToastMessage(qsTr("Disconnected from %1").arg(dAppUrl), false)
} }
} }

View File

@ -128,6 +128,7 @@ QObject {
function disconnectDapp(url) { function disconnectDapp(url) {
wcSDK.getActiveSessions((allSessionsAllProfiles) => { wcSDK.getActiveSessions((allSessionsAllProfiles) => {
const sessions = DAppsHelpers.filterActiveSessionsForKnownAccounts(allSessionsAllProfiles, validAccounts) const sessions = DAppsHelpers.filterActiveSessionsForKnownAccounts(allSessionsAllProfiles, validAccounts)
let dappFoundInWcSessions = false
for (const sessionID in sessions) { for (const sessionID in sessions) {
const session = sessions[sessionID] const session = sessions[sessionID]
const accountsInSession = DAppsHelpers.getAccountsInSession(session) const accountsInSession = DAppsHelpers.getAccountsInSession(session)
@ -137,13 +138,19 @@ QObject {
if (!dappsProvider.selectedAddress || if (!dappsProvider.selectedAddress ||
(accountsInSession.includes(dappsProvider.selectedAddress))) (accountsInSession.includes(dappsProvider.selectedAddress)))
{ {
dappFoundInWcSessions = true
wcSDK.disconnectSession(topic) wcSDK.disconnectSession(topic)
} }
} }
} }
});
root.revokeSession(url) // TODO: #16044 - Refactor Wallet connect service to handle multiple SDKs
if (!dappFoundInWcSessions) {
// Revoke browser plugin session
root.revokeSession(url)
d.notifyDappDisconnect(url, false)
}
});
} }
function getDApp(dAppUrl) { function getDApp(dAppUrl) {
@ -336,18 +343,7 @@ QObject {
sdk: root.wcSDK sdk: root.wcSDK
store: root.store store: root.store
supportedAccountsModel: SortFilterProxyModel { supportedAccountsModel: d.supportedAccountsModel
objectName: "SelectedAddressModelForDAppsListProvider"
sourceModel: d.supportedAccountsModel
filters: FastExpressionFilter {
enabled: !root.walletRootStore.showAllAccounts
expression: root.walletRootStore.selectedAddress.toLowerCase() === model.address.toLowerCase()
expectedRoles: ["address"]
}
}
selectedAddress: root.walletRootStore.selectedAddress selectedAddress: root.walletRootStore.selectedAddress
} }