fix(@wallet): display currency price rather than 24h change

fixes #7268
This commit is contained in:
Anthony Laibe 2022-09-09 10:13:04 +02:00 committed by Anthony Laibe
parent b782cd1c93
commit 81300b655f
9 changed files with 23 additions and 3 deletions

View File

@ -61,6 +61,7 @@ proc setAssets(self: Module, tokens: seq[WalletTokenDto]) =
t.changePctDay,
t.changePct24hour,
t.change24hour,
t.currencyPrice,
)
items.add(item)

View File

@ -65,6 +65,7 @@ method refreshWalletAccounts*(self: Module) =
t.changePctDay,
t.changePct24hour,
t.change24hour,
t.currencyPrice,
))
)

View File

@ -92,6 +92,7 @@ proc setAssetsAndBalance(self: Module, tokens: seq[WalletTokenDto]) =
t.changePctDay,
t.changePct24hour,
t.change24hour,
t.currencyPrice,
)
items.add(item)
totalCurrencyBalanceForAllAssets += t.enabledNetworkBalance.currencybalance

View File

@ -24,6 +24,7 @@ type
changePctDay: string
changePct24hour: string
change24hour: string
currencyPrice: float
proc initItem*(
name, symbol: string,
@ -44,6 +45,7 @@ proc initItem*(
changePctDay: string,
changePct24hour: string,
change24hour: string,
currencyPrice: float
): Item =
result.name = name
result.symbol = symbol
@ -65,6 +67,7 @@ proc initItem*(
result.changePctDay = changePctDay
result.changePct24hour = changePct24hour
result.change24hour = change24hour
result.currencyPrice = currencyPrice
proc `$`*(self: Item): string =
result = fmt"""AllTokensItem(
@ -86,6 +89,7 @@ proc `$`*(self: Item): string =
changePctDay: {self.changePctDay},
changePct24hour: {self.changePct24hour},
change24hour: {self.change24hour},
currencyPrice: {self.currencyPrice},
]"""
proc getName*(self: Item): string =
@ -144,3 +148,6 @@ proc getChangePct24hour*(self: Item): string =
proc getChange24hour*(self: Item): string =
return self.change24hour
proc getCurrencyPrice*(self: Item): float =
return self.currencyPrice

View File

@ -23,6 +23,7 @@ type
ChangePctDay
ChangePct24hour
Change24hour
CurrencyPrice
QtObject:
type
@ -77,6 +78,7 @@ QtObject:
ModelRole.ChangePctDay.int:"changePctDay",
ModelRole.ChangePct24hour.int:"changePct24hour",
ModelRole.Change24hour.int:"change24hour",
ModelRole.CurrencyPrice.int:"currencyPrice",
}.toTable
method data(self: Model, index: QModelIndex, role: int): QVariant =
@ -128,6 +130,8 @@ QtObject:
result = newQVariant(item.getChangePct24hour())
of ModelRole.Change24hour:
result = newQVariant(item.getChange24hour())
of ModelRole.CurrencyPrice:
result = newQVariant(item.getCurrencyPrice())
proc rowData(self: Model, index: int, column: string): string {.slot.} =
if (index >= self.items.len):
@ -152,6 +156,7 @@ QtObject:
of "changePctDay": result = $item.getChangePctDay()
of "changePct24hour": result = $item.getChangePct24hour()
of "change24hour": result = $item.getChange24hour()
of "currencyPrice": result = $item.getCurrencyPrice()
proc setItems*(self: Model, items: seq[Item]) =
self.beginResetModel()

View File

@ -325,6 +325,7 @@ const prepareTokensTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
changePctDay: changePctDay,
changePct24hour: changePct24hour,
change24hour: change24hour,
currencyPrice: prices[networkDto.nativeCurrencySymbol],
)
)
@ -406,6 +407,7 @@ const prepareTokensTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
changePctDay: changePctDay,
changePct24hour: changePct24hour,
change24hour: change24hour,
currencyPrice: prices[tokenDto.symbol],
)
)

View File

@ -37,6 +37,7 @@ type
changePctDay*: string
changePct24hour*: string
change24hour*: string
currencyPrice*: float64
type
WalletAccountDto* = ref object of RootObj
@ -125,6 +126,7 @@ proc toWalletTokenDto*(jsonObj: JsonNode): WalletTokenDto =
discard jsonObj.getProp("changePctDay", result.changePctDay)
discard jsonObj.getProp("changePct24hour", result.changePct24hour)
discard jsonObj.getProp("change24hour", result.change24hour)
discard jsonObj.getProp("currencyPrice", result.currencyPrice)
var totalBalanceObj: JsonNode
if(jsonObj.getProp("totalBalance", totalBalanceObj)):
@ -165,5 +167,6 @@ proc walletTokenDtoToJson*(dto: WalletTokenDto): JsonNode =
"changePctHour": dto.changePctHour,
"changePctDay": dto.changePctDay,
"changePct24hour": dto.changePct24hour,
"change24hour": dto.change24hour
"change24hour": dto.change24hour,
"currencyPrice": dto.currencyPrice,
}

View File

@ -408,7 +408,7 @@ QtObject:
var tokens: seq[WalletTokenDto]
if(responseObj.getProp(wAddress, tokensArr)):
tokens = map(tokensArr.getElems(), proc(x: JsonNode): WalletTokenDto = x.toWalletTokenDto())
tokens.sort(priorityTokenCmp)
self.walletAccounts[wAddress].tokens = tokens
data.accountsTokens[wAddress] = tokens

View File

@ -69,7 +69,7 @@ Item {
font.pixelSize: 15
font.strikeout: false
color: valueColumn.textColor
text: change24hour !== "" ? change24hour : "---"
text: currencyPrice.toLocaleCurrencyString(Qt.locale(), RootStore.currencyStore.currentCurrencySymbol)
}
Rectangle {
width: 1