mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
refactor config helper
This commit is contained in:
parent
e9fbf3e4cb
commit
07bb1bfde0
@ -1,19 +1,15 @@
|
|||||||
export interface ConfigHelper {
|
import Config from '../models/Config'
|
||||||
|
|
||||||
|
export interface ConfigHelperConfig extends Config {
|
||||||
chainId?: number
|
chainId?: number
|
||||||
network: string
|
network: 'mainnet' | 'rinkeby' | 'development' | string
|
||||||
url: string
|
|
||||||
factoryAddress: string
|
|
||||||
poolFactoryAddress: string
|
|
||||||
oceanTokenAddress: string
|
|
||||||
metadataStoreUri: string
|
|
||||||
providerUri: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const configs = [
|
const configs: ConfigHelperConfig[] = [
|
||||||
{
|
{
|
||||||
chaindId: null,
|
chainId: null,
|
||||||
network: 'development',
|
network: 'development',
|
||||||
url: 'http://localhost:8545',
|
nodeUri: 'http://localhost:8545',
|
||||||
factoryAddress: null,
|
factoryAddress: null,
|
||||||
metadataStoreUri: 'http://127.0.0.1:5000',
|
metadataStoreUri: 'http://127.0.0.1:5000',
|
||||||
providerUri: 'http://127.0.0.1:8030',
|
providerUri: 'http://127.0.0.1:8030',
|
||||||
@ -23,7 +19,7 @@ const configs = [
|
|||||||
{
|
{
|
||||||
chainId: 4,
|
chainId: 4,
|
||||||
network: 'rinkeby',
|
network: 'rinkeby',
|
||||||
url: 'https://rinkeby.infura.io/v3',
|
nodeUri: 'https://rinkeby.infura.io/v3',
|
||||||
factoryAddress: '0x3ECd1429101f93149D799Ef257C07a2B1Dc30897',
|
factoryAddress: '0x3ECd1429101f93149D799Ef257C07a2B1Dc30897',
|
||||||
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
|
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
|
||||||
metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
||||||
@ -34,7 +30,7 @@ const configs = [
|
|||||||
{
|
{
|
||||||
chainId: 1,
|
chainId: 1,
|
||||||
network: 'mainnet',
|
network: 'mainnet',
|
||||||
url: 'https://mainnet.infura.io/v3',
|
nodeUri: 'https://mainnet.infura.io/v3',
|
||||||
factoryAddress: '0x1234',
|
factoryAddress: '0x1234',
|
||||||
oceanTokenAddress: '0x985dd3d42de1e256d09e1c10f112bccb8015ad41',
|
oceanTokenAddress: '0x985dd3d42de1e256d09e1c10f112bccb8015ad41',
|
||||||
metadataStoreUri: null,
|
metadataStoreUri: null,
|
||||||
@ -45,59 +41,23 @@ const configs = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export class ConfigHelper {
|
export class ConfigHelper {
|
||||||
public getConfig(network: string, infuraProjectId?: string): ConfigHelper {
|
private getNodeUri(config: ConfigHelperConfig, infuraProjectId?: string) {
|
||||||
const confighelp = new ConfigHelper()
|
const nodeUri = infuraProjectId
|
||||||
// fill unknown values
|
? `${config.nodeUri}/${infuraProjectId}`
|
||||||
confighelp.chainId = null
|
: config.nodeUri
|
||||||
confighelp.factoryAddress = null
|
|
||||||
confighelp.url = null
|
|
||||||
confighelp.network = network
|
|
||||||
confighelp.oceanTokenAddress = null
|
|
||||||
confighelp.metadataStoreUri = null
|
|
||||||
confighelp.providerUri = null
|
|
||||||
confighelp.poolFactoryAddress = null
|
|
||||||
|
|
||||||
const knownconfig = configs.find((c) => c.network === network)
|
return nodeUri
|
||||||
|
|
||||||
if (knownconfig) {
|
|
||||||
confighelp.chainId = knownconfig.chainId
|
|
||||||
confighelp.factoryAddress = knownconfig.factoryAddress
|
|
||||||
confighelp.oceanTokenAddress = knownconfig.oceanTokenAddress
|
|
||||||
confighelp.url = `${knownconfig.url}/${infuraProjectId}`
|
|
||||||
confighelp.network = knownconfig.network
|
|
||||||
confighelp.metadataStoreUri = knownconfig.metadataStoreUri
|
|
||||||
confighelp.providerUri = knownconfig.providerUri
|
|
||||||
confighelp.poolFactoryAddress = knownconfig.poolFactoryAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
return confighelp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getConfigById(chainId: number, infuraProjectId?: string): ConfigHelper {
|
public getConfig(network: string, infuraProjectId?: string): ConfigHelperConfig {
|
||||||
const confighelp = new ConfigHelper()
|
const knownconfig = configs.find((c) => c.network === network)
|
||||||
// fill unknown values
|
const nodeUri = this.getNodeUri(knownconfig, infuraProjectId)
|
||||||
confighelp.chainId = chainId
|
return knownconfig ? { ...knownconfig, nodeUri } : null
|
||||||
confighelp.factoryAddress = null
|
}
|
||||||
confighelp.url = null
|
|
||||||
confighelp.network = null
|
|
||||||
confighelp.oceanTokenAddress = null
|
|
||||||
confighelp.metadataStoreUri = null
|
|
||||||
confighelp.providerUri = null
|
|
||||||
confighelp.poolFactoryAddress = null
|
|
||||||
|
|
||||||
|
public getConfigById(chainId: number, infuraProjectId?: string): ConfigHelperConfig {
|
||||||
const knownconfig = configs.find((c) => c.chainId === chainId)
|
const knownconfig = configs.find((c) => c.chainId === chainId)
|
||||||
|
const nodeUri = this.getNodeUri(knownconfig, infuraProjectId)
|
||||||
if (knownconfig) {
|
return knownconfig ? { ...knownconfig, nodeUri } : null
|
||||||
confighelp.chainId = knownconfig.chainId
|
|
||||||
confighelp.factoryAddress = knownconfig.factoryAddress
|
|
||||||
confighelp.oceanTokenAddress = knownconfig.oceanTokenAddress
|
|
||||||
confighelp.url = `${knownconfig.url}/${infuraProjectId}`
|
|
||||||
confighelp.network = knownconfig.network
|
|
||||||
confighelp.metadataStoreUri = knownconfig.metadataStoreUri
|
|
||||||
confighelp.providerUri = knownconfig.providerUri
|
|
||||||
confighelp.poolFactoryAddress = knownconfig.poolFactoryAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
return confighelp
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user