Skip to content

Commit efd1bdc

Browse files
authored
feat: enable multi-approval processing fixing USDT payment issue (#132)
1 parent 41acd52 commit efd1bdc

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/components/payment-section.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,24 @@ export function PaymentSection({ serverInvoice }: PaymentSectionProps) {
285285

286286
const handleDirectPayments = async (paymentData: any, signer: any) => {
287287
const isApprovalNeeded = paymentData.metadata.needsApproval;
288+
const paymentTransactionIndex =
289+
paymentData.metadata.paymentTransactionIndex;
288290

289291
if (isApprovalNeeded) {
290292
setPaymentProgress("approving");
291293
toast("Payment Approval Required", {
292294
description: "Please approve the payment in your wallet",
293295
});
294296

295-
const approvalIndex = paymentData.metadata.approvalTransactionIndex;
296-
297-
const approvalTransaction = await signer.sendTransaction(
298-
paymentData.transactions[approvalIndex],
299-
);
300-
301-
await approvalTransaction.wait();
297+
// Execute all approval transactions (all transactions except the payment transaction)
298+
for (let i = 0; i < paymentData.transactions.length; i++) {
299+
if (i !== paymentTransactionIndex) {
300+
const approvalTransaction = await signer.sendTransaction(
301+
paymentData.transactions[i],
302+
);
303+
await approvalTransaction.wait();
304+
}
305+
}
302306
}
303307

304308
setPaymentProgress("paying");
@@ -308,7 +312,7 @@ export function PaymentSection({ serverInvoice }: PaymentSectionProps) {
308312
});
309313

310314
const paymentTransaction = await signer.sendTransaction(
311-
paymentData.transactions[isApprovalNeeded ? 1 : 0],
315+
paymentData.transactions[paymentTransactionIndex],
312316
);
313317

314318
await paymentTransaction.wait();
@@ -333,7 +337,7 @@ export function PaymentSection({ serverInvoice }: PaymentSectionProps) {
333337
ID_TO_APPKIT_NETWORK[targetChain as keyof typeof ID_TO_APPKIT_NETWORK];
334338

335339
toast("Switching to network", {
336-
description: `Switching to ${targetAppkitNetwork.name} network`,
340+
description: `Switching to ${targetAppkitNetwork?.name} network`,
337341
});
338342

339343
try {

0 commit comments

Comments
 (0)