Skip to content

Commit

Permalink
Merge pull request #6685 from guardian/ahe/prevent-large-amount
Browse files Browse the repository at this point in the history
One-time checkout: prevent large other amount causing error
  • Loading branch information
andrewHEguardian authored Jan 13, 2025
2 parents ff416fa + 52d226f commit 5ed01ed
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,15 @@ function getFinalAmount(
selectedPriceCard: number | 'other',
otherAmount: string,
minAmount: number,
maxAmount: number,
coverTransactionCostSelected: boolean,
): number | undefined {
const transactionMultiplier: number = coverTransactionCostSelected ? 1.04 : 1;
if (selectedPriceCard === 'other') {
const parsedAmount = parseFloat(otherAmount);
return Number.isNaN(parsedAmount) || parsedAmount < minAmount
return Number.isNaN(parsedAmount) ||
parsedAmount < minAmount ||
parsedAmount > maxAmount
? undefined
: roundToDecimalPlaces(parsedAmount * transactionMultiplier);
}
Expand Down Expand Up @@ -242,13 +245,20 @@ export function OneTimeCheckoutComponent({
useState<boolean>(false);

const amountWithoutCoverCost =
getFinalAmount(selectedPriceCard, otherAmount, minAmount, false) ?? 0;
getFinalAmount(
selectedPriceCard,
otherAmount,
minAmount,
maxAmount,
false,
) ?? 0;
const transactionCoverCost = amountWithoutCoverCost * 0.04;

const finalAmount = getFinalAmount(
selectedPriceCard,
otherAmount,
minAmount,
maxAmount,
coverTransactionCost,
);

Expand Down

0 comments on commit 5ed01ed

Please sign in to comment.