mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
provide global loadOcean method
This commit is contained in:
parent
125df58464
commit
5d40c87c07
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"typescript.tsdk": "node_modules/typescript/lib"
|
|
||||||
}
|
|
@ -1,15 +1,23 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { Ocean, Account } from '@oceanprotocol/squid'
|
import { Ocean, Account, Config } from '@oceanprotocol/squid'
|
||||||
import { User } from '.'
|
import { User } from '.'
|
||||||
import { provideOcean, requestFromFaucet, FaucetResponse } from '../ocean'
|
import { provideOcean, requestFromFaucet, FaucetResponse } from '../ocean'
|
||||||
import { nodeUri } from '../config'
|
|
||||||
import MarketProvider from './MarketProvider'
|
import MarketProvider from './MarketProvider'
|
||||||
import { MetamaskProvider } from './MetamaskProvider'
|
import { MetamaskProvider } from './MetamaskProvider'
|
||||||
import { BurnerWalletProvider } from './BurnerWalletProvider'
|
import { BurnerWalletProvider } from './BurnerWalletProvider'
|
||||||
|
|
||||||
import { NetworkSwitcher } from '../components/molecules/NetworkSwitcher'
|
import { NetworkSwitcher } from '../components/molecules/NetworkSwitcher'
|
||||||
|
|
||||||
|
import {
|
||||||
|
aquariusUri,
|
||||||
|
brizoUri,
|
||||||
|
brizoAddress,
|
||||||
|
nodeUri,
|
||||||
|
secretStoreUri,
|
||||||
|
verbose
|
||||||
|
} from '../config'
|
||||||
|
|
||||||
const POLL_ACCOUNTS = 1000 // every 1s
|
const POLL_ACCOUNTS = 1000 // every 1s
|
||||||
const POLL_NETWORK = POLL_ACCOUNTS * 60 // every 1 min
|
const POLL_NETWORK = POLL_ACCOUNTS * 60 // every 1 min
|
||||||
const DEFAULT_WEB3 = new Web3(new Web3.providers.HttpProvider(nodeUri)) // default web3
|
const DEFAULT_WEB3 = new Web3(new Web3.providers.HttpProvider(nodeUri)) // default web3
|
||||||
@ -31,9 +39,19 @@ interface UserProviderState {
|
|||||||
loginMetamask(): Promise<any>
|
loginMetamask(): Promise<any>
|
||||||
loginBurnerWallet(): Promise<any>
|
loginBurnerWallet(): Promise<any>
|
||||||
logoutBurnerWallet(): Promise<any>
|
logoutBurnerWallet(): Promise<any>
|
||||||
|
loadOcean: (config: Config) => Promise<Ocean | void>
|
||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const oceanConfig = {
|
||||||
|
nodeUri,
|
||||||
|
aquariusUri,
|
||||||
|
brizoUri,
|
||||||
|
brizoAddress,
|
||||||
|
secretStoreUri,
|
||||||
|
verbose
|
||||||
|
}
|
||||||
|
|
||||||
export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
||||||
private loginMetamask = async () => {
|
private loginMetamask = async () => {
|
||||||
const metamaskProvider = new MetamaskProvider()
|
const metamaskProvider = new MetamaskProvider()
|
||||||
@ -46,7 +64,10 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
web3
|
web3
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
this.loadOcean()
|
this.loadOcean({
|
||||||
|
web3Provider: this.state.web3,
|
||||||
|
...oceanConfig
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -62,7 +83,10 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
web3
|
web3
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
this.loadOcean()
|
this.loadOcean({
|
||||||
|
web3Provider: this.state.web3,
|
||||||
|
...oceanConfig
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -89,6 +113,7 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
loginMetamask: () => this.loginMetamask(),
|
loginMetamask: () => this.loginMetamask(),
|
||||||
loginBurnerWallet: () => this.loginBurnerWallet(),
|
loginBurnerWallet: () => this.loginBurnerWallet(),
|
||||||
logoutBurnerWallet: () => this.logoutBurnerWallet(),
|
logoutBurnerWallet: () => this.logoutBurnerWallet(),
|
||||||
|
loadOcean: (config: Config) => this.loadOcean(config),
|
||||||
message: 'Connecting to Ocean...'
|
message: 'Connecting to Ocean...'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,13 +145,19 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
web3: DEFAULT_WEB3
|
web3: DEFAULT_WEB3
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
this.loadOcean()
|
this.loadOcean({
|
||||||
|
web3Provider: this.state.web3,
|
||||||
|
...oceanConfig
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadOcean = async () => {
|
private loadOcean = async (config: Config) => {
|
||||||
const { ocean } = await provideOcean(this.state.web3)
|
const { ocean } = await provideOcean({
|
||||||
|
web3Provider: this.state.web3,
|
||||||
|
...config
|
||||||
|
})
|
||||||
this.setState({ ocean, isLoading: false }, () => {
|
this.setState({ ocean, isLoading: false }, () => {
|
||||||
this.initNetworkPoll()
|
this.initNetworkPoll()
|
||||||
this.initAccountsPoll()
|
this.initAccountsPoll()
|
||||||
@ -152,7 +183,10 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
web3
|
web3
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
this.loadOcean()
|
this.loadOcean({
|
||||||
|
web3Provider: this.state.web3,
|
||||||
|
...oceanConfig
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,30 +1,8 @@
|
|||||||
import { Ocean, Logger } from '@oceanprotocol/squid'
|
import { Ocean, Logger, Config } from '@oceanprotocol/squid'
|
||||||
import Web3 from 'web3'
|
import { faucetUri } from './config'
|
||||||
import { User } from './context'
|
|
||||||
|
|
||||||
import {
|
export async function provideOcean(config: Config) {
|
||||||
aquariusUri,
|
const ocean: Ocean = await Ocean.getInstance(config)
|
||||||
brizoUri,
|
|
||||||
brizoAddress,
|
|
||||||
faucetUri,
|
|
||||||
nodeUri,
|
|
||||||
secretStoreUri,
|
|
||||||
verbose
|
|
||||||
} from './config'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export async function provideOcean(web3Provider: Web3) {
|
|
||||||
const config = {
|
|
||||||
web3Provider,
|
|
||||||
nodeUri,
|
|
||||||
aquariusUri,
|
|
||||||
brizoUri,
|
|
||||||
brizoAddress,
|
|
||||||
secretStoreUri,
|
|
||||||
verbose
|
|
||||||
}
|
|
||||||
const ocean: any = await Ocean.getInstance(config)
|
|
||||||
return { ocean }
|
return { ocean }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user