Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/components/payment-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,24 @@ export function PaymentSection({ serverInvoice }: PaymentSectionProps) {

const handleDirectPayments = async (paymentData: any, signer: any) => {
const isApprovalNeeded = paymentData.metadata.needsApproval;
const paymentTransactionIndex =
paymentData.metadata.paymentTransactionIndex;

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

const approvalIndex = paymentData.metadata.approvalTransactionIndex;

const approvalTransaction = await signer.sendTransaction(
paymentData.transactions[approvalIndex],
);

await approvalTransaction.wait();
// Execute all approval transactions (all transactions except the payment transaction)
for (let i = 0; i < paymentData.transactions.length; i++) {
if (i !== paymentTransactionIndex) {
const approvalTransaction = await signer.sendTransaction(
paymentData.transactions[i],
);
await approvalTransaction.wait();
}
}
}

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

const paymentTransaction = await signer.sendTransaction(
paymentData.transactions[isApprovalNeeded ? 1 : 0],
paymentData.transactions[paymentTransactionIndex],
);

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

toast("Switching to network", {
description: `Switching to ${targetAppkitNetwork.name} network`,
description: `Switching to ${targetAppkitNetwork?.name} network`,
});

try {
Expand Down