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
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)
}
}

View File

@ -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

View File

@ -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) {

View File

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

View File

@ -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

View File

@ -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 ""