Problem
Converting monetary amounts to JavaScript Number can cause silent precision loss, which is unsafe for financial operations.
Current Implementation
In src/app/(dashboard)/s/[id]/_components/subscription-plan-preview.tsx (line ~97):
const recurringPaymentBody = {
payee: subscriptionPlan.recipient,
amount: Number(subscriptionPlan.amount), // ⚠️ Unsafe conversion
invoiceCurrency: subscriptionPlan.paymentCurrency as PayoutCurrency,
// ...
};
Suggested Solution
Send atomic units (string or bigint) end-to-end to avoid precision loss:
const recurringPaymentBody = {
payee: subscriptionPlan.recipient,
amountAtomic: amount.toString(), // Send as string
invoiceCurrency: subscriptionPlan.paymentCurrency as PayoutCurrency,
// ...
};
Required Changes
- Update the
recurringPaymentBody to use amountAtomic: string (or bigint)
- Update
useCreateRecurringPayment hook to accept atomic units
- Update API types and backend handlers to accept and validate atomic unit strings
- Compute human-readable display values from atomic units when needed
Context
Impact
Priority: High - affects financial calculations and could lead to incorrect payment amounts.
Problem
Converting monetary amounts to JavaScript
Numbercan cause silent precision loss, which is unsafe for financial operations.Current Implementation
In
src/app/(dashboard)/s/[id]/_components/subscription-plan-preview.tsx(line ~97):Suggested Solution
Send atomic units (string or bigint) end-to-end to avoid precision loss:
Required Changes
recurringPaymentBodyto useamountAtomic: string(or bigint)useCreateRecurringPaymenthook to accept atomic unitsContext
Impact
Priority: High - affects financial calculations and could lead to incorrect payment amounts.