add token approval for dev environment

This commit is contained in:
Barry Gitarts 2018-12-01 15:32:00 -05:00
parent e6c74f731a
commit 764de025d0
4 changed files with 34 additions and 7 deletions

View File

@ -90,11 +90,11 @@ const CreateFunding = () => (
>
{currencies.map(option => (
<MenuItem style={{ display: 'flex', alignItems: 'center' }} key={option.value} value={option.value}>
<img
{option.icon || <img
src={option.img || `${TOKEN_ICON_API}/${option.value}.png`}
style={{ width: '3%', marginRight: '3%' }}
/>
{option.label}
/>}
{option.label}
</MenuItem>
))}
</TextField>

View File

@ -6,7 +6,7 @@ import web3 from "Embark/web3";
import Divider from '@material-ui/core/Divider';
import AddFunder from './components/AddFunder';
import CreateFunding from './components/CreateFunding';
import { initVaultAndLP } from './utils/initialize';
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval } from './utils/initialize'
const { getNetworkType } = web3.eth.net;
@ -20,9 +20,11 @@ class App extends React.Component {
EmbarkJS.onReady(async (err) => {
getNetworkType().then(async network => {
const { environment } = EmbarkJS
const needsInit = Number(await LiquidPledgingMock.methods.getInitializationBlock().call())
+ Number(await LPVault.methods.getInitializationBlock().call())
const needsInit = await vaultPledgingNeedsInit();
this.setState({ network, environment })
//methods during testing to help setup
if (environment === 'development') standardTokenApproval()
if (!needsInit) initVaultAndLP(LiquidPledgingMock, LPVault)
});
});

View File

@ -16,7 +16,8 @@ export const currencies = [
},
{
value: '0xd8a512EBD6fd82f44dFFD968EEB0835265497d20',
label: 'Standard Token'
label: 'Standard Token',
icon: '🤔',
}
]

View File

@ -1,6 +1,30 @@
import LPVault from 'Embark/contracts/LPVault'
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()
console.log(vaultInit)
const lpInit = await lp.methods.initialize(vault._address).send()
console.log(lpInit)
}
export const vaultPledgingNeedsInit = async () => {
const needsInit = Number(await LiquidPledgingMock.methods.getInitializationBlock().call())
+ Number(await LPVault.methods.getInitializationBlock().call())
return needsInit
}
export const standardTokenApproval = async () => {
const { approve, 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()
}
}