fix(@wallet): asset formatting
Fix asset formating and display of network only enabled
This commit is contained in:
parent
b2e26dfaa2
commit
215f9e0fa6
|
@ -8,6 +8,7 @@ type
|
|||
Address
|
||||
Balance
|
||||
CurrencyBalance
|
||||
Enabled
|
||||
|
||||
QtObject:
|
||||
type
|
||||
|
@ -47,6 +48,7 @@ QtObject:
|
|||
ModelRole.Address.int:"address",
|
||||
ModelRole.Balance.int:"balance",
|
||||
ModelRole.CurrencyBalance.int:"currencyBalance",
|
||||
ModelRole.Enabled.int:"enabled",
|
||||
}.toTable
|
||||
|
||||
method data(self: BalanceModel, index: QModelIndex, role: int): QVariant =
|
||||
|
@ -68,6 +70,8 @@ QtObject:
|
|||
result = newQVariant(item.balance)
|
||||
of ModelRole.CurrencyBalance:
|
||||
result = newQVariant(item.currencyBalance)
|
||||
of ModelRole.Enabled:
|
||||
result = newQVariant(item.enabled)
|
||||
|
||||
proc rowData(self: BalanceModel, index: int, column: string): string {.slot.} =
|
||||
if (index >= self.items.len):
|
||||
|
@ -78,6 +82,7 @@ QtObject:
|
|||
of "address": result = $item.address
|
||||
of "balance": result = $item.balance
|
||||
of "currencyBalance": result = $item.currencyBalance
|
||||
of "enabled": result = $item.enabled
|
||||
|
||||
proc setItems*(self: BalanceModel, items: seq[BalanceDto]) =
|
||||
self.beginResetModel()
|
||||
|
|
|
@ -276,7 +276,8 @@ const prepareTokensTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
|||
balance: chainBalance,
|
||||
currencyBalance: chainBalance * prices[network.nativeCurrencySymbol],
|
||||
chainId: network.chainId,
|
||||
address: "0x0000000000000000000000000000000000000000"
|
||||
address: "0x0000000000000000000000000000000000000000",
|
||||
enabled: network.enabled,
|
||||
)
|
||||
if network.enabled:
|
||||
enabledNetworkBalance.balance += balancesPerChain[network.chainId].balance
|
||||
|
@ -342,11 +343,17 @@ const prepareTokensTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
|||
for token in tokens:
|
||||
let balanceForToken = tokenBalances{address}{token.addressAsString()}.getStr
|
||||
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(
|
||||
balance: chainBalanceForToken,
|
||||
currencyBalance: chainBalanceForToken * prices[token.symbol],
|
||||
chainId: token.chainId,
|
||||
address: $token.address
|
||||
address: $token.address,
|
||||
enabled: enabled,
|
||||
)
|
||||
if isNetworkEnabledForChainId(arg.networks, token.chainId):
|
||||
visible = true
|
||||
|
|
|
@ -13,6 +13,7 @@ type BalanceDto* = object
|
|||
currencyBalance*: float64
|
||||
address*: string
|
||||
chainId*: int
|
||||
enabled*: bool
|
||||
|
||||
type
|
||||
WalletTokenDto* = object
|
||||
|
@ -107,6 +108,7 @@ proc toBalanceDto*(jsonObj: JsonNode): BalanceDto =
|
|||
discard jsonObj.getProp("currencyBalance", result.currencyBalance)
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("chainId", result.chainId)
|
||||
discard jsonObj.getProp("enabled", result.enabled)
|
||||
|
||||
proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto =
|
||||
result = WalletTokenDto()
|
||||
|
|
|
@ -77,6 +77,7 @@ Control {
|
|||
id: chainRepeater
|
||||
model: balances ? balances : null
|
||||
delegate: InformationTag {
|
||||
visible: model.enabled
|
||||
tagPrimaryLabel.text: model.balance
|
||||
tagPrimaryLabel.color: root.getNetworkColor(model.chainId)
|
||||
image.source: Style.svg("tiny/%1".arg(root.getNetworkIcon(model.chainId)))
|
||||
|
|
|
@ -43,8 +43,8 @@ Item {
|
|||
asset.name: token && token.symbol ? Style.png("tokens/%1".arg(token.symbol)) : ""
|
||||
asset.isImage: true
|
||||
primaryText: token ? token.name : ""
|
||||
secondaryText: token ? qsTr("%1 %2").arg(Utils.toLocaleString(token.totalBalance, RootStore.locale, {"currency": true})).arg(token.symbol) : ""
|
||||
tertiaryText: token ? "%1 %2".arg(Utils.toLocaleString(token.totalCurrencyBalance.toFixed(2), RootStore.locale, {"currency": true})).arg(RootStore.currencyStore.currentCurrency.toUpperCase()) : ""
|
||||
secondaryText: token ? `${token.enabledNetworkBalance} ${token.symbol}` : ""
|
||||
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
|
||||
getNetworkColor: function(chainId){
|
||||
return RootStore.getNetworkColor(chainId)
|
||||
|
|
|
@ -46,7 +46,7 @@ Item {
|
|||
objectName: "AssetView_TokenListItem_" + symbol
|
||||
width: parent.width
|
||||
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.isImage: true
|
||||
components: [
|
||||
|
|
Loading…
Reference in New Issue