From a6429133e0cc04b4c5f9e5360b358f11d5aac71f Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Thu, 6 Apr 2023 14:59:24 +0200 Subject: [PATCH] fix(@desktop/wallet): Wallet: Active account changes when clicking send transaction from a watched account fixes #9815 --- .../shared/popups/AccountsModalHeader.qml | 47 +++++-------------- ui/imports/shared/popups/SendModal.qml | 41 +++++++--------- .../shared/stores/NetworkConnectionStore.qml | 2 +- ui/imports/shared/stores/TransactionStore.qml | 6 +++ .../shared/views/TabAddressSelectorView.qml | 3 +- ui/imports/shared/views/TokenListView.qml | 2 +- 6 files changed, 40 insertions(+), 61 deletions(-) diff --git a/ui/imports/shared/popups/AccountsModalHeader.qml b/ui/imports/shared/popups/AccountsModalHeader.qml index dd700c7a59..5c1bdb0091 100644 --- a/ui/imports/shared/popups/AccountsModalHeader.qml +++ b/ui/imports/shared/popups/AccountsModalHeader.qml @@ -19,7 +19,7 @@ StatusFloatingButtonsSelector { id: root property var selectedAccount - // Expected signature: function(newAccount, newIndex) + // Expected signature: function(newAccount) property var changeSelectedAccount: function(){} property bool showAllWalletTypes: false @@ -27,20 +27,10 @@ StatusFloatingButtonsSelector { signal updatedSelectedAccount(var account) - QtObject { - id: d - property var firstModelData: null - - function isWalletTypeAccepted(walletType, index) { - return (root.showAllWalletTypes || walletType !== Constants.watchWalletType) - } - } - delegate: Rectangle { width: button.width height: button.height radius: 8 - visible: root.visibleIndices.includes(index) && d.isWalletTypeAccepted(walletType, index) color: Theme.palette.baseColor3 StatusButton { id: button @@ -55,31 +45,21 @@ StatusFloatingButtonsSelector { hoverColor: Theme.palette.statusFloatingButtonHighlight highlighted: index === root.currentIndex onClicked: { - changeSelectedAccount(model, index) + changeSelectedAccount(model) root.currentIndex = index } Component.onCompleted: { - // On startup make the preseected wallet in the floating menu, - // and if the selectedAccount is watch only then select 0th item - if(index === 0) { - d.firstModelData = model - } - - if(name !== root.selectedAccount.name) { - return - } - - if(name === root.selectedAccount.name) { - if(d.isWalletTypeAccepted(walletType, index)) { - // If the selected index wont be displayed, added it to the visible indices - if(index > 2) { - visibleIndices = [0, 1, index] - } - root.currentIndex = index + // on model reset, set the selected account to the one that was previously selected + if(root.selectedAccount === null) { + if(root.currentIndex === index) { + changeSelectedAccount(model) } - else { - changeSelectedAccount(root.selectedAccount, 0) - root.currentIndex = 0 + } + else { + // if the selectedAccount is watch only then select 0th item + if(index === 0 && !!root.selectedAccount && root.selectedAccount.walletType === Constants.watchWalletType) { + changeSelectedAccount(model) + root.currentIndex = index } } } @@ -96,10 +76,9 @@ StatusFloatingButtonsSelector { asset.isLetterIdenticon: !!model.emoji asset.bgColor: Theme.palette.indirectColor1 onClicked: { - changeSelectedAccount(model, index) + changeSelectedAccount(model) root.selectItem(index) } - visible: !root.visibleIndices.includes(index) && d.isWalletTypeAccepted(walletType, index) } } diff --git a/ui/imports/shared/popups/SendModal.qml b/ui/imports/shared/popups/SendModal.qml index 0cd1e96e18..8ba47af886 100644 --- a/ui/imports/shared/popups/SendModal.qml +++ b/ui/imports/shared/popups/SendModal.qml @@ -15,6 +15,8 @@ import StatusQ.Core 0.1 import StatusQ.Core.Theme 0.1 import StatusQ.Controls.Validators 0.1 +import SortFilterProxyModel 0.2 + import "../panels" import "../controls" import "../views" @@ -46,14 +48,6 @@ StatusDialog { standardButtons: StandardButton.Ok } - Connections { - target: store.currentAccount.assets - function onModelReset() { - popup.selectedAccount = null - popup.selectedAccount = store.currentAccount - } - } - property var sendTransaction: function() { let recipientAddress = Utils.isValidAddress(popup.addressText) ? popup.addressText : d.resolvedENSAddress d.isPendingTx = true @@ -181,13 +175,17 @@ StatusDialog { header: AccountsModalHeader { anchors.top: parent.top anchors.topMargin: -height - 18 - model: popup.store.accounts - selectedAccount: popup.selectedAccount - changeSelectedAccount: function(newAccount, newIndex) { - if (newIndex > popup.store.accounts) { - return + model: SortFilterProxyModel { + sourceModel: popup.store.accounts + filters: ValueFilter { + roleName: "walletType" + value: Constants.watchWalletType + inverted: true } - popup.store.switchAccount(newIndex) + } + selectedAccount: popup.selectedAccount + changeSelectedAccount: function(newAccount) { + popup.selectedAccount = newAccount } } @@ -244,7 +242,7 @@ StatusDialog { Layout.fillWidth: true Layout.alignment: Qt.AlignTop | Qt.AlignLeft enabled: popup.interactive - assets: popup.selectedAccount && popup.selectedAccount.assets ? popup.selectedAccount.assets : [] + assets: popup.selectedAccount && popup.selectedAccount.assets ? popup.selectedAccount.assets : null defaultToken: Style.png("tokens/DEFAULT-TOKEN@3x") placeholderText: qsTr("Select token") currentCurrencySymbol: RootStore.currencyStore.currentCurrencySymbol @@ -252,10 +250,7 @@ StatusDialog { return symbol ? Style.png("tokens/%1".arg(symbol)) : defaultToken } searchTokenSymbolByAddressFn: function (address) { - if(popup.selectedAccount) { - return popup.selectedAccount.findTokenSymbolByAddress(address) - } - return "" + return store.findTokenSymbolByAddress(address) } getNetworkIcon: function(chainId){ return RootStore.getNetworkIcon(chainId) @@ -330,12 +325,9 @@ StatusDialog { Layout.fillWidth: true visible: !assetSelector.selectedAsset - assets: popup.selectedAccount && popup.selectedAccount.assets ? popup.selectedAccount.assets : [] + assets: popup.selectedAccount && popup.selectedAccount.assets ? popup.selectedAccount.assets : null searchTokenSymbolByAddressFn: function (address) { - if(popup.selectedAccount) { - return popup.selectedAccount.findTokenSymbolByAddress(address) - } - return "" + return store.findTokenSymbolByAddress(address) } getNetworkIcon: function(chainId){ return RootStore.getNetworkIcon(chainId) @@ -445,6 +437,7 @@ StatusDialog { anchors.leftMargin: Style.current.bigPadding anchors.rightMargin: Style.current.bigPadding store: popup.store + selectedAccount: popup.selectedAccount onContactSelected: { recipientSelector.input.text = address popup.isLoading = true diff --git a/ui/imports/shared/stores/NetworkConnectionStore.qml b/ui/imports/shared/stores/NetworkConnectionStore.qml index 38ffecba79..81e3e714a9 100644 --- a/ui/imports/shared/stores/NetworkConnectionStore.qml +++ b/ui/imports/shared/stores/NetworkConnectionStore.qml @@ -53,7 +53,7 @@ QtObject { readonly property bool ensNetworkAvailable: !blockchainNetworksDown.includes(profileSectionModule.ensUsernamesModule.chainId.toString()) readonly property string ensNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg( networksModule.all.getNetworkFullName(profileSectionModule.ensUsernamesModule.chainId)) - readonly property bool stickersNetworkAvailable: false//!blockchainNetworksDown.includes(stickersModule.getChainIdForStickers().toString()) + readonly property bool stickersNetworkAvailable: !blockchainNetworksDown.includes(stickersModule.getChainIdForStickers().toString()) readonly property string stickersNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg( networksModule.all.getNetworkFullName(stickersModule.getChainIdForStickers())) function getBlockchainNetworkDownTextForToken(balances) { diff --git a/ui/imports/shared/stores/TransactionStore.qml b/ui/imports/shared/stores/TransactionStore.qml index 8e42f21d7e..5156b42c13 100644 --- a/ui/imports/shared/stores/TransactionStore.qml +++ b/ui/imports/shared/stores/TransactionStore.qml @@ -259,4 +259,10 @@ QtObject { selectedAccount.prepareTokenBalanceOnChain(chainId, tokenSymbol) return selectedAccount.getPreparedTokenBalanceOnChain() } + + function findTokenSymbolByAddress(address) { + if (Global.appIsReady) + return walletSectionAllTokens.findTokenSymbolByAddress(address) + return "" + } } diff --git a/ui/imports/shared/views/TabAddressSelectorView.qml b/ui/imports/shared/views/TabAddressSelectorView.qml index adcf4f9d77..73001ec44c 100644 --- a/ui/imports/shared/views/TabAddressSelectorView.qml +++ b/ui/imports/shared/views/TabAddressSelectorView.qml @@ -21,6 +21,7 @@ Item { clip: true implicitHeight: visible ? accountSelectionTabBar.height + stackLayout.height + Style.current.bigPadding: 0 + property var selectedAccount property var store signal contactSelected(string address, int type) @@ -193,7 +194,7 @@ Item { } delegate: StatusListItem { - property bool isIncoming: to === store.currentAccount.address + property bool isIncoming: root.selectedAccount ? to === root.selectedAccount.address : false implicitWidth: parent.width height: visible ? 64 : 0 title: isIncoming ? from : to diff --git a/ui/imports/shared/views/TokenListView.qml b/ui/imports/shared/views/TokenListView.qml index 78a5007f0b..aaa6342e2f 100644 --- a/ui/imports/shared/views/TokenListView.qml +++ b/ui/imports/shared/views/TokenListView.qml @@ -15,7 +15,7 @@ import "../controls" Item { id: root - property var assets: [] + property var assets: null signal tokenSelected(var selectedToken) property var searchTokenSymbolByAddressFn: function (address) { return ""