feat(dapps): fetch max fees per gas from blockchain if not provided

Updates: #15192
This commit is contained in:
Stefan 2024-07-10 16:58:42 +03:00 committed by Stefan Dunca
parent 4deea3461f
commit fae3d14d50
4 changed files with 23 additions and 10 deletions

View File

@ -71,5 +71,5 @@ QtObject:
proc sendTransaction*(self: Controller, address: string, chainId: int, password: string, txJson: string): string {.slot.} =
return self.service.sendTransaction(address, chainId, password, txJson)
proc getEstimatedTimeMinutesInterval(self: Controller, chainId: int, maxFeePerGas: string): int {.slot.} =
return self.service.getEstimatedTimeMinutesInterval(chainId, maxFeePerGas).int
proc getEstimatedTime(self: Controller, chainId: int, maxFeePerGasHex: string): int {.slot.} =
return self.service.getEstimatedTime(chainId, maxFeePerGasHex).int

View File

@ -208,6 +208,20 @@ QtObject:
return txResponse.getStr
proc getEstimatedTimeMinutesInterval*(self: Service, chainId: int, maxFeePerGas: string): EstimatedTime =
let maxFeePerGasInt = parseHexInt(maxFeePerGas)
return self.transactions.getEstimatedTime(chainId, $(maxFeePerGasInt.float))
# empty maxFeePerGasHex will fetch the current chain's maxFeePerGas
proc getEstimatedTime*(self: Service, chainId: int, maxFeePerGasHex: string): EstimatedTime =
var maxFeePerGas: float64
if maxFeePerGasHex.isEmptyOrWhitespace:
let chainFees = self.transactions.suggestedFees(chainId)
if chainFees.isNil:
return EstimatedTime.Unknown
# For non-EIP-1559 chains, we use the high fee
if chainFees.eip1559Enabled:
maxFeePerGas = chainFees.maxFeePerGasM
else:
maxFeePerGas = chainFees.maxFeePerGasL
else:
let maxFeePerGasInt = parseHexInt(maxFeePerGasHex)
maxFeePerGas = maxFeePerGasInt.float
return self.transactions.getEstimatedTime(chainId, $(maxFeePerGas))

View File

@ -337,15 +337,13 @@ QObject {
tx = SessionRequest.methods.sendTransaction.getTxObjFromData(data)
}
// Empty string instructs getEstimatedTime to fetch the blockchain value
var maxFeePerGas = ""
if (!!tx.maxFeePerGas) {
maxFeePerGas = tx.maxFeePerGas
} else if (!!tx.gasPrice) {
maxFeePerGas = tx.gasPrice
}
if (!maxFeePerGas) {
return ""
}
return root.store.getEstimatedTime(chainId, maxFeePerGas)
}

View File

@ -64,9 +64,10 @@ QObject {
return tx
}
// Empty maxFeePerGas will fetch the current chain's maxFeePerGas
// Returns ui/imports/utils -> Constants.TransactionEstimatedTime values
function getEstimatedTime(chainId, maxFeePerGas) {
return controller.getEstimatedTime(chainId, maxFeePerGas)
function getEstimatedTime(chainId, maxFeePerGasHex) {
return controller.getEstimatedTime(chainId, maxFeePerGasHex)
}
// Returns the hex encoded signature of the transaction or empty string if error