1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

network config refactor

This commit is contained in:
Matthias Kretschmann 2020-07-22 13:56:42 +02:00
parent bf0375f58f
commit f327ec0e43
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 32 additions and 26 deletions

View File

@ -1,5 +1,4 @@
# Network, possible values: development, pacific, rinkeby, mainnet
GATSBY_NETWORK="rinkeby"
#GATSBY_INFURA_PROJECT_ID="xxx"
#GATSBY_MARKET_ADDRESS="xxx"
#GATSBY_INFURA_PROJECT_ID="xxx"

View File

@ -1,8 +1,10 @@
const { ConfigHelper } = require('@oceanprotocol/lib')
const network = process.env.GATSBY_NETWORK || 'rinkeby'
function getDefaultOceanConfig() {
return new ConfigHelper().getConfig(
process.env.GATSBY_NETWORK || 'rinkeby',
network,
process.env.GATSBY_INFURA_PROJECT_ID
)
}
@ -12,9 +14,7 @@ const appConfig = {
...getDefaultOceanConfig(),
verbose: 3
},
// Main, Rinkeby, Kovan
// networks: [1, 4, 42],
networks: [4],
network,
infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx'
}

View File

@ -21,9 +21,7 @@ export default function Web3Feedback({
const isOceanConnectionError = status === -1
const correctNetwork = isCorrectNetwork(chainId)
const showFeedback = !account || isOceanConnectionError || !correctNetwork
const allowedNetworkNames = appConfig.networks.map((network: number) =>
getNetworkName(network)
)
const networkName = getNetworkName(appConfig.network)
const state = !account
? 'error'
@ -50,7 +48,7 @@ export default function Web3Feedback({
: isOceanConnectionError
? 'Please try again.'
: !correctNetwork
? `Please connect to ${allowedNetworkNames}.`
? `Please connect to ${networkName}.`
: isBalanceInsufficient === true
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
: 'Something went wrong.'

View File

@ -15,7 +15,7 @@ const query = graphql`
}
appConfig {
infuraProjectId
networks
network
}
}
}

View File

@ -1,7 +1,7 @@
import { OceanProviderValue } from '@oceanprotocol/react'
import { appConfig } from '../../app.config'
const { infuraProjectId, networks } = appConfig
const { infuraProjectId, network, oceanConfig } = appConfig
const web3ModalTheme = {
background: 'var(--brand-white)',
@ -29,18 +29,14 @@ export async function connectWallet(
}
},
torus: {
package: Torus
// options: {
// networkParams: {
// host: 'https://localhost:8545' // optional
// chainId: 1337, // optional
// networkId: 1337 // optional
// },
// config: {
// buildEnv: 'development' // optional
// }
// }
// }
package: Torus,
options: {
networkParams: {
host: oceanConfig.url // optional
// chainId: 1337, // optional
// networkId: 1337 // optional
}
}
}
}
@ -48,8 +44,8 @@ export async function connectWallet(
}
export function isCorrectNetwork(chainId: number): boolean {
const allowedIds = networks
return allowedIds.includes(chainId)
const configuredNetwork = getChainId(network)
return configuredNetwork === chainId
}
export function accountTruncate(account: string): string {
@ -70,3 +66,16 @@ export function getNetworkName(chainId: number): string {
return 'Unknown'
}
}
export function getChainId(network: string): number {
switch (network) {
case 'mainnet':
return 1
case 'rinkeby':
return 4
case 'kovan':
return 42
default:
return 0
}
}