fix: do not show watch-only accounts as “from address”

Fixes: #2257.

If a user had selected a watch-only address in the wallet, the backend `walletModel.currentAccount` property would also change. When loading a transaction modal, this property was used to set the `selectedAccount` value for the “from” `AccountSelector`, regardless if the account was a watch-only address.

This PR updates the logic for `selectedAccount` such that it will only allow the account to be selected if it is not a watch-only account.
This commit is contained in:
Eric Mastro 2021-04-22 14:03:46 +10:00 committed by Iuri Matias
parent 3a7c95967a
commit daabef3a3c
6 changed files with 38 additions and 7 deletions

View File

@ -36,7 +36,13 @@ ModalPopup {
AccountSelector { AccountSelector {
id: selectFromAccount id: selectFromAccount
accounts: walletModel.accounts accounts: walletModel.accounts
selectedAccount: walletModel.currentAccount selectedAccount: {
const currAcc = walletModel.currentAccount
if (currAcc.walletType !== Constants.watchWalletType) {
return currAcc
}
return null
}
currency: walletModel.defaultCurrency currency: walletModel.defaultCurrency
width: stack.width width: stack.width
label: { label: {

View File

@ -64,7 +64,13 @@ ModalPopup {
AccountSelector { AccountSelector {
id: selectFromAccount id: selectFromAccount
accounts: walletModel.accounts accounts: walletModel.accounts
selectedAccount: walletModel.currentAccount selectedAccount: {
const currAcc = walletModel.currentAccount
if (currAcc.walletType !== Constants.watchWalletType) {
return currAcc
}
return null
}
currency: walletModel.defaultCurrency currency: walletModel.defaultCurrency
width: stack.width width: stack.width
//% "Choose account" //% "Choose account"

View File

@ -69,7 +69,13 @@ ModalPopup {
AccountSelector { AccountSelector {
id: selectFromAccount id: selectFromAccount
accounts: walletModel.accounts accounts: walletModel.accounts
selectedAccount: walletModel.currentAccount selectedAccount: {
const currAcc = walletModel.currentAccount
if (currAcc.walletType !== Constants.watchWalletType) {
return currAcc
}
return null
}
currency: walletModel.defaultCurrency currency: walletModel.defaultCurrency
width: stack.width width: stack.width
//% "Choose account" //% "Choose account"

View File

@ -56,7 +56,13 @@ ModalPopup {
AccountSelector { AccountSelector {
id: selectFromAccount id: selectFromAccount
accounts: walletModel.accounts accounts: walletModel.accounts
selectedAccount: walletModel.currentAccount selectedAccount: {
const currAcc = walletModel.currentAccount
if (currAcc.walletType !== Constants.watchWalletType) {
return currAcc
}
return null
}
currency: walletModel.defaultCurrency currency: walletModel.defaultCurrency
width: stack.width width: stack.width
//% "From account" //% "From account"

View File

@ -2,6 +2,7 @@ import QtQuick 2.13
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13 import QtQuick.Layouts 1.13
import QtGraphicalEffects 1.13 import QtGraphicalEffects 1.13
import QtQml.Models 2.14
import "../imports" import "../imports"
import "../shared" import "../shared"
import "../shared/status" import "../shared/status"
@ -187,7 +188,7 @@ Item {
id: menuItem id: menuItem
MenuItem { MenuItem {
id: itemContainer id: itemContainer
visible: walletType !== 'watch' visible: walletType !== Constants.watchWalletType
property bool isFirstItem: index === 0 property bool isFirstItem: index === 0
property bool isLastItem: index === accounts.rowCount() - 1 property bool isLastItem: index === accounts.rowCount() - 1
@ -197,7 +198,7 @@ Item {
} }
} }
height: walletType === 'watch' ? 0 : (accountName.height + 14 + accountAddress.height + 14) height: walletType === Constants.watchWalletType ? 0 : (accountName.height + 14 + accountAddress.height + 14)
SVGImage { SVGImage {
id: iconImg id: iconImg
anchors.left: parent.left anchors.left: parent.left

View File

@ -73,7 +73,13 @@ ModalPopup {
AccountSelector { AccountSelector {
id: selectFromAccount id: selectFromAccount
accounts: walletModel.accounts accounts: walletModel.accounts
selectedAccount: walletModel.currentAccount selectedAccount: {
const currAcc = walletModel.currentAccount
if (currAcc.walletType !== Constants.watchWalletType) {
return currAcc
}
return null
}
currency: walletModel.defaultCurrency currency: walletModel.defaultCurrency
width: stack.width width: stack.width
//% "Choose account" //% "Choose account"