diff --git a/admin/src/components/Proposals/index.tsx b/admin/src/components/Proposals/index.tsx index 2c3b5ea6..37ffe224 100644 --- a/admin/src/components/Proposals/index.tsx +++ b/admin/src/components/Proposals/index.tsx @@ -33,7 +33,7 @@ class ProposalsNaked extends React.Component { } render() { - const id = this.props.match.params.id; + const id = Number(this.props.match.params.id); const { proposals, proposalsFetched } = store; if (!proposalsFetched) { @@ -118,7 +118,8 @@ class ProposalItemNaked extends React.Component { disabled={true} /> - {p.title} {p.proposalId} + {p.title} [{p.proposalId}]{p.proposalAddress}{' '} + { state = {}; render() { @@ -324,7 +325,7 @@ const ContractMethod = view(ContractMethodNaked); // tslint:disable-next-line:max-classes-per-file class ContractMethodSendNaked extends React.Component< - TContractMethod & { proposalId: string; name: string } + TContractMethod & { proposalId: number; name: string } > { state = { args: this.props.input.map(i => (i.type === 'boolean' ? false : '')) as any[], diff --git a/admin/src/store.ts b/admin/src/store.ts index ef1c1c0b..b20dd94b 100644 --- a/admin/src/store.ts +++ b/admin/src/store.ts @@ -54,7 +54,7 @@ async function fetchProposals() { return data; } -async function deleteProposal(id: string) { +async function deleteProposal(id: number) { const { data } = await api.delete('/admin/proposals/' + id); return data; } @@ -144,14 +144,15 @@ const app = store({ } }, - async populateProposalContract(proposalId: string) { + async populateProposalContract(proposalId: number) { + console.log(proposalId); if (web3) { await populateProposalContract(app, web3, proposalId); } }, async proposalContractSend( - proposalId: string, + proposalId: number, methodName: keyof Contract, inputs: ContractMethodInput[], args: any[], @@ -161,7 +162,7 @@ const app = store({ } }, - async deleteProposal(id: string) { + async deleteProposal(id: number) { try { await deleteProposal(id); app.proposals = app.proposals.filter(p => p.proposalId === id); diff --git a/admin/src/types.ts b/admin/src/types.ts index 10198311..d8a69e0c 100644 --- a/admin/src/types.ts +++ b/admin/src/types.ts @@ -13,7 +13,8 @@ export interface Milestone { title: string; } export interface Proposal { - proposalId: string; + proposalId: number; + proposalAddress: string; dateCreated: number; title: string; body: string; diff --git a/admin/src/web3helper.ts b/admin/src/web3helper.ts index 274efad3..1eeee75e 100644 --- a/admin/src/web3helper.ts +++ b/admin/src/web3helper.ts @@ -71,16 +71,17 @@ function checkCrowdFundFactory(app: TApp, web3: Web3) { export async function proposalContractSend( app: TApp, web3: Web3, - proposalId: string, + proposalId: number, methodName: keyof Contract, inputs: ContractMethodInput[], args: any[], ) { const storeProposal = app.proposals.find(p => p.proposalId === proposalId); if (storeProposal) { + const { proposalAddress } = storeProposal; await getAccount(app, web3); const storeMethod = storeProposal.contract[methodName]; - const contract = new web3.eth.Contract(CrowdFund.abi, proposalId); + const contract = new web3.eth.Contract(CrowdFund.abi, proposalAddress); app.crowdFundGeneralStatus = `calling (${storeProposal.title}).${methodName}...`; try { console.log(args); @@ -120,12 +121,13 @@ export async function proposalContractSend( export async function populateProposalContract( app: TApp, web3: Web3, - proposalId: string, + proposalId: number, ) { const storeProposal = app.proposals.find(p => p.proposalId === proposalId); - const contract = new web3.eth.Contract(CrowdFund.abi, proposalId); if (storeProposal) { + const { proposalAddress } = storeProposal; + const contract = new web3.eth.Contract(CrowdFund.abi, proposalAddress); storeProposal.contractStatus = 'loading...'; const methods = Object.keys(INITIAL_CONTRACT).map(k => k as keyof Contract); for (const method of methods) { @@ -137,7 +139,7 @@ export async function populateProposalContract( try { storeMethod.status = 'loading'; if (methodType === 'eth' && method === 'getBalance') { - storeMethod.value = (await web3.eth.getBalance(proposalId)) + ''; + storeMethod.value = (await web3.eth.getBalance(proposalAddress)) + ''; } else if (methodType === 'array') { const result = await collectArrayElements(contractMethod, app.ethAccount); if (method === 'milestones') { diff --git a/frontend/client/components/Proposal/CampaignBlock/index.tsx b/frontend/client/components/Proposal/CampaignBlock/index.tsx index 43c413e0..4e8958df 100644 --- a/frontend/client/components/Proposal/CampaignBlock/index.tsx +++ b/frontend/client/components/Proposal/CampaignBlock/index.tsx @@ -76,7 +76,7 @@ export class ProposalCampaignBlock extends React.Component { sendTransaction = () => { const { proposal, fundCrowdFund } = this.props; - fundCrowdFund(proposal.crowdFundContract, this.state.amountToRaise); + fundCrowdFund(proposal, this.state.amountToRaise); this.setState({ amountToRaise: '' }); }; diff --git a/frontend/client/components/Proposal/CancelModal.tsx b/frontend/client/components/Proposal/CancelModal.tsx index e3cab626..303be079 100644 --- a/frontend/client/components/Proposal/CancelModal.tsx +++ b/frontend/client/components/Proposal/CancelModal.tsx @@ -90,7 +90,7 @@ class CancelModal extends React.Component { }; private cancelProposal = () => { - this.props.triggerRefund(this.props.proposal.crowdFundContract); + this.props.triggerRefund(this.props.proposal); }; } diff --git a/frontend/client/components/Proposal/Governance/Refunds.tsx b/frontend/client/components/Proposal/Governance/Refunds.tsx index 880d4f8c..40fd0968 100644 --- a/frontend/client/components/Proposal/Governance/Refunds.tsx +++ b/frontend/client/components/Proposal/Governance/Refunds.tsx @@ -197,12 +197,12 @@ class GovernanceRefunds extends React.Component { } voteRefund = (vote: boolean) => { - this.props.voteRefund(this.props.proposal.crowdFundContract, vote); + this.props.voteRefund(this.props.proposal, vote); }; withdrawRefund = () => { const { proposal, account } = this.props; - this.props.withdrawRefund(proposal.crowdFundContract, account); + this.props.withdrawRefund(proposal, account); }; } diff --git a/frontend/client/components/Proposal/Milestones/MilestoneAction.tsx b/frontend/client/components/Proposal/Milestones/MilestoneAction.tsx index f59da576..a8d25ee9 100644 --- a/frontend/client/components/Proposal/Milestones/MilestoneAction.tsx +++ b/frontend/client/components/Proposal/Milestones/MilestoneAction.tsx @@ -234,18 +234,15 @@ export class Milestones extends React.Component { } private requestPayout = (milestoneIndex: number) => { - const { crowdFundContract } = this.props.proposal; - this.props.requestMilestonePayout(crowdFundContract, milestoneIndex); + this.props.requestMilestonePayout(this.props.proposal, milestoneIndex); }; private payPayout = (milestoneIndex: number) => { - const { crowdFundContract } = this.props.proposal; - this.props.payMilestonePayout(crowdFundContract, milestoneIndex); + this.props.payMilestonePayout(this.props.proposal, milestoneIndex); }; private votePayout = (milestoneIndex: number, vote: boolean) => { - const { crowdFundContract } = this.props.proposal; - this.props.voteMilestonePayout(crowdFundContract, milestoneIndex, vote); + this.props.voteMilestonePayout(this.props.proposal, milestoneIndex, vote); }; } diff --git a/frontend/client/components/Proposals/ProposalCard/index.tsx b/frontend/client/components/Proposals/ProposalCard/index.tsx index 834cdcde..da0e99d1 100644 --- a/frontend/client/components/Proposals/ProposalCard/index.tsx +++ b/frontend/client/components/Proposals/ProposalCard/index.tsx @@ -25,7 +25,7 @@ export class ProposalCard extends React.Component { } const { title, - proposalId, + proposalAddress, proposalUrlId, category, dateCreated, @@ -77,7 +77,7 @@ export class ProposalCard extends React.Component { ))} -
{proposalId}
+
{proposalAddress}
AppState; @@ -194,20 +194,21 @@ export function resetCreateCrowdFund() { } export type TRequestMilestonePayout = typeof requestMilestonePayout; -export function requestMilestonePayout(crowdFundContract: any, index: number) { +export function requestMilestonePayout(proposal: ProposalWithCrowdFund, index: number) { return async (dispatch: Dispatch, getState: GetState) => { dispatch({ type: types.REQUEST_MILESTONE_PAYOUT_PENDING, }); const state = getState(); const account = state.web3.accounts[0]; + const { crowdFundContract, proposalId } = proposal; try { await crowdFundContract.methods .requestMilestonePayout(index) .send({ from: account }) .once('confirmation', async () => { await sleep(5000); - await dispatch(fetchProposal(crowdFundContract._address)); + await dispatch(fetchProposal(proposalId)); dispatch({ type: types.REQUEST_MILESTONE_PAYOUT_FULFILLED, }); @@ -223,20 +224,22 @@ export function requestMilestonePayout(crowdFundContract: any, index: number) { } export type TPayMilestonePayout = typeof payMilestonePayout; -export function payMilestonePayout(crowdFundContract: any, index: number) { +export function payMilestonePayout(proposal: ProposalWithCrowdFund, index: number) { return async (dispatch: Dispatch, getState: GetState) => { dispatch({ type: types.PAY_MILESTONE_PAYOUT_PENDING, }); const state = getState(); const account = state.web3.accounts[0]; + const { crowdFundContract, proposalId } = proposal; + try { await crowdFundContract.methods .payMilestonePayout(index) .send({ from: account }) .once('confirmation', async () => { await sleep(5000); - await dispatch(fetchProposal(crowdFundContract._address)); + await dispatch(fetchProposal(proposalId)); dispatch({ type: types.PAY_MILESTONE_PAYOUT_FULFILLED, }); @@ -254,7 +257,7 @@ export function payMilestonePayout(crowdFundContract: any, index: number) { // TODO: BigNumber me export type TSendTransaction = typeof fundCrowdFund; -export function fundCrowdFund(crowdFundContract: any, value: number | string) { +export function fundCrowdFund(proposal: ProposalWithCrowdFund, value: number | string) { return async (dispatch: Dispatch, getState: GetState) => { dispatch({ type: types.SEND_PENDING, @@ -262,6 +265,7 @@ export function fundCrowdFund(crowdFundContract: any, value: number | string) { const state = getState(); const web3 = state.web3.web3; const account = state.web3.accounts[0]; + const { crowdFundContract, proposalId } = proposal; try { if (!web3) { @@ -272,7 +276,7 @@ export function fundCrowdFund(crowdFundContract: any, value: number | string) { .send({ from: account, value: web3.utils.toWei(String(value), 'ether') }) .once('confirmation', async () => { await sleep(5000); - await dispatch(fetchProposal(crowdFundContract._address)); + await dispatch(fetchProposal(proposalId)); dispatch({ type: types.SEND_FULFILLED, }); @@ -289,7 +293,7 @@ export function fundCrowdFund(crowdFundContract: any, value: number | string) { } export function voteMilestonePayout( - crowdFundContract: any, + proposal: ProposalWithCrowdFund, index: number, vote: boolean, ) { @@ -297,6 +301,7 @@ export function voteMilestonePayout( dispatch({ type: types.VOTE_AGAINST_MILESTONE_PAYOUT_PENDING }); const state = getState(); const account = state.web3.accounts[0]; + const { crowdFundContract, proposalId } = proposal; try { await crowdFundContract.methods @@ -304,7 +309,7 @@ export function voteMilestonePayout( .send({ from: account }) .once('confirmation', async () => { await sleep(5000); - await dispatch(fetchProposal(crowdFundContract._address)); + await dispatch(fetchProposal(proposalId)); dispatch({ type: types.VOTE_AGAINST_MILESTONE_PAYOUT_FULFILLED }); }); } catch (err) { @@ -318,11 +323,12 @@ export function voteMilestonePayout( }; } -export function voteRefund(crowdFundContract: any, vote: boolean) { +export function voteRefund(proposal: ProposalWithCrowdFund, vote: boolean) { return async (dispatch: Dispatch, getState: GetState) => { dispatch({ type: types.VOTE_REFUND_PENDING }); const state = getState(); const account = state.web3.accounts[0]; + const { crowdFundContract, proposalId } = proposal; try { await crowdFundContract.methods @@ -330,7 +336,7 @@ export function voteRefund(crowdFundContract: any, vote: boolean) { .send({ from: account }) .once('confirmation', async () => { await sleep(5000); - await dispatch(fetchProposal(crowdFundContract._address)); + await dispatch(fetchProposal(proposalId)); dispatch({ type: types.VOTE_REFUND_FULFILLED }); }); } catch (err) { @@ -366,15 +372,16 @@ async function freezeContract(crowdFundContract: any, account: string) { } } -export function triggerRefund(crowdFundContract: any) { +export function triggerRefund(proposal: ProposalWithCrowdFund) { return async (dispatch: Dispatch, getState: GetState) => { dispatch({ type: types.WITHDRAW_REFUND_PENDING }); const state = getState(); const account = state.web3.accounts[0]; + const { crowdFundContract, proposalId } = proposal; try { await freezeContract(crowdFundContract, account); - await dispatch(fetchProposal(crowdFundContract._address)); + await dispatch(fetchProposal(proposalId)); dispatch({ type: types.TRIGGER_REFUND_FULFILLED }); } catch (err) { dispatch({ @@ -386,11 +393,12 @@ export function triggerRefund(crowdFundContract: any) { }; } -export function withdrawRefund(crowdFundContract: any, address: string) { +export function withdrawRefund(proposal: ProposalWithCrowdFund, address: string) { return async (dispatch: Dispatch, getState: GetState) => { dispatch({ type: types.WITHDRAW_REFUND_PENDING }); const state = getState(); const account = state.web3.accounts[0]; + const { crowdFundContract, proposalId } = proposal; try { await freezeContract(crowdFundContract, account); @@ -399,7 +407,7 @@ export function withdrawRefund(crowdFundContract: any, address: string) { .send({ from: account }) .once('confirmation', async () => { await sleep(5000); - await dispatch(fetchProposal(crowdFundContract._address)); + await dispatch(fetchProposal(proposalId)); dispatch({ type: types.WITHDRAW_REFUND_FULFILLED }); }); } catch (err) {