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:
parent
bf0375f58f
commit
f327ec0e43
@ -1,5 +1,4 @@
|
|||||||
# Network, possible values: development, pacific, rinkeby, mainnet
|
# Network, possible values: development, pacific, rinkeby, mainnet
|
||||||
GATSBY_NETWORK="rinkeby"
|
GATSBY_NETWORK="rinkeby"
|
||||||
|
|
||||||
#GATSBY_INFURA_PROJECT_ID="xxx"
|
#GATSBY_INFURA_PROJECT_ID="xxx"
|
||||||
#GATSBY_MARKET_ADDRESS="xxx"
|
|
@ -1,8 +1,10 @@
|
|||||||
const { ConfigHelper } = require('@oceanprotocol/lib')
|
const { ConfigHelper } = require('@oceanprotocol/lib')
|
||||||
|
|
||||||
|
const network = process.env.GATSBY_NETWORK || 'rinkeby'
|
||||||
|
|
||||||
function getDefaultOceanConfig() {
|
function getDefaultOceanConfig() {
|
||||||
return new ConfigHelper().getConfig(
|
return new ConfigHelper().getConfig(
|
||||||
process.env.GATSBY_NETWORK || 'rinkeby',
|
network,
|
||||||
process.env.GATSBY_INFURA_PROJECT_ID
|
process.env.GATSBY_INFURA_PROJECT_ID
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -12,9 +14,7 @@ const appConfig = {
|
|||||||
...getDefaultOceanConfig(),
|
...getDefaultOceanConfig(),
|
||||||
verbose: 3
|
verbose: 3
|
||||||
},
|
},
|
||||||
// Main, Rinkeby, Kovan
|
network,
|
||||||
// networks: [1, 4, 42],
|
|
||||||
networks: [4],
|
|
||||||
infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx'
|
infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,7 @@ export default function Web3Feedback({
|
|||||||
const isOceanConnectionError = status === -1
|
const isOceanConnectionError = status === -1
|
||||||
const correctNetwork = isCorrectNetwork(chainId)
|
const correctNetwork = isCorrectNetwork(chainId)
|
||||||
const showFeedback = !account || isOceanConnectionError || !correctNetwork
|
const showFeedback = !account || isOceanConnectionError || !correctNetwork
|
||||||
const allowedNetworkNames = appConfig.networks.map((network: number) =>
|
const networkName = getNetworkName(appConfig.network)
|
||||||
getNetworkName(network)
|
|
||||||
)
|
|
||||||
|
|
||||||
const state = !account
|
const state = !account
|
||||||
? 'error'
|
? 'error'
|
||||||
@ -50,7 +48,7 @@ export default function Web3Feedback({
|
|||||||
: isOceanConnectionError
|
: isOceanConnectionError
|
||||||
? 'Please try again.'
|
? 'Please try again.'
|
||||||
: !correctNetwork
|
: !correctNetwork
|
||||||
? `Please connect to ${allowedNetworkNames}.`
|
? `Please connect to ${networkName}.`
|
||||||
: isBalanceInsufficient === true
|
: isBalanceInsufficient === true
|
||||||
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
||||||
: 'Something went wrong.'
|
: 'Something went wrong.'
|
||||||
|
@ -15,7 +15,7 @@ const query = graphql`
|
|||||||
}
|
}
|
||||||
appConfig {
|
appConfig {
|
||||||
infuraProjectId
|
infuraProjectId
|
||||||
networks
|
network
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { OceanProviderValue } from '@oceanprotocol/react'
|
import { OceanProviderValue } from '@oceanprotocol/react'
|
||||||
import { appConfig } from '../../app.config'
|
import { appConfig } from '../../app.config'
|
||||||
|
|
||||||
const { infuraProjectId, networks } = appConfig
|
const { infuraProjectId, network, oceanConfig } = appConfig
|
||||||
|
|
||||||
const web3ModalTheme = {
|
const web3ModalTheme = {
|
||||||
background: 'var(--brand-white)',
|
background: 'var(--brand-white)',
|
||||||
@ -29,18 +29,14 @@ export async function connectWallet(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
torus: {
|
torus: {
|
||||||
package: Torus
|
package: Torus,
|
||||||
// options: {
|
options: {
|
||||||
// networkParams: {
|
networkParams: {
|
||||||
// host: 'https://localhost:8545' // optional
|
host: oceanConfig.url // optional
|
||||||
// chainId: 1337, // optional
|
// chainId: 1337, // optional
|
||||||
// networkId: 1337 // optional
|
// networkId: 1337 // optional
|
||||||
// },
|
}
|
||||||
// config: {
|
}
|
||||||
// buildEnv: 'development' // optional
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,8 +44,8 @@ export async function connectWallet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isCorrectNetwork(chainId: number): boolean {
|
export function isCorrectNetwork(chainId: number): boolean {
|
||||||
const allowedIds = networks
|
const configuredNetwork = getChainId(network)
|
||||||
return allowedIds.includes(chainId)
|
return configuredNetwork === chainId
|
||||||
}
|
}
|
||||||
|
|
||||||
export function accountTruncate(account: string): string {
|
export function accountTruncate(account: string): string {
|
||||||
@ -70,3 +66,16 @@ export function getNetworkName(chainId: number): string {
|
|||||||
return 'Unknown'
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user