fix(TokenManagement): Asset balance threshold value not reflected in main wallet view

- take the balance threshold value into account when presenting the
assets in the main wallet view
- additional fix from Emil for storing the threshold value
- storybook fixes to display the correct `currentCurrencyBalance` values
based on the address/wallet filters and mocking the threshold values
using TransactionStore

Fixes: #14017
This commit is contained in:
Lukáš Tinkl 2024-03-20 00:34:25 +01:00 committed by Lukáš Tinkl
parent e71d749ef2
commit 9ef513b419
9 changed files with 71 additions and 39 deletions

View File

@ -203,8 +203,14 @@ QtObject:
proc getDisplayAssetsBelowBalanceThreshold(self: View): QVariant {.slot.} =
return newQVariant(self.delegate.getDisplayAssetsBelowBalanceThreshold())
proc setDisplayAssetsBelowBalanceThreshold(self: View, threshold: int) {.slot.} =
if not self.delegate.setDisplayAssetsBelowBalanceThreshold(int64(threshold)):
proc setDisplayAssetsBelowBalanceThreshold(self: View, threshold: string) {.slot.} =
var num: int64
try:
num = parseInt(threshold)
except ValueError:
error "Failed to parse displayAssetsBelowBalanceThreshold"
return
if not self.delegate.setDisplayAssetsBelowBalanceThreshold(num):
error "Failed to set displayAssetsBelowBalanceThreshold"
return
self.displayAssetsBelowBalanceThresholdChanged()

View File

@ -12,6 +12,7 @@ import StatusQ.Core.Utils 0.1 as SQUtils
import mainui 1.0
import utils 1.0
import shared.controls 1.0
import shared.views 1.0
import shared.stores 1.0
@ -33,28 +34,21 @@ SplitView {
id: d
readonly property string networksChainsCurrentlySelected: {
let supportNwChains = ":"
for (let i =0; i< networksRepeater.count; i++) {
let supportedNwChains = []
for (let i = 0; i< networksRepeater.count; i++) {
if (networksRepeater.itemAt(i).checked && networksRepeater.itemAt(i).visible)
supportNwChains += networksRepeater.itemAt(i).chainID + ":"
supportedNwChains.push(networksRepeater.itemAt(i).chainID)
}
return supportNwChains
return supportedNwChains.join(":")
}
readonly property string addressesSelected: {
let supportedAddresses = ""
let allChecked = true
let allUnchecked = true
for (let i =0; i< accountsRepeater.count; i++) {
let supportedAddresses = []
for (let i = 0; i< accountsRepeater.count; i++) {
if (accountsRepeater.itemAt(i).checked && accountsRepeater.itemAt(i).visible)
supportedAddresses += accountsRepeater.itemAt(i).address
allChecked = allChecked && accountsRepeater.itemAt(i).checked
allUnchecked = allUnchecked && !accountsRepeater.itemAt(i).checked
supportedAddresses.push(accountsRepeater.itemAt(i).address)
}
if(allChecked || allUnchecked) {
supportedAddresses = ""
}
return supportedAddresses
return supportedAddresses.join(":")
}
readonly property var currencyStore: CurrenciesStore {}
@ -70,13 +64,12 @@ SplitView {
submodelRoleName: "balances"
delegateModel: SortFilterProxyModel {
sourceModel: submodel
filters: ExpressionFilter {
filters: FastExpressionFilter {
expression: {
d.networksChainsCurrentlySelected
d.addressesSelected
return d.networksChainsCurrentlySelected.split(":").includes(chainId+"") &&
(!!d.addressesSelected ? d.addressesSelected.toUpperCase() === account.toUpperCase() : true)
return d.networksChainsCurrentlySelected.split(":").includes(model.chainId+"")
}
expectedRoles: ["chainId"]
}
}
}
@ -118,6 +111,10 @@ SplitView {
}
filterVisible: ctrlFilterVisible.checked
currencyStore: d.currencyStore
tokensStore: TokensStore {
displayAssetsBelowBalance: ctrlBalanceThresholdSwitch.checked
getDisplayAssetsBelowBalanceThresholdDisplayAmount: () => ctrlBalanceThreshold.value
}
networkFilters: d.networksChainsCurrentlySelected
addressFilters: d.addressesSelected
onAssetClicked: {
@ -206,6 +203,19 @@ SplitView {
}
}
}
ColumnLayout {
Layout.fillWidth: true
Switch {
id: ctrlBalanceThresholdSwitch
text: qsTr("Currency balance threshold")
checked: false
}
CurrencyAmountInput {
id: ctrlBalanceThreshold
value: 10.1
}
}
}
}
}

View File

@ -8,7 +8,7 @@ ListModel {
tokensKey: "DAI",
balances: [
{ account: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240", chainId: 5, balance: "0"},
{ account: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881", chainId: 5, balance: "0"}
{ account: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881", chainId: 5, balance: "123456789123456789"}
]
},
{

View File

@ -2,4 +2,7 @@ import QtQuick 2.15
QtObject {
id: root
property bool displayAssetsBelowBalance: false
property var getDisplayAssetsBelowBalanceThresholdDisplayAmount
}

View File

@ -173,7 +173,7 @@ Item {
property bool dirty: false
property var thresholdCurrency: root.tokensStore.getDisplayAssetsBelowBalanceThresholdCurrency()
readonly property var thresholdCurrency: root.tokensStore.getDisplayAssetsBelowBalanceThresholdCurrency()
spacing: 8
StatusListItem {

View File

@ -149,6 +149,7 @@ RightTabBaseView {
overview: RootStore.overview
currencyStore: RootStore.currencyStore
networkConnectionStore: root.networkConnectionStore
tokensStore: RootStore.tokensStore
assetDetailsLaunched: stack.currentIndex === 2
filterVisible: filterButton.checked
onAssetClicked: {

View File

@ -303,7 +303,7 @@ QtObject {
}
return 0
}
expectedRoles: ["marketDetails", "currentBalance", "symbol"]
expectedRoles: ["marketDetails", "currentBalance"]
}
]
filters: [
@ -324,12 +324,17 @@ QtObject {
},
FastExpressionFilter {
expression: {
root.walletAssetStore.assetsController.revision
if (!root.walletAssetStore.assetsController.filterAcceptsSymbol(model.symbol)) // explicitely hidden
return false
if (model.isCommunityAsset)
return true
return model.currentCurrencyBalance > processedAssetsModel.displayAssetsBelowBalanceThresholdAmount
if (tokensStore.displayAssetsBelowBalance)
return model.currentCurrencyBalance > processedAssetsModel.displayAssetsBelowBalanceThresholdAmount
return true
}
expectedRoles: ["isCommunityAsset", "currentCurrencyBalance"]
enabled: tokensStore.displayAssetsBelowBalance
expectedRoles: ["symbol", "isCommunityAsset", "currentCurrencyBalance"]
}
]
sorters: RoleSorter {

View File

@ -32,6 +32,7 @@ ColumnLayout {
property var currencyStore
property var networkConnectionStore
required property var tokensStore
property var overview
property bool assetDetailsLaunched: false
property bool filterVisible
@ -54,12 +55,19 @@ ColumnLayout {
readonly property bool isCustomView: cmbTokenOrder.currentValue === SortOrderComboBox.TokenOrderCustom
function tokenIsVisible(symbol) {
function tokenIsVisible(symbol, currentCurrencyBalance, isCommunityAsset) {
// NOTE Backend returns ETH, SNT, STT and DAI by default
if (!root.controller.filterAcceptsSymbol(symbol)) // explicitely hidden
return false
// Received tokens can have 0 balance, which indicate previosuly owned token
return true // TODO handle UI threshold (#12611)
if (isCommunityAsset)
return true
// Received tokens can have 0 balance, which indicate previously owned token
if (root.tokensStore.displayAssetsBelowBalance) {
const threshold = root.tokensStore.getDisplayAssetsBelowBalanceThresholdDisplayAmount()
if (threshold > 0)
return currentCurrencyBalance > threshold
}
return true
}
function getTotalBalance(balances, decimals, key) {
@ -89,13 +97,11 @@ ColumnLayout {
expression: {
if(!model.communityId) {
if (!!model.marketDetails) {
return model.currentBalance * model.marketDetails.currencyPrice.amount
}
return model.currentBalance * model.marketDetails.currencyPrice.amount
}
return 0
}
else {
return model.currentBalance
}
return model.currentBalance
}
expectedRoles: ["marketDetails", "communityId", "currentBalance"]
},
@ -126,9 +132,10 @@ ColumnLayout {
FastExpressionFilter {
expression: {
root.controller.revision
return d.tokenIsVisible(model.symbol)
root.tokensStore.displayAssetsBelowBalance
return d.tokenIsVisible(model.symbol, model.currentCurrencyBalance, model.isCommunityAsset)
}
expectedRoles: ["symbol"]
expectedRoles: ["symbol", "currentCurrencyBalance", "isCommunityAsset"]
}
]
sorters: [
@ -337,7 +344,7 @@ ColumnLayout {
onTriggered: root.manageTokensRequested()
}
StatusAction {
enabled: symbol !== "ETH"
enabled: symbol !== Constants.ethToken
type: StatusAction.Type.Danger
icon.name: "hide"
text: qsTr("Hide asset")

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit c7e7445f5c68ab9a9196cc3db5d3bba32292f8da
Subproject commit 296b44f9ab5a0e1d987dfb07bbb213145951f639