2018-12-15 17:03:19 +00:00
|
|
|
import React from 'react'
|
|
|
|
import { HashRouter as Router, Route, Link, Switch } from 'react-router-dom'
|
2018-12-21 18:32:12 +00:00
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
|
|
|
import LPVault from 'Embark/contracts/LPVault';
|
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'
|
2018-12-15 10:49:08 +00:00
|
|
|
import { getAllLPEvents, getAllVaultEvents, getProfileEvents, formatFundProfileEvent, getAuthorizedPayments } from './utils/events'
|
2018-12-18 19:30:50 +00:00
|
|
|
import { getAllPledges, appendToExistingPledges, transferBetweenPledges } from './utils/pledges'
|
2018-12-04 22:10:43 +00:00
|
|
|
import { FundingContext } from './context'
|
2018-12-07 14:47:00 +00:00
|
|
|
import { cancelProfile } from './utils/fundProfiles'
|
2018-12-15 12:01:40 +00:00
|
|
|
import MainCointainer from './components/MainCointainer'
|
2018-12-18 19:30:50 +00:00
|
|
|
import { getTransfersMemo } from './selectors/pledging'
|
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 = {
|
|
|
|
lpAllowance: 0,
|
|
|
|
fundProfiles: [],
|
|
|
|
allPledges: [],
|
2018-12-18 19:30:50 +00:00
|
|
|
needsInit: true,
|
|
|
|
transfers: [],
|
2018-12-19 14:27:09 +00:00
|
|
|
allLpEvents: [],
|
|
|
|
vaultEvents: []
|
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) {
|
2018-12-21 19:31:46 +00:00
|
|
|
console.log('mock_time:', await LiquidPledging.mock_time.call())
|
2018-12-08 01:25:38 +00:00
|
|
|
const lpAllowance = await getLpAllowance()
|
|
|
|
const fundProfiles = await getProfileEvents()
|
|
|
|
const allPledges = await getAllPledges()
|
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()
|
2018-12-14 19:10:08 +00:00
|
|
|
const allLpEvents = await getAllLPEvents()
|
2018-12-15 20:31:24 +00:00
|
|
|
const vaultEvents = await getAllVaultEvents()
|
2018-12-18 19:30:50 +00:00
|
|
|
const transfers = getTransfersMemo({ allLpEvents })
|
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,
|
|
|
|
needsInit: false,
|
|
|
|
lpAllowance,
|
|
|
|
fundProfiles,
|
2018-12-12 19:55:43 +00:00
|
|
|
allPledges,
|
2018-12-14 19:10:08 +00:00
|
|
|
authorizedPayments,
|
|
|
|
allLpEvents,
|
2018-12-15 20:31:24 +00:00
|
|
|
vaultEvents,
|
2018-12-14 19:10:08 +00:00
|
|
|
transfers
|
2018-12-08 01:25:38 +00:00
|
|
|
})
|
|
|
|
}
|
2018-12-16 17:59:33 +00:00
|
|
|
})
|
|
|
|
})
|
2018-11-28 16:12:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 14:46:20 +00:00
|
|
|
appendFundProfile = async event => {
|
|
|
|
const formattedEvent = await formatFundProfileEvent(event)
|
|
|
|
this.setState((state) => {
|
2018-12-13 20:41:40 +00:00
|
|
|
const { fundProfiles } = state
|
2018-12-02 14:46:20 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
fundProfiles: [ ...fundProfiles, formattedEvent ]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-12-03 17:15:16 +00:00
|
|
|
appendPledges = () => {
|
|
|
|
const { allPledges } = this.state
|
|
|
|
appendToExistingPledges(allPledges, this.setState)
|
|
|
|
}
|
|
|
|
|
2018-12-04 22:10:43 +00:00
|
|
|
transferPledgeAmounts = tx => {
|
|
|
|
transferBetweenPledges(this.setState.bind(this), tx)
|
|
|
|
}
|
|
|
|
|
2018-12-07 14:47:00 +00:00
|
|
|
cancelFundProfile = id => {
|
|
|
|
this.setState((state) => cancelProfile(state, id))
|
|
|
|
}
|
|
|
|
|
2018-11-28 16:12:50 +00:00
|
|
|
render() {
|
2018-12-18 19:30:50 +00:00
|
|
|
const { account, needsInit, lpAllowance, fundProfiles, allPledges, allLpEvents, authorizedPayments, transfers, vaultEvents } = this.state
|
2018-12-07 14:47:00 +00:00
|
|
|
const { appendFundProfile, appendPledges, transferPledgeAmounts, cancelFundProfile } = this
|
2018-12-18 19:30:50 +00:00
|
|
|
const fundingContext = { allPledges, allLpEvents, appendPledges, appendFundProfile, account, transferPledgeAmounts, authorizedPayments, cancelFundProfile, fundProfiles, needsInit, initVaultAndLP, standardTokenApproval, transfers, vaultEvents }
|
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>
|
2018-12-15 20:31:24 +00:00
|
|
|
<MainCointainer />
|
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
|