Skip to content

Commit

Permalink
Speedup loading network configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Aug 18, 2022
1 parent 7f5943e commit 46c86d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/app/state/network/saga.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as oasis from '@oasisprotocol/client'
import { PayloadAction } from '@reduxjs/toolkit'
import { config } from 'config'
import { call, put, select, takeLatest } from 'typed-redux-saga'
import { all, call, put, select, takeLatest } from 'typed-redux-saga'
import { backend, backendApi } from 'vendors/backend'

import { networkActions } from '.'
Expand Down Expand Up @@ -32,19 +32,18 @@ export function* getExplorerAPIs(network?: NetworkType) {

export function* selectNetwork({ payload: network }: PayloadAction<NetworkType>) {
const nic = yield* call(getOasisNic, network)
const epoch = yield* call([nic, nic.beaconGetEpoch], oasis.consensus.HEIGHT_LATEST)
const ticker = yield* call([nic, nic.stakingTokenSymbol])
const chainContext = yield* call([nic, nic.consensusGetChainContext])
const stakingParams = yield* call([nic, nic.stakingConsensusParameters], oasis.consensus.HEIGHT_LATEST)
const minimumStakingAmount = Number(oasis.quantity.toBigInt(stakingParams.min_delegation)) / 10 ** 9
const { epoch, chainContext } = yield* all({
epoch: call([nic, nic.beaconGetEpoch], oasis.consensus.HEIGHT_LATEST),
chainContext: call([nic, nic.consensusGetChainContext]),
})

yield* put(
networkActions.networkSelected({
chainContext: chainContext,
ticker: ticker,
epoch: Number(epoch),
ticker: config[network].ticker,
epoch: Number(epoch), // TODO: numeric precision
selectedNetwork: network,
minimumStakingAmount: minimumStakingAmount,
minimumStakingAmount: config[network].min_delegation,
}),
)
}
Expand Down
10 changes: 9 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type BackendApiUrls = {

type BackendProviders = {
grpc: string
ticker: string // from nic.stakingTokenSymbol()
min_delegation: number // from nic.stakingConsensusParameters().min_delegation
[BackendAPIs.OasisMonitor]: BackendApiUrls
[BackendAPIs.OasisScan]: BackendApiUrls
}
Expand All @@ -19,6 +21,9 @@ type BackendConfig = {

export const config: BackendConfig = {
mainnet: {
grpc: 'https://grpc.oasis.dev',
ticker: 'ROSE',
min_delegation: 100,
[BackendAPIs.OasisMonitor]: {
explorer: 'https://monitor.oasis.dev',
blockExplorer: 'https://oasismonitor.com/operation/{{txHash}}',
Expand All @@ -28,10 +33,11 @@ export const config: BackendConfig = {
blockExplorer: 'https://oasisscan.com/transactions/{{txHash}}',
blockExplorerParatimes: 'https://oasisscan.com/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
},
grpc: 'https://grpc.oasis.dev',
},
testnet: {
grpc: 'https://testnet.grpc.oasis.dev',
ticker: 'TEST',
min_delegation: 100,
[BackendAPIs.OasisMonitor]: {
explorer: 'https://monitor.oasis.dev/api/testnet',
blockExplorer: 'https://testnet.oasismonitor.com/operation/{{txHash}}',
Expand All @@ -45,6 +51,8 @@ export const config: BackendConfig = {
},
local: {
grpc: 'http://localhost:42280',
ticker: 'TEST',
min_delegation: 100,
[BackendAPIs.OasisMonitor]: {
explorer: 'http://localhost:9001',
blockExplorer: 'http://localhost:9001/data/transactions?operation_id={{txHash}}',
Expand Down

0 comments on commit 46c86d0

Please sign in to comment.