From 81300b655f2160b1b10790a90a0c645fd240926d Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Fri, 9 Sep 2022 10:13:04 +0200 Subject: [PATCH] fix(@wallet): display currency price rather than 24h change fixes #7268 --- .../main/browser_section/current_account/module.nim | 1 + src/app/modules/main/wallet_section/accounts/module.nim | 1 + .../modules/main/wallet_section/current_account/module.nim | 1 + src/app/modules/shared_models/token_item.nim | 7 +++++++ src/app/modules/shared_models/token_model.nim | 5 +++++ src/app_service/service/wallet_account/async_tasks.nim | 2 ++ src/app_service/service/wallet_account/dto.nim | 5 ++++- src/app_service/service/wallet_account/service.nim | 2 +- ui/imports/shared/views/AssetsView.qml | 2 +- 9 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/app/modules/main/browser_section/current_account/module.nim b/src/app/modules/main/browser_section/current_account/module.nim index a114df3a52..ce37015bb3 100644 --- a/src/app/modules/main/browser_section/current_account/module.nim +++ b/src/app/modules/main/browser_section/current_account/module.nim @@ -61,6 +61,7 @@ proc setAssets(self: Module, tokens: seq[WalletTokenDto]) = t.changePctDay, t.changePct24hour, t.change24hour, + t.currencyPrice, ) items.add(item) diff --git a/src/app/modules/main/wallet_section/accounts/module.nim b/src/app/modules/main/wallet_section/accounts/module.nim index 2d385a9f69..2eccbee1bc 100644 --- a/src/app/modules/main/wallet_section/accounts/module.nim +++ b/src/app/modules/main/wallet_section/accounts/module.nim @@ -65,6 +65,7 @@ method refreshWalletAccounts*(self: Module) = t.changePctDay, t.changePct24hour, t.change24hour, + t.currencyPrice, )) ) diff --git a/src/app/modules/main/wallet_section/current_account/module.nim b/src/app/modules/main/wallet_section/current_account/module.nim index ceff3221a4..92fdee5413 100644 --- a/src/app/modules/main/wallet_section/current_account/module.nim +++ b/src/app/modules/main/wallet_section/current_account/module.nim @@ -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 diff --git a/src/app/modules/shared_models/token_item.nim b/src/app/modules/shared_models/token_item.nim index f42b5f4e88..e59d83f8e6 100644 --- a/src/app/modules/shared_models/token_item.nim +++ b/src/app/modules/shared_models/token_item.nim @@ -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 diff --git a/src/app/modules/shared_models/token_model.nim b/src/app/modules/shared_models/token_model.nim index c575ab18f3..718a8d1fe5 100644 --- a/src/app/modules/shared_models/token_model.nim +++ b/src/app/modules/shared_models/token_model.nim @@ -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() diff --git a/src/app_service/service/wallet_account/async_tasks.nim b/src/app_service/service/wallet_account/async_tasks.nim index 50d08f7e7c..2ef0cf3238 100644 --- a/src/app_service/service/wallet_account/async_tasks.nim +++ b/src/app_service/service/wallet_account/async_tasks.nim @@ -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], ) ) diff --git a/src/app_service/service/wallet_account/dto.nim b/src/app_service/service/wallet_account/dto.nim index 145eea6d08..bf4925fc5f 100644 --- a/src/app_service/service/wallet_account/dto.nim +++ b/src/app_service/service/wallet_account/dto.nim @@ -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, } diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index b4543adb7c..2ebd18d0ec 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -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 diff --git a/ui/imports/shared/views/AssetsView.qml b/ui/imports/shared/views/AssetsView.qml index 03ca0f9d69..2361bf34e3 100644 --- a/ui/imports/shared/views/AssetsView.qml +++ b/ui/imports/shared/views/AssetsView.qml @@ -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