add authorizePayment event to get paymentId

This commit is contained in:
Barry Gitarts 2018-12-12 14:55:43 -05:00
parent 12f685bfb5
commit a2143d5b84
3 changed files with 52 additions and 20 deletions

View File

@ -15,6 +15,7 @@ import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'
import LPVault from 'Embark/contracts/LPVault' import LPVault from 'Embark/contracts/LPVault'
import { getTokenLabel } from '../../utils/currencies' import { getTokenLabel } from '../../utils/currencies'
import { toWei } from '../../utils/conversions' import { toWei } from '../../utils/conversions'
import { FundingContext } from '../../context'
const { withdraw } = LiquidPledgingMock.methods const { withdraw } = LiquidPledgingMock.methods
const { confirmPayment } = LPVault.methods const { confirmPayment } = LPVault.methods
@ -58,27 +59,31 @@ class Withdraw extends PureComponent {
const { show } = this.state const { show } = this.state
const isPaying = rowData[7] === "1" const isPaying = rowData[7] === "1"
return ( return (
<FundingContext.Consumer>
{({ authorizedPayments }) =>
<Formik <Formik
initialValues={{}} initialValues={{}}
onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => { onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => {
const { amount } = values const { amount } = values
const args = isPaying ? [rowData.id] : [rowData.id, toWei(amount)] const paymentId = authorizedPayments.find(r => r.ref === rowData.id)['idPayment']
const args = isPaying ? [paymentId] : [paymentId, toWei(amount)]
const sendFn = isPaying ? confirmPayment : withdraw const sendFn = isPaying ? confirmPayment : withdraw
try {
const toSend = sendFn(...args); const toSend = sendFn(...args);
const estimateGas = await toSend.estimateGas();
const estimateGas = await toSend.estimateGas(); toSend.send({ gas: estimateGas + 1000 })
.then(res => {
toSend.send({gas: estimateGas + 1000}) console.log({res})
.then(res => { })
console.log({res}) .catch(e => {
}) console.log({e})
.catch(e => { })
console.log({e}) .finally(() => {
}) this.close()
.finally(() => { })
this.close() } catch (error) {
}) console.log(error)
}
}} }}
> >
{({ {({
@ -121,6 +126,8 @@ class Withdraw extends PureComponent {
</Collapse> </Collapse>
)} )}
</Formik> </Formik>
}
</FundingContext.Consumer>
) )
} }
} }

View File

@ -10,7 +10,7 @@ import CreateFunding from './components/CreateFunding';
import FunderProfilesTable from './components/FunderProfilesTable' import FunderProfilesTable from './components/FunderProfilesTable'
import PledgesTable from './components/PledgesTable' import PledgesTable from './components/PledgesTable'
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize' import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
import { getProfileEvents, formatFundProfileEvent } from './utils/events'; import { getProfileEvents, formatFundProfileEvent, getAuthorizedPayments } from './utils/events';
import { getAllPledges, appendToExistingPledges, transferBetweenPledges } from './utils/pledges'; import { getAllPledges, appendToExistingPledges, transferBetweenPledges } from './utils/pledges';
import { FundingContext } from './context' import { FundingContext } from './context'
import { cancelProfile } from './utils/fundProfiles' import { cancelProfile } from './utils/fundProfiles'
@ -39,13 +39,15 @@ class App extends React.Component {
const lpAllowance = await getLpAllowance() const lpAllowance = await getLpAllowance()
const fundProfiles = await getProfileEvents() const fundProfiles = await getProfileEvents()
const allPledges = await getAllPledges() const allPledges = await getAllPledges()
const authorizedPayments = await getAuthorizedPayments()
this.setState({ this.setState({
network, network,
environment, environment,
needsInit: false, needsInit: false,
lpAllowance, lpAllowance,
fundProfiles, fundProfiles,
allPledges allPledges,
authorizedPayments
}) })
} }
}); });
@ -77,9 +79,9 @@ class App extends React.Component {
} }
render() { render() {
const { needsInit, lpAllowance, fundProfiles, allPledges } = this.state; const { needsInit, lpAllowance, fundProfiles, allPledges, authorizedPayments } = this.state;
const { appendFundProfile, appendPledges, transferPledgeAmounts, cancelFundProfile } = this const { appendFundProfile, appendPledges, transferPledgeAmounts, cancelFundProfile } = this
const fundingContext = { transferPledgeAmounts } const fundingContext = { transferPledgeAmounts, authorizedPayments }
return ( return (
<FundingContext.Provider value={fundingContext}> <FundingContext.Provider value={fundingContext}>
<div> <div>

View File

@ -1,6 +1,8 @@
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock' import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'
import LPVault from 'Embark/contracts/LPVault'
import web3 from 'Embark/web3' import web3 from 'Embark/web3'
const AUTHORIZE_PAYMENT = 'AuthorizePayment'
const GIVER_ADDED = 'GiverAdded' const GIVER_ADDED = 'GiverAdded'
const DELEGATE_ADDED = 'DelegateAdded' const DELEGATE_ADDED = 'DelegateAdded'
const PROJECT_ADDED = 'ProjectAdded' const PROJECT_ADDED = 'ProjectAdded'
@ -19,6 +21,26 @@ const lookups = {
} }
} }
const formatVaultEvent = async event => {
const { returnValues } = event
return {
...returnValues,
ref: Number(returnValues.ref.slice(2))
}
}
const getPastVaultEvents = async event => {
const events = await LPVault.getPastEvents(event, {
addr: await web3.eth.getCoinbase(),
fromBlock: 0,
toBlock: 'latest'
})
const formattedEvents = await Promise.all(
events.map(formatVaultEvent)
)
return formattedEvents
}
const { getPledgeAdmin } = LiquidPledgingMock.methods const { getPledgeAdmin } = LiquidPledgingMock.methods
export const formatFundProfileEvent = async event => { export const formatFundProfileEvent = async event => {
const lookup = lookups[event.event] const lookup = lookups[event.event]
@ -50,6 +72,7 @@ const getPastEvents = async event => {
export const getFunderProfiles = async () => await getPastEvents(GIVER_ADDED) export const getFunderProfiles = async () => await getPastEvents(GIVER_ADDED)
export const getDelegateProfiles = async () => await getPastEvents(DELEGATE_ADDED) export const getDelegateProfiles = async () => await getPastEvents(DELEGATE_ADDED)
export const getProjectProfiles = async () => await getPastEvents(PROJECT_ADDED) export const getProjectProfiles = async () => await getPastEvents(PROJECT_ADDED)
export const getAuthorizedPayments = async () => getPastVaultEvents(AUTHORIZE_PAYMENT)
export const getProfileEvents = async () => { export const getProfileEvents = async () => {
const [ funderProfiles, delegateProfiles, projectProfiles] const [ funderProfiles, delegateProfiles, projectProfiles]
= await Promise.all([getFunderProfiles(), getDelegateProfiles(), getProjectProfiles()]) = await Promise.all([getFunderProfiles(), getDelegateProfiles(), getProjectProfiles()])