@@ -8,8 +8,9 @@ import { backend, backendApi } from 'vendors/backend'
88
99import { networkActions } from '.'
1010import { SyncedRootState } from '../persist/types'
11- import { selectSelectedNetwork } from './selectors'
11+ import { selectChainContext , selectSelectedNetwork } from './selectors'
1212import { NetworkType } from './types'
13+ import { WalletError , WalletErrors } from 'types/errors'
1314
1415/**
1516 * Return a nic client for the specified network,
@@ -32,6 +33,23 @@ export function* getExplorerAPIs() {
3233 return backendApi ( url )
3334}
3435
36+ export function * getChainContext ( ) {
37+ const chainContext = yield * select ( selectChainContext )
38+ if ( chainContext ) {
39+ return chainContext
40+ }
41+
42+ try {
43+ const selectedNetwork = yield * select ( selectSelectedNetwork )
44+ const nic = yield * call ( getOasisNic , selectedNetwork )
45+ const fetchedChainContext = yield * call ( [ nic , nic . consensusGetChainContext ] )
46+ yield * put ( networkActions . setChainContext ( fetchedChainContext ) )
47+ return fetchedChainContext
48+ } catch ( error ) {
49+ throw new WalletError ( WalletErrors . UnknownGrpcError , 'Could not fetch data' )
50+ }
51+ }
52+
3553export function * selectNetwork ( {
3654 network,
3755 isInitializing,
@@ -40,12 +58,10 @@ export function* selectNetwork({
4058 isInitializing : boolean
4159} ) {
4260 const nic = yield * call ( getOasisNic , network )
43- const { epoch, chainContext } = yield * all ( {
61+ const { epoch } = yield * all ( {
4462 epoch : call ( [ nic , nic . beaconGetEpoch ] , oasis . consensus . HEIGHT_LATEST ) ,
45- chainContext : call ( [ nic , nic . consensusGetChainContext ] ) ,
4663 } )
4764 const networkState = {
48- chainContext : chainContext ,
4965 ticker : config [ network ] . ticker ,
5066 epoch : Number ( epoch ) , // Will lose precision in a few billion years at 1 epoch per hour
5167 selectedNetwork : network ,
0 commit comments