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:
parent
6edabc3c8e
commit
21227893c2
|
@ -60,19 +60,15 @@ QObject {
|
|||
let dappsList = JSON.parse(dappsJson);
|
||||
for (let i = 0; i < dappsList.length; i++) {
|
||||
const cachedEntry = dappsList[i];
|
||||
let accountAddresses = cachedEntry.accountAddresses
|
||||
if (!accountAddresses) {
|
||||
accountAddresses = [{address: ''}];
|
||||
}
|
||||
|
||||
// TODO #15075: on SDK dApps refresh update the model that has data source from persistence instead of using reset
|
||||
const dappEntryWithRequiredRoles = {
|
||||
description: cachedEntry.description,
|
||||
description: "",
|
||||
url: cachedEntry.url,
|
||||
name: cachedEntry.name,
|
||||
iconUrl: cachedEntry.url,
|
||||
accountAddresses: cachedEntry.accountAddresses
|
||||
iconUrl: cachedEntry.iconUrl,
|
||||
accountAddresses: [{address: ''}]
|
||||
}
|
||||
dapps.append(dappsList[i]);
|
||||
dapps.append(dappEntryWithRequiredRoles);
|
||||
}
|
||||
}
|
||||
root.store.dappsListReceived.connect(dappsListReceivedFn);
|
||||
|
@ -103,7 +99,7 @@ QObject {
|
|||
if (existingDApp) {
|
||||
// In Qt5.15.2 this is the way to make a "union" of two arrays
|
||||
// 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);
|
||||
} else {
|
||||
dapp.accountAddresses = accounts
|
||||
|
|
|
@ -482,7 +482,6 @@ WalletConnectSDKBase {
|
|||
controller.recallDAppPermission(dAppUrl)
|
||||
const session = { url: dAppUrl, name: "", icon: "" }
|
||||
root.wcService.connectorDAppsProvider.revokeSession(JSON.stringify(session))
|
||||
root.wcService.displayToastMessage(qsTr("Disconnected from %1").arg(dAppUrl), false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ QObject {
|
|||
function disconnectDapp(url) {
|
||||
wcSDK.getActiveSessions((allSessionsAllProfiles) => {
|
||||
const sessions = DAppsHelpers.filterActiveSessionsForKnownAccounts(allSessionsAllProfiles, validAccounts)
|
||||
let dappFoundInWcSessions = false
|
||||
for (const sessionID in sessions) {
|
||||
const session = sessions[sessionID]
|
||||
const accountsInSession = DAppsHelpers.getAccountsInSession(session)
|
||||
|
@ -137,13 +138,19 @@ QObject {
|
|||
if (!dappsProvider.selectedAddress ||
|
||||
(accountsInSession.includes(dappsProvider.selectedAddress)))
|
||||
{
|
||||
dappFoundInWcSessions = true
|
||||
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) {
|
||||
|
@ -336,18 +343,7 @@ QObject {
|
|||
|
||||
sdk: root.wcSDK
|
||||
store: root.store
|
||||
supportedAccountsModel: SortFilterProxyModel {
|
||||
objectName: "SelectedAddressModelForDAppsListProvider"
|
||||
sourceModel: d.supportedAccountsModel
|
||||
filters: FastExpressionFilter {
|
||||
enabled: !root.walletRootStore.showAllAccounts
|
||||
|
||||
expression: root.walletRootStore.selectedAddress.toLowerCase() === model.address.toLowerCase()
|
||||
|
||||
expectedRoles: ["address"]
|
||||
}
|
||||
}
|
||||
|
||||
supportedAccountsModel: d.supportedAccountsModel
|
||||
selectedAddress: root.walletRootStore.selectedAddress
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue