sync with subgraph without account info

This commit is contained in:
Barry Gitarts 2019-08-19 14:25:29 -04:00 committed by Barry G
parent 53135c8d9f
commit bd399646d1
1 changed files with 38 additions and 27 deletions

View File

@ -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 (
<ApolloProvider client={client}>