fix: add and handle RpcExceptions for wallet functions that would not allow login when offline
This commit is contained in:
parent
0278379495
commit
9c9abe8ef9
|
@ -100,7 +100,11 @@ proc sendTransaction*(from_address: string, to: string, assetAddress: string, va
|
|||
|
||||
proc getBalance*(address: string): string =
|
||||
let payload = %* [address, "latest"]
|
||||
parseJson(callPrivateRPC("eth_getBalance", payload))["result"].str
|
||||
let response = parseJson(callPrivateRPC("eth_getBalance", payload))
|
||||
if response.hasKey("error"):
|
||||
raise newException(RpcException, "Error getting balance: " & $response["error"])
|
||||
else:
|
||||
result = response["result"].str
|
||||
|
||||
proc hex2Eth*(input: string): string =
|
||||
var value = fromHex(Stuint[256], input)
|
||||
|
|
|
@ -12,6 +12,9 @@ import wallet/collectibles
|
|||
export account, collectibles
|
||||
export Transaction
|
||||
|
||||
logScope:
|
||||
topics = "wallet-model"
|
||||
|
||||
type WalletModel* = ref object
|
||||
events*: EventEmitter
|
||||
accounts*: seq[WalletAccount]
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import strformat, strutils, stint, httpclient, json
|
||||
import strformat, strutils, stint, httpclient, json, chronicles
|
||||
import ../libstatus/wallet as status_wallet
|
||||
import ../libstatus/tokens as status_tokens
|
||||
import ../libstatus/types as status_types
|
||||
import ../utils/cache
|
||||
import account
|
||||
|
||||
logScope:
|
||||
topics = "balance-manager"
|
||||
|
||||
type BalanceManager* = ref object
|
||||
pricePairs: CachedValues
|
||||
tokenBalances: CachedValues
|
||||
|
@ -62,6 +66,7 @@ proc updateBalance*(asset: Asset, currency: string) =
|
|||
asset.fiatValue = fmt"{fiat_balance:.2f} {currency}"
|
||||
|
||||
proc updateBalance*(account: WalletAccount, currency: string) =
|
||||
try:
|
||||
let eth_balance = getBalance("ETH", account.address, "")
|
||||
let usd_balance = getFiatValue(eth_balance, "ETH", currency)
|
||||
var totalAccountBalance = usd_balance
|
||||
|
@ -69,3 +74,5 @@ proc updateBalance*(account: WalletAccount, currency: string) =
|
|||
account.balance = fmt"{totalAccountBalance:.2f} {currency}"
|
||||
for asset in account.assetList:
|
||||
updateBalance(asset, currency)
|
||||
except RpcException:
|
||||
error "Error in updateBalance", message = getCurrentExceptionMsg()
|
||||
|
|
Loading…
Reference in New Issue