fix(@wallet): fix token list

there is 2 type of token list, the whole list for send modal and the
list for asset view
This commit is contained in:
Anthony Laibe 2022-12-06 10:49:57 +01:00 committed by Anthony Laibe
parent 9391cabcba
commit f7704c719a
10 changed files with 41 additions and 19 deletions

View File

@ -53,7 +53,8 @@ proc setAssets(self: Module, tokens: seq[WalletTokenDto]) =
t.getCurrencyBalance(chainIds), t.getCurrencyBalance(chainIds),
t.getBalance(enabledChainIds), t.getBalance(enabledChainIds),
t.getCurrencyBalance(enabledChainIds), t.getCurrencyBalance(enabledChainIds),
t.getVisible(enabledChainIds), t.getVisibleForNetwork(enabledChainIds),
t.getVisibleForNetworkWithPositiveBalance(enabledChainIds),
t.getBalances(enabledChainIds), t.getBalances(enabledChainIds),
t.description, t.description,
t.assetWebsiteUrl, t.assetWebsiteUrl,

View File

@ -84,7 +84,8 @@ method refreshWalletAccounts*(self: Module) =
t.getCurrencyBalance(chainIds), t.getCurrencyBalance(chainIds),
t.getBalance(enabledChainIds), t.getBalance(enabledChainIds),
t.getCurrencyBalance(enabledChainIds), t.getCurrencyBalance(enabledChainIds),
t.getVisible(enabledChainIds), t.getVisibleForNetwork(enabledChainIds),
t.getVisibleForNetworkWithPositiveBalance(enabledChainIds),
t.getBalances(enabledChainIds), t.getBalances(enabledChainIds),
t.description, t.description,
t.assetWebsiteUrl, t.assetWebsiteUrl,

View File

@ -84,7 +84,8 @@ proc setAssetsAndBalance(self: Module, tokens: seq[WalletTokenDto]) =
t.getCurrencyBalance(chainIds), t.getCurrencyBalance(chainIds),
t.getBalance(enabledChainIds), t.getBalance(enabledChainIds),
t.getCurrencyBalance(enabledChainIds), t.getCurrencyBalance(enabledChainIds),
t.getVisible(enabledChainIds), t.getVisibleForNetwork(enabledChainIds),
t.getVisibleForNetworkWithPositiveBalance(enabledChainIds),
t.getBalances(enabledChainIds), t.getBalances(enabledChainIds),
t.description, t.description,
t.assetWebsiteUrl, t.assetWebsiteUrl,

View File

@ -11,7 +11,8 @@ type
totalCurrencyBalance: float totalCurrencyBalance: float
enabledNetworkCurrencyBalance: float enabledNetworkCurrencyBalance: float
enabledNetworkBalance: float enabledNetworkBalance: float
networkVisible: bool visibleForNetwork: bool
visibleForNetworkWithPositiveBalance: bool
balances: balance_model.BalanceModel balances: balance_model.BalanceModel
description: string description: string
assetWebsiteUrl: string assetWebsiteUrl: string
@ -33,7 +34,8 @@ proc initItem*(
totalCurrencyBalance: float, totalCurrencyBalance: float,
enabledNetworkBalance: float, enabledNetworkBalance: float,
enabledNetworkCurrencyBalance: float, enabledNetworkCurrencyBalance: float,
networkVisible: bool, visibleForNetwork: bool,
visibleForNetworkWithPositiveBalance: bool,
balances: seq[BalanceDto], balances: seq[BalanceDto],
description: string, description: string,
assetWebsiteUrl: string, assetWebsiteUrl: string,
@ -55,7 +57,8 @@ proc initItem*(
result.totalCurrencyBalance = totalCurrencyBalance result.totalCurrencyBalance = totalCurrencyBalance
result.enabledNetworkBalance = enabledNetworkBalance result.enabledNetworkBalance = enabledNetworkBalance
result.enabledNetworkCurrencyBalance = enabledNetworkCurrencyBalance result.enabledNetworkCurrencyBalance = enabledNetworkCurrencyBalance
result.networkVisible = networkVisible result.visibleForNetwork = visibleForNetwork
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
@ -80,7 +83,8 @@ proc `$`*(self: Item): string =
totalCurrencyBalance: {self.totalCurrencyBalance}, totalCurrencyBalance: {self.totalCurrencyBalance},
enabledNetworkBalance: {self.enabledNetworkBalance}, enabledNetworkBalance: {self.enabledNetworkBalance},
enabledNetworkCurrencyBalance: {self.enabledNetworkCurrencyBalance}, enabledNetworkCurrencyBalance: {self.enabledNetworkCurrencyBalance},
networkVisible: {self.networkVisible}, visibleForNetworkWithPositiveBalance: {self.visibleForNetworkWithPositiveBalance},
visibleForNetwork: {self.visibleForNetwork},
description: {self.description}, description: {self.description},
assetWebsiteUrl: {self.assetWebsiteUrl} assetWebsiteUrl: {self.assetWebsiteUrl}
builtOn: {self.builtOn} builtOn: {self.builtOn}
@ -114,8 +118,11 @@ proc getEnabledNetworkBalance*(self: Item): float =
proc getEnabledNetworkCurrencyBalance*(self: Item): float = proc getEnabledNetworkCurrencyBalance*(self: Item): float =
return self.enabledNetworkCurrencyBalance return self.enabledNetworkCurrencyBalance
proc getNetworkVisible*(self: Item): bool = proc getVisibleForNetwork*(self: Item): bool =
return self.networkVisible return self.visibleForNetwork
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

@ -10,7 +10,8 @@ type
TotalCurrencyBalance TotalCurrencyBalance
EnabledNetworkCurrencyBalance EnabledNetworkCurrencyBalance
EnabledNetworkBalance EnabledNetworkBalance
NetworkVisible VisibleForNetwork
VisibleForNetworkWithPositiveBalance
Balances Balances
Description Description
AssetWebsiteUrl AssetWebsiteUrl
@ -66,7 +67,8 @@ 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.NetworkVisible.int:"networkVisible", ModelRole.VisibleForNetwork.int:"visibleForNetwork",
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",
@ -106,8 +108,10 @@ 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.NetworkVisible: of ModelRole.VisibleForNetwork:
result = newQVariant(item.getNetworkVisible()) result = newQVariant(item.getVisibleForNetwork())
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:
@ -148,7 +152,8 @@ QtObject:
of "totalCurrencyBalance": result = $item.getTotalCurrencyBalance() of "totalCurrencyBalance": result = $item.getTotalCurrencyBalance()
of "enabledNetworkCurrencyBalance": result = $item.getEnabledNetworkCurrencyBalance() of "enabledNetworkCurrencyBalance": result = $item.getEnabledNetworkCurrencyBalance()
of "enabledNetworkBalance": result = $item.getEnabledNetworkBalance() of "enabledNetworkBalance": result = $item.getEnabledNetworkBalance()
of "networkVisible": result = $item.getNetworkVisible() of "visibleForNetwork": result = $item.getVisibleForNetwork()
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

@ -130,7 +130,14 @@ proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int]): float64 =
return sum return sum
proc getVisible*(self: WalletTokenDto, chainIds: seq[int]): bool = proc getVisibleForNetwork*(self: WalletTokenDto, chainIds: seq[int]): bool =
for chainId in chainIds:
if self.balancesPerChain.hasKey(chainId):
return true
return false
proc getVisibleForNetworkWithPositiveBalance*(self: WalletTokenDto, chainIds: seq[int]): bool =
for chainId in chainIds: for chainId in chainIds:
if alwaysVisible.hasKey(chainId) and self.symbol in alwaysVisible[chainId]: if alwaysVisible.hasKey(chainId) and self.symbol in alwaysVisible[chainId]:
return true return true

View File

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

View File

@ -76,7 +76,7 @@ Item {
ExpressionFilter { ExpressionFilter {
expression: { expression: {
var tokenSymbolByAddress = searchTokenSymbolByAddressFn(d.searchString) var tokenSymbolByAddress = searchTokenSymbolByAddressFn(d.searchString)
return networkVisible && ( return visibleForNetwork && (
symbol.startsWith(d.searchString.toUpperCase()) || name.toUpperCase().startsWith(d.searchString.toUpperCase()) || (tokenSymbolByAddress!=="" && symbol.startsWith(tokenSymbolByAddress)) symbol.startsWith(d.searchString.toUpperCase()) || name.toUpperCase().startsWith(d.searchString.toUpperCase()) || (tokenSymbolByAddress!=="" && symbol.startsWith(tokenSymbolByAddress))
) )
} }

View File

@ -36,7 +36,7 @@ Item {
sourceModel: account.assets sourceModel: account.assets
filters: [ filters: [
ExpressionFilter { ExpressionFilter {
expression: networkVisible expression: visibleForNetworkWithPositiveBalance
} }
] ]
} }

View File

@ -45,7 +45,7 @@ Rectangle {
ExpressionFilter { ExpressionFilter {
expression: { expression: {
var tokenSymbolByAddress = searchTokenSymbolByAddressFn(d.searchString) var tokenSymbolByAddress = searchTokenSymbolByAddressFn(d.searchString)
return networkVisible && ( return visibleForNetwork && (
symbol.startsWith(d.searchString.toUpperCase()) || name.toUpperCase().startsWith(d.searchString.toUpperCase()) || (tokenSymbolByAddress!=="" && symbol.startsWith(tokenSymbolByAddress)) symbol.startsWith(d.searchString.toUpperCase()) || name.toUpperCase().startsWith(d.searchString.toUpperCase()) || (tokenSymbolByAddress!=="" && symbol.startsWith(tokenSymbolByAddress))
) )
} }