diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index ce2e0ebbed..1efd74e948 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -150,11 +150,11 @@ QtObject: self.accountListChanged() proc getFiatValue*(self: WalletView, cryptoBalance: string, cryptoSymbol: string, fiatSymbol: string): string {.slot.} = - let val = self.status.wallet.getFiatValue(cryptoBalance, cryptoSymbol, fiatSymbol) + let val = self.status.wallet.convertValue(cryptoBalance, cryptoSymbol, fiatSymbol) result = fmt"{val:.2f}" proc getCryptoValue*(self: WalletView, fiatBalance: string, fiatSymbol: string, cryptoSymbol: string): string {.slot.} = - result = fmt"{self.status.wallet.getFiatValue(fiatBalance, fiatSymbol, cryptoSymbol)}" + result = fmt"{self.status.wallet.convertValue(fiatBalance, fiatSymbol, cryptoSymbol)}" proc generateNewAccount*(self: WalletView, password: string, accountName: string, color: string): string {.slot.} = result = self.status.wallet.generateNewAccount(password, accountName, color) diff --git a/src/status/wallet.nim b/src/status/wallet.nim index 0df61a4293..722458caa5 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -95,8 +95,8 @@ proc getTotalFiatBalance*(self: WalletModel): string = var newBalance = 0.0 fmt"{self.totalBalance:.2f} {self.defaultCurrency}" -proc getFiatValue*(self: WalletModel, cryptoBalance: string, cryptoSymbol: string, fiatSymbol: string): float = - result = getFiatValue(cryptoBalance, cryptoSymbol, fiatSymbol) +proc convertValue*(self: WalletModel, balance: string, fromCurrency: string, toCurrency: string): float = + result = convertValue(balance, fromCurrency, toCurrency) proc calculateTotalFiatBalance*(self: WalletModel) = self.totalBalance = 0.0 diff --git a/src/status/wallet/balance_manager.nim b/src/status/wallet/balance_manager.nim index c1b997197e..b7b9d1ff53 100644 --- a/src/status/wallet/balance_manager.nim +++ b/src/status/wallet/balance_manager.nim @@ -49,19 +49,19 @@ proc getBalance*(symbol: string, accountAddress: string, tokenAddress: string): result = $status_tokens.getTokenBalance(tokenAddress, accountAddress) balanceManager.tokenBalances.cacheValue(cacheKey, result) -proc getFiatValue*(crypto_balance: string, crypto_symbol: string, fiat_symbol: string): float = - if crypto_balance == "0.0": return 0.0 - let cacheKey = fmt"{crypto_symbol}-{fiat_symbol}" +proc convertValue*(balance: string, fromCurrency: string, toCurrency: string): float = + if balance == "0.0": return 0.0 + let cacheKey = fmt"{fromCurrency}-{toCurrency}" if balanceManager.pricePairs.isCached(cacheKey): - return parseFloat(crypto_balance) * parseFloat(balanceManager.pricePairs.get(cacheKey)) + return parseFloat(balance) * parseFloat(balanceManager.pricePairs.get(cacheKey)) - var fiat_crypto_price = getPrice(crypto_symbol, fiat_symbol) + var fiat_crypto_price = getPrice(fromCurrency, toCurrency) balanceManager.pricePairs.cacheValue(cacheKey, fiat_crypto_price) - parseFloat(crypto_balance) * parseFloat(fiat_crypto_price) + parseFloat(balance) * parseFloat(fiat_crypto_price) proc updateBalance*(asset: Asset, currency: string) = var token_balance = getBalance(asset.symbol, asset.accountAddress, asset.address) - let fiat_balance = getFiatValue(token_balance, asset.symbol, currency) + let fiat_balance = convertValue(token_balance, asset.symbol, currency) asset.value = token_balance asset.fiatBalanceDisplay = fmt"{fiat_balance:.2f} {currency}" asset.fiatBalance = fmt"{fiat_balance:.2f}" @@ -69,7 +69,7 @@ proc updateBalance*(asset: Asset, currency: string) = proc updateBalance*(account: WalletAccount, currency: string) = try: let eth_balance = getBalance("ETH", account.address, "") - let usd_balance = getFiatValue(eth_balance, "ETH", currency) + let usd_balance = convertValue(eth_balance, "ETH", currency) var totalAccountBalance = usd_balance account.realFiatBalance = totalAccountBalance account.balance = fmt"{totalAccountBalance:.2f} {currency}"