coinley-pay 0.29.0 → 0.31.0

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.
@@ -5,7 +5,7 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
5
5
  import { useState, useRef, useEffect, useCallback, useMemo } from "react";
6
6
  import { useConnect, useAccount, useSwitchChain, useSendTransaction, useWaitForTransactionReceipt, WagmiProvider, useDisconnect } from "wagmi";
7
7
  import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
8
- import { s as sdkAnalytics, c as clarityAnalytics, d as dist, a as Buffer2, B as Buffer$1, g as getCurrencyInfo, p as prefetchRates, i as isSupportedCurrency, b as convertToUSD, f as formatCurrency } from "./index-fkUYCNSE.js";
8
+ import { s as sdkAnalytics, c as clarityAnalytics, d as dist, a as Buffer2, B as Buffer$1, g as getCurrencyInfo, p as prefetchRates, i as isSupportedCurrency, b as convertToUSD, f as formatCurrency } from "./index-DLEW836a.js";
9
9
  import { createConfig, fallback, http, getAccount as getAccount$1, getWalletClient, simulateContract, writeContract, readContract, waitForTransactionReceipt, estimateFeesPerGas as estimateFeesPerGas$1 } from "@wagmi/core";
10
10
  import { injected, metaMask, coinbaseWallet, walletConnect } from "@wagmi/connectors";
11
11
  import { defineChain as defineChain$1, erc20Abi, http as http$1, createPublicClient, fallback as fallback$1 } from "viem";
@@ -2428,6 +2428,18 @@ class SimplePaymentAPI {
2428
2428
  async getDepositBalance(paymentId) {
2429
2429
  return await this.request(`/api/deposits/balance/${paymentId}`);
2430
2430
  }
2431
+ /**
2432
+ * Request refund for an underpaid deposit payment
2433
+ * @param {string} paymentId - Payment ID
2434
+ * @param {string} refundAddress - Customer refund wallet address
2435
+ * @returns {Promise<{success: boolean, payment: Object}>}
2436
+ */
2437
+ async requestDepositRefund(paymentId, refundAddress) {
2438
+ return await this.request(`/api/deposits/refund-request/${paymentId}`, {
2439
+ method: "POST",
2440
+ body: JSON.stringify({ refundAddress })
2441
+ });
2442
+ }
2431
2443
  // ==================== BRIDGE ROUTING API ====================
2432
2444
  async getBridgeRoute(params) {
2433
2445
  const response = await this.request("/api/bridge/quote", {
@@ -21121,7 +21133,7 @@ const WalletSelector = ({
21121
21133
  try {
21122
21134
  setAppKitError(null);
21123
21135
  setWalletConnectAddress(solanaAccountState.address);
21124
- const { createWalletConnectAdapter } = await import("./appKitSolana-Brjblem7.js");
21136
+ const { createWalletConnectAdapter } = await import("./appKitSolana-CHASGJ9W.js");
21125
21137
  const adapter = createWalletConnectAdapter(solanaAccountState.address);
21126
21138
  await solanaWallet.connectWalletConnect(adapter, solanaAccountState.address);
21127
21139
  console.log("✅ WalletConnect synced with SDK");
@@ -21226,7 +21238,7 @@ const WalletSelector = ({
21226
21238
  setAppKitLoading(true);
21227
21239
  setAppKitError(null);
21228
21240
  try {
21229
- const { initializeAppKitEVM, openAppKitModal } = await import("./appKitEVM--PzCfGQT.js");
21241
+ const { initializeAppKitEVM, openAppKitModal } = await import("./appKitEVM-DolBzIzZ.js");
21230
21242
  await initializeAppKitEVM(wagmiConfig);
21231
21243
  await openAppKitModal();
21232
21244
  } catch (error) {
@@ -21246,7 +21258,7 @@ const WalletSelector = ({
21246
21258
  setAppKitError(null);
21247
21259
  try {
21248
21260
  console.log("📦 Loading AppKit Solana module...");
21249
- const { initializeAppKitSolana } = await import("./appKitSolana-Brjblem7.js");
21261
+ const { initializeAppKitSolana } = await import("./appKitSolana-CHASGJ9W.js");
21250
21262
  console.log("✅ Module loaded, initializing...");
21251
21263
  const modal = await initializeAppKitSolana(solanaWallet);
21252
21264
  console.log("✅ AppKit Solana initialized successfully");
@@ -23290,6 +23302,8 @@ const CoinleyPaymentInternal = ({
23290
23302
  const [underpaymentView, setUnderpaymentView] = useState("choice");
23291
23303
  const [refundAddress, setRefundAddress] = useState("");
23292
23304
  const [refundRequestSubmitted, setRefundRequestSubmitted] = useState(false);
23305
+ const [refundRequestStatus, setRefundRequestStatus] = useState(null);
23306
+ const [refundRequestMessage, setRefundRequestMessage] = useState("");
23293
23307
  const manualCheckTimeout = useRef(null);
23294
23308
  const [copiedField, setCopiedField] = useState(null);
23295
23309
  const [expirationTime, setExpirationTime] = useState(null);
@@ -23528,6 +23542,8 @@ const CoinleyPaymentInternal = ({
23528
23542
  });
23529
23543
  setManualCheckStatus(null);
23530
23544
  setRefundRequestSubmitted((submitted) => recoveryChoice === "refund" ? submitted : false);
23545
+ setRefundRequestStatus((status) => status);
23546
+ setRefundRequestMessage((message) => message);
23531
23547
  return true;
23532
23548
  }, [normalizeUnderpaymentInfo, paymentData == null ? void 0 : paymentData.id, readUnderpaymentRecovery]);
23533
23549
  const activateUnderpaymentFromDepositBalance = useCallback((balanceResult) => {
@@ -23922,6 +23938,13 @@ const CoinleyPaymentInternal = ({
23922
23938
  }, [paymentTimeoutMs, timeRemaining > 0]);
23923
23939
  useEffect(() => {
23924
23940
  if (timeRemaining === 0 && currentStep !== PAYMENT_STEPS.SUCCESS) {
23941
+ if (refundRequestSubmitted || refundRequestStatus === "submitting" || refundRequestStatus === "pending" || refundRequestStatus === "refunded") {
23942
+ console.log("[CheckoutTimer] Timeout reached after refund request; leaving refund flow open.", {
23943
+ paymentId: paymentData == null ? void 0 : paymentData.id,
23944
+ refundRequestStatus
23945
+ });
23946
+ return;
23947
+ }
23925
23948
  if (hasCommittedTransaction || transactionStep === "settlement_pending") {
23926
23949
  console.warn("[CheckoutTimer] Timeout reached after transaction commit; keeping payment in processing state.", {
23927
23950
  paymentId: paymentData == null ? void 0 : paymentData.id,
@@ -23964,7 +23987,7 @@ const CoinleyPaymentInternal = ({
23964
23987
  }
23965
23988
  onClose();
23966
23989
  }
23967
- }, [currentStep, hasCommittedTransaction, onClose, onError, paymentData == null ? void 0 : paymentData.id, selectedNetwork == null ? void 0 : selectedNetwork.shortName, selectedToken == null ? void 0 : selectedToken.symbol, config == null ? void 0 : config.amount, config == null ? void 0 : config.callbackUrl, timeRemaining, transactionStep]);
23990
+ }, [currentStep, hasCommittedTransaction, onClose, onError, paymentData == null ? void 0 : paymentData.id, selectedNetwork == null ? void 0 : selectedNetwork.shortName, selectedToken == null ? void 0 : selectedToken.symbol, config == null ? void 0 : config.amount, config == null ? void 0 : config.callbackUrl, timeRemaining, transactionStep, refundRequestSubmitted, refundRequestStatus]);
23968
23991
  const formatCountdown = useCallback((ms) => {
23969
23992
  if (ms <= 0) return "00:00";
23970
23993
  const totalSeconds = Math.floor(ms / 1e3);
@@ -23998,11 +24021,6 @@ const CoinleyPaymentInternal = ({
23998
24021
  try {
23999
24022
  const statusResult = await paymentFlow.api.getDepositStatus(paymentData.id);
24000
24023
  if (statusResult.success && statusResult.payment) {
24001
- if (activateUnderpaymentFlow(statusResult.payment)) {
24002
- clearInterval(pollInterval);
24003
- setCurrentStep(PAYMENT_STEPS.CONFIRM);
24004
- return;
24005
- }
24006
24024
  const status = statusResult.payment.status;
24007
24025
  const txHash = statusResult.payment.depositTxHash || statusResult.payment.sweepTxHash || statusResult.payment.transactionHash;
24008
24026
  if ((status === "completed" || status === "swept") && txHash) {
@@ -24034,6 +24052,12 @@ const CoinleyPaymentInternal = ({
24034
24052
  paymentDetails: statusResult.payment
24035
24053
  });
24036
24054
  }
24055
+ return;
24056
+ }
24057
+ if (activateUnderpaymentFlow(statusResult.payment)) {
24058
+ clearInterval(pollInterval);
24059
+ setCurrentStep(PAYMENT_STEPS.CONFIRM);
24060
+ return;
24037
24061
  } else if (status === "failed" || status === "sweep_failed") {
24038
24062
  clearInterval(pollInterval);
24039
24063
  clearUnderpaymentRecovery(paymentData.id);
@@ -25589,10 +25613,6 @@ const CoinleyPaymentInternal = ({
25589
25613
  try {
25590
25614
  const statusResult = await paymentFlow.api.getDepositStatus(paymentData.id);
25591
25615
  if (statusResult.success && statusResult.payment) {
25592
- if (activateUnderpaymentFlow(statusResult.payment)) {
25593
- clearInterval(pollInterval);
25594
- return;
25595
- }
25596
25616
  const status = statusResult.payment.status;
25597
25617
  const txHash = statusResult.payment.depositTxHash || statusResult.payment.sweepTxHash || statusResult.payment.transactionHash;
25598
25618
  if ((status === "completed" || status === "swept") && txHash) {
@@ -25612,6 +25632,11 @@ const CoinleyPaymentInternal = ({
25612
25632
  paymentDetails: statusResult.payment
25613
25633
  });
25614
25634
  }
25635
+ return;
25636
+ }
25637
+ if (activateUnderpaymentFlow(statusResult.payment)) {
25638
+ clearInterval(pollInterval);
25639
+ return;
25615
25640
  } else if (status === "processing" || statusResult.payment.depositDetectedAt) {
25616
25641
  console.log("⏳ Auto-detected: Deposit received, processing...");
25617
25642
  clearInterval(pollInterval);
@@ -25654,6 +25679,8 @@ const CoinleyPaymentInternal = ({
25654
25679
  setUnderpaymentView(recoveryState.view === "refund" ? "refund" : "offset");
25655
25680
  setManualCheckStatus(null);
25656
25681
  setRefundRequestSubmitted(false);
25682
+ setRefundRequestStatus(null);
25683
+ setRefundRequestMessage("");
25657
25684
  return;
25658
25685
  }
25659
25686
  setUnderpaymentInfo(null);
@@ -25661,6 +25688,8 @@ const CoinleyPaymentInternal = ({
25661
25688
  setUnderpaymentView("choice");
25662
25689
  setRefundAddress("");
25663
25690
  setRefundRequestSubmitted(false);
25691
+ setRefundRequestStatus(null);
25692
+ setRefundRequestMessage("");
25664
25693
  }, [paymentData == null ? void 0 : paymentData.id, readUnderpaymentRecovery, selectedNetwork, selectedToken]);
25665
25694
  useEffect(() => {
25666
25695
  if (!(paymentData == null ? void 0 : paymentData.id) || !underpaymentInfo || !underpaymentChoice || underpaymentView === "choice") {
@@ -25668,10 +25697,12 @@ const CoinleyPaymentInternal = ({
25668
25697
  }
25669
25698
  writeUnderpaymentRecovery(underpaymentChoice, underpaymentView, underpaymentInfo);
25670
25699
  }, [paymentData == null ? void 0 : paymentData.id, underpaymentInfo, underpaymentChoice, underpaymentView, writeUnderpaymentRecovery]);
25671
- const handleRefundRequestSubmit = useCallback(() => {
25700
+ const handleRefundRequestSubmit = useCallback(async () => {
25701
+ var _a2;
25672
25702
  const trimmedAddress = refundAddress.trim();
25673
- if (!trimmedAddress) return;
25674
- setRefundRequestSubmitted(true);
25703
+ if (!trimmedAddress || !(paymentData == null ? void 0 : paymentData.id) || refundRequestStatus === "submitting") return;
25704
+ setRefundRequestStatus("submitting");
25705
+ setRefundRequestMessage("");
25675
25706
  setManualCheckStatus(null);
25676
25707
  clearUnderpaymentRecovery(paymentData == null ? void 0 : paymentData.id);
25677
25708
  const refundPayload = {
@@ -25690,16 +25721,27 @@ const CoinleyPaymentInternal = ({
25690
25721
  detail: refundPayload
25691
25722
  }));
25692
25723
  }
25693
- }, [clearUnderpaymentRecovery, config, refundAddress, paymentData == null ? void 0 : paymentData.id, selectedNetwork == null ? void 0 : selectedNetwork.shortName, selectedToken == null ? void 0 : selectedToken.symbol, underpaymentInfo]);
25724
+ try {
25725
+ const result = await paymentFlow.api.requestDepositRefund(paymentData.id, trimmedAddress);
25726
+ const refundStatus = ((_a2 = result == null ? void 0 : result.payment) == null ? void 0 : _a2.refundStatus) || "pending";
25727
+ setRefundRequestSubmitted(true);
25728
+ setRefundRequestStatus(refundStatus === "refunded" ? "refunded" : "pending");
25729
+ setRefundRequestMessage(
25730
+ refundStatus === "refunded" ? "Refund sent successfully." : "Refund request received. We will process it automatically; if network gas is low, it may remain pending until the sweeper wallet is funded."
25731
+ );
25732
+ } catch (error2) {
25733
+ console.warn("[RefundRequest] Error:", error2.message);
25734
+ setRefundRequestSubmitted(false);
25735
+ setRefundRequestStatus("error");
25736
+ setRefundRequestMessage(error2.message || "Failed to submit refund request. Please try again.");
25737
+ }
25738
+ }, [clearUnderpaymentRecovery, config, refundAddress, refundRequestStatus, paymentData == null ? void 0 : paymentData.id, paymentFlow.api, selectedNetwork == null ? void 0 : selectedNetwork.shortName, selectedToken == null ? void 0 : selectedToken.symbol, underpaymentInfo]);
25694
25739
  const handleDepositManualCheck = useCallback(async () => {
25695
25740
  if (manualCheckStatus === "checking" || !(paymentData == null ? void 0 : paymentData.id)) return;
25696
25741
  setManualCheckStatus("checking");
25697
25742
  try {
25698
25743
  const statusResult = await paymentFlow.api.getDepositStatus(paymentData.id);
25699
25744
  if (statusResult.success && statusResult.payment) {
25700
- if (activateUnderpaymentFlow(statusResult.payment)) {
25701
- return;
25702
- }
25703
25745
  const status = statusResult.payment.status;
25704
25746
  const txHash = statusResult.payment.depositTxHash || statusResult.payment.sweepTxHash || statusResult.payment.transactionHash;
25705
25747
  if ((status === "completed" || status === "swept") && txHash) {
@@ -25720,6 +25762,9 @@ const CoinleyPaymentInternal = ({
25720
25762
  }
25721
25763
  return;
25722
25764
  }
25765
+ if (activateUnderpaymentFlow(statusResult.payment)) {
25766
+ return;
25767
+ }
25723
25768
  if (status === "processing" || statusResult.payment.depositDetectedAt) {
25724
25769
  setManualCheckStatus(null);
25725
25770
  clearUnderpaymentRecovery(paymentData.id);
@@ -25885,6 +25930,8 @@ const CoinleyPaymentInternal = ({
25885
25930
  onClick: () => {
25886
25931
  setUnderpaymentChoice(choice);
25887
25932
  setRefundRequestSubmitted(false);
25933
+ setRefundRequestStatus(null);
25934
+ setRefundRequestMessage("");
25888
25935
  },
25889
25936
  className: `relative flex min-h-[118px] flex-1 flex-col items-start rounded-xl border p-3 text-left transition-colors ${selected ? "border-[#8B5CF6] bg-[#F4EEFF]" : "border-[#ECEEF2] bg-white hover:border-[#D7C5FF]"}`,
25890
25937
  children: [
@@ -25999,13 +26046,13 @@ const CoinleyPaymentInternal = ({
25999
26046
  "button",
26000
26047
  {
26001
26048
  type: "button",
26002
- disabled: !refundAddress.trim(),
26049
+ disabled: !refundAddress.trim() || refundRequestStatus === "submitting" || refundRequestStatus === "pending" || refundRequestStatus === "refunded",
26003
26050
  onClick: handleRefundRequestSubmit,
26004
- className: `h-11 w-full rounded-xl px-4 text-sm font-semibold text-white transition-colors ${refundAddress.trim() ? "bg-[#7042D2] hover:bg-[#5b34b1]" : "cursor-not-allowed bg-[#B59AE9]"}`,
26005
- children: refundRequestSubmitted ? "Refund request submitted" : "Submit refund request"
26051
+ className: `h-11 w-full rounded-xl px-4 text-sm font-semibold text-white transition-colors ${refundAddress.trim() && refundRequestStatus !== "submitting" && refundRequestStatus !== "pending" && refundRequestStatus !== "refunded" ? "bg-[#7042D2] hover:bg-[#5b34b1]" : "cursor-not-allowed bg-[#B59AE9]"}`,
26052
+ children: refundRequestStatus === "submitting" ? "Submitting refund request..." : refundRequestSubmitted ? "Refund request submitted" : "Submit refund request"
26006
26053
  }
26007
26054
  ),
26008
- refundRequestSubmitted && /* @__PURE__ */ jsx("p", { className: "mt-2 text-center text-xs leading-5 text-[#8B8E98]", children: "Keep this screen open while we continue checking the payment status." })
26055
+ refundRequestMessage && /* @__PURE__ */ jsx("p", { className: `mt-2 text-center text-xs leading-5 ${refundRequestStatus === "error" ? "text-red-600" : "text-[#8B8E98]"}`, children: refundRequestMessage })
26009
26056
  ] });
26010
26057
  const transferNetworks = networks.filter((network) => {
26011
26058
  const chainId = parseInt(network.chainId);
@@ -27019,6 +27066,8 @@ const CoinleyPaymentInternal = ({
27019
27066
  setUnderpaymentView("choice");
27020
27067
  setRefundAddress("");
27021
27068
  setRefundRequestSubmitted(false);
27069
+ setRefundRequestStatus(null);
27070
+ setRefundRequestMessage("");
27022
27071
  await resetAllTransactionState();
27023
27072
  setActiveTab(PAYMENT_TABS.TRANSFER);
27024
27073
  };
@@ -27113,4 +27162,4 @@ export {
27113
27162
  isFeatureEnabled as i,
27114
27163
  logo as l
27115
27164
  };
27116
- //# sourceMappingURL=CoinleyPayment-DvR9sd7O.js.map
27165
+ //# sourceMappingURL=CoinleyPayment-BvxUgI2r.js.map
@@ -1,4 +1,4 @@
1
- import { i as isFeatureEnabled, F as FEATURES, c as chainTransports, W as WALLETCONNECT_PROJECT_ID, l as logo } from "./CoinleyPayment-DvR9sd7O.js";
1
+ import { i as isFeatureEnabled, F as FEATURES, c as chainTransports, W as WALLETCONNECT_PROJECT_ID, l as logo } from "./CoinleyPayment-BvxUgI2r.js";
2
2
  let appKitInstance = null;
3
3
  let isInitializing = false;
4
4
  let initializationPromise = null;
@@ -112,4 +112,4 @@ export {
112
112
  initializeAppKitEVM,
113
113
  openAppKitModal
114
114
  };
115
- //# sourceMappingURL=appKitEVM--PzCfGQT.js.map
115
+ //# sourceMappingURL=appKitEVM-DolBzIzZ.js.map
@@ -1,4 +1,4 @@
1
- import { F as FEATURES, l as logo, W as WALLETCONNECT_PROJECT_ID } from "./CoinleyPayment-DvR9sd7O.js";
1
+ import { F as FEATURES, l as logo, W as WALLETCONNECT_PROJECT_ID } from "./CoinleyPayment-BvxUgI2r.js";
2
2
  let appKitInstance = null;
3
3
  let isInitializing = false;
4
4
  let initializationPromise = null;
@@ -242,4 +242,4 @@ export {
242
242
  disconnectWalletConnect,
243
243
  initializeAppKitSolana
244
244
  };
245
- //# sourceMappingURL=appKitSolana-Brjblem7.js.map
245
+ //# sourceMappingURL=appKitSolana-CHASGJ9W.js.map