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.getBalance(enabledChainIds), tokenFormat),
currencyAmountToItem(t.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
t.getVisibleForNetworkWithPositiveBalance(enabledChainIds),
t.getBalances(chainIds).map(b => balanceToItemBalanceItem(b, tokenFormat)),
t.description,
t.assetWebsiteUrl,

View File

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

View File

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

View File

@ -6,15 +6,6 @@ include app_service/common/json_utils
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
TokenMarketValuesDto* = object
marketCap*: float64
@ -188,12 +179,4 @@ proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int], currency: str
sum += self.balancesPerChain[chainId].getCurrencyBalance(price)
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"
},
changePct24hour: -2.1,
visibleForNetworkWithPositiveBalance: true
},
{
symbol: "AAVE",
@ -295,7 +294,6 @@ SplitView {
symbol: "AAVE"
},
changePct24hour: 4.56,
visibleForNetworkWithPositiveBalance: true
},
{
symbol: "POLY",
@ -304,7 +302,6 @@ SplitView {
symbol: "POLY"
},
changePct24hour: -11.6789,
visibleForNetworkWithPositiveBalance: true
},
{
symbol: "CDT",
@ -313,7 +310,6 @@ SplitView {
symbol: "CDT"
},
changePct24hour: 0,
visibleForNetworkWithPositiveBalance: true
},
{
symbol: "MKR",
@ -322,13 +318,11 @@ SplitView {
symbol: "MKR"
},
//changePct24hour: undefined // NB 'undefined' on purpose
visibleForNetworkWithPositiveBalance: true
},
{
symbol: "InvisibleHere",
enabledNetworkBalance: {},
changePct24hour: 0,
visibleForNetworkWithPositiveBalance: false
}
]
Component.onCompleted: append(data)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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