fix(@wallet): asset formatting

Fix asset formating and display of network only enabled
This commit is contained in:
Anthony Laibe 2022-09-15 09:49:15 +02:00 committed by Anthony Laibe
parent b2e26dfaa2
commit 215f9e0fa6
6 changed files with 20 additions and 5 deletions

View File

@ -8,6 +8,7 @@ type
Address Address
Balance Balance
CurrencyBalance CurrencyBalance
Enabled
QtObject: QtObject:
type type
@ -47,6 +48,7 @@ QtObject:
ModelRole.Address.int:"address", ModelRole.Address.int:"address",
ModelRole.Balance.int:"balance", ModelRole.Balance.int:"balance",
ModelRole.CurrencyBalance.int:"currencyBalance", ModelRole.CurrencyBalance.int:"currencyBalance",
ModelRole.Enabled.int:"enabled",
}.toTable }.toTable
method data(self: BalanceModel, index: QModelIndex, role: int): QVariant = method data(self: BalanceModel, index: QModelIndex, role: int): QVariant =
@ -68,6 +70,8 @@ QtObject:
result = newQVariant(item.balance) result = newQVariant(item.balance)
of ModelRole.CurrencyBalance: of ModelRole.CurrencyBalance:
result = newQVariant(item.currencyBalance) result = newQVariant(item.currencyBalance)
of ModelRole.Enabled:
result = newQVariant(item.enabled)
proc rowData(self: BalanceModel, index: int, column: string): string {.slot.} = proc rowData(self: BalanceModel, index: int, column: string): string {.slot.} =
if (index >= self.items.len): if (index >= self.items.len):
@ -78,6 +82,7 @@ QtObject:
of "address": result = $item.address of "address": result = $item.address
of "balance": result = $item.balance of "balance": result = $item.balance
of "currencyBalance": result = $item.currencyBalance of "currencyBalance": result = $item.currencyBalance
of "enabled": result = $item.enabled
proc setItems*(self: BalanceModel, items: seq[BalanceDto]) = proc setItems*(self: BalanceModel, items: seq[BalanceDto]) =
self.beginResetModel() self.beginResetModel()

View File

@ -276,7 +276,8 @@ const prepareTokensTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
balance: chainBalance, balance: chainBalance,
currencyBalance: chainBalance * prices[network.nativeCurrencySymbol], currencyBalance: chainBalance * prices[network.nativeCurrencySymbol],
chainId: network.chainId, chainId: network.chainId,
address: "0x0000000000000000000000000000000000000000" address: "0x0000000000000000000000000000000000000000",
enabled: network.enabled,
) )
if network.enabled: if network.enabled:
enabledNetworkBalance.balance += balancesPerChain[network.chainId].balance enabledNetworkBalance.balance += balancesPerChain[network.chainId].balance
@ -342,11 +343,17 @@ const prepareTokensTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
for token in tokens: for token in tokens:
let balanceForToken = tokenBalances{address}{token.addressAsString()}.getStr let balanceForToken = tokenBalances{address}{token.addressAsString()}.getStr
let chainBalanceForToken = parsefloat(hex2Balance(balanceForToken, token.decimals)) let chainBalanceForToken = parsefloat(hex2Balance(balanceForToken, token.decimals))
var enabled = false
for network in arg.networks:
if network.chainId == token.chainId:
enabled = true
balancesPerChain[token.chainId] = BalanceDto( balancesPerChain[token.chainId] = BalanceDto(
balance: chainBalanceForToken, balance: chainBalanceForToken,
currencyBalance: chainBalanceForToken * prices[token.symbol], currencyBalance: chainBalanceForToken * prices[token.symbol],
chainId: token.chainId, chainId: token.chainId,
address: $token.address address: $token.address,
enabled: enabled,
) )
if isNetworkEnabledForChainId(arg.networks, token.chainId): if isNetworkEnabledForChainId(arg.networks, token.chainId):
visible = true visible = true

View File

@ -13,6 +13,7 @@ type BalanceDto* = object
currencyBalance*: float64 currencyBalance*: float64
address*: string address*: string
chainId*: int chainId*: int
enabled*: bool
type type
WalletTokenDto* = object WalletTokenDto* = object
@ -107,6 +108,7 @@ proc toBalanceDto*(jsonObj: JsonNode): BalanceDto =
discard jsonObj.getProp("currencyBalance", result.currencyBalance) discard jsonObj.getProp("currencyBalance", result.currencyBalance)
discard jsonObj.getProp("address", result.address) discard jsonObj.getProp("address", result.address)
discard jsonObj.getProp("chainId", result.chainId) discard jsonObj.getProp("chainId", result.chainId)
discard jsonObj.getProp("enabled", result.enabled)
proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto = proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto =
result = WalletTokenDto() result = WalletTokenDto()

View File

@ -77,6 +77,7 @@ Control {
id: chainRepeater id: chainRepeater
model: balances ? balances : null model: balances ? balances : null
delegate: InformationTag { delegate: InformationTag {
visible: model.enabled
tagPrimaryLabel.text: model.balance tagPrimaryLabel.text: model.balance
tagPrimaryLabel.color: root.getNetworkColor(model.chainId) tagPrimaryLabel.color: root.getNetworkColor(model.chainId)
image.source: Style.svg("tiny/%1".arg(root.getNetworkIcon(model.chainId))) image.source: Style.svg("tiny/%1".arg(root.getNetworkIcon(model.chainId)))

View File

@ -43,8 +43,8 @@ Item {
asset.name: token && token.symbol ? Style.png("tokens/%1".arg(token.symbol)) : "" asset.name: token && token.symbol ? Style.png("tokens/%1".arg(token.symbol)) : ""
asset.isImage: true asset.isImage: true
primaryText: token ? token.name : "" primaryText: token ? token.name : ""
secondaryText: token ? qsTr("%1 %2").arg(Utils.toLocaleString(token.totalBalance, RootStore.locale, {"currency": true})).arg(token.symbol) : "" secondaryText: token ? `${token.enabledNetworkBalance} ${token.symbol}` : ""
tertiaryText: token ? "%1 %2".arg(Utils.toLocaleString(token.totalCurrencyBalance.toFixed(2), RootStore.locale, {"currency": true})).arg(RootStore.currencyStore.currentCurrency.toUpperCase()) : "" tertiaryText: token ? "%1 %2".arg(Utils.toLocaleString(token.enabledNetworkCurrencyBalance.toFixed(2), RootStore.locale, {"currency": true})).arg(RootStore.currencyStore.currentCurrency.toUpperCase()) : ""
balances: token && token.balances ? token.balances : null balances: token && token.balances ? token.balances : null
getNetworkColor: function(chainId){ getNetworkColor: function(chainId){
return RootStore.getNetworkColor(chainId) return RootStore.getNetworkColor(chainId)

View File

@ -46,7 +46,7 @@ Item {
objectName: "AssetView_TokenListItem_" + symbol objectName: "AssetView_TokenListItem_" + symbol
width: parent.width width: parent.width
title: name title: name
subTitle: qsTr("%1 %2").arg(Utils.toLocaleString(enabledNetworkBalance, RootStore.locale, {"currency": true})).arg(symbol) subTitle: `${enabledNetworkBalance} ${symbol}`
asset.name: symbol ? Style.png("tokens/" + symbol) : "" asset.name: symbol ? Style.png("tokens/" + symbol) : ""
asset.isImage: true asset.isImage: true
components: [ components: [