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,10 +66,13 @@ 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) =
|
||||||
let eth_balance = getBalance("ETH", account.address, "")
|
try:
|
||||||
let usd_balance = getFiatValue(eth_balance, "ETH", currency)
|
let eth_balance = getBalance("ETH", account.address, "")
|
||||||
var totalAccountBalance = usd_balance
|
let usd_balance = getFiatValue(eth_balance, "ETH", currency)
|
||||||
account.realFiatBalance = totalAccountBalance
|
var totalAccountBalance = usd_balance
|
||||||
account.balance = fmt"{totalAccountBalance:.2f} {currency}"
|
account.realFiatBalance = totalAccountBalance
|
||||||
for asset in account.assetList:
|
account.balance = fmt"{totalAccountBalance:.2f} {currency}"
|
||||||
updateBalance(asset, currency)
|
for asset in account.assetList:
|
||||||
|
updateBalance(asset, currency)
|
||||||
|
except RpcException:
|
||||||
|
error "Error in updateBalance", message = getCurrentExceptionMsg()
|
||||||
|
|
Loading…
Reference in New Issue