-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: wallet connect - sake.lido.fi dApp - staking transaction gets stuck #16348
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
import stint, json, strutils | ||
import stint, json, strutils, chronicles | ||
|
||
include app_service/common/json_utils | ||
|
||
proc hexToDec*(hex: string): string = | ||
return stint.parse(hex, UInt256, 16).toString() | ||
|
||
proc getFloatFromJson(jsonObj: JsonNode, key: string): float = | ||
if jsonObj.contains(key): | ||
case jsonObj[key].kind | ||
of JFloat: | ||
result = jsonObj[key].getFloat | ||
of JString: | ||
result = parseFloat(jsonObj[key].getStr) | ||
of JInt: | ||
result = float(jsonObj[key].getInt) | ||
else: | ||
raise newException(CatchableError, "cannot resolve value for key: " & key) | ||
|
||
proc convertFeesInfoToHex*(feesInfoJson: string): string = | ||
let parsedJson = parseJson(feesInfoJson) | ||
try: | ||
if feesInfoJson.len == 0: | ||
raise newException(CatchableError, "feesInfoJson is empty") | ||
|
||
let maxFeeFloat = parsedJson["maxFeePerGas"].getFloat() | ||
let maxFeeWei = int64(maxFeeFloat * 1e9) | ||
let | ||
parsedJson = parseJson(feesInfoJson) | ||
|
||
let maxPriorityFeeFloat = parsedJson["maxPriorityFeePerGas"].getFloat() | ||
let maxPriorityFeeWei = int64(maxPriorityFeeFloat * 1e9) | ||
maxFeePerGasFloat = getFloatFromJson(parsedJson, "maxFeePerGas") | ||
a = maxFeePerGasFloat * 1e9 | ||
maxFeePerGasWei = uint64(maxFeePerGasFloat * 1e9) | ||
|
||
# Assemble the JSON and return it | ||
var resultJson = %* { | ||
"maxFeePerGas": "0x" & toHex(maxFeeWei).strip(chars = {'0'}, trailing = false), | ||
"maxPriorityFeePerGas": "0x" & toHex(maxPriorityFeeWei).strip(chars = {'0'}, trailing = false) | ||
} | ||
return $resultJson | ||
maxPriorityFeePerGasFloat = getFloatFromJson(parsedJson, "maxPriorityFeePerGas") | ||
maxPriorityFeePerGasWei = uint64(maxPriorityFeePerGasFloat * 1e9) | ||
|
||
# Assemble the JSON and return it | ||
var resultJson = %* { | ||
"maxFeePerGas": "0x" & toHex(maxFeePerGasWei).strip(chars = {'0'}, trailing = false), | ||
"maxPriorityFeePerGas": "0x" & toHex(maxPriorityFeePerGasWei).strip(chars = {'0'}, trailing = false) | ||
} | ||
return $resultJson | ||
except Exception as e: | ||
error "cannot convert fees info to hex: ", msg=e.msg |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,13 +484,11 @@ SQUtils.QObject { | |
|
||
// Beware, the tx values are standard blockchain hex big number values; the fees values are nim's float64 values, hence the complex conversions | ||
if (!!tx.maxFeePerGas && !!tx.maxPriorityFeePerGas) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as we are ine post eip1559 case, both are present, we do not need to set gas price i believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exactly, that was my question about, here. |
||
let maxFeePerGasDec = root.store.hexToDec(tx.maxFeePerGas) | ||
const gasPriceInWei = BigOps.fromString(maxFeePerGasDec) | ||
maxFeePerGas = hexToGwei(tx.maxFeePerGas) | ||
maxPriorityFeePerGas = hexToGwei(tx.maxPriorityFeePerGas) | ||
|
||
// TODO: check why we need to set gasPrice here and why if it's not checked we cannot send the tx and fees are unknown???? | ||
gasPrice = hexToGwei(tx.maxFeePerGas) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why |
||
// Source fees info from the incoming transaction for when we process it | ||
maxFeePerGas = root.store.hexToDec(tx.maxFeePerGas) | ||
let maxPriorityFeePerGasDec = hexToGwei(tx.maxPriorityFeePerGas) | ||
maxPriorityFeePerGas = maxPriorityFeePerGasDec | ||
} else { | ||
let fees = root.store.getSuggestedFees(chainId) | ||
maxPriorityFeePerGas = fees.maxPriorityFeePerGas | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All functions in this file should have this check
and obj[prop].kind == ....
but when I did that I couldn't start the app (got crash) which undoubtedly means that in some places we have incorrect type usage or receiving incorrect json data. That should be fixed in another PR.