add DelegateAdded event

This commit is contained in:
Barry Gitarts 2018-12-03 08:50:15 -05:00
parent 95bef6267c
commit 8409705bc7
3 changed files with 42 additions and 16 deletions

View File

@ -12,10 +12,11 @@ const FunderProfilesTable = ({ data }) => (
<Fragment> <Fragment>
<MaterialTable <MaterialTable
columns={[ columns={[
{ title: 'Profile Id', field: 'idGiver', type: 'numeric' }, { title: 'Profile Id', field: 'idProfile', type: 'numeric' },
{ title: 'Name', field: 'name' }, { title: 'Name', field: 'name' },
{ title: 'Url', field: 'url' }, { title: 'Url', field: 'url' },
{ title: 'Commit Time', field: 'commitTime', type: 'numeric' }, { title: 'Commit Time', field: 'commitTime', type: 'numeric' },
{ title: 'Type', field: 'type' },
{ title: 'Canceled', field: 'canceled' } { title: 'Canceled', field: 'canceled' }
]} ]}
data={data.map(formatField)} data={data.map(formatField)}

View File

@ -9,7 +9,7 @@ import AddFunder from './components/AddFunder';
import CreateFunding from './components/CreateFunding'; import CreateFunding from './components/CreateFunding';
import FunderProfilesTable from './components/FunderProfilesTable.jsx' import FunderProfilesTable from './components/FunderProfilesTable.jsx'
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize' import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
import { getUserFundProfiles, formatFundProfileEvent } from './utils/events'; import { getProfileEvents, formatFundProfileEvent } from './utils/events';
const { getNetworkType } = web3.eth.net; const { getNetworkType } = web3.eth.net;
@ -25,7 +25,7 @@ class App extends React.Component {
const { environment } = EmbarkJS const { environment } = EmbarkJS
const needsInit = await vaultPledgingNeedsInit() const needsInit = await vaultPledgingNeedsInit()
const lpAllowance = await getLpAllowance() const lpAllowance = await getLpAllowance()
const fundProfiles = await getUserFundProfiles() const fundProfiles = await getProfileEvents()
this.setState({ this.setState({
network, network,
environment, environment,

View File

@ -1,25 +1,50 @@
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock' import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'
import web3 from 'Embark/web3' import web3 from 'Embark/web3'
const { getPledgeAdmin } = LiquidPledgingMock.methods const GIVER_ADDED = 'GiverAdded'
export const formatFundProfileEvent = async event => { const DELEGATE_ADDED = 'DelegateAdded'
const { returnValues: { idGiver, url } } = event const lookups = {
const { commitTime, name, canceled } = await getPledgeAdmin(idGiver).call() [GIVER_ADDED]: {
return { id: 'idGiver',
idGiver, type: 'Funder'
url, },
commitTime, [DELEGATE_ADDED]: {
name, id: 'idDelegate',
canceled type: 'Delegate'
} }
} }
export const getUserFundProfiles = async () => { const { getPledgeAdmin } = LiquidPledgingMock.methods
const events = await LiquidPledgingMock.getPastEvents('GiverAdded', { export const formatFundProfileEvent = async event => {
const lookup = lookups[event.event]
const { returnValues: { url } } = event
const idProfile = event.returnValues[lookup.id]
const { commitTime, name, canceled } = await getPledgeAdmin(idProfile).call()
return {
idProfile,
url,
commitTime,
name,
canceled,
type: lookups[event.event].type
}
}
const getPastEvents = async event => {
const events = await LiquidPledgingMock.getPastEvents(event, {
addr: await web3.eth.getCoinbase(), addr: await web3.eth.getCoinbase(),
fromBlock: 0, fromBlock: 0,
toBlock: 'latest' toBlock: 'latest'
}) })
const formattedEvents = await Promise.all(events.map(formatFundProfileEvent)) const formattedEvents = await Promise.all(
events.map(formatFundProfileEvent)
)
return formattedEvents return formattedEvents
} }
export const getFunderProfiles = async () => await getPastEvents('GiverAdded')
export const getDelegateProfiles = async () => await getPastEvents('DelegateAdded')
export const getProfileEvents = async () => {
const funderProfiles = await getFunderProfiles()
const delegateProfiles = await getDelegateProfiles()
return [ ...funderProfiles, ...delegateProfiles]
}