From 5acd634fe6f609f9116ff795059e5c9da6277465 Mon Sep 17 00:00:00 2001 From: RomanChornii Date: Tue, 30 Jul 2024 01:14:04 +0300 Subject: [PATCH] Draft. --- .../main/wallet_section/accounts/model.nim | 2 +- storybook/pages/DAppsWorkflowPage.qml | 2 + .../Wallet/controls/DappsComboBox.qml | 2 +- .../AppLayouts/Wallet/panels/WalletHeader.qml | 5 ++- .../services/dapps/DAppsListProvider.qml | 31 +++++++++++-- .../services/dapps/WalletConnectService.qml | 44 +++++++++++++++++-- .../Wallet/services/dapps/helpers.js | 12 ++--- 7 files changed, 81 insertions(+), 17 deletions(-) diff --git a/src/app/modules/main/wallet_section/accounts/model.nim b/src/app/modules/main/wallet_section/accounts/model.nim index 681f5476e27..0839bd24462 100644 --- a/src/app/modules/main/wallet_section/accounts/model.nim +++ b/src/app/modules/main/wallet_section/accounts/model.nim @@ -163,4 +163,4 @@ QtObject: defer: index.delete self.dataChanged(index, index, @[ModelRole.PreferredSharingChainIds.int]) break - i.inc \ No newline at end of file + i.inc diff --git a/storybook/pages/DAppsWorkflowPage.qml b/storybook/pages/DAppsWorkflowPage.qml index c281a253b31..11de19d1358 100644 --- a/storybook/pages/DAppsWorkflowPage.qml +++ b/storybook/pages/DAppsWorkflowPage.qml @@ -418,6 +418,8 @@ Item { // Name mismatch between storybook and production readonly property var groupedAccountAssetsModel: groupedAccountsAssetsModel } + + readonly property string selectedAddress: "" } onDisplayToastMessage: (message, isErr) => { diff --git a/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml b/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml index 642b88dea8f..11bced76935 100644 --- a/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml +++ b/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml @@ -26,7 +26,7 @@ ComboBox { background: SQP.StatusComboboxBackground { objectName: "dappsBackground" - active: root.down || root.hovered + active: root.down || root.hovered || !root.enabled } indicator: null diff --git a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml index 342d8ba513e..c03d2f5cffb 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml @@ -133,9 +133,12 @@ Item { spacing: 8 - visible: !root.walletStore.showSavedAddresses && Global.featureFlags.dappsEnabled + visible: !root.walletStore.showSavedAddresses + && Global.featureFlags.dappsEnabled + && Global.walletConnectService.isServiceAvailableForAddressSelection enabled: !!Global.walletConnectService + wcService: Global.walletConnectService loginType: root.store.loginType selectedAccountAddress: root.walletStore.selectedAddress diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml index a4989f52bee..95c9b71cb8d 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml @@ -1,7 +1,10 @@ import QtQuick 2.15 +import StatusQ 0.1 import StatusQ.Core.Utils 0.1 +import SortFilterProxyModel 0.2 + import AppLayouts.Wallet.services.dapps 1.0 import shared.stores 1.0 @@ -15,7 +18,28 @@ QObject { required property DAppsStore store required property var supportedAccountsModel - readonly property alias dappsModel: d.dappsModel + property string selectedAddress: "" + + readonly property SortFilterProxyModel dappsModel: SortFilterProxyModel { + objectName: "dappsModelSorted" + sourceModel: d.dappsModel + filters: [ + FastExpressionFilter { + enabled: !!root.selectedAddress + + function isAddressIncluded(addresses) { + const dataArray = ModelUtils.modelToArray(addresses, ["address"]).map(obj => obj.address); + return dataArray.includes(root.selectedAddress) + } + + expression: { + root.selectedAddress + return isAddressIncluded(model.accountAddresses) + } + expectedRoles: ["accountAddresses"] + } + ] + } function updateDapps() { d.updateDappsModel() @@ -26,6 +50,7 @@ QObject { property ListModel dappsModel: ListModel { id: dapps + objectName: "DAppsModel" } property var dappsListReceivedFn: null @@ -54,7 +79,7 @@ QObject { let tmpMap = {} var topics = [] - const sessions = Helpers.filterActiveSessionsForKnownAccounts(allSessions, root.supportedAccountsModel) + const sessions = Helpers.filterActiveSessionsForKnownAccounts(allSessions) for (let key in sessions) { let dapp = sessions[key].peer.metadata if (!!dapp.icons && dapp.icons.length > 0) { @@ -87,4 +112,4 @@ QObject { } } } -} \ No newline at end of file +} diff --git a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml index 259be4fb929..047f8cca8b1 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml @@ -35,6 +35,8 @@ QObject { readonly property alias dappsModel: dappsProvider.dappsModel readonly property alias requestHandler: requestHandler + readonly property bool isServiceAvailableForAddressSelection: dappsProvider.supportedAccountsModel.count + readonly property var validAccounts: SortFilterProxyModel { sourceModel: d.supportedAccountsModel proxyRoles: [ @@ -110,7 +112,7 @@ QObject { function disconnectDapp(url) { wcSDK.getActiveSessions((allSessions) => { - const sessions = Helpers.filterActiveSessionsForKnownAccounts(allSessions, d.supportedAccountsModel) + const sessions = Helpers.filterActiveSessionsForKnownAccounts(allSessions) for (let session in sessions) { let dapp = session.peer.metadata let topic = session.topic @@ -225,7 +227,13 @@ QObject { QObject { id: d - readonly property var supportedAccountsModel: root.walletRootStore.nonWatchAccounts + readonly property var supportedAccountsModel: SortFilterProxyModel { + sourceModel: root.walletRootStore.nonWatchAccounts + filters: ValueFilter { + roleName: "keycardAccount" + value: false + } + } property var currentSessionProposal: null property var acceptedSessionProposal: null @@ -264,7 +272,37 @@ QObject { sdk: root.wcSDK store: root.store - supportedAccountsModel: d.supportedAccountsModel + supportedAccountsModel: SortFilterProxyModel { + objectName: "SelectedAddressModelForDAppsListProvider" + sourceModel: d.supportedAccountsModel + filters: [ + FastExpressionFilter { + expression: root.walletRootStore.selectedAddress === model.address; + expectedRoles: ["address"] + enabled: !root.walletRootStore.showAllAccounts + } + ] + } + + // onSelectedAddressChanged: { + // console.log("####@ onSupportedAccountsModelChanged: ", JSON.stringify(supportedAccountsModel), + // "\n####@ count: ", supportedAccountsModel.count) + // dappsProvider.updateDapps(); + // } + + selectedAddress: root.walletRootStore.selectedAddress + + // readonly property SortFilterProxyModel selectedAddressModel: SortFilterProxyModel { + // objectName: "SelectedAddressModel" + // sourceModel: d.supportedAccountsModel + // filters: ValueFilter { + // roleName: "address" + // value: root.walletRootStore.selectedAddress + // onValueChanged: { + // console.log("####@ value changed: ", value) + // } + // } + // } } // Timeout for the corner case where the URL was already dismissed and the SDK doesn't respond with an error nor advances with the proposal diff --git a/ui/app/AppLayouts/Wallet/services/dapps/helpers.js b/ui/app/AppLayouts/Wallet/services/dapps/helpers.js index 85b2fbc9300..a9f5404db33 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/helpers.js +++ b/ui/app/AppLayouts/Wallet/services/dapps/helpers.js @@ -96,7 +96,7 @@ function extractInfoFromPairUri(uri) { return { topic, expiry } } -function filterActiveSessionsForKnownAccounts(sessions, accountsModel) { +function filterActiveSessionsForKnownAccounts(sessions) { let knownSessions = ({}) Object.keys(sessions).forEach((topic) => { const session = sessions[topic] @@ -105,13 +105,9 @@ function filterActiveSessionsForKnownAccounts(sessions, accountsModel) { eip155Addresses.map(eip155Address => eip155Address.split(':').pop().trim()) ); const uniqueAddresses = Array.from(accountSet); - const firstAccount = SQUtils.ModelUtils.getFirstModelEntryIf(accountsModel, (account) => { - return uniqueAddresses.includes(account.address) - }) - if (!firstAccount) { - return - } + + session.peer.metadata.accountAddresses = uniqueAddresses.map(value => ({ address: value })); knownSessions[topic] = session }) return knownSessions -} \ No newline at end of file +}