1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

Ocean bootstrap tweaks

This commit is contained in:
Matthias Kretschmann 2019-04-12 18:00:44 +02:00
parent 823281f967
commit ffd290ad3f
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -109,8 +109,9 @@ class App extends Component<{}, AppState> {
public async componentDidMount() { public async componentDidMount() {
await this.bootstrap() await this.bootstrap()
// this.initAccountsPoll()
// this.initNetworkPoll() this.initAccountsPoll()
this.initNetworkPoll()
} }
private bootstrap = async () => { private bootstrap = async () => {
@ -131,8 +132,8 @@ class App extends Component<{}, AppState> {
if (err) return if (err) return
isNile = netId === 8995 isNile = netId === 8995
const network = isNile ? 'Nile' : netId.toString()
this.setState({ isNile, network: netId.toString() }) this.setState({ isNile, network })
}) })
if (!isNile) { if (!isNile) {
@ -146,16 +147,22 @@ class App extends Component<{}, AppState> {
const { ocean } = await provideOcean(web3provider) const { ocean } = await provideOcean(web3provider)
this.setState({ ocean, isLoading: false }) this.setState({ ocean, isLoading: false })
// Get accounts // Set proper network names now that we have Ocean
const network = await ocean.keeper.getNetworkName()
isNile = network === 'Nile'
this.setState({ isNile, network })
// Get accounts with Ocean
const accounts = await ocean.accounts.list() const accounts = await ocean.accounts.list()
if (accounts.length > 0) { if (accounts.length > 0) {
const balance = await accounts[0].getBalance()
this.setState({ this.setState({
isLogged: true, isLogged: true,
balance,
account: accounts[0].getId() account: accounts[0].getId()
}) })
const balance = await accounts[0].getBalance()
this.setState({ balance })
} }
} else { } else {
// //
@ -181,7 +188,7 @@ class App extends Component<{}, AppState> {
} }
private initAccountsPoll() { private initAccountsPoll() {
if (!this.accountsInterval) { if (!this.accountsInterval && this.state.ocean.length) {
this.accountsInterval = setInterval( this.accountsInterval = setInterval(
this.fetchAccounts, this.fetchAccounts,
POLL_ACCOUNTS POLL_ACCOUNTS
@ -190,7 +197,7 @@ class App extends Component<{}, AppState> {
} }
private initNetworkPoll() { private initNetworkPoll() {
if (!this.networkInterval) { if (!this.networkInterval && this.state.ocean.length) {
this.networkInterval = setInterval(this.fetchNetwork, POLL_NETWORK) this.networkInterval = setInterval(this.fetchNetwork, POLL_NETWORK)
} }
} }
@ -206,8 +213,16 @@ class App extends Component<{}, AppState> {
const account = accounts[0].getId() const account = accounts[0].getId()
if (account !== this.state.account) { if (account !== this.state.account) {
const balance = await accounts[0].getBalance() this.setState({ account, isLogged: true })
this.setState({ account, balance, isLogged: true }) }
const balance = await accounts[0].getBalance()
if (
balance.eth !== this.state.balance.eth ||
balance.ocn !== this.state.balance.ocn
) {
this.setState({ balance })
} }
} else { } else {
this.state.isLogged !== false && this.state.isLogged !== false &&