diff --git a/src/modules/dashboard/components/Dialogs/CreatePaymentDialog/CreatePaymentDialogForm.tsx b/src/modules/dashboard/components/Dialogs/CreatePaymentDialog/CreatePaymentDialogForm.tsx index 3531ea8a63..06a3a7b62e 100644 --- a/src/modules/dashboard/components/Dialogs/CreatePaymentDialog/CreatePaymentDialogForm.tsx +++ b/src/modules/dashboard/components/Dialogs/CreatePaymentDialog/CreatePaymentDialogForm.tsx @@ -119,19 +119,26 @@ const supRenderAvatar = (address: Address, item: ItemDataType) => ( ); +// NOTE: The equation to calculate totalToPay is as following (in Wei) +// totalToPay = (receivedAmount + 1) * (feeInverse / (feeInverse -1)) +// The network adds 1 wei extra fee after the percentage calculation +// For more info check out +// https://github.com/JoinColony/colonyNetwork/blob/806e4d5750dc3a6b9fa80f6e007773b28327c90f/contracts/colony/ColonyFunding.sol#L656 + export const calculateFee = ( receivedAmount: string, // amount that the recipient finally receives feeInverse: string, decimals: number, ): { feesInWei: string; totalToPay: string } => { const amountInWei = moveDecimal(receivedAmount, decimals); - const totalToPay = bigNumberify(amountInWei) + const totalToPayInWei = bigNumberify(amountInWei) + .add(1) .mul(feeInverse) - .div(bigNumberify(feeInverse).sub(1)); // this formula is easily derivable - const feesInWei = totalToPay.sub(amountInWei); + .div(bigNumberify(feeInverse).sub(1)); + const feesInWei = totalToPayInWei.sub(amountInWei); return { feesInWei: feesInWei.toString(), - totalToPay: moveDecimal(totalToPay, -1 * decimals), + totalToPay: moveDecimal(totalToPayInWei, -1 * decimals), }; // NOTE: seems like moveDecimal does not have strict typing };