fix(@desktop/wallet): fix wallet account item balances

Fixes: #8582
This commit is contained in:
Dario Gabriel Lipicar 2022-12-02 15:14:50 -03:00 committed by dlipicar
parent 0c7442d696
commit 8fd5e9d1af
2 changed files with 10 additions and 13 deletions

View File

@ -113,7 +113,7 @@ method refreshWalletAccounts*(self: Module) =
x.walletType, x.walletType,
x.isWallet, x.isWallet,
x.isChat, x.isChat,
x.getBalance(enabledChainIds), x.getCurrencyBalance(enabledChainIds),
x.emoji, x.emoji,
x.derivedfrom, x.derivedfrom,
)) ))
@ -128,7 +128,7 @@ method refreshWalletAccounts*(self: Module) =
w.walletType, w.walletType,
w.isWallet, w.isWallet,
w.isChat, w.isChat,
w.getBalance(enabledChainIds), w.getCurrencyBalance(enabledChainIds),
assets, assets,
w.emoji, w.emoji,
w.derivedfrom, w.derivedfrom,

View File

@ -114,6 +114,14 @@ proc getBalances*(self: WalletTokenDto, chainIds: seq[int]): seq[BalanceDto] =
if self.balancesPerChain.hasKey(chainId): if self.balancesPerChain.hasKey(chainId):
result.add(self.balancesPerChain[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 = proc getCurrencyBalance*(self: WalletTokenDto, chainIds: seq[int]): float64 =
var sum = 0.0 var sum = 0.0
for chainId in chainIds: for chainId in chainIds:
@ -135,17 +143,6 @@ proc getVisible*(self: WalletTokenDto, chainIds: seq[int]): bool =
proc getCurrencyBalance*(self: WalletAccountDto, chainIds: seq[int]): float64 = proc getCurrencyBalance*(self: WalletAccountDto, chainIds: seq[int]): float64 =
return self.tokens.map(t => t.getCurrencyBalance(chainIds)).foldl(a + b, 0.0) 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 = proc toBalanceDto*(jsonObj: JsonNode): BalanceDto =
result = BalanceDto() result = BalanceDto()
result.balance = jsonObj{"balance"}.getStr.parseFloat() result.balance = jsonObj{"balance"}.getStr.parseFloat()