diff --git a/app/dapp.js b/app/dapp.js index 033f5b6..4dbb137 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -8,6 +8,7 @@ import Button from '@material-ui/core/Button'; import AddFunder from './components/AddFunder'; import CreateFunding from './components/CreateFunding'; import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize' +import { getUserFundProfiles } from './utils/events'; const { getNetworkType } = web3.eth.net; @@ -21,13 +22,15 @@ class App extends React.Component { EmbarkJS.onReady(async (err) => { getNetworkType().then(async network => { const { environment } = EmbarkJS - const needsInit = await vaultPledgingNeedsInit(); - const lpAllowance = await getLpAllowance(); + const needsInit = await vaultPledgingNeedsInit() + const lpAllowance = await getLpAllowance() + const fundProfiles = await getUserFundProfiles() this.setState({ network, environment, needsInit: needsInit === 0, - lpAllowance + lpAllowance, + fundProfiles }) }); }); diff --git a/app/utils/events.js b/app/utils/events.js new file mode 100644 index 0000000..bbb3e47 --- /dev/null +++ b/app/utils/events.js @@ -0,0 +1,25 @@ +import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock' +import web3 from 'Embark/web3' + +const { getPledgeAdmin } = LiquidPledgingMock.methods +const formatFundProfileEvent = async event => { + const { returnValues: { idGiver, url } } = event + const { commitTime, name, canceled } = await getPledgeAdmin(idGiver).call() + return { + idGiver, + url, + commitTime, + name, + canceled + } +} + +export const getUserFundProfiles = async () => { + const events = await LiquidPledgingMock.getPastEvents('GiverAdded', { + addr: await web3.eth.getCoinbase(), + fromBlock: 0, + toBlock: 'latest' + }) + const formattedEvents = await Promise.all(events.map(formatFundProfileEvent)) + return formattedEvents +} diff --git a/contracts/PledgeAdmins.sol b/contracts/PledgeAdmins.sol index eaa6e0d..6f1e88d 100644 --- a/contracts/PledgeAdmins.sol +++ b/contracts/PledgeAdmins.sol @@ -28,7 +28,7 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins { uint constant MAX_INTERPROJECT_LEVEL = 20; // Events - event GiverAdded(uint64 indexed idGiver, string url); + event GiverAdded(uint64 indexed idGiver, address indexed addr, string url); event GiverUpdated(uint64 indexed idGiver, string url); event DelegateAdded(uint64 indexed idDelegate, string url); event DelegateUpdated(uint64 indexed idDelegate, string url); @@ -88,7 +88,7 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins { url) ); - GiverAdded(idGiver, url); + GiverAdded(idGiver, addr, url); } /// @notice Updates a Giver's info to change the address, name, url, or @@ -356,4 +356,4 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins { PledgeAdmin storage parent = _findAdmin(a.parentProject); return _getProjectLevel(parent) + 1; } -} \ No newline at end of file +}