@volr/react-ui 0.1.134 → 0.1.135

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6026,6 +6026,15 @@ function usePaymentModalState(open, onOpenChange) {
6026
6026
  });
6027
6027
  createdPaymentId = payment.id;
6028
6028
  dispatch({ type: "SET_CREATED_PAYMENT", payment });
6029
+ if (payment.status !== "PENDING") {
6030
+ const alreadyProcessedError = new Error(
6031
+ payment.status === "CONFIRMED" ? "This payment has already been completed. If you used an idempotencyKey, the original payment was already processed." : `Payment already processed with status: ${payment.status}. If you used an idempotencyKey, the original payment was already processed.`
6032
+ );
6033
+ alreadyProcessedError.code = "PAYMENT_ALREADY_PROCESSED";
6034
+ alreadyProcessedError.paymentStatus = payment.status;
6035
+ alreadyProcessedError.payment = payment;
6036
+ throw alreadyProcessedError;
6037
+ }
6029
6038
  paymentOptions.options.handlers?.onCreated?.({ id: payment.id });
6030
6039
  const evmClient = evm.client(tokenInfo.chainId);
6031
6040
  dispatch({ type: "SET_PROCESSING_STEP", step: "broadcasting" });
@@ -6071,13 +6080,28 @@ function usePaymentModalState(open, onOpenChange) {
6071
6080
  }
6072
6081
  } catch (err) {
6073
6082
  console.error("Payment failed:", err);
6074
- if (createdPaymentId) {
6083
+ const isAlreadyProcessed = err.code === "PAYMENT_ALREADY_PROCESSED";
6084
+ if (createdPaymentId && !isAlreadyProcessed) {
6075
6085
  try {
6076
6086
  await failPendingPayment(createdPaymentId);
6077
6087
  } catch (failErr) {
6078
6088
  console.error("Failed to mark payment as failed:", failErr);
6079
6089
  }
6080
6090
  }
6091
+ if (isAlreadyProcessed && err.payment) {
6092
+ dispatch({ type: "PAYMENT_SUCCESS", payment: err.payment });
6093
+ if (err.payment.status === "CONFIRMED") {
6094
+ paymentOptions?.onComplete?.(err.payment);
6095
+ } else {
6096
+ const paymentError2 = {
6097
+ code: err.code || "PAYMENT_ALREADY_PROCESSED",
6098
+ message: err.message || "Payment already processed."
6099
+ };
6100
+ dispatch({ type: "PAYMENT_ERROR", error: paymentError2 });
6101
+ paymentOptions?.onError?.(paymentError2);
6102
+ }
6103
+ return;
6104
+ }
6081
6105
  const paymentError = {
6082
6106
  code: err.code || "PAYMENT_FAILED",
6083
6107
  message: err.message || "Payment failed. Please try again."