Skip to content

Commit

Permalink
Make sure we round properly wallet transfer fee and balance for display
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuoch committed Feb 10, 2022
1 parent bdf3a74 commit 1228648
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/libs/PaymentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ function formatPaymentMethods(bankAccountList, cardList, payPalMeUsername = '',
}

/**
* @param {Number} currentBalance
* @param {Number} currentBalance, in cents
* @param {String} methodType
* @returns {Number}
* @returns {Number} the fee, in cents
*/
function calculateWalletTransferBalanceFee(currentBalance, methodType) {
const transferMethodTypeFeeStructure = methodType === CONST.WALLET.TRANSFER_METHOD_TYPE.INSTANT
? CONST.WALLET.TRANSFER_METHOD_TYPE_FEE.INSTANT
: CONST.WALLET.TRANSFER_METHOD_TYPE_FEE.ACH;
const calculateFee = (currentBalance * transferMethodTypeFeeStructure.RATE) / 100;
const calculateFee = Math.ceil(currentBalance * (transferMethodTypeFeeStructure.RATE / 100));
return Math.max(calculateFee, transferMethodTypeFeeStructure.MINIMUM_FEE);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/unit/PaymentUtilsTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import CONST from '../../src/CONST';

const paymentUtils = require('../../src/libs/PaymentUtils');

describe('PaymentUtils', () => {
it('Test rounding wallet transfer instant fee', () => {
expect(paymentUtils.calculateWalletTransferBalanceFee(2100, CONST.WALLET.TRANSFER_METHOD_TYPE.INSTANT)).toBe(32);
});
});

0 comments on commit 1228648

Please sign in to comment.