fix(@wallet): token not always visible

fixes #12508
This commit is contained in:
Anthony Laibe 2023-10-23 12:03:21 +02:00
parent d7707a14a8
commit 0ba9ce9c8e
13 changed files with 7 additions and 68 deletions

View File

@ -86,7 +86,6 @@ proc walletTokenToItem*(
currencyAmountToItem(t.getCurrencyBalance(chainIds, currency), currencyFormat), currencyAmountToItem(t.getCurrencyBalance(chainIds, currency), currencyFormat),
currencyAmountToItem(t.getBalance(enabledChainIds), tokenFormat), currencyAmountToItem(t.getBalance(enabledChainIds), tokenFormat),
currencyAmountToItem(t.getCurrencyBalance(enabledChainIds, currency), currencyFormat), currencyAmountToItem(t.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
t.getVisibleForNetworkWithPositiveBalance(enabledChainIds),
t.getBalances(chainIds).map(b => balanceToItemBalanceItem(b, tokenFormat)), t.getBalances(chainIds).map(b => balanceToItemBalanceItem(b, tokenFormat)),
t.description, t.description,
t.assetWebsiteUrl, t.assetWebsiteUrl,

View File

@ -14,7 +14,6 @@ type
totalCurrencyBalance: CurrencyAmount totalCurrencyBalance: CurrencyAmount
enabledNetworkCurrencyBalance: CurrencyAmount enabledNetworkCurrencyBalance: CurrencyAmount
enabledNetworkBalance: CurrencyAmount enabledNetworkBalance: CurrencyAmount
visibleForNetworkWithPositiveBalance: bool
balances: balance_model.BalanceModel balances: balance_model.BalanceModel
description: string description: string
assetWebsiteUrl: string assetWebsiteUrl: string
@ -37,7 +36,6 @@ proc initItem*(
totalCurrencyBalance: CurrencyAmount, totalCurrencyBalance: CurrencyAmount,
enabledNetworkBalance: CurrencyAmount, enabledNetworkBalance: CurrencyAmount,
enabledNetworkCurrencyBalance: CurrencyAmount, enabledNetworkCurrencyBalance: CurrencyAmount,
visibleForNetworkWithPositiveBalance: bool,
balances: seq[balance_item.Item], balances: seq[balance_item.Item],
description: string, description: string,
assetWebsiteUrl: string, assetWebsiteUrl: string,
@ -61,7 +59,6 @@ proc initItem*(
result.totalCurrencyBalance = totalCurrencyBalance result.totalCurrencyBalance = totalCurrencyBalance
result.enabledNetworkBalance = enabledNetworkBalance result.enabledNetworkBalance = enabledNetworkBalance
result.enabledNetworkCurrencyBalance = enabledNetworkCurrencyBalance result.enabledNetworkCurrencyBalance = enabledNetworkCurrencyBalance
result.visibleForNetworkWithPositiveBalance = visibleForNetworkWithPositiveBalance
result.balances = balance_model.newModel() result.balances = balance_model.newModel()
result.balances.setItems(balances) result.balances.setItems(balances)
result.description = description result.description = description
@ -88,7 +85,6 @@ proc `$`*(self: Item): string =
totalCurrencyBalance: {self.totalCurrencyBalance}, totalCurrencyBalance: {self.totalCurrencyBalance},
enabledNetworkBalance: {self.enabledNetworkBalance}, enabledNetworkBalance: {self.enabledNetworkBalance},
enabledNetworkCurrencyBalance: {self.enabledNetworkCurrencyBalance}, enabledNetworkCurrencyBalance: {self.enabledNetworkCurrencyBalance},
visibleForNetworkWithPositiveBalance: {self.visibleForNetworkWithPositiveBalance},
description: {self.description}, description: {self.description},
assetWebsiteUrl: {self.assetWebsiteUrl} assetWebsiteUrl: {self.assetWebsiteUrl}
builtOn: {self.builtOn} builtOn: {self.builtOn}
@ -114,7 +110,6 @@ proc initLoadingItem*(): Item =
totalCurrencyBalance = newCurrencyAmount(), totalCurrencyBalance = newCurrencyAmount(),
enabledNetworkBalance = newCurrencyAmount(), enabledNetworkBalance = newCurrencyAmount(),
enabledNetworkCurrencyBalance = newCurrencyAmount(), enabledNetworkCurrencyBalance = newCurrencyAmount(),
visibleForNetworkWithPositiveBalance = false,
balances = @[], balances = @[],
description = "", description = "",
assetWebsiteUrl = "", assetWebsiteUrl = "",
@ -153,9 +148,6 @@ proc getEnabledNetworkBalance*(self: Item): CurrencyAmount =
proc getEnabledNetworkCurrencyBalance*(self: Item): CurrencyAmount = proc getEnabledNetworkCurrencyBalance*(self: Item): CurrencyAmount =
return self.enabledNetworkCurrencyBalance return self.enabledNetworkCurrencyBalance
proc getVisibleForNetworkWithPositiveBalance*(self: Item): bool =
return self.visibleForNetworkWithPositiveBalance
proc getBalances*(self: Item): balance_model.BalanceModel = proc getBalances*(self: Item): balance_model.BalanceModel =
return self.balances return self.balances

View File

@ -12,7 +12,6 @@ type
TotalCurrencyBalance TotalCurrencyBalance
EnabledNetworkCurrencyBalance EnabledNetworkCurrencyBalance
EnabledNetworkBalance EnabledNetworkBalance
VisibleForNetworkWithPositiveBalance
Balances Balances
Description Description
AssetWebsiteUrl AssetWebsiteUrl
@ -70,7 +69,6 @@ QtObject:
ModelRole.TotalCurrencyBalance.int:"totalCurrencyBalance", ModelRole.TotalCurrencyBalance.int:"totalCurrencyBalance",
ModelRole.EnabledNetworkCurrencyBalance.int:"enabledNetworkCurrencyBalance", ModelRole.EnabledNetworkCurrencyBalance.int:"enabledNetworkCurrencyBalance",
ModelRole.EnabledNetworkBalance.int:"enabledNetworkBalance", ModelRole.EnabledNetworkBalance.int:"enabledNetworkBalance",
ModelRole.VisibleForNetworkWithPositiveBalance.int:"visibleForNetworkWithPositiveBalance",
ModelRole.Balances.int:"balances", ModelRole.Balances.int:"balances",
ModelRole.Description.int:"description", ModelRole.Description.int:"description",
ModelRole.AssetWebsiteUrl.int:"assetWebsiteUrl", ModelRole.AssetWebsiteUrl.int:"assetWebsiteUrl",
@ -113,8 +111,6 @@ QtObject:
result = newQVariant(item.getEnabledNetworkCurrencyBalance()) result = newQVariant(item.getEnabledNetworkCurrencyBalance())
of ModelRole.EnabledNetworkBalance: of ModelRole.EnabledNetworkBalance:
result = newQVariant(item.getEnabledNetworkBalance()) result = newQVariant(item.getEnabledNetworkBalance())
of ModelRole.VisibleForNetworkWithPositiveBalance:
result = newQVariant(item.getVisibleForNetworkWithPositiveBalance())
of ModelRole.Balances: of ModelRole.Balances:
result = newQVariant(item.getBalances()) result = newQVariant(item.getBalances())
of ModelRole.Description: of ModelRole.Description:
@ -158,7 +154,6 @@ QtObject:
of "totalCurrencyBalance": result = $item.getTotalCurrencyBalance().toJsonNode() of "totalCurrencyBalance": result = $item.getTotalCurrencyBalance().toJsonNode()
of "enabledNetworkCurrencyBalance": result = $item.getEnabledNetworkCurrencyBalance() of "enabledNetworkCurrencyBalance": result = $item.getEnabledNetworkCurrencyBalance()
of "enabledNetworkBalance": result = $item.getEnabledNetworkBalance() of "enabledNetworkBalance": result = $item.getEnabledNetworkBalance()
of "visibleForNetworkWithPositiveBalance": result = $item.getVisibleForNetworkWithPositiveBalance()
of "description": result = $item.getDescription() of "description": result = $item.getDescription()
of "assetWebsiteUrl": result = $item.getAssetWebsiteUrl() of "assetWebsiteUrl": result = $item.getAssetWebsiteUrl()
of "builtOn": result = $item.getBuiltOn() of "builtOn": result = $item.getBuiltOn()

View File

@ -6,15 +6,6 @@ include app_service/common/json_utils
export balance_dto export balance_dto
const alwaysVisible = {
1: @["ETH", "SNT", "DAI"],
10: @["ETH", "SNT", "DAI"],
42161: @["ETH", "SNT", "DAI"],
5: @["ETH", "STT", "DAI"],
420: @["ETH", "STT", "DAI"],
421613: @["ETH", "STT", "DAI"],
}.toTable
type type
TokenMarketValuesDto* = object TokenMarketValuesDto* = object
marketCap*: float64 marketCap*: float64
@ -188,12 +179,4 @@ proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int], currency: str
sum += self.balancesPerChain[chainId].getCurrencyBalance(price) sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
return sum return sum
proc getVisibleForNetworkWithPositiveBalance*(self: WalletTokenDto, chainIds: seq[int]): bool =
for chainId in chainIds:
if alwaysVisible.hasKey(chainId) and self.symbol in alwaysVisible[chainId]:
return true
if self.balancesPerChain.hasKey(chainId) and self.balancesPerChain[chainId].balance > 0:
return true
return false

View File

@ -286,7 +286,6 @@ SplitView {
symbol: "MANA" symbol: "MANA"
}, },
changePct24hour: -2.1, changePct24hour: -2.1,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
symbol: "AAVE", symbol: "AAVE",
@ -295,7 +294,6 @@ SplitView {
symbol: "AAVE" symbol: "AAVE"
}, },
changePct24hour: 4.56, changePct24hour: 4.56,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
symbol: "POLY", symbol: "POLY",
@ -304,7 +302,6 @@ SplitView {
symbol: "POLY" symbol: "POLY"
}, },
changePct24hour: -11.6789, changePct24hour: -11.6789,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
symbol: "CDT", symbol: "CDT",
@ -313,7 +310,6 @@ SplitView {
symbol: "CDT" symbol: "CDT"
}, },
changePct24hour: 0, changePct24hour: 0,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
symbol: "MKR", symbol: "MKR",
@ -322,13 +318,11 @@ SplitView {
symbol: "MKR" symbol: "MKR"
}, },
//changePct24hour: undefined // NB 'undefined' on purpose //changePct24hour: undefined // NB 'undefined' on purpose
visibleForNetworkWithPositiveBalance: true
}, },
{ {
symbol: "InvisibleHere", symbol: "InvisibleHere",
enabledNetworkBalance: {}, enabledNetworkBalance: {},
changePct24hour: 0, changePct24hour: 0,
visibleForNetworkWithPositiveBalance: false
} }
] ]
Component.onCompleted: append(data) Component.onCompleted: append(data)

View File

@ -35,7 +35,6 @@ SplitView {
symbol: "MANA" symbol: "MANA"
}, },
changePct24hour: -2.1, changePct24hour: -2.1,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
name: "Ave Maria", name: "Ave Maria",
@ -45,7 +44,6 @@ SplitView {
symbol: "AAVE" symbol: "AAVE"
}, },
changePct24hour: 4.56, changePct24hour: 4.56,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
name: "Polymorphism", name: "Polymorphism",
@ -55,7 +53,6 @@ SplitView {
symbol: "POLY" symbol: "POLY"
}, },
changePct24hour: -11.6789, changePct24hour: -11.6789,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
name: "Common DDT", name: "Common DDT",
@ -65,7 +62,6 @@ SplitView {
symbol: "CDT" symbol: "CDT"
}, },
changePct24hour: 0, changePct24hour: 0,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
name: "Makers' choice", name: "Makers' choice",
@ -75,14 +71,12 @@ SplitView {
symbol: "MKR" symbol: "MKR"
}, },
changePct24hour: -1, changePct24hour: -1,
visibleForNetworkWithPositiveBalance: true
}, },
{ {
name: "GetOuttaHere", name: "GetOuttaHere",
symbol: "InvisibleHere", symbol: "InvisibleHere",
enabledNetworkBalance: {}, enabledNetworkBalance: {},
changePct24hour: 0, changePct24hour: 0,
visibleForNetworkWithPositiveBalance: false
} }
] ]
Component.onCompleted: append(data) Component.onCompleted: append(data)

View File

@ -16,7 +16,6 @@ ListModel {
stripTrailingZeroes: true, stripTrailingZeroes: true,
amount: 3.234 amount: 3.234
}), }),
visibleForNetworkWithPositiveBalance: true,
symbol: "ETH", symbol: "ETH",
name: "Ethereum", name: "Ethereum",
balances: [ balances: [
@ -46,7 +45,6 @@ ListModel {
stripTrailingZeroes: true, stripTrailingZeroes: true,
amount: 23333213.234 amount: 23333213.234
}), }),
visibleForNetworkWithPositiveBalance: true,
symbol: "SNT", symbol: "SNT",
name: "Status", name: "Status",
balances: [ balances: [
@ -76,7 +74,6 @@ ListModel {
stripTrailingZeroes: true, stripTrailingZeroes: true,
amount: 53333213.234 amount: 53333213.234
}), }),
visibleForNetworkWithPositiveBalance: true,
symbol: "DAI", symbol: "DAI",
name: "DAI Stablecoin", name: "DAI Stablecoin",
balances: [ balances: [

View File

@ -9,8 +9,8 @@ ProfileShowcasePanel {
settingsKey: "assets" settingsKey: "assets"
keyRole: "symbol" keyRole: "symbol"
roleNames: ["symbol", "name", "visibleForNetworkWithPositiveBalance", "enabledNetworkBalance"] roleNames: ["symbol", "name", "enabledNetworkBalance"]
filterFunc: (modelData) => modelData.visibleForNetworkWithPositiveBalance && !showcaseModel.hasItem(modelData.symbol) filterFunc: (modelData) => !showcaseModel.hasItem(modelData.symbol)
hiddenPlaceholderBanner: qsTr("Assets here will show on your profile") hiddenPlaceholderBanner: qsTr("Assets here will show on your profile")
showcasePlaceholderBanner: qsTr("Assets here will be hidden from your profile") showcasePlaceholderBanner: qsTr("Assets here will be hidden from your profile")

View File

@ -18,7 +18,6 @@ Item {
anchors.right: parent.right anchors.right: parent.right
anchors.left: parent.left anchors.left: parent.left
visible: visibleForNetworkWithPositiveBalance
height: visible ? 40 + 2 * Style.current.padding : 0 height: visible ? 40 + 2 * Style.current.padding : 0
Image { Image {

View File

@ -96,7 +96,7 @@ Item {
ExpressionFilter { ExpressionFilter {
expression: { expression: {
d.uppercaseSearchText; // Force re-evaluation when searchText changes d.uppercaseSearchText; // Force re-evaluation when searchText changes
return visibleForNetworkWithPositiveBalance && ( return (
d.uppercaseSearchText === "" || d.uppercaseSearchText === "" ||
symbol.startsWith(d.uppercaseSearchText) || symbol.startsWith(d.uppercaseSearchText) ||
name.toUpperCase().startsWith(d.uppercaseSearchText) | name.toUpperCase().startsWith(d.uppercaseSearchText) |

View File

@ -128,9 +128,9 @@ Item {
expression: { expression: {
var tokenSymbolByAddress = searchTokenSymbolByAddressFn(d.assetSearchString) var tokenSymbolByAddress = searchTokenSymbolByAddressFn(d.assetSearchString)
tokenList.positionViewAtBeginning() tokenList.positionViewAtBeginning()
return visibleForNetworkWithPositiveBalance && ( return (
symbol.startsWith(d.assetSearchString.toUpperCase()) || name.toUpperCase().startsWith(d.assetSearchString.toUpperCase()) || (tokenSymbolByAddress!=="" && symbol.startsWith(tokenSymbolByAddress)) symbol.startsWith(d.assetSearchString.toUpperCase()) || name.toUpperCase().startsWith(d.assetSearchString.toUpperCase()) || (tokenSymbolByAddress!=="" && symbol.startsWith(tokenSymbolByAddress))
) )
} }
} }
] ]

View File

@ -33,21 +33,11 @@ Item {
id: assetListView id: assetListView
objectName: "assetViewStatusListView" objectName: "assetViewStatusListView"
anchors.fill: parent anchors.fill: parent
model: filteredModel model: !!assets ? assets : null
reuseItems: true reuseItems: true
delegate: delegateLoader delegate: delegateLoader
} }
SortFilterProxyModel {
id: filteredModel
sourceModel: !!assets ? assets : null
filters: [
ExpressionFilter {
expression: visibleForNetworkWithPositiveBalance || loading
}
]
}
Component { Component {
id: delegateLoader id: delegateLoader
Loader { Loader {

View File

@ -338,10 +338,6 @@ Control {
model: SortFilterProxyModel { model: SortFilterProxyModel {
// TODO show assets for all accounts, not just the current one? // TODO show assets for all accounts, not just the current one?
sourceModel: root.isCurrentUser ? root.walletStore.assets : null // TODO show other users too sourceModel: root.isCurrentUser ? root.walletStore.assets : null // TODO show other users too
filters: ValueFilter {
roleName: "visibleForNetworkWithPositiveBalance"
value: true
}
sorters: [ sorters: [
StringSorter { StringSorter {
roleName: "name" roleName: "name"