From 78961e90ddc4a6e9bd14c73bfb48f7844fe131d2 Mon Sep 17 00:00:00 2001 From: hans Date: Thu, 6 Jan 2022 18:42:58 -0800 Subject: [PATCH] updated to use api v1.0.1 --- packages/react-app/src/controllers/mongodbController.js | 8 ++++++++ .../react-app/src/routes/party/components/Distribute.jsx | 6 ++---- packages/react-app/src/routes/party/components/Vote.jsx | 7 +++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/react-app/src/controllers/mongodbController.js b/packages/react-app/src/controllers/mongodbController.js index 42876365..3a1e4f09 100644 --- a/packages/react-app/src/controllers/mongodbController.js +++ b/packages/react-app/src/controllers/mongodbController.js @@ -18,4 +18,12 @@ export default class MongoDBController { const url = `${process.env.REACT_APP_API_URL}/party/${id}`; return this.http.put(url, data); } + async addPartyReceipt(id, data) { + const url = `${process.env.REACT_APP_API_URL}/party/${id}/distribute`; + return this.http.put(url, data); + } + async addPartyBallot(id, data) { + const url = `${process.env.REACT_APP_API_URL}/party/${id}/vote`; + return this.http.put(url, data); + } } diff --git a/packages/react-app/src/routes/party/components/Distribute.jsx b/packages/react-app/src/routes/party/components/Distribute.jsx index 6cce1f9b..6e8b79c3 100644 --- a/packages/react-app/src/routes/party/components/Distribute.jsx +++ b/packages/react-app/src/routes/party/components/Distribute.jsx @@ -98,7 +98,7 @@ export const Distribute = ({ }; const handleReceipt = res => { - if (res && (res.status === "confirmed" || res.status === 1)) { + if (res && res.hash && (res.status === "confirmed" || res.status === 1)) { console.log(" 🍾 Transaction " + res.hash + " finished!"); const receipt = { account: address, @@ -106,9 +106,7 @@ export const Distribute = ({ token: tokenInstance?.address, txn: res.hash, }; - partyData.receipts.push(receipt); - // NOTE: When updating the party, be sure include ALL the updated data - dbInstance.updateParty(partyData.id, { ballots: partyData.ballots, receipts: partyData.receipts }); + dbInstance.addPartyReceipt(partyData.id, receipt); } setIsDistributionLoading(false); }; diff --git a/packages/react-app/src/routes/party/components/Vote.jsx b/packages/react-app/src/routes/party/components/Vote.jsx index fe7c2b83..7171fac1 100644 --- a/packages/react-app/src/routes/party/components/Vote.jsx +++ b/packages/react-app/src/routes/party/components/Vote.jsx @@ -72,14 +72,13 @@ export const Vote = ({ dbInstance, partyData, address, userSigner, targetNetwork // TODO: Check if account has already submitted a ballot if (cast.length === 0) { // Push a ballot to the parties sumbitted ballots array - ballots.push({ signature: sig, data: ballot }); - return ballots; + return { signature: sig, data: ballot }; } else { throw "Error: Account already voted!"; } }) - .then(ballots => { - dbInstance.updateParty(partyData.id, { ballots: ballots, receipts: partyData.receipts }); + .then(b => { + dbInstance.addPartyBallot(partyData.id, b); }) .catch(err => { console.log(err);