2018-12-15 17:03:19 +00:00
|
|
|
import React from 'react'
|
2019-01-25 20:16:55 +00:00
|
|
|
import { HashRouter as Router } from 'react-router-dom'
|
|
|
|
import EmbarkJS from 'Embark/EmbarkJS'
|
2018-12-21 19:31:46 +00:00
|
|
|
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
2018-12-15 20:15:17 +00:00
|
|
|
import web3 from 'Embark/web3'
|
2018-12-01 22:16:58 +00:00
|
|
|
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
|
2019-01-25 20:16:55 +00:00
|
|
|
import { getAuthorizedPayments } from './utils/events'
|
2018-12-04 22:10:43 +00:00
|
|
|
import { FundingContext } from './context'
|
2018-12-15 12:01:40 +00:00
|
|
|
import MainCointainer from './components/MainCointainer'
|
2019-01-25 20:16:55 +00:00
|
|
|
import { getAndAddLpEvents } from './actions/lpEvents'
|
|
|
|
import { getAndAddVaultEvents } from './actions/vaultEvents'
|
|
|
|
import { addFormattedProfiles } from './actions/profiles'
|
2019-02-05 18:41:17 +00:00
|
|
|
import { updateStalePledges, getAndAddPledges } from './actions/pledges'
|
2018-11-28 16:12:50 +00:00
|
|
|
|
2018-12-14 19:10:08 +00:00
|
|
|
const { getNetworkType } = web3.eth.net
|
2018-11-28 16:12:50 +00:00
|
|
|
|
|
|
|
class App extends React.Component {
|
2018-12-08 01:25:38 +00:00
|
|
|
state = {
|
2019-01-10 20:44:45 +00:00
|
|
|
loading: true,
|
2018-12-08 01:25:38 +00:00
|
|
|
lpAllowance: 0,
|
2018-12-18 19:30:50 +00:00
|
|
|
needsInit: true,
|
2018-12-08 01:25:38 +00:00
|
|
|
};
|
2018-11-28 16:12:50 +00:00
|
|
|
|
|
|
|
componentDidMount(){
|
2018-11-29 16:45:57 +00:00
|
|
|
EmbarkJS.onReady(async (err) => {
|
2018-12-01 14:31:04 +00:00
|
|
|
getNetworkType().then(async network => {
|
2018-11-28 16:12:50 +00:00
|
|
|
const { environment } = EmbarkJS
|
2018-12-08 01:25:38 +00:00
|
|
|
const isInitialized = await vaultPledgingNeedsInit()
|
|
|
|
if (!!isInitialized) {
|
2019-01-02 20:32:28 +00:00
|
|
|
if (environment === 'development') console.log('mock_time:', await LiquidPledging.mock_time.call())
|
2019-01-25 20:16:55 +00:00
|
|
|
|
2018-12-08 01:25:38 +00:00
|
|
|
const lpAllowance = await getLpAllowance()
|
2019-01-25 20:16:55 +00:00
|
|
|
//TODO add block based sync
|
2018-12-12 19:55:43 +00:00
|
|
|
const authorizedPayments = await getAuthorizedPayments()
|
2018-12-13 20:41:40 +00:00
|
|
|
const account = await web3.eth.getCoinbase()
|
2019-01-25 20:16:55 +00:00
|
|
|
this.syncWithRemote()
|
2018-12-08 01:25:38 +00:00
|
|
|
this.setState({
|
2018-12-13 20:41:40 +00:00
|
|
|
account,
|
2018-12-08 01:25:38 +00:00
|
|
|
network,
|
|
|
|
environment,
|
|
|
|
lpAllowance,
|
2018-12-14 19:10:08 +00:00
|
|
|
authorizedPayments,
|
2019-01-25 20:16:55 +00:00
|
|
|
needsInit: false
|
2018-12-08 01:25:38 +00:00
|
|
|
})
|
|
|
|
}
|
2018-12-16 17:59:33 +00:00
|
|
|
})
|
|
|
|
})
|
2018-11-28 16:12:50 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 20:16:55 +00:00
|
|
|
async syncWithRemote() {
|
|
|
|
// not running in parallel due to possible metamask / infura limitation
|
|
|
|
await getAndAddLpEvents()
|
|
|
|
await getAndAddVaultEvents()
|
2019-02-14 14:41:26 +00:00
|
|
|
|
|
|
|
// Profiles must be loaded before pledges to set profile on pledge model
|
2019-01-25 20:16:55 +00:00
|
|
|
await addFormattedProfiles()
|
2019-02-14 14:41:26 +00:00
|
|
|
await getAndAddPledges()
|
2019-02-05 18:41:17 +00:00
|
|
|
await updateStalePledges()
|
2019-01-25 20:16:55 +00:00
|
|
|
this.setState({ loading: false })
|
2018-12-07 14:47:00 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 16:12:50 +00:00
|
|
|
render() {
|
2019-01-25 20:16:55 +00:00
|
|
|
const { account, needsInit, lpAllowance, loading, authorizedPayments } = this.state
|
|
|
|
const { appendFundProfile, appendPledges, transferPledgeAmounts } = this
|
|
|
|
const fundingContext = { appendPledges, appendFundProfile, account, transferPledgeAmounts, authorizedPayments, needsInit, initVaultAndLP, standardTokenApproval }
|
2018-11-28 16:12:50 +00:00
|
|
|
return (
|
2018-12-04 22:10:43 +00:00
|
|
|
<FundingContext.Provider value={fundingContext}>
|
2018-12-15 17:03:19 +00:00
|
|
|
<Router>
|
2019-01-10 20:44:45 +00:00
|
|
|
<MainCointainer loading={loading} />
|
2018-12-15 17:03:19 +00:00
|
|
|
</Router>
|
2018-12-04 22:10:43 +00:00
|
|
|
</FundingContext.Provider>
|
2018-11-28 16:12:50 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 16:41:29 +00:00
|
|
|
|
2018-12-15 12:01:40 +00:00
|
|
|
export default App
|