diff --git a/src/dapp.js b/src/dapp.js index 0cf77ba..ed3f99b 100644 --- a/src/dapp.js +++ b/src/dapp.js @@ -36,32 +36,7 @@ class App extends React.Component { this.setGraphClient(network) this.getAndSetPrices() - EmbarkJS.onReady(async (err) => { - if (err) { - console.error(err); - } else { - getNetworkType().then(async network => { - const { environment } = EmbarkJS - const isInitialized = await vaultPledgingNeedsInit() - if (isInitialized) { - if (environment === 'development') console.log('mock_time:', await LiquidPledging.mock_time.call()) - const account = await web3.eth.getCoinbase() - this.setState({ account }) - //TODO add block based sync - const authorizedPayments = await getAuthorizedPayments() - this.syncWithRemote() - this.setState({ - account, - network, - environment, - authorizedPayments, - needsInit: false - }) - } - }) - } - }) } setGraphClient = network => { @@ -91,6 +66,7 @@ class App extends React.Component { await EmbarkJS.enableEthereum() const account = await web3.eth.getCoinbase() this.setState({ account }) + this.web3Init() } getAndSetPrices = async () => { @@ -118,6 +94,30 @@ class App extends React.Component { this.setState({ prices: { ...prices, [key]: price }}) } + web3Init = () => { + EmbarkJS.onReady(async (err) => { + if (err) { + console.error(err); + } else { + getNetworkType().then(async network => { + const { environment } = EmbarkJS + const isInitialized = await vaultPledgingNeedsInit() + if (isInitialized) { + if (environment === 'development') console.log('mock_time:', await LiquidPledging.mock_time.call()) + const authorizedPayments = await getAuthorizedPayments() + this.syncWithRemote() + this.setState({ + network, + environment, + authorizedPayments, + needsInit: false + }) + } + }) + } + }) + } + render() { const { account, needsInit, lpAllowance: _lpAllowance, loading, authorizedPayments, snackbar, prices } = this.state const { appendFundProfile, appendPledges, transferPledgeAmounts, openSnackBar, closeSnackBar, syncWithRemote, updateUsdPrice, client, enableEthereum } = this