fix(@desktop/wallet): Wallet: Active account changes when clicking send transaction from a watched account

fixes #9815
This commit is contained in:
Khushboo Mehta 2023-04-06 14:59:24 +02:00 committed by Khushboo-dev-cpp
parent 358869fd6c
commit a6429133e0
6 changed files with 40 additions and 61 deletions

View File

@ -19,7 +19,7 @@ StatusFloatingButtonsSelector {
id: root id: root
property var selectedAccount property var selectedAccount
// Expected signature: function(newAccount, newIndex) // Expected signature: function(newAccount)
property var changeSelectedAccount: function(){} property var changeSelectedAccount: function(){}
property bool showAllWalletTypes: false property bool showAllWalletTypes: false
@ -27,20 +27,10 @@ StatusFloatingButtonsSelector {
signal updatedSelectedAccount(var account) signal updatedSelectedAccount(var account)
QtObject {
id: d
property var firstModelData: null
function isWalletTypeAccepted(walletType, index) {
return (root.showAllWalletTypes || walletType !== Constants.watchWalletType)
}
}
delegate: Rectangle { delegate: Rectangle {
width: button.width width: button.width
height: button.height height: button.height
radius: 8 radius: 8
visible: root.visibleIndices.includes(index) && d.isWalletTypeAccepted(walletType, index)
color: Theme.palette.baseColor3 color: Theme.palette.baseColor3
StatusButton { StatusButton {
id: button id: button
@ -55,31 +45,21 @@ StatusFloatingButtonsSelector {
hoverColor: Theme.palette.statusFloatingButtonHighlight hoverColor: Theme.palette.statusFloatingButtonHighlight
highlighted: index === root.currentIndex highlighted: index === root.currentIndex
onClicked: { onClicked: {
changeSelectedAccount(model, index) changeSelectedAccount(model)
root.currentIndex = index root.currentIndex = index
} }
Component.onCompleted: { Component.onCompleted: {
// On startup make the preseected wallet in the floating menu, // on model reset, set the selected account to the one that was previously selected
// and if the selectedAccount is watch only then select 0th item if(root.selectedAccount === null) {
if(index === 0) { if(root.currentIndex === index) {
d.firstModelData = model changeSelectedAccount(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
} }
else { }
changeSelectedAccount(root.selectedAccount, 0) else {
root.currentIndex = 0 // 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.isLetterIdenticon: !!model.emoji
asset.bgColor: Theme.palette.indirectColor1 asset.bgColor: Theme.palette.indirectColor1
onClicked: { onClicked: {
changeSelectedAccount(model, index) changeSelectedAccount(model)
root.selectItem(index) root.selectItem(index)
} }
visible: !root.visibleIndices.includes(index) && d.isWalletTypeAccepted(walletType, index)
} }
} }

View File

@ -15,6 +15,8 @@ import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
import StatusQ.Controls.Validators 0.1 import StatusQ.Controls.Validators 0.1
import SortFilterProxyModel 0.2
import "../panels" import "../panels"
import "../controls" import "../controls"
import "../views" import "../views"
@ -46,14 +48,6 @@ StatusDialog {
standardButtons: StandardButton.Ok standardButtons: StandardButton.Ok
} }
Connections {
target: store.currentAccount.assets
function onModelReset() {
popup.selectedAccount = null
popup.selectedAccount = store.currentAccount
}
}
property var sendTransaction: function() { property var sendTransaction: function() {
let recipientAddress = Utils.isValidAddress(popup.addressText) ? popup.addressText : d.resolvedENSAddress let recipientAddress = Utils.isValidAddress(popup.addressText) ? popup.addressText : d.resolvedENSAddress
d.isPendingTx = true d.isPendingTx = true
@ -181,13 +175,17 @@ StatusDialog {
header: AccountsModalHeader { header: AccountsModalHeader {
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: -height - 18 anchors.topMargin: -height - 18
model: popup.store.accounts model: SortFilterProxyModel {
selectedAccount: popup.selectedAccount sourceModel: popup.store.accounts
changeSelectedAccount: function(newAccount, newIndex) { filters: ValueFilter {
if (newIndex > popup.store.accounts) { roleName: "walletType"
return 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.fillWidth: true
Layout.alignment: Qt.AlignTop | Qt.AlignLeft Layout.alignment: Qt.AlignTop | Qt.AlignLeft
enabled: popup.interactive 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") defaultToken: Style.png("tokens/DEFAULT-TOKEN@3x")
placeholderText: qsTr("Select token") placeholderText: qsTr("Select token")
currentCurrencySymbol: RootStore.currencyStore.currentCurrencySymbol currentCurrencySymbol: RootStore.currencyStore.currentCurrencySymbol
@ -252,10 +250,7 @@ StatusDialog {
return symbol ? Style.png("tokens/%1".arg(symbol)) : defaultToken return symbol ? Style.png("tokens/%1".arg(symbol)) : defaultToken
} }
searchTokenSymbolByAddressFn: function (address) { searchTokenSymbolByAddressFn: function (address) {
if(popup.selectedAccount) { return store.findTokenSymbolByAddress(address)
return popup.selectedAccount.findTokenSymbolByAddress(address)
}
return ""
} }
getNetworkIcon: function(chainId){ getNetworkIcon: function(chainId){
return RootStore.getNetworkIcon(chainId) return RootStore.getNetworkIcon(chainId)
@ -330,12 +325,9 @@ StatusDialog {
Layout.fillWidth: true Layout.fillWidth: true
visible: !assetSelector.selectedAsset 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) { searchTokenSymbolByAddressFn: function (address) {
if(popup.selectedAccount) { return store.findTokenSymbolByAddress(address)
return popup.selectedAccount.findTokenSymbolByAddress(address)
}
return ""
} }
getNetworkIcon: function(chainId){ getNetworkIcon: function(chainId){
return RootStore.getNetworkIcon(chainId) return RootStore.getNetworkIcon(chainId)
@ -445,6 +437,7 @@ StatusDialog {
anchors.leftMargin: Style.current.bigPadding anchors.leftMargin: Style.current.bigPadding
anchors.rightMargin: Style.current.bigPadding anchors.rightMargin: Style.current.bigPadding
store: popup.store store: popup.store
selectedAccount: popup.selectedAccount
onContactSelected: { onContactSelected: {
recipientSelector.input.text = address recipientSelector.input.text = address
popup.isLoading = true popup.isLoading = true

View File

@ -53,7 +53,7 @@ QtObject {
readonly property bool ensNetworkAvailable: !blockchainNetworksDown.includes(profileSectionModule.ensUsernamesModule.chainId.toString()) 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 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())) readonly property string stickersNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg( networksModule.all.getNetworkFullName(stickersModule.getChainIdForStickers()))
function getBlockchainNetworkDownTextForToken(balances) { function getBlockchainNetworkDownTextForToken(balances) {

View File

@ -259,4 +259,10 @@ QtObject {
selectedAccount.prepareTokenBalanceOnChain(chainId, tokenSymbol) selectedAccount.prepareTokenBalanceOnChain(chainId, tokenSymbol)
return selectedAccount.getPreparedTokenBalanceOnChain() return selectedAccount.getPreparedTokenBalanceOnChain()
} }
function findTokenSymbolByAddress(address) {
if (Global.appIsReady)
return walletSectionAllTokens.findTokenSymbolByAddress(address)
return ""
}
} }

View File

@ -21,6 +21,7 @@ Item {
clip: true clip: true
implicitHeight: visible ? accountSelectionTabBar.height + stackLayout.height + Style.current.bigPadding: 0 implicitHeight: visible ? accountSelectionTabBar.height + stackLayout.height + Style.current.bigPadding: 0
property var selectedAccount
property var store property var store
signal contactSelected(string address, int type) signal contactSelected(string address, int type)
@ -193,7 +194,7 @@ Item {
} }
delegate: StatusListItem { delegate: StatusListItem {
property bool isIncoming: to === store.currentAccount.address property bool isIncoming: root.selectedAccount ? to === root.selectedAccount.address : false
implicitWidth: parent.width implicitWidth: parent.width
height: visible ? 64 : 0 height: visible ? 64 : 0
title: isIncoming ? from : to title: isIncoming ? from : to

View File

@ -15,7 +15,7 @@ import "../controls"
Item { Item {
id: root id: root
property var assets: [] property var assets: null
signal tokenSelected(var selectedToken) signal tokenSelected(var selectedToken)
property var searchTokenSymbolByAddressFn: function (address) { property var searchTokenSymbolByAddressFn: function (address) {
return "" return ""