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