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:
parent
4b3925eff3
commit
f345a12c76
@ -1,20 +1,14 @@
|
|||||||
import React, { useState, useContext, useEffect, useRef } from 'react'
|
import React, { useState, useContext, useEffect, useRef } from 'react'
|
||||||
import { urlq } from '../../utils/utils'
|
import { urlq, getObjByKey } from '../../utils/utils'
|
||||||
import { CONNECTIONS } from '../../config'
|
import { CONNECTIONS } from '../../config'
|
||||||
import { User } from '../../context'
|
import { User } from '../../context'
|
||||||
import styles from './NetworkSwitcher.module.scss'
|
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) => {
|
export const oceanConfig: any = getNetworkConfig(netUrlParam)
|
||||||
// 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'
|
|
||||||
)
|
|
||||||
|
|
||||||
/* NETWORK SWITCHER */
|
/* NETWORK SWITCHER */
|
||||||
export function NetworkSwitcher() {
|
export function NetworkSwitcher() {
|
||||||
|
@ -66,7 +66,7 @@ export const VersionTableCommons = () => {
|
|||||||
<td>
|
<td>
|
||||||
<code className={styles.label}>{key}</code>
|
<code className={styles.label}>{key}</code>
|
||||||
</td>
|
</td>
|
||||||
<td>{val}</td>
|
<td>${val}</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -26,8 +26,6 @@ export const ipfsNodeUri =
|
|||||||
// OCEAN REMOTE CONNECTIONS
|
// OCEAN REMOTE CONNECTIONS
|
||||||
//
|
//
|
||||||
|
|
||||||
console.log(process.env.REACT_APP_OCEAN_NETWORK)
|
|
||||||
|
|
||||||
const altNetwork =
|
const altNetwork =
|
||||||
process.env.REACT_APP_OCEAN_NETWORK === 'spree'
|
process.env.REACT_APP_OCEAN_NETWORK === 'spree'
|
||||||
? {
|
? {
|
||||||
|
@ -13,6 +13,9 @@ export function formatBytes(a: number, b: number) {
|
|||||||
|
|
||||||
export const urlq = new URLSearchParams(window.location.search)
|
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[]) {
|
export function arraySum(array: number[]) {
|
||||||
return array.reduce((a, b) => a + b, 0)
|
return array.reduce((a, b) => a + b, 0)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user