-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wallet connect - sake.lido.fi dApp - staking transaction gets stuck
Fixes #16096
- Loading branch information
1 parent
ff45e76
commit ea8827e
Showing
4 changed files
with
51 additions
and
22 deletions.
There are no files selected for viewing
45 changes: 33 additions & 12 deletions
45
src/app/modules/shared_modules/wallet_connect/helpers.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters