Skip to content

Commit

Permalink
last PR fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolalombardim committed Feb 9, 2024
1 parent 9c73493 commit efdc805
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions components/choices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ const updateChoiceById = async (req, response) => {
let i = 0;

try {
const { votesData } = getInputFromSigPayload(payloadBytes);
const values = getInputFromSigPayload(payloadBytes);
let db_connect = dbo.getDb("Lite");

const pollID = votesData[0].pollID;
const pollID = values[0].pollID;

const poll = await db_connect
.collection("Polls")
Expand All @@ -67,11 +67,11 @@ const updateChoiceById = async (req, response) => {
const address = getPkhfromPk(publicKey);

// Validate values
if (votesData.length === 0) {
if (values.length === 0) {
throw new Error("No choices sent in the request");
}

votesData.forEach((value) => {
values.forEach((value) => {
if (value.address !== address) {
throw new Error("Invalid Proposal Body, Invalid Address in choices");
}
Expand All @@ -80,7 +80,7 @@ const updateChoiceById = async (req, response) => {
}
});

const choiceIds = votesData.map((value) => value.choiceId);
const choiceIds = values.map((value) => value.choiceId);
let duplicates = choiceIds.filter(
(item, index) => choiceIds.indexOf(item.trim()) !== index
);
Expand All @@ -107,7 +107,7 @@ const updateChoiceById = async (req, response) => {
}

await Promise.all(
votesData.map(async (value) => {
values.map(async (value) => {
const { choiceId } = value;

let walletVote = {
Expand Down Expand Up @@ -177,7 +177,7 @@ const updateChoiceById = async (req, response) => {
const mongoClient = dbo.getClient();
const session = mongoClient.startSession();

const distributedWeight = total.div(new BigNumber(votesData.length));
const distributedWeight = total.div(new BigNumber(values.length));

walletVote.balanceAtReferenceBlock = distributedWeight.toString();

Expand Down Expand Up @@ -208,7 +208,7 @@ const updateChoiceById = async (req, response) => {
i++;
})
.then((res) => {
if (i === votesData.length) {
if (i === values.length) {
// response.json({ success: true });
}
});
Expand All @@ -224,8 +224,8 @@ const updateChoiceById = async (req, response) => {
} else {
let newId = { _id: ObjectId(choice._id) };

if (votesData.length > 1) {
const distributedWeight = total.div(new BigNumber(votesData.length));
if (values.length > 1) {
const distributedWeight = total.div(new BigNumber(values.length));
walletVote.balanceAtReferenceBlock = distributedWeight.toString();
}
let data = {
Expand All @@ -239,7 +239,7 @@ const updateChoiceById = async (req, response) => {

j++;

if (j === votesData.length) {
if (j === values.length) {
// response.json({ success: true });
} else {
return;
Expand Down

0 comments on commit efdc805

Please sign in to comment.