refactor: rename getFiatValue to convertValue

This commit is contained in:
Pascal Precht 2020-08-06 13:48:54 +02:00 committed by Iuri Matias
parent 56568f68c8
commit 441d58a4cb
3 changed files with 12 additions and 12 deletions

View File

@ -150,11 +150,11 @@ QtObject:
self.accountListChanged() self.accountListChanged()
proc getFiatValue*(self: WalletView, cryptoBalance: string, cryptoSymbol: string, fiatSymbol: string): string {.slot.} = 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}" result = fmt"{val:.2f}"
proc getCryptoValue*(self: WalletView, fiatBalance: string, fiatSymbol: string, cryptoSymbol: string): string {.slot.} = 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.} = proc generateNewAccount*(self: WalletView, password: string, accountName: string, color: string): string {.slot.} =
result = self.status.wallet.generateNewAccount(password, accountName, color) result = self.status.wallet.generateNewAccount(password, accountName, color)

View File

@ -95,8 +95,8 @@ proc getTotalFiatBalance*(self: WalletModel): string =
var newBalance = 0.0 var newBalance = 0.0
fmt"{self.totalBalance:.2f} {self.defaultCurrency}" fmt"{self.totalBalance:.2f} {self.defaultCurrency}"
proc getFiatValue*(self: WalletModel, cryptoBalance: string, cryptoSymbol: string, fiatSymbol: string): float = proc convertValue*(self: WalletModel, balance: string, fromCurrency: string, toCurrency: string): float =
result = getFiatValue(cryptoBalance, cryptoSymbol, fiatSymbol) result = convertValue(balance, fromCurrency, toCurrency)
proc calculateTotalFiatBalance*(self: WalletModel) = proc calculateTotalFiatBalance*(self: WalletModel) =
self.totalBalance = 0.0 self.totalBalance = 0.0

View File

@ -49,19 +49,19 @@ proc getBalance*(symbol: string, accountAddress: string, tokenAddress: string):
result = $status_tokens.getTokenBalance(tokenAddress, accountAddress) result = $status_tokens.getTokenBalance(tokenAddress, accountAddress)
balanceManager.tokenBalances.cacheValue(cacheKey, result) balanceManager.tokenBalances.cacheValue(cacheKey, result)
proc getFiatValue*(crypto_balance: string, crypto_symbol: string, fiat_symbol: string): float = proc convertValue*(balance: string, fromCurrency: string, toCurrency: string): float =
if crypto_balance == "0.0": return 0.0 if balance == "0.0": return 0.0
let cacheKey = fmt"{crypto_symbol}-{fiat_symbol}" let cacheKey = fmt"{fromCurrency}-{toCurrency}"
if balanceManager.pricePairs.isCached(cacheKey): 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) 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) = proc updateBalance*(asset: Asset, currency: string) =
var token_balance = getBalance(asset.symbol, asset.accountAddress, asset.address) 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.value = token_balance
asset.fiatBalanceDisplay = fmt"{fiat_balance:.2f} {currency}" asset.fiatBalanceDisplay = fmt"{fiat_balance:.2f} {currency}"
asset.fiatBalance = fmt"{fiat_balance:.2f}" asset.fiatBalance = fmt"{fiat_balance:.2f}"
@ -69,7 +69,7 @@ proc updateBalance*(asset: Asset, currency: string) =
proc updateBalance*(account: WalletAccount, currency: string) = proc updateBalance*(account: WalletAccount, currency: string) =
try: try:
let eth_balance = getBalance("ETH", account.address, "") 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 var totalAccountBalance = usd_balance
account.realFiatBalance = totalAccountBalance account.realFiatBalance = totalAccountBalance
account.balance = fmt"{totalAccountBalance:.2f} {currency}" account.balance = fmt"{totalAccountBalance:.2f} {currency}"