From 8fd5e9d1afc011b520e14b6e6523afac0ab2245d Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Fri, 2 Dec 2022 15:14:50 -0300 Subject: [PATCH] fix(@desktop/wallet): fix wallet account item balances Fixes: #8582 --- .../main/wallet_section/accounts/module.nim | 4 ++-- .../service/wallet_account/dto.nim | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/app/modules/main/wallet_section/accounts/module.nim b/src/app/modules/main/wallet_section/accounts/module.nim index f7b339e875..3b36c0c9fd 100644 --- a/src/app/modules/main/wallet_section/accounts/module.nim +++ b/src/app/modules/main/wallet_section/accounts/module.nim @@ -113,7 +113,7 @@ method refreshWalletAccounts*(self: Module) = x.walletType, x.isWallet, x.isChat, - x.getBalance(enabledChainIds), + x.getCurrencyBalance(enabledChainIds), x.emoji, x.derivedfrom, )) @@ -128,7 +128,7 @@ method refreshWalletAccounts*(self: Module) = w.walletType, w.isWallet, w.isChat, - w.getBalance(enabledChainIds), + w.getCurrencyBalance(enabledChainIds), assets, w.emoji, w.derivedfrom, diff --git a/src/app_service/service/wallet_account/dto.nim b/src/app_service/service/wallet_account/dto.nim index 3722001f91..02f6199ba2 100644 --- a/src/app_service/service/wallet_account/dto.nim +++ b/src/app_service/service/wallet_account/dto.nim @@ -114,6 +114,14 @@ proc getBalances*(self: WalletTokenDto, chainIds: seq[int]): seq[BalanceDto] = if self.balancesPerChain.hasKey(chainId): result.add(self.balancesPerChain[chainId]) +proc getBalance*(self: WalletTokenDto, chainIds: seq[int]): float64 = + var sum = 0.0 + for chainId in chainIds: + if self.balancesPerChain.hasKey(chainId): + sum += self.balancesPerChain[chainId].balance + + return sum + proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int]): float64 = var sum = 0.0 for chainId in chainIds: @@ -135,17 +143,6 @@ proc getVisible*(self: WalletTokenDto, chainIds: seq[int]): bool = proc getCurrencyBalance*(self: WalletAccountDto, chainIds: seq[int]): float64 = return self.tokens.map(t => t.getCurrencyBalance(chainIds)).foldl(a + b, 0.0) -proc getBalance*(self: WalletTokenDto, chainIds: seq[int]): float64 = - var sum = 0.0 - for chainId in chainIds: - if self.balancesPerChain.hasKey(chainId): - sum += self.balancesPerChain[chainId].balance - - return sum - -proc getBalance*(self: WalletAccountDto, chainIds: seq[int]): float64 = - return self.tokens.map(t => t.getBalance(chainIds)).foldl(a + b, 0.0) - proc toBalanceDto*(jsonObj: JsonNode): BalanceDto = result = BalanceDto() result.balance = jsonObj{"balance"}.getStr.parseFloat()