2018-12-01 23:32:56 +00:00
|
|
|
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'
|
|
|
|
import web3 from 'Embark/web3'
|
|
|
|
|
2018-12-03 13:50:15 +00:00
|
|
|
const GIVER_ADDED = 'GiverAdded'
|
|
|
|
const DELEGATE_ADDED = 'DelegateAdded'
|
|
|
|
const lookups = {
|
|
|
|
[GIVER_ADDED]: {
|
|
|
|
id: 'idGiver',
|
|
|
|
type: 'Funder'
|
|
|
|
},
|
|
|
|
[DELEGATE_ADDED]: {
|
|
|
|
id: 'idDelegate',
|
|
|
|
type: 'Delegate'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 23:32:56 +00:00
|
|
|
const { getPledgeAdmin } = LiquidPledgingMock.methods
|
2018-12-02 14:46:20 +00:00
|
|
|
export const formatFundProfileEvent = async event => {
|
2018-12-03 13:50:15 +00:00
|
|
|
const lookup = lookups[event.event]
|
|
|
|
const { returnValues: { url } } = event
|
|
|
|
const idProfile = event.returnValues[lookup.id]
|
|
|
|
const { commitTime, name, canceled } = await getPledgeAdmin(idProfile).call()
|
2018-12-01 23:32:56 +00:00
|
|
|
return {
|
2018-12-03 13:50:15 +00:00
|
|
|
idProfile,
|
2018-12-01 23:32:56 +00:00
|
|
|
url,
|
|
|
|
commitTime,
|
|
|
|
name,
|
2018-12-03 13:50:15 +00:00
|
|
|
canceled,
|
|
|
|
type: lookups[event.event].type
|
2018-12-01 23:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-03 13:50:15 +00:00
|
|
|
const getPastEvents = async event => {
|
|
|
|
const events = await LiquidPledgingMock.getPastEvents(event, {
|
2018-12-01 23:32:56 +00:00
|
|
|
addr: await web3.eth.getCoinbase(),
|
|
|
|
fromBlock: 0,
|
|
|
|
toBlock: 'latest'
|
|
|
|
})
|
2018-12-03 13:50:15 +00:00
|
|
|
const formattedEvents = await Promise.all(
|
|
|
|
events.map(formatFundProfileEvent)
|
|
|
|
)
|
2018-12-01 23:32:56 +00:00
|
|
|
return formattedEvents
|
|
|
|
}
|
2018-12-03 13:50:15 +00:00
|
|
|
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]
|
|
|
|
}
|