Skip to content

Commit

Permalink
Merge pull request #97 from hansmrtn/api-bugfix
Browse files Browse the repository at this point in the history
updated to use api v1.0.1
  • Loading branch information
hmrtn authored Jan 7, 2022
2 parents 3dce976 + 78961e9 commit 45a2954
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 8 additions & 0 deletions packages/react-app/src/controllers/mongodbController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 2 additions & 4 deletions packages/react-app/src/routes/party/components/Distribute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,15 @@ 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,
amount: total,
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);
};
Expand Down
7 changes: 3 additions & 4 deletions packages/react-app/src/routes/party/components/Vote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 45a2954

Please sign in to comment.