* admin adjustments for proposalId / proposalAddress * ensure fetchProposal called with proposalId * have ProposalCard display proposalAddress
This commit is contained in:
parent
250d5fb7a9
commit
22487b331b
|
@ -33,7 +33,7 @@ class ProposalsNaked extends React.Component<Props> {
|
|||
}
|
||||
|
||||
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<Proposal> {
|
|||
disabled={true}
|
||||
/>
|
||||
</div>
|
||||
<b>{p.title}</b> {p.proposalId} <Field title="category" value={p.category} />
|
||||
<b>{p.title}</b> [{p.proposalId}]{p.proposalAddress}{' '}
|
||||
<Field title="category" value={p.category} />
|
||||
<Field title="dateCreated" value={p.dateCreated * 1000} isTime={true} />
|
||||
<Field title="stage" value={p.stage} />
|
||||
<Field
|
||||
|
@ -230,7 +231,7 @@ const ProposalItem = view(ProposalItemNaked);
|
|||
|
||||
// tslint:disable-next-line:max-classes-per-file
|
||||
class ContractMethodNaked extends React.Component<
|
||||
TContractMethod & { proposalId: string; name: string }
|
||||
TContractMethod & { proposalId: number; name: string }
|
||||
> {
|
||||
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[],
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -13,7 +13,8 @@ export interface Milestone {
|
|||
title: string;
|
||||
}
|
||||
export interface Proposal {
|
||||
proposalId: string;
|
||||
proposalId: number;
|
||||
proposalAddress: string;
|
||||
dateCreated: number;
|
||||
title: string;
|
||||
body: string;
|
||||
|
|
|
@ -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') {
|
||||
|
|
|
@ -76,7 +76,7 @@ export class ProposalCampaignBlock extends React.Component<Props, State> {
|
|||
|
||||
sendTransaction = () => {
|
||||
const { proposal, fundCrowdFund } = this.props;
|
||||
fundCrowdFund(proposal.crowdFundContract, this.state.amountToRaise);
|
||||
fundCrowdFund(proposal, this.state.amountToRaise);
|
||||
|
||||
this.setState({ amountToRaise: '' });
|
||||
};
|
||||
|
|
|
@ -90,7 +90,7 @@ class CancelModal extends React.Component<Props> {
|
|||
};
|
||||
|
||||
private cancelProposal = () => {
|
||||
this.props.triggerRefund(this.props.proposal.crowdFundContract);
|
||||
this.props.triggerRefund(this.props.proposal);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -197,12 +197,12 @@ class GovernanceRefunds extends React.Component<Props> {
|
|||
}
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -234,18 +234,15 @@ export class Milestones extends React.Component<Props> {
|
|||
}
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ export class ProposalCard extends React.Component<Props> {
|
|||
}
|
||||
const {
|
||||
title,
|
||||
proposalId,
|
||||
proposalAddress,
|
||||
proposalUrlId,
|
||||
category,
|
||||
dateCreated,
|
||||
|
@ -77,7 +77,7 @@ export class ProposalCard extends React.Component<Props> {
|
|||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="ProposalCard-address">{proposalId}</div>
|
||||
<div className="ProposalCard-address">{proposalAddress}</div>
|
||||
|
||||
<div className="ProposalCard-info">
|
||||
<div
|
||||
|
|
|
@ -9,7 +9,7 @@ import { fetchProposal, fetchProposals } from 'modules/proposals/actions';
|
|||
import { PROPOSAL_CATEGORY } from 'api/constants';
|
||||
import { AppState } from 'store/reducers';
|
||||
import { Wei } from 'utils/units';
|
||||
import { TeamMember, AuthSignatureData } from 'types';
|
||||
import { TeamMember, AuthSignatureData, ProposalWithCrowdFund } from 'types';
|
||||
|
||||
type GetState = () => 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<any>, 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<any>, 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<any>, 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<any>, 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<any>, 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<any>, 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) {
|
||||
|
|
Loading…
Reference in New Issue