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 =
|
proc getBalance*(address: string): string =
|
||||||
let payload = %* [address, "latest"]
|
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 =
|
proc hex2Eth*(input: string): string =
|
||||||
var value = fromHex(Stuint[256], input)
|
var value = fromHex(Stuint[256], input)
|
||||||
|
|
|
@ -12,6 +12,9 @@ import wallet/collectibles
|
||||||
export account, collectibles
|
export account, collectibles
|
||||||
export Transaction
|
export Transaction
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "wallet-model"
|
||||||
|
|
||||||
type WalletModel* = ref object
|
type WalletModel* = ref object
|
||||||
events*: EventEmitter
|
events*: EventEmitter
|
||||||
accounts*: seq[WalletAccount]
|
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/wallet as status_wallet
|
||||||
import ../libstatus/tokens as status_tokens
|
import ../libstatus/tokens as status_tokens
|
||||||
|
import ../libstatus/types as status_types
|
||||||
import ../utils/cache
|
import ../utils/cache
|
||||||
import account
|
import account
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "balance-manager"
|
||||||
|
|
||||||
type BalanceManager* = ref object
|
type BalanceManager* = ref object
|
||||||
pricePairs: CachedValues
|
pricePairs: CachedValues
|
||||||
tokenBalances: CachedValues
|
tokenBalances: CachedValues
|
||||||
|
@ -62,6 +66,7 @@ proc updateBalance*(asset: Asset, currency: string) =
|
||||||
asset.fiatValue = fmt"{fiat_balance:.2f} {currency}"
|
asset.fiatValue = fmt"{fiat_balance:.2f} {currency}"
|
||||||
|
|
||||||
proc updateBalance*(account: WalletAccount, currency: string) =
|
proc updateBalance*(account: WalletAccount, currency: string) =
|
||||||
|
try:
|
||||||
let eth_balance = getBalance("ETH", account.address, "")
|
let eth_balance = getBalance("ETH", account.address, "")
|
||||||
let usd_balance = getFiatValue(eth_balance, "ETH", currency)
|
let usd_balance = getFiatValue(eth_balance, "ETH", currency)
|
||||||
var totalAccountBalance = usd_balance
|
var totalAccountBalance = usd_balance
|
||||||
|
@ -69,3 +74,5 @@ proc updateBalance*(account: WalletAccount, currency: string) =
|
||||||
account.balance = fmt"{totalAccountBalance:.2f} {currency}"
|
account.balance = fmt"{totalAccountBalance:.2f} {currency}"
|
||||||
for asset in account.assetList:
|
for asset in account.assetList:
|
||||||
updateBalance(asset, currency)
|
updateBalance(asset, currency)
|
||||||
|
except RpcException:
|
||||||
|
error "Error in updateBalance", message = getCurrentExceptionMsg()
|
||||||
|
|
Loading…
Reference in New Issue