From 81f97157e65358ca45755868302b34a2cbbb8382 Mon Sep 17 00:00:00 2001 From: Michal Iskierko Date: Fri, 14 Apr 2023 14:26:41 +0200 Subject: [PATCH] fix(@desktop/communities): Fix computing balances for different chains during deployment Fix #10308 --- .../service/community_tokens/service.nim | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app_service/service/community_tokens/service.nim b/src/app_service/service/community_tokens/service.nim index 14554af9ca..21cc8c6e0b 100644 --- a/src/app_service/service/community_tokens/service.nim +++ b/src/app_service/service/community_tokens/service.nim @@ -265,13 +265,14 @@ QtObject: proc onSuggestedFees*(self:Service, response: string) {.slot.} = let responseJson = response.parseJson() + const ethSymbol = "ETH" if responseJson{"error"}.kind != JNull and responseJson{"error"}.getStr != "": let errorMessage = responseJson["error"].getStr var errorCode = ComputeFeeErrorCode.Other if errorMessage.contains("403 Forbidden") or errorMessage.contains("exceed"): errorCode = ComputeFeeErrorCode.Infura - let ethCurrency = newCurrencyAmount(0.0, "ETH", 1, false) + let ethCurrency = newCurrencyAmount(0.0, ethSymbol, 1, false) let fiatCurrency = newCurrencyAmount(0.0, self.settingsService.getCurrency(), 1, false) let data = ComputeDeployFeeArgs(ethCurrency: ethCurrency, fiatCurrency: fiatCurrency, errorCode: errorCode) self.events.emit(SIGNAL_COMPUTE_DEPLOY_FEE, data) @@ -282,17 +283,21 @@ QtObject: let maxFees = suggestedFees.maxFeePerGasM let gasPrice = if suggestedFees.eip1559Enabled: maxFees else: suggestedFees.gasPrice - const ethSymbol = "ETH" - let weiValue = gwei2Wei(gasPrice) * contractGasUnits.u256 let ethValueStr = wei2Eth(weiValue) let ethValue = parseFloat(ethValueStr) let fiatValue = self.getFiatValue(ethValue, ethSymbol) let wallet = self.walletAccountService.getAccountByAddress(self.tempAccountAddress) - let balance = wallet.getCurrencyBalance(@[self.tempChainId], ethSymbol) - let ethCurrency = newCurrencyAmount(ethValue, "ETH", 4, false) + var balance = 0.0 + let tokens = wallet.tokens + for token in tokens: + if token.symbol == ethSymbol: + balance = token.balancesPerChain[self.tempChainId].balance + break + + let ethCurrency = newCurrencyAmount(ethValue, ethSymbol, 4, false) let fiatCurrency = newCurrencyAmount(fiatValue, self.settingsService.getCurrency(), 2, false) let data = ComputeDeployFeeArgs(ethCurrency: ethCurrency, fiatCurrency: fiatCurrency,