Skip to content

Commit

Permalink
Merge pull request #215 from DAOmasons/fixRounding
Browse files Browse the repository at this point in the history
fix totals and perc collection
  • Loading branch information
jordanlesich authored Jun 13, 2024
2 parents edca326 + d7cda48 commit 0273912
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/voting/ConfirmationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const ConfirmationPanel = ({
const totalPercent = useMemo(
() =>
form.values.ships.reduce((acc, curr) => {
return acc + Number(curr.shipPerc);
return Number((acc + Number(curr.shipPerc.toFixed(2))).toFixed(2));
}, 0),
[form.values]
);
Expand Down Expand Up @@ -127,11 +127,20 @@ export const ConfirmationPanel = ({
(choice) => choice.shipId === ship.shipId
)?.id;

const perc = ship.shipPerc || 0;

console.log('perc', perc);

const percToInt = parseFloat((perc * 1e6).toFixed());

console.log('percToInt', percToInt);

const tokenAmount =
(userTokenData.totalUserTokenBalance *
BigInt(Number(ship.shipPerc) * 1e6)) /
(userTokenData.totalUserTokenBalance * BigInt(percToInt)) /
BigInt(100 * 1e6);

console.log('tokenAmount', tokenAmount);

const pinRes = await pinJSONToIPFS({
voteReason: ship.shipComment,
});
Expand Down Expand Up @@ -199,6 +208,7 @@ export const ConfirmationPanel = ({
},
});
} catch (error: any) {
console.error(error);
notifications.show({
title: 'Error',
message: `Vote submission failed: ${error.message}`,
Expand Down

0 comments on commit 0273912

Please sign in to comment.