@@ -285,20 +285,24 @@ export function PaymentSection({ serverInvoice }: PaymentSectionProps) {
285
285
286
286
const handleDirectPayments = async ( paymentData : any , signer : any ) => {
287
287
const isApprovalNeeded = paymentData . metadata . needsApproval ;
288
+ const paymentTransactionIndex =
289
+ paymentData . metadata . paymentTransactionIndex ;
288
290
289
291
if ( isApprovalNeeded ) {
290
292
setPaymentProgress ( "approving" ) ;
291
293
toast ( "Payment Approval Required" , {
292
294
description : "Please approve the payment in your wallet" ,
293
295
} ) ;
294
296
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
+ }
302
306
}
303
307
304
308
setPaymentProgress ( "paying" ) ;
@@ -308,7 +312,7 @@ export function PaymentSection({ serverInvoice }: PaymentSectionProps) {
308
312
} ) ;
309
313
310
314
const paymentTransaction = await signer . sendTransaction (
311
- paymentData . transactions [ isApprovalNeeded ? 1 : 0 ] ,
315
+ paymentData . transactions [ paymentTransactionIndex ] ,
312
316
) ;
313
317
314
318
await paymentTransaction . wait ( ) ;
@@ -333,7 +337,7 @@ export function PaymentSection({ serverInvoice }: PaymentSectionProps) {
333
337
ID_TO_APPKIT_NETWORK [ targetChain as keyof typeof ID_TO_APPKIT_NETWORK ] ;
334
338
335
339
toast ( "Switching to network" , {
336
- description : `Switching to ${ targetAppkitNetwork . name } network` ,
340
+ description : `Switching to ${ targetAppkitNetwork ? .name } network` ,
337
341
} ) ;
338
342
339
343
try {
0 commit comments