add init buttons
This commit is contained in:
parent
764de025d0
commit
a64517e0b3
22
app/dapp.js
22
app/dapp.js
|
@ -4,9 +4,10 @@ import LPVault from 'Embark/contracts/LPVault';
|
|||
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock';
|
||||
import web3 from "Embark/web3";
|
||||
import Divider from '@material-ui/core/Divider';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import AddFunder from './components/AddFunder';
|
||||
import CreateFunding from './components/CreateFunding';
|
||||
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval } from './utils/initialize'
|
||||
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
|
||||
|
||||
const { getNetworkType } = web3.eth.net;
|
||||
|
||||
|
@ -21,21 +22,30 @@ class App extends React.Component {
|
|||
getNetworkType().then(async network => {
|
||||
const { environment } = EmbarkJS
|
||||
const needsInit = await vaultPledgingNeedsInit();
|
||||
this.setState({ network, environment })
|
||||
|
||||
//methods during testing to help setup
|
||||
if (environment === 'development') standardTokenApproval()
|
||||
if (!needsInit) initVaultAndLP(LiquidPledgingMock, LPVault)
|
||||
const lpAllowance = await getLpAllowance();
|
||||
this.setState({
|
||||
network,
|
||||
environment,
|
||||
needsInit: needsInit === 0,
|
||||
lpAllowance
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { needsInit, lpAllowance } = this.state;
|
||||
return (
|
||||
<div>
|
||||
<AddFunder />
|
||||
<Divider variant="middle" />
|
||||
<CreateFunding />
|
||||
{needsInit && <Button variant="outlined" color="secondary" onClick={initVaultAndLP}>
|
||||
Initialize Contracts
|
||||
</Button>}
|
||||
<Button variant="outlined" color="primary" onClick={standardTokenApproval}>
|
||||
GIVE VAULT TOKEN APPROVAL
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import StandardToken from 'Embark/contracts/StandardToken'
|
||||
|
||||
export const TOKEN_ICON_API = 'https://raw.githubusercontent.com/TrustWallet/tokens/master/images'
|
||||
export const TOKEN_COIN_API = 'https://raw.githubusercontent.com/TrustWallet/tokens/master/coins'
|
||||
export const currencies = [
|
||||
|
@ -15,7 +17,7 @@ export const currencies = [
|
|||
label: 'DAI',
|
||||
},
|
||||
{
|
||||
value: '0xd8a512EBD6fd82f44dFFD968EEB0835265497d20',
|
||||
value: StandardToken._address,
|
||||
label: 'Standard Token',
|
||||
icon: '🤔',
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'
|
|||
import StandardToken from 'Embark/contracts/StandardToken'
|
||||
import web3 from "Embark/web3"
|
||||
|
||||
export const initVaultAndLP = async (lp, vault) => {
|
||||
const vaultInit = await vault.methods.initialize(lp._address).send()
|
||||
export const initVaultAndLP = async () => {
|
||||
const vaultInit = await LPVault.methods.initialize(LiquidPledgingMock._address).send()
|
||||
console.log(vaultInit)
|
||||
const lpInit = await lp.methods.initialize(vault._address).send()
|
||||
const lpInit = await LiquidPledgingMock.methods.initialize(LPVault._address).send()
|
||||
console.log(lpInit)
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,18 @@ export const vaultPledgingNeedsInit = async () => {
|
|||
}
|
||||
|
||||
export const standardTokenApproval = async () => {
|
||||
const { approve, allowance } = StandardToken.methods
|
||||
const { approve } = StandardToken.methods
|
||||
const spender = LiquidPledgingMock._address
|
||||
return await approve(
|
||||
spender,
|
||||
web3.utils.toWei('10000000', 'tether')
|
||||
).send()
|
||||
}
|
||||
|
||||
export const getLpAllowance = async () => {
|
||||
const { allowance } = StandardToken.methods
|
||||
const account = await web3.eth.getCoinbase()
|
||||
const spender = LiquidPledgingMock._address
|
||||
const allowanceAmt = Number(await allowance(account, spender).call())
|
||||
if (allowanceAmt < 1000) {
|
||||
return await approve(
|
||||
spender,
|
||||
web3.utils.toWei('10000000', 'tether')
|
||||
).send()
|
||||
}
|
||||
return allowanceAmt
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue