-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1468 from oasisprotocol/lw/balance
Show total balance in account selector
- Loading branch information
Showing
23 changed files
with
141 additions
and
128 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { addressToPublicKey, parseRpcBalance } from 'app/lib/helpers' | ||
import { call } from 'typed-redux-saga' | ||
import { getExplorerAPIs, getOasisNic } from '../state/network/saga' | ||
import { Account } from '../state/account/types' | ||
|
||
function* getBalanceGRPC(address: string) { | ||
const nic = yield* call(getOasisNic) | ||
const publicKey = yield* call(addressToPublicKey, address) | ||
const account = yield* call([nic, nic.stakingAccount], { owner: publicKey, height: 0 }) | ||
const grpcBalance = parseRpcBalance(account) | ||
return { | ||
address, | ||
available: grpcBalance.available, | ||
delegations: null, | ||
debonding: null, | ||
total: null, | ||
} | ||
} | ||
|
||
export function* getAccountBalanceWithFallback(address: string) { | ||
const { getAccount } = yield* call(getExplorerAPIs) | ||
|
||
try { | ||
const account: Account = yield* call(getAccount, address) | ||
return account | ||
} catch (apiError: any) { | ||
console.error('get account failed, continuing to RPC fallback.', apiError) | ||
try { | ||
const account: Account = yield* call(getBalanceGRPC, address) | ||
return account | ||
} catch (rpcError) { | ||
console.error('get account with RPC failed, continuing without updated account.', rpcError) | ||
throw apiError | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.