2018-11-28 16:12:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
2018-11-29 16:45:57 +00:00
|
|
|
import LPVault from 'Embark/contracts/LPVault';
|
|
|
|
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock';
|
2018-11-28 16:12:50 +00:00
|
|
|
import web3 from "Embark/web3";
|
2018-12-01 14:31:04 +00:00
|
|
|
import Divider from '@material-ui/core/Divider';
|
2018-12-01 22:16:58 +00:00
|
|
|
import Button from '@material-ui/core/Button';
|
2018-11-30 11:02:57 +00:00
|
|
|
import AddFunder from './components/AddFunder';
|
2018-11-30 18:36:09 +00:00
|
|
|
import CreateFunding from './components/CreateFunding';
|
2018-12-02 13:24:31 +00:00
|
|
|
import FunderProfilesTable from './components/FunderProfilesTable.jsx'
|
2018-12-01 22:16:58 +00:00
|
|
|
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
|
2018-12-02 14:46:20 +00:00
|
|
|
import { getUserFundProfiles, formatFundProfileEvent } from './utils/events';
|
2018-11-28 16:12:50 +00:00
|
|
|
|
|
|
|
const { getNetworkType } = web3.eth.net;
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
state = { admin: false };
|
|
|
|
|
|
|
|
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-01 23:32:56 +00:00
|
|
|
const needsInit = await vaultPledgingNeedsInit()
|
|
|
|
const lpAllowance = await getLpAllowance()
|
|
|
|
const fundProfiles = await getUserFundProfiles()
|
2018-12-01 22:16:58 +00:00
|
|
|
this.setState({
|
|
|
|
network,
|
|
|
|
environment,
|
|
|
|
needsInit: needsInit === 0,
|
2018-12-01 23:32:56 +00:00
|
|
|
lpAllowance,
|
|
|
|
fundProfiles
|
2018-12-01 22:16:58 +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) => {
|
|
|
|
const { fundProfiles } = state;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
fundProfiles: [ ...fundProfiles, formattedEvent ]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-28 16:12:50 +00:00
|
|
|
render() {
|
2018-12-02 13:24:31 +00:00
|
|
|
const { needsInit, lpAllowance, fundProfiles } = this.state;
|
2018-12-02 14:46:20 +00:00
|
|
|
const { appendFundProfile } = this;
|
2018-11-28 16:12:50 +00:00
|
|
|
return (
|
2018-11-28 16:41:29 +00:00
|
|
|
<div>
|
2018-12-02 13:24:31 +00:00
|
|
|
{fundProfiles && <FunderProfilesTable data={fundProfiles} />}
|
2018-12-02 14:46:20 +00:00
|
|
|
<AddFunder appendFundProfile={appendFundProfile} />
|
2018-12-01 14:31:04 +00:00
|
|
|
<Divider variant="middle" />
|
2018-11-30 18:36:09 +00:00
|
|
|
<CreateFunding />
|
2018-12-01 22:16:58 +00:00
|
|
|
{needsInit && <Button variant="outlined" color="secondary" onClick={initVaultAndLP}>
|
|
|
|
Initialize Contracts
|
|
|
|
</Button>}
|
|
|
|
<Button variant="outlined" color="primary" onClick={standardTokenApproval}>
|
|
|
|
GIVE VAULT TOKEN APPROVAL
|
|
|
|
</Button>
|
2018-11-28 16:41:29 +00:00
|
|
|
</div>
|
2018-11-28 16:12:50 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 16:41:29 +00:00
|
|
|
|
|
|
|
export default App;
|