Skip to content

Commit

Permalink
chore: add check valid id
Browse files Browse the repository at this point in the history
  • Loading branch information
0xExp-po committed Nov 22, 2024
1 parent 1751a5e commit e71db29
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions dapp/src/components/page/proposal/ProposalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,41 +60,43 @@ const ProposalPage: React.FC = () => {
}
};
const getProposalDetails = async () => {
const proposal = demoProposalData.find((p) => p.id === id);
if (proposal) {
let proposalStatusView;
if (id) {
const proposal = demoProposalData.find((p) => p.id === id);
if (proposal) {
let proposalStatusView;

if (proposal.status === "accepted") {
proposalStatusView = "approved";
} else if (proposal.status === "active") {
if (proposal.endDate !== null) {
const endDateTimestamp = new Date(proposal.endDate).setHours(
0,
0,
0,
0,
);
const currentTime = new Date().setHours(0, 0, 0, 0);
if (endDateTimestamp < currentTime) {
proposalStatusView = "voted";
} else {
proposalStatusView = "active";
if (proposal.status === "accepted") {
proposalStatusView = "approved";
} else if (proposal.status === "active") {
if (proposal.endDate !== null) {
const endDateTimestamp = new Date(proposal.endDate).setHours(
0,
0,
0,
0,
);
const currentTime = new Date().setHours(0, 0, 0, 0);
if (endDateTimestamp < currentTime) {
proposalStatusView = "voted";
} else {
proposalStatusView = "active";
}
}
} else {
proposalStatusView = proposal.status;
}
const proposalView: ProposalView = {
...proposal,
status: proposalStatusView as ProposalViewStatus,
};
setProposal(proposalView);
const description = await fetchProposalFromIPFS(proposal.ipfsLink);
setDescription(description);
const outcome = await fetchOutcomeDataFromIPFS(proposal.ipfsLink);
setOutcome(outcome);
} else {
proposalStatusView = proposal.status;
alert("Proposal not found");
}
const proposalView: ProposalView = {
...proposal,
status: proposalStatusView as ProposalViewStatus,
};
setProposal(proposalView);
const description = await fetchProposalFromIPFS(proposal.ipfsLink);
setDescription(description);
const outcome = await fetchOutcomeDataFromIPFS(proposal.ipfsLink);
setOutcome(outcome);
} else {
alert("Proposal not found");
}
};

Expand Down

0 comments on commit e71db29

Please sign in to comment.