diff --git a/app/components/FunderProfilesTable.jsx b/app/components/FunderProfilesTable.jsx index 61e3e10..a46dc52 100644 --- a/app/components/FunderProfilesTable.jsx +++ b/app/components/FunderProfilesTable.jsx @@ -12,10 +12,11 @@ const FunderProfilesTable = ({ data }) => ( { - const { returnValues: { idGiver, url } } = event - const { commitTime, name, canceled } = await getPledgeAdmin(idGiver).call() - return { - idGiver, - url, - commitTime, - name, - canceled +const GIVER_ADDED = 'GiverAdded' +const DELEGATE_ADDED = 'DelegateAdded' +const lookups = { + [GIVER_ADDED]: { + id: 'idGiver', + type: 'Funder' + }, + [DELEGATE_ADDED]: { + id: 'idDelegate', + type: 'Delegate' } } -export const getUserFundProfiles = async () => { - const events = await LiquidPledgingMock.getPastEvents('GiverAdded', { +const { getPledgeAdmin } = LiquidPledgingMock.methods +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(), fromBlock: 0, toBlock: 'latest' }) - const formattedEvents = await Promise.all(events.map(formatFundProfileEvent)) + const formattedEvents = await Promise.all( + events.map(formatFundProfileEvent) + ) 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] +}