1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

refactor getNetworkConfig, handling default network based on REACT_APP_OCEAN_NETWORK env var

This commit is contained in:
Max Berman 2020-01-17 13:36:38 +01:00
parent 4b3925eff3
commit f345a12c76
4 changed files with 9 additions and 14 deletions

View File

@ -1,20 +1,14 @@
import React, { useState, useContext, useEffect, useRef } from 'react'
import { urlq } from '../../utils/utils'
import { urlq, getObjByKey } from '../../utils/utils'
import { CONNECTIONS } from '../../config'
import { User } from '../../context'
import styles from './NetworkSwitcher.module.scss'
const networkUrlParam = urlq.get('network') || ''
const defaultNetwork = process.env.REACT_APP_OCEAN_NETWORK || 'pacific'
const netUrlParam: string = urlq.get('network') || defaultNetwork
const getNetworkConfig = (network: string) => getObjByKey(CONNECTIONS, network)
const getNetworkConfig = (network: string) => {
// TypeScript doesn't let access CONNECTIONS[networkName] directly
const idx = Object.keys(CONNECTIONS).indexOf(network)
return idx !== -1 ? Object.values(CONNECTIONS)[idx] : CONNECTIONS.pacific // Use default config in case of mispelled URL params
}
export const oceanConfig = getNetworkConfig(
networkUrlParam !== '' ? networkUrlParam : 'pacific'
)
export const oceanConfig: any = getNetworkConfig(netUrlParam)
/* NETWORK SWITCHER */
export function NetworkSwitcher() {

View File

@ -66,7 +66,7 @@ export const VersionTableCommons = () => {
<td>
<code className={styles.label}>{key}</code>
</td>
<td>{val}</td>
<td>${val}</td>
</tr>
))}
</tbody>

View File

@ -26,8 +26,6 @@ export const ipfsNodeUri =
// OCEAN REMOTE CONNECTIONS
//
console.log(process.env.REACT_APP_OCEAN_NETWORK)
const altNetwork =
process.env.REACT_APP_OCEAN_NETWORK === 'spree'
? {

View File

@ -13,6 +13,9 @@ export function formatBytes(a: number, b: number) {
export const urlq = new URLSearchParams(window.location.search)
export const getObjByKey = (obj: any, key: string) =>
Object.values(obj)[Object.keys(obj).indexOf(key)]
export function arraySum(array: number[]) {
return array.reduce((a, b) => a + b, 0)
}