coinley-pay 0.22.0 → 0.24.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-BLIQ06qE.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-BuM1IGbr.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";
@@ -2123,6 +2123,13 @@ class SimplePaymentAPI {
2123
2123
  };
2124
2124
  }
2125
2125
  }
2126
+ async getPayableNetworks() {
2127
+ try {
2128
+ return await this.request("/api/networks/payable");
2129
+ } catch (error) {
2130
+ return this.getNetworks();
2131
+ }
2132
+ }
2126
2133
  async getTokens() {
2127
2134
  try {
2128
2135
  return await this.request("/api/networks/stablecoins");
@@ -2285,6 +2292,13 @@ class SimplePaymentAPI {
2285
2292
  };
2286
2293
  }
2287
2294
  }
2295
+ async getPayableTokens() {
2296
+ try {
2297
+ return await this.request("/api/networks/payable/stablecoins");
2298
+ } catch (error) {
2299
+ return this.getTokens();
2300
+ }
2301
+ }
2288
2302
  async createPayment(data) {
2289
2303
  return await this.request("/api/payments/create", {
2290
2304
  method: "POST",
@@ -2552,7 +2566,9 @@ const getBridgeTokenAddress = (symbol, bridgeTokens) => {
2552
2566
  const usePaymentFlow = (apiUrl, apiKey, apiSecret) => {
2553
2567
  const [currentStep, setCurrentStep] = useState("method");
2554
2568
  const [networks, setNetworks] = useState([]);
2569
+ const [merchantNetworks, setMerchantNetworks] = useState([]);
2555
2570
  const [tokens, setTokens] = useState([]);
2571
+ const [merchantTokens, setMerchantTokens] = useState([]);
2556
2572
  const [selectedNetwork, setSelectedNetwork] = useState(null);
2557
2573
  const [selectedToken, setSelectedToken] = useState(null);
2558
2574
  const [paymentMethod, setPaymentMethod] = useState(null);
@@ -2568,18 +2584,19 @@ const usePaymentFlow = (apiUrl, apiKey, apiSecret) => {
2568
2584
  const [bridgeDestination, setBridgeDestination] = useState(null);
2569
2585
  const api = useRef(new SimplePaymentAPI(apiUrl, apiKey, apiSecret));
2570
2586
  const loadData = async () => {
2571
- var _a, _b;
2572
2587
  try {
2573
2588
  setLoading(true);
2574
2589
  setError("");
2575
- const [networksRes, tokensRes] = await Promise.all([
2590
+ const [merchantNetworksRes, merchantTokensRes, payableNetworksRes, payableTokensRes] = await Promise.all([
2576
2591
  api.current.getNetworks(),
2577
- api.current.getTokens()
2592
+ api.current.getTokens(),
2593
+ api.current.getPayableNetworks ? api.current.getPayableNetworks() : api.current.getNetworks(),
2594
+ api.current.getPayableTokens ? api.current.getPayableTokens() : api.current.getTokens()
2578
2595
  ]);
2579
2596
  const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
2580
2597
  typeof navigator !== "undefined" ? navigator.userAgent : ""
2581
2598
  );
2582
- const uniqueNetworks = ((_a = networksRes.networks) == null ? void 0 : _a.reduce((acc, network) => {
2599
+ const normalizeNetworks = (networkList = []) => networkList.reduce((acc, network) => {
2583
2600
  if (network.shortName === "tron" || network.shortName === "algorand") {
2584
2601
  return acc;
2585
2602
  }
@@ -2603,14 +2620,16 @@ const usePaymentFlow = (apiUrl, apiKey, apiSecret) => {
2603
2620
  acc.push(network);
2604
2621
  }
2605
2622
  return acc;
2606
- }, [])) || [];
2607
- const uniqueTokens = ((_b = tokensRes.stablecoins) == null ? void 0 : _b.reduce((acc, token) => {
2608
- var _a2, _b2, _c, _d, _e, _f, _g;
2623
+ }, []);
2624
+ const uniqueNetworks = normalizeNetworks(payableNetworksRes.networks || merchantNetworksRes.networks || []);
2625
+ const uniqueMerchantNetworks = normalizeNetworks(merchantNetworksRes.networks || []);
2626
+ const normalizeTokens = (tokenList = []) => tokenList.reduce((acc, token) => {
2627
+ var _a, _b, _c, _d, _e, _f, _g;
2609
2628
  const allowedTokens = ["USDC", "USDT", "SOL"];
2610
2629
  if (!allowedTokens.includes(token.symbol)) {
2611
2630
  return acc;
2612
2631
  }
2613
- if (((_a2 = token.Network) == null ? void 0 : _a2.shortName) === "tron" || ((_b2 = token.Network) == null ? void 0 : _b2.shortName) === "algorand") {
2632
+ if (((_a = token.Network) == null ? void 0 : _a.shortName) === "tron" || ((_b = token.Network) == null ? void 0 : _b.shortName) === "algorand") {
2614
2633
  return acc;
2615
2634
  }
2616
2635
  if (((_c = token.Network) == null ? void 0 : _c.shortName) === "arbitrum-nova" || parseInt((_d = token.Network) == null ? void 0 : _d.chainId) === 42170) {
@@ -2622,29 +2641,33 @@ const usePaymentFlow = (apiUrl, apiKey, apiSecret) => {
2622
2641
  }
2623
2642
  const key = `${token.symbol}-${((_g = token.Network) == null ? void 0 : _g.shortName) || token.networkId}`;
2624
2643
  if (!acc.some((t) => {
2625
- var _a3;
2626
- return `${t.symbol}-${((_a3 = t.Network) == null ? void 0 : _a3.shortName) || t.networkId}` === key;
2644
+ var _a2;
2645
+ return `${t.symbol}-${((_a2 = t.Network) == null ? void 0 : _a2.shortName) || t.networkId}` === key;
2627
2646
  })) {
2628
2647
  acc.push(token);
2629
2648
  }
2630
2649
  return acc;
2631
- }, [])) || [];
2650
+ }, []);
2651
+ const uniqueTokens = normalizeTokens(payableTokensRes.stablecoins || merchantTokensRes.stablecoins || []);
2652
+ const uniqueMerchantTokens = normalizeTokens(merchantTokensRes.stablecoins || []);
2632
2653
  setNetworks(uniqueNetworks);
2654
+ setMerchantNetworks(uniqueMerchantNetworks);
2633
2655
  setTokens(uniqueTokens);
2634
- loadBridgeNetworks(uniqueNetworks);
2656
+ setMerchantTokens(uniqueMerchantTokens);
2657
+ loadBridgeNetworks(uniqueMerchantNetworks);
2635
2658
  } catch (err) {
2636
2659
  setError("Failed to load payment options. Using fallback data.");
2637
2660
  } finally {
2638
2661
  setLoading(false);
2639
2662
  }
2640
2663
  };
2641
- const loadBridgeNetworks = async (merchantNetworks) => {
2664
+ const loadBridgeNetworks = async (merchantNetworks2) => {
2642
2665
  try {
2643
2666
  const merchantChainIds = new Set(
2644
- merchantNetworks.filter((n) => n.chainId && n.shortName !== "solana" && n.chainType !== "solana").map((n) => parseInt(n.chainId))
2667
+ merchantNetworks2.filter((n) => n.chainId && n.shortName !== "solana" && n.chainType !== "solana").map((n) => parseInt(n.chainId))
2645
2668
  );
2646
2669
  if (merchantChainIds.size === 0) return;
2647
- const bestDest = getBestDestinationChain(merchantNetworks);
2670
+ const bestDest = getBestDestinationChain(merchantNetworks2);
2648
2671
  if (!bestDest) return;
2649
2672
  const destChainId = parseInt(bestDest.chainId);
2650
2673
  const destBridgeTokens = getKnownBridgeTokens(destChainId);
@@ -2915,14 +2938,14 @@ const usePaymentFlow = (apiUrl, apiKey, apiSecret) => {
2915
2938
  const getMerchantStablecoin = (network) => {
2916
2939
  const networkShortName = network == null ? void 0 : network.shortName;
2917
2940
  if (!networkShortName) return null;
2918
- const usdc = tokens.find(
2941
+ const usdc = merchantTokens.find(
2919
2942
  (t) => {
2920
2943
  var _a;
2921
2944
  return t.symbol === "USDC" && ((_a = t.Network) == null ? void 0 : _a.shortName) === networkShortName && !t.isSwapToken;
2922
2945
  }
2923
2946
  );
2924
2947
  if (usdc) return usdc;
2925
- const usdt = tokens.find(
2948
+ const usdt = merchantTokens.find(
2926
2949
  (t) => {
2927
2950
  var _a;
2928
2951
  return t.symbol === "USDT" && ((_a = t.Network) == null ? void 0 : _a.shortName) === networkShortName && !t.isSwapToken;
@@ -2962,7 +2985,9 @@ const usePaymentFlow = (apiUrl, apiKey, apiSecret) => {
2962
2985
  // State
2963
2986
  currentStep,
2964
2987
  networks,
2988
+ merchantNetworks,
2965
2989
  tokens,
2990
+ merchantTokens,
2966
2991
  selectedNetwork,
2967
2992
  selectedToken,
2968
2993
  paymentMethod,
@@ -21095,7 +21120,7 @@ const WalletSelector = ({
21095
21120
  try {
21096
21121
  setAppKitError(null);
21097
21122
  setWalletConnectAddress(solanaAccountState.address);
21098
- const { createWalletConnectAdapter } = await import("./appKitSolana-KE60037B.js");
21123
+ const { createWalletConnectAdapter } = await import("./appKitSolana-C2Tow7WJ.js");
21099
21124
  const adapter = createWalletConnectAdapter(solanaAccountState.address);
21100
21125
  await solanaWallet.connectWalletConnect(adapter, solanaAccountState.address);
21101
21126
  console.log("✅ WalletConnect synced with SDK");
@@ -21200,7 +21225,7 @@ const WalletSelector = ({
21200
21225
  setAppKitLoading(true);
21201
21226
  setAppKitError(null);
21202
21227
  try {
21203
- const { initializeAppKitEVM, openAppKitModal } = await import("./appKitEVM-Bs-au6VA.js");
21228
+ const { initializeAppKitEVM, openAppKitModal } = await import("./appKitEVM-BeGg9nUC.js");
21204
21229
  await initializeAppKitEVM(wagmiConfig);
21205
21230
  await openAppKitModal();
21206
21231
  } catch (error) {
@@ -21220,7 +21245,7 @@ const WalletSelector = ({
21220
21245
  setAppKitError(null);
21221
21246
  try {
21222
21247
  console.log("📦 Loading AppKit Solana module...");
21223
- const { initializeAppKitSolana } = await import("./appKitSolana-KE60037B.js");
21248
+ const { initializeAppKitSolana } = await import("./appKitSolana-C2Tow7WJ.js");
21224
21249
  console.log("✅ Module loaded, initializing...");
21225
21250
  const modal = await initializeAppKitSolana(solanaWallet);
21226
21251
  console.log("✅ AppKit Solana initialized successfully");
@@ -23331,6 +23356,7 @@ const CoinleyPaymentInternal = ({
23331
23356
  const {
23332
23357
  currentStep,
23333
23358
  networks,
23359
+ merchantNetworks,
23334
23360
  tokens,
23335
23361
  selectedNetwork,
23336
23362
  selectedToken,
@@ -23354,6 +23380,18 @@ const CoinleyPaymentInternal = ({
23354
23380
  setIsBridgePayment,
23355
23381
  setBridgeDestination
23356
23382
  } = paymentFlow;
23383
+ const merchantReceiveNetworks = (merchantNetworks == null ? void 0 : merchantNetworks.length) ? merchantNetworks : networks;
23384
+ const isMerchantReceiveNetwork = useCallback((network) => {
23385
+ var _a2;
23386
+ const shortName = (_a2 = network == null ? void 0 : network.shortName) == null ? void 0 : _a2.toLowerCase();
23387
+ if (!shortName) return false;
23388
+ return (merchantReceiveNetworks || []).some(
23389
+ (merchantNetwork) => {
23390
+ var _a3;
23391
+ return ((_a3 = merchantNetwork == null ? void 0 : merchantNetwork.shortName) == null ? void 0 : _a3.toLowerCase()) === shortName;
23392
+ }
23393
+ );
23394
+ }, [merchantReceiveNetworks]);
23357
23395
  const {
23358
23396
  connectedWallet,
23359
23397
  address,
@@ -23383,7 +23421,11 @@ const CoinleyPaymentInternal = ({
23383
23421
  const hasCommittedTransaction = Boolean(
23384
23422
  currentTransactionHash || (solanaTransaction == null ? void 0 : solanaTransaction.txSignature) || (paymentData == null ? void 0 : paymentData.transactionHash)
23385
23423
  );
23386
- const isSwapOrBridgeFlow = requiresDepositRouting(selectedNetwork, selectedToken);
23424
+ const selectedNetworkIsSolana = (selectedNetwork == null ? void 0 : selectedNetwork.chainType) === "solana" || (selectedNetwork == null ? void 0 : selectedNetwork.shortName) === "solana";
23425
+ const sourceNeedsMerchantBridge = Boolean(
23426
+ selectedNetwork && !selectedNetworkIsSolana && !isMerchantReceiveNetwork(selectedNetwork)
23427
+ );
23428
+ const isSwapOrBridgeFlow = requiresDepositRouting(selectedNetwork, selectedToken) || sourceNeedsMerchantBridge;
23387
23429
  const paymentTimeoutMs = isSwapOrBridgeFlow ? BRIDGE_PAYMENT_TIMEOUT_MS : STANDARD_PAYMENT_TIMEOUT_MS;
23388
23430
  useEffect(() => {
23389
23431
  if (hasCommittedTransaction) return;
@@ -23447,10 +23489,10 @@ const CoinleyPaymentInternal = ({
23447
23489
  };
23448
23490
  const STALE_ATTEMPT_MESSAGE = "Your payment quote changed while you were switching networks or tokens. Please try again.";
23449
23491
  const UNSUPPORTED_ROUTE_MESSAGE = "This network is temporarily unavailable for this payment route. Try another token or network.";
23450
- const getBridgeDestinationCandidates = (merchantNetworks, originNetwork = null, limit = 3) => {
23492
+ const getBridgeDestinationCandidates = (merchantNetworks2, originNetwork = null, limit = 3) => {
23451
23493
  var _a2, _b;
23452
23494
  const originShortName = (_a2 = originNetwork == null ? void 0 : originNetwork.shortName) == null ? void 0 : _a2.toLowerCase();
23453
- const byShortName = new Map((merchantNetworks || []).filter((network) => network == null ? void 0 : network.shortName).map((network) => [network.shortName.toLowerCase(), network]));
23495
+ const byShortName = new Map((merchantNetworks2 || []).filter((network) => network == null ? void 0 : network.shortName).map((network) => [network.shortName.toLowerCase(), network]));
23454
23496
  const ordered = [];
23455
23497
  for (const preferred of BRIDGE_DESTINATION_PRIORITY) {
23456
23498
  const network = byShortName.get(preferred);
@@ -24325,15 +24367,16 @@ const CoinleyPaymentInternal = ({
24325
24367
  const isSolanaSwap = (selectedNetwork == null ? void 0 : selectedNetwork.shortName) === "solana" || (selectedNetwork == null ? void 0 : selectedNetwork.chainType) === "solana";
24326
24368
  const originChainId = isSolanaSwap ? RELAY_SOLANA_CHAIN_ID : parseInt(selectedNetwork.chainId);
24327
24369
  const chainHasCreate2 = DEPOSIT_SUPPORTED_CHAINS.includes(originChainId);
24370
+ const sourceIsMerchantDestination = isMerchantReceiveNetwork(selectedNetwork);
24328
24371
  let destChainId, merchantStable, destStablecoinAddress, destinationCandidates = null;
24329
- if (chainHasCreate2) {
24372
+ if (chainHasCreate2 && sourceIsMerchantDestination) {
24330
24373
  destChainId = originChainId;
24331
24374
  merchantStable = paymentFlow.getMerchantStablecoin(selectedNetwork);
24332
24375
  if (!merchantStable) return;
24333
24376
  const destBridgeTokens = selectedNetwork.bridgeTokens || {};
24334
24377
  destStablecoinAddress = getBridgeTokenAddress(merchantStable.symbol, destBridgeTokens) || merchantStable.contractAddress;
24335
24378
  } else {
24336
- destinationCandidates = getBridgeDestinationCandidates(networks, selectedNetwork, 3);
24379
+ destinationCandidates = getBridgeDestinationCandidates(merchantReceiveNetworks, selectedNetwork, 3);
24337
24380
  if (destinationCandidates.length === 0) return;
24338
24381
  console.log("[Swap] Cross-chain destination trials:", {
24339
24382
  fromChain: originChainId,
@@ -24441,7 +24484,7 @@ const CoinleyPaymentInternal = ({
24441
24484
  }
24442
24485
  } else {
24443
24486
  const originChainId = parseInt(selectedNetwork.chainId);
24444
- const destinationCandidates = getBridgeDestinationCandidates(networks, selectedNetwork, 3);
24487
+ const destinationCandidates = getBridgeDestinationCandidates(merchantReceiveNetworks, selectedNetwork, 3);
24445
24488
  if (destinationCandidates.length === 0 || !selectedToken.contractAddress || selectedToken.contractAddress === "native") return;
24446
24489
  console.log("[Bridge] Cross-chain stablecoin destination trials:", {
24447
24490
  token: selectedToken.symbol,
@@ -24461,7 +24504,18 @@ const CoinleyPaymentInternal = ({
24461
24504
  logPrefix: "[Bridge]"
24462
24505
  });
24463
24506
  }
24464
- }, [selectedNetwork == null ? void 0 : selectedNetwork.id, selectedToken == null ? void 0 : selectedToken.id, address, solanaWallet == null ? void 0 : solanaWallet.publicKey, paymentAmount, retryEpoch, isSwapOrBridgeFlow]);
24507
+ }, [
24508
+ selectedNetwork == null ? void 0 : selectedNetwork.id,
24509
+ selectedNetwork == null ? void 0 : selectedNetwork.shortName,
24510
+ selectedToken == null ? void 0 : selectedToken.id,
24511
+ address,
24512
+ solanaWallet == null ? void 0 : solanaWallet.publicKey,
24513
+ paymentAmount,
24514
+ retryEpoch,
24515
+ isSwapOrBridgeFlow,
24516
+ merchantReceiveNetworks,
24517
+ isMerchantReceiveNetwork
24518
+ ]);
24465
24519
  useEffect(() => {
24466
24520
  if (!isSwapOrBridgeFlow || !(selectedToken == null ? void 0 : selectedToken.id) || relayBridge.bridgeStatus === "quoting") {
24467
24521
  return;
@@ -24554,6 +24608,56 @@ const CoinleyPaymentInternal = ({
24554
24608
  }
24555
24609
  })();
24556
24610
  }, [paymentData == null ? void 0 : paymentData.depositAddress]);
24611
+ const getBridgeQuoteForDepositExecution = async (activePaymentData) => {
24612
+ if (!isSwapOrBridgeFlow || !(activePaymentData == null ? void 0 : activePaymentData.depositAddress)) {
24613
+ return relayBridge.bridgeQuote;
24614
+ }
24615
+ const currentQuote = relayBridge.bridgeQuote;
24616
+ if (!currentQuote) {
24617
+ throw new Error("Bridge route unavailable. Please try again.");
24618
+ }
24619
+ const expectedDepositAddress = normalizeEvmAddress(activePaymentData.depositAddress);
24620
+ const quoteRecipient = normalizeEvmAddress(currentQuote.requestedRecipient);
24621
+ const quoteEffectiveRecipient = normalizeEvmAddress(currentQuote.effectiveRecipient);
24622
+ if (expectedDepositAddress && quoteRecipient === expectedDepositAddress && (!quoteEffectiveRecipient || quoteEffectiveRecipient === expectedDepositAddress)) {
24623
+ return currentQuote;
24624
+ }
24625
+ const activeAttempt = activeAttemptRef.current;
24626
+ if (!activeAttempt) {
24627
+ throw new Error(STALE_ATTEMPT_MESSAGE);
24628
+ }
24629
+ const amount = paymentAmount || parseFloat(config == null ? void 0 : config.amount) || 0;
24630
+ if (amount <= 0) {
24631
+ throw new Error("Invalid payment amount. Please refresh and try again.");
24632
+ }
24633
+ console.log("[Swap] Awaiting deposit-recipient quote before execution:", {
24634
+ paymentId: activePaymentData.id,
24635
+ depositAddress: activePaymentData.depositAddress,
24636
+ currentRecipient: currentQuote.requestedRecipient,
24637
+ attemptId: activeAttempt.id
24638
+ });
24639
+ const reQuoteUser = currentQuote.originChainId === RELAY_SOLANA_CHAIN_ID ? solanaWallet == null ? void 0 : solanaWallet.publicKey : void 0;
24640
+ const quote = await relayBridge.getBridgeQuote(
24641
+ currentQuote.originChainId,
24642
+ currentQuote.destChainId,
24643
+ currentQuote.originTokenAddress,
24644
+ currentQuote.originTokenSymbol,
24645
+ selectedToken.decimals || 18,
24646
+ currentQuote.destTokenAddress,
24647
+ currentQuote.destTokenSymbol,
24648
+ amount.toString(),
24649
+ activePaymentData.depositAddress,
24650
+ null,
24651
+ null,
24652
+ reQuoteUser,
24653
+ void 0,
24654
+ buildAttemptMeta(activeAttempt)
24655
+ );
24656
+ if (!quote) {
24657
+ throw new Error("Bridge route unavailable for this deposit address. Please try another network or token.");
24658
+ }
24659
+ return quote;
24660
+ };
24557
24661
  useEffect(() => {
24558
24662
  const amount = paymentAmount || parseFloat(config == null ? void 0 : config.amount) || 0;
24559
24663
  if (connectedWalletType === "solana" && (solanaWallet == null ? void 0 : solanaWallet.publicKey) && (selectedNetwork == null ? void 0 : selectedNetwork.shortName) === "solana") {
@@ -24723,8 +24827,8 @@ const CoinleyPaymentInternal = ({
24723
24827
  return;
24724
24828
  }
24725
24829
  } else if (connectedWalletType === "solana" && !merchantHasSolanaWallet) {
24726
- const quotedDest = ((_e = relayBridge.bridgeQuote) == null ? void 0 : _e.destChainId) ? networks.find((network) => parseInt(network.chainId) === parseInt(relayBridge.bridgeQuote.destChainId)) : null;
24727
- const bestDest = quotedDest || getBestDestinationChain(networks);
24830
+ const quotedDest = ((_e = relayBridge.bridgeQuote) == null ? void 0 : _e.destChainId) ? merchantReceiveNetworks.find((network) => parseInt(network.chainId) === parseInt(relayBridge.bridgeQuote.destChainId)) : null;
24831
+ const bestDest = quotedDest || getBestDestinationChain(merchantReceiveNetworks);
24728
24832
  const effectiveNetwork = (bestDest == null ? void 0 : bestDest.shortName) || "base";
24729
24833
  console.log(`[Payment] Solana bridge: no Solana wallet, bridging to ${effectiveNetwork}`);
24730
24834
  const depositConfig = {
@@ -24755,17 +24859,18 @@ const CoinleyPaymentInternal = ({
24755
24859
  const DEPOSIT_SUPPORTED_CHAINS = [8453, 56, 42161, 137, 10, 43114, 143, 59144, 534352, 130];
24756
24860
  const selectedChainId = parseInt(selectedNetwork == null ? void 0 : selectedNetwork.chainId);
24757
24861
  const chainHasCreate2 = DEPOSIT_SUPPORTED_CHAINS.includes(selectedChainId);
24862
+ const sourceIsMerchantDestination = isMerchantReceiveNetwork(selectedNetwork);
24758
24863
  let effectiveNetwork;
24759
24864
  let merchantStable;
24760
24865
  if (selectedNetwork == null ? void 0 : selectedNetwork.isBridgeNetwork) {
24761
24866
  effectiveNetwork = (_g = selectedNetwork.bridgeDestination) == null ? void 0 : _g.shortName;
24762
24867
  merchantStable = paymentFlow.getMerchantStablecoin({ shortName: effectiveNetwork });
24763
- } else if (chainHasCreate2) {
24868
+ } else if (chainHasCreate2 && sourceIsMerchantDestination) {
24764
24869
  effectiveNetwork = selectedNetwork.shortName;
24765
24870
  merchantStable = paymentFlow.getMerchantStablecoin(selectedNetwork);
24766
24871
  } else {
24767
- const quotedDest = ((_h = relayBridge.bridgeQuote) == null ? void 0 : _h.destChainId) ? networks.find((network) => parseInt(network.chainId) === parseInt(relayBridge.bridgeQuote.destChainId)) : null;
24768
- const bestDest = quotedDest || getBestDestinationChain(networks);
24872
+ const quotedDest = ((_h = relayBridge.bridgeQuote) == null ? void 0 : _h.destChainId) ? merchantReceiveNetworks.find((network) => parseInt(network.chainId) === parseInt(relayBridge.bridgeQuote.destChainId)) : null;
24873
+ const bestDest = quotedDest || getBestDestinationChain(merchantReceiveNetworks);
24769
24874
  effectiveNetwork = (bestDest == null ? void 0 : bestDest.shortName) || "base";
24770
24875
  merchantStable = paymentFlow.getMerchantStablecoin(bestDest || { shortName: "base" });
24771
24876
  console.log(`[Swap] Chain ${selectedChainId} has no CREATE2, bridging to ${effectiveNetwork}`);
@@ -24802,12 +24907,26 @@ const CoinleyPaymentInternal = ({
24802
24907
  setError("Payment could not be prepared. Please try again.");
24803
24908
  return;
24804
24909
  }
24910
+ let bridgeQuoteForExecution = null;
24911
+ if (isSwapOrBridgeFlow && (effectivePaymentData == null ? void 0 : effectivePaymentData.depositAddress)) {
24912
+ try {
24913
+ bridgeQuoteForExecution = await getBridgeQuoteForDepositExecution(effectivePaymentData);
24914
+ } catch (e) {
24915
+ if ((e == null ? void 0 : e.message) === STALE_ATTEMPT_MESSAGE) {
24916
+ setError(STALE_ATTEMPT_MESSAGE);
24917
+ } else {
24918
+ setError((e == null ? void 0 : e.message) || "Payment quote is not ready. Please try again.");
24919
+ }
24920
+ return;
24921
+ }
24922
+ }
24805
24923
  setShowWalletConfirm(false);
24806
- await executePayment(effectivePaymentData);
24924
+ await executePayment(effectivePaymentData, bridgeQuoteForExecution);
24807
24925
  };
24808
- const executePayment = async (paymentOverride = null) => {
24809
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
24926
+ const executePayment = async (paymentOverride = null, bridgeQuoteOverride = null) => {
24927
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
24810
24928
  const activePaymentData = paymentOverride || paymentData;
24929
+ const activeBridgeQuote = bridgeQuoteOverride || relayBridge.bridgeQuote;
24811
24930
  if (!(activePaymentData == null ? void 0 : activePaymentData.id)) {
24812
24931
  setError("Payment could not be prepared. Please try again.");
24813
24932
  return;
@@ -24851,7 +24970,7 @@ const CoinleyPaymentInternal = ({
24851
24970
  setError(STALE_ATTEMPT_MESSAGE);
24852
24971
  return;
24853
24972
  }
24854
- const quoteAttemptId = ((_a2 = relayBridge.bridgeQuote) == null ? void 0 : _a2.attemptId) ?? null;
24973
+ const quoteAttemptId = (activeBridgeQuote == null ? void 0 : activeBridgeQuote.attemptId) ?? null;
24855
24974
  if (quoteAttemptId && quoteAttemptId !== activeAttempt.id) {
24856
24975
  console.warn("[Attempt] executePayment blocked — bridgeQuote attempt mismatch", {
24857
24976
  quoteAttemptId,
@@ -24864,7 +24983,7 @@ const CoinleyPaymentInternal = ({
24864
24983
  console.log("[Attempt] executePayment proceeding", {
24865
24984
  attemptId: activeAttempt.id,
24866
24985
  hasPaymentData: !!activePaymentData,
24867
- hasQuote: !!relayBridge.bridgeQuote
24986
+ hasQuote: !!activeBridgeQuote
24868
24987
  });
24869
24988
  }
24870
24989
  if (isSolana) {
@@ -24876,7 +24995,7 @@ const CoinleyPaymentInternal = ({
24876
24995
  setCurrentStep(PAYMENT_STEPS.PROCESSING);
24877
24996
  if ((activePaymentData == null ? void 0 : activePaymentData.isDepositPayment) && (activePaymentData == null ? void 0 : activePaymentData.depositAddress)) {
24878
24997
  console.log("[Solana] Bridged payment — executing Relay Solana→EVM bridge");
24879
- const bestDest = getBestDestinationChain(networks);
24998
+ const bestDest = getBestDestinationChain(merchantReceiveNetworks);
24880
24999
  const destChainId = bestDest ? parseInt(bestDest.chainId) : 8453;
24881
25000
  const knownUSDC = {
24882
25001
  8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
@@ -24890,11 +25009,11 @@ const CoinleyPaymentInternal = ({
24890
25009
  const amount = paymentAmount || parseFloat(config == null ? void 0 : config.amount) || 0;
24891
25010
  const SOL_MINT = "So11111111111111111111111111111111111111112";
24892
25011
  const tokenMint = selectedToken == null ? void 0 : selectedToken.contractAddress;
24893
- const isNativeSOL = tokenMint === "native" || ((_b = selectedToken == null ? void 0 : selectedToken.symbol) == null ? void 0 : _b.toUpperCase()) === "SOL";
25012
+ const isNativeSOL = tokenMint === "native" || ((_a2 = selectedToken == null ? void 0 : selectedToken.symbol) == null ? void 0 : _a2.toUpperCase()) === "SOL";
24894
25013
  let quote = relayBridge.bridgeQuote;
24895
25014
  if (!quote) {
24896
25015
  console.log("[Solana Bridge] No quote cached — fetching fresh quote...");
24897
- const originTokenAddress = isNativeSOL ? SOLANA_TOKEN_ADDRESSES.SOL : SOLANA_TOKEN_ADDRESSES[(_c = selectedToken == null ? void 0 : selectedToken.symbol) == null ? void 0 : _c.toUpperCase()] || tokenMint;
25016
+ const originTokenAddress = isNativeSOL ? SOLANA_TOKEN_ADDRESSES.SOL : SOLANA_TOKEN_ADDRESSES[(_b = selectedToken == null ? void 0 : selectedToken.symbol) == null ? void 0 : _b.toUpperCase()] || tokenMint;
24898
25017
  quote = await relayBridge.getBridgeQuote(
24899
25018
  RELAY_SOLANA_CHAIN_ID,
24900
25019
  destChainId,
@@ -24931,7 +25050,7 @@ const CoinleyPaymentInternal = ({
24931
25050
  if (!solQuote) {
24932
25051
  throw new Error("Unable to find a bridge route. Try paying with SOL, USDC, or USDT.");
24933
25052
  }
24934
- const solNeededLamports = BigInt(((_f = (_e = (_d = solQuote.raw) == null ? void 0 : _d.details) == null ? void 0 : _e.currencyIn) == null ? void 0 : _f.amount) || "0");
25053
+ const solNeededLamports = BigInt(((_e = (_d = (_c = solQuote.raw) == null ? void 0 : _c.details) == null ? void 0 : _d.currencyIn) == null ? void 0 : _e.amount) || "0");
24935
25054
  const solWithBuffer = solNeededLamports * 105n / 100n;
24936
25055
  const solAmount = Number(solWithBuffer) / 1e9;
24937
25056
  console.log(`[Solana Bridge] Need ~${solAmount.toFixed(6)} SOL for bridge`);
@@ -24973,8 +25092,8 @@ const CoinleyPaymentInternal = ({
24973
25092
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
24974
25093
  try {
24975
25094
  const status = await paymentFlow.api.getDepositStatus(activePaymentData.id);
24976
- console.log(`[Solana Bridge] Deposit check ${attempt + 1}/${maxAttempts}:`, (_g = status == null ? void 0 : status.payment) == null ? void 0 : _g.status);
24977
- if (((_h = status == null ? void 0 : status.payment) == null ? void 0 : _h.detectedAt) || ((_i = status == null ? void 0 : status.payment) == null ? void 0 : _i.status) === "completed" || ((_j = status == null ? void 0 : status.payment) == null ? void 0 : _j.status) === "swept") {
25095
+ console.log(`[Solana Bridge] Deposit check ${attempt + 1}/${maxAttempts}:`, (_f = status == null ? void 0 : status.payment) == null ? void 0 : _f.status);
25096
+ if (((_g = status == null ? void 0 : status.payment) == null ? void 0 : _g.detectedAt) || ((_h = status == null ? void 0 : status.payment) == null ? void 0 : _h.status) === "completed" || ((_i = status == null ? void 0 : status.payment) == null ? void 0 : _i.status) === "swept") {
24978
25097
  detected = true;
24979
25098
  console.log("[Solana Bridge] Deposit detected on destination chain!");
24980
25099
  break;
@@ -25097,7 +25216,7 @@ const CoinleyPaymentInternal = ({
25097
25216
  if (!(activePaymentData == null ? void 0 : activePaymentData.depositAddress)) {
25098
25217
  throw new Error("Payment is missing a deposit address. Please refresh and try again.");
25099
25218
  }
25100
- if (!relayBridge.bridgeQuote) {
25219
+ if (!activeBridgeQuote) {
25101
25220
  throw new Error(
25102
25221
  `Bridge route unavailable for ${selectedToken.symbol} on ${selectedNetwork.name}. Please try a different token or network.`
25103
25222
  );
@@ -25107,8 +25226,8 @@ const CoinleyPaymentInternal = ({
25107
25226
  const { getWalletClient: getWalletClient2 } = await import("@wagmi/core");
25108
25227
  const targetChainId = parseInt(selectedNetwork.chainId);
25109
25228
  const expectedDepositAddress = normalizeEvmAddress(activePaymentData.depositAddress);
25110
- const quoteRequestedRecipient = normalizeEvmAddress((_k = relayBridge.bridgeQuote) == null ? void 0 : _k.requestedRecipient);
25111
- const quoteEffectiveRecipient = normalizeEvmAddress((_l = relayBridge.bridgeQuote) == null ? void 0 : _l.effectiveRecipient);
25229
+ const quoteRequestedRecipient = normalizeEvmAddress(activeBridgeQuote == null ? void 0 : activeBridgeQuote.requestedRecipient);
25230
+ const quoteEffectiveRecipient = normalizeEvmAddress(activeBridgeQuote == null ? void 0 : activeBridgeQuote.effectiveRecipient);
25112
25231
  console.log(`[${action}] validating deposit recipient`, {
25113
25232
  expectedDepositAddress,
25114
25233
  quoteRequestedRecipient,
@@ -25133,10 +25252,10 @@ const CoinleyPaymentInternal = ({
25133
25252
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
25134
25253
  try {
25135
25254
  walletClient = await getWalletClient2(wagmiConfig, { chainId: targetChainId });
25136
- console.log(`[${action}] connector confirmed: chain=${(_m = walletClient.chain) == null ? void 0 : _m.id} | attempts=${attempt + 1}`);
25255
+ console.log(`[${action}] connector confirmed: chain=${(_j = walletClient.chain) == null ? void 0 : _j.id} | attempts=${attempt + 1}`);
25137
25256
  break;
25138
25257
  } catch (e) {
25139
- if (((_n = e.message) == null ? void 0 : _n.includes("does not match")) && attempt < maxAttempts - 1) {
25258
+ if (((_k = e.message) == null ? void 0 : _k.includes("does not match")) && attempt < maxAttempts - 1) {
25140
25259
  console.log(`[${action}] connector still settling, attempt ${attempt + 1}: ${e.message}`);
25141
25260
  await new Promise((resolve) => setTimeout(resolve, 200));
25142
25261
  continue;
@@ -25153,7 +25272,7 @@ const CoinleyPaymentInternal = ({
25153
25272
  }
25154
25273
  const result = await executeSwapToDeposit(
25155
25274
  relayBridge,
25156
- relayBridge.bridgeQuote,
25275
+ activeBridgeQuote,
25157
25276
  walletClient,
25158
25277
  (step, message) => {
25159
25278
  console.log(`[${action}] ${step}: ${message}`);
@@ -26649,4 +26768,4 @@ export {
26649
26768
  isFeatureEnabled as i,
26650
26769
  logo as l
26651
26770
  };
26652
- //# sourceMappingURL=CoinleyPayment-pbTQ15wF.js.map
26771
+ //# sourceMappingURL=CoinleyPayment-BNHoVBKU.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-pbTQ15wF.js";
1
+ import { i as isFeatureEnabled, F as FEATURES, c as chainTransports, W as WALLETCONNECT_PROJECT_ID, l as logo } from "./CoinleyPayment-BNHoVBKU.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-Bs-au6VA.js.map
115
+ //# sourceMappingURL=appKitEVM-BeGg9nUC.js.map
@@ -1,4 +1,4 @@
1
- import { F as FEATURES, l as logo, W as WALLETCONNECT_PROJECT_ID } from "./CoinleyPayment-pbTQ15wF.js";
1
+ import { F as FEATURES, l as logo, W as WALLETCONNECT_PROJECT_ID } from "./CoinleyPayment-BNHoVBKU.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-KE60037B.js.map
245
+ //# sourceMappingURL=appKitSolana-C2Tow7WJ.js.map