fix(@desktop/communities): Fix computing balances for different chains during deployment

Fix #10308
This commit is contained in:
Michal Iskierko 2023-04-14 14:26:41 +02:00 committed by Michał Iskierko
parent 7055a77a96
commit 81f97157e6
1 changed files with 10 additions and 5 deletions

View File

@ -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,