[0]): string | null => {
+ const decimals = currency.currency.decimals;
+ const amountInMinorUnits = convertToSmallestUnit(receivingAmountStr, decimals);
+ const minDisplay = convertFromSmallestUnit(currency.min, decimals);
+ const maxDisplay = convertFromSmallestUnit(currency.max, decimals);
+
+ if (amountInMinorUnits < currency.min) {
+ return `Receiving amount is below the minimum of ${minDisplay} ${currency.currency.code}`;
+ }
+ if (amountInMinorUnits > currency.max) {
+ return `Receiving amount exceeds the maximum of ${maxDisplay} ${currency.currency.code}`;
+ }
+ return null;
+ };
+
const updateAmounts = (amount: string, field: 'usd' | 'receiving') => {
if (!amount || !receivingCurrency || isUpdatingAmounts) return;
- // Check if we have a lookup response with supported currencies
const lookupData = lookupResponse?.data as LookupResponse;
const supportedCurrency = lookupData?.supportedCurrencies?.[0];
@@ -45,14 +60,19 @@ export default function PaymentInitiation({ currUser, lookupResponse, onQuoteSuc
setLastEditedField(field);
try {
+ let newReceivingAmount: string;
if (field === 'usd') {
- // User updated sending amount: receiving = exchangeRate * sending
const convertedAmount = (supportedCurrency.estimatedExchangeRate) * parseFloat(amount);
- setReceivingAmount(convertedAmount.toFixed(6));
+ newReceivingAmount = convertedAmount.toFixed(6);
+ setReceivingAmount(newReceivingAmount);
} else {
- // User updated receiving amount: sending = receiving / exchangeRate
const convertedAmount = parseFloat(amount) / (supportedCurrency.estimatedExchangeRate);
setUsdAmount(convertedAmount.toFixed(6));
+ newReceivingAmount = amount;
+ }
+
+ if (supportedCurrency.min && supportedCurrency.max) {
+ setAmountError(validateReceivingAmount(newReceivingAmount, supportedCurrency));
}
} catch (error) {
console.error('Error updating amounts:', error);
@@ -181,10 +201,16 @@ export default function PaymentInitiation({ currUser, lookupResponse, onQuoteSuc
+ {amountError && (
+
+ {amountError}
+
+ )}
+
;
requiredPayerDataFields?: Array<{ name: string; mandatory: boolean }>;
}