fix(@wallet): estimate gas fail when not enough fund

fixes #5267
This commit is contained in:
Anthony Laibe 2022-04-05 15:38:45 +02:00 committed by Anthony Laibe
parent f18e09769a
commit b1775357c3
2 changed files with 36 additions and 34 deletions

View File

@ -110,7 +110,6 @@ QtObject:
proc estimateGas*(self: View, from_addr: string, to: string, assetAddress: string, value: string, data: string): string {.slot.} =
result = self.delegate.estimateGas(from_addr, to, assetAddress, value, data)
result = self.delegate.estimateGas(from_addr, to, assetAddress, value, data)
proc transactionSent*(self: View, txResult: string) {.signal.}

View File

@ -224,7 +224,6 @@ QtObject:
): string {.slot.} =
var response: RpcResponse[JsonNode]
# TODO make this async
try:
if assetAddress != ZERO_ADDRESS and not assetAddress.isEmptyOrWhitespace:
var tx = buildTokenTransaction(
parseAddress(from_addr),
@ -240,24 +239,28 @@ QtObject:
let transfer = Transfer(to: parseAddress(to), value: conversion.eth2Wei(parseFloat(value), token.decimals))
let transferproc = ERC20_procS.toTable["transfer"]
var success: bool
try:
let gas = transferproc.estimateGas(tx, transfer, success)
let res = fromHex[int](gas)
result = $(%* { "result": res, "success": success })
else:
return $(%* { "result": res, "success": success })
except Exception as e:
error "Error estimating gas", msg = e.msg
return $(%* { "result": "-1", "success": false, "error": { "message": e.msg } })
var tx = ens_utils.buildTransaction(
parseAddress(from_addr),
eth2Wei(parseFloat(value), 18),
data = data
)
tx.to = parseAddress(to).some
try:
response = eth.estimateGas(%*[%tx])
let res = fromHex[int](response.result.getStr)
result = $(%* { "result": %res, "success": true })
except Exception as e:
error "Error estimating gas", msg = e.msg
result = $(%* { "result": "-1", "success": false, "error": { "message": e.msg } })
return $(%* { "result": "-1", "success": false })
proc transferEth*(
self: Service,