From bd399646d1a713ba10401582cb93346d6afa09df Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Mon, 19 Aug 2019 14:25:29 -0400 Subject: [PATCH] sync with subgraph without account info --- src/dapp.js | 65 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/src/dapp.js b/src/dapp.js index f422bae..8b81acc 100644 --- a/src/dapp.js +++ b/src/dapp.js @@ -24,46 +24,56 @@ const { getNetworkType } = web3.eth.net class App extends React.Component { state = { - loading: true, + loading: false, lpAllowance: 0, needsInit: true, prices: {} }; componentDidMount(){ + getNetworkType().then(async network => { + this.setGraphClient(network) + }) + EmbarkJS.onReady(async (err) => { if (err) { console.error(err); - } - 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()) + } 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 graphUri = uris[network] - this.client = new ApolloClient({ - uri: graphUri, - }) - const account = await web3.eth.getCoinbase() - this.getAndSetPrices() - this.setState({ account }) - //TODO add block based sync - const authorizedPayments = await getAuthorizedPayments() - this.syncWithRemote() - this.setState({ - account, - network, - graphUri, - environment, - authorizedPayments, - needsInit: false - }) - } - }) + const account = await web3.eth.getCoinbase() + console.log({account}) + this.getAndSetPrices() + this.setState({ account }) + //TODO add block based sync + const authorizedPayments = await getAuthorizedPayments() + this.syncWithRemote() + this.setState({ + account, + network, + environment, + authorizedPayments, + needsInit: false + }) + } + }) + } }) } + setGraphClient = network => { + const graphUri = uris[network] + const client = new ApolloClient({ + uri: graphUri, + }) + this.client = client + this.setState({ clientReady: true }) + } + syncWithRemote = async () => { this.setState({ loading: true }) // not running in parallel due to possible metamask / infura limitation @@ -121,6 +131,7 @@ class App extends React.Component { prices, updateUsdPrice } + console.log({client, loading}) if (client) return (