fix(wallet) forever loading balances

Allow the balances to be nil in the BalanceDTO.

It seems in some corner-cases the balances are returned with rawBalance
as "<nil>" which can't be parsed as a valid Int256; see change cbf56fec.

"<nil>" is not a valid json value, so this is still a workaround.

Closes: #12330
This commit is contained in:
Stefan 2023-10-04 19:20:37 +03:00 committed by Stefan Dunca
parent cd4d92aef0
commit a587e504ef
1 changed files with 6 additions and 1 deletions

View File

@ -22,7 +22,12 @@ proc getCurrencyBalance*(self: BalanceDto, currencyPrice: float64): float64 =
proc toBalanceDto*(jsonObj: JsonNode): BalanceDto =
result = BalanceDto()
result.rawBalance = jsonObj{"rawBalance"}.getStr.parse(Uint256)
# Expecting "<nil>" values comming from status-go when the entry is nil
let rawBalanceStr = jsonObj{"rawBalance"}.getStr
if not rawBalanceStr.contains("nil"):
result.rawBalance = rawBalanceStr.parse(Uint256)
result.balance = jsonObj{"balance"}.getStr.parseFloat()
discard jsonObj.getProp("address", result.address)
discard jsonObj.getProp("chainId", result.chainId)