uniport-sdk 0.0.1 → 0.0.3

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.
@@ -1,18 +1,82 @@
1
- import React, { useState, useEffect, useCallback, useRef } from 'react';
1
+ import { useState, useEffect, useCallback, useRef } from 'react';
2
+ import ReactDOM from 'react-dom';
2
3
  import { QRCodeSVG } from 'qrcode.react';
3
- import { QuoteRequest, OneClickService, ApiError } from '@defuse-protocol/one-click-sdk-typescript';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
 
6
6
  // src/components/UniportButton.tsx
7
- function getConfig() {
8
- {
9
- throw new Error(
10
- "Uniport SDK not initialized. Call initUniport() first."
11
- );
12
- }
7
+
8
+ // src/core/config.ts
9
+ var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
10
+ var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
11
+ function normalizeBackendUrl(url) {
12
+ return url.replace(/\/+$/, "");
13
+ }
14
+ function getUniportConfig() {
15
+ const backendUrl = DEFAULT_HOSTED_BACKEND_URL;
16
+ return {
17
+ backendUrl: normalizeBackendUrl(backendUrl),
18
+ requestTimeoutMs: DEFAULT_REQUEST_TIMEOUT_MS
19
+ };
13
20
  }
14
21
 
15
22
  // src/core/intents.ts
23
+ var UniportError = class extends Error {
24
+ constructor(params) {
25
+ super(params.message);
26
+ this.name = "UniportError";
27
+ this.code = params.code;
28
+ this.details = params.details;
29
+ this.status = params.status;
30
+ }
31
+ };
32
+ function isAbortError(error) {
33
+ return error instanceof Error && error.name === "AbortError";
34
+ }
35
+ function extractDetailMessage(details) {
36
+ if (typeof details === "string" && details.trim()) {
37
+ return details;
38
+ }
39
+ if (Array.isArray(details)) {
40
+ const firstString = details.find(
41
+ (detail) => typeof detail === "string" && detail.trim().length > 0
42
+ );
43
+ return firstString;
44
+ }
45
+ if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
46
+ const message = details.message.trim();
47
+ return message || void 0;
48
+ }
49
+ return void 0;
50
+ }
51
+ function toUniportError(body, fallback) {
52
+ const detailMessage = extractDetailMessage(body.details);
53
+ return new UniportError({
54
+ code: body.code || fallback.code,
55
+ message: detailMessage || body.message || fallback.message,
56
+ details: body.details,
57
+ status: fallback.status
58
+ });
59
+ }
60
+ function createTimeoutSignal(timeoutMs, externalSignal) {
61
+ const controller = new AbortController();
62
+ let timedOut = false;
63
+ const timeoutId = setTimeout(() => {
64
+ timedOut = true;
65
+ controller.abort();
66
+ }, timeoutMs);
67
+ const abortFromExternal = () => controller.abort();
68
+ externalSignal?.addEventListener("abort", abortFromExternal, {
69
+ once: true
70
+ });
71
+ return {
72
+ signal: controller.signal,
73
+ didTimeout: () => timedOut,
74
+ cleanup: () => {
75
+ clearTimeout(timeoutId);
76
+ externalSignal?.removeEventListener("abort", abortFromExternal);
77
+ }
78
+ };
79
+ }
16
80
  function toSmallestUnits(amount, decimals) {
17
81
  const [whole, fraction = ""] = amount.split(".");
18
82
  const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
@@ -22,16 +86,7 @@ function generateDeadline(hoursFromNow = 1) {
22
86
  const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
23
87
  return deadline.toISOString();
24
88
  }
25
- function ensureInitialized() {
26
- {
27
- throw new Error(
28
- "Uniport SDK not initialized. Call initUniport() first."
29
- );
30
- }
31
- }
32
89
  async function getQuote(options) {
33
- ensureInitialized();
34
- const config = getConfig();
35
90
  const {
36
91
  originToken,
37
92
  destinationToken,
@@ -43,78 +98,102 @@ async function getQuote(options) {
43
98
  swapType = "EXACT_INPUT",
44
99
  deadline,
45
100
  dry = false,
46
- referral = config.referral || "uniport"
101
+ referral = "uniport",
102
+ signal
47
103
  } = options;
48
104
  const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
49
- const quoteRequest = {
50
- dry,
51
- swapType: QuoteRequest.swapType[swapType],
52
- slippageTolerance,
53
- originAsset: originToken.assetId,
54
- depositType: QuoteRequest.depositType.ORIGIN_CHAIN,
55
- destinationAsset: destinationToken.assetId,
56
- amount: amountInSmallestUnits,
57
- refundTo,
58
- refundType: QuoteRequest.refundType.ORIGIN_CHAIN,
59
- recipient,
60
- recipientType: QuoteRequest.recipientType.DESTINATION_CHAIN,
61
- deadline: deadline?.toISOString() || generateDeadline(1),
62
- referral
63
- };
105
+ const { backendUrl, requestTimeoutMs } = getUniportConfig();
106
+ const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
107
+ requestTimeoutMs,
108
+ signal
109
+ );
110
+ let response;
64
111
  try {
65
- const response = await OneClickService.getQuote(quoteRequest);
66
- const quote = response.quote;
67
- return {
68
- depositAddress: quote.depositAddress || "",
69
- memo: quote.depositMemo,
70
- amountIn: quote.amountIn,
71
- amountOut: quote.amountOut,
72
- amountOutFormatted: quote.amountOutFormatted,
73
- amountOutUsd: quote.amountOutUsd,
74
- deadline: quote.deadline,
75
- timeWhenInactive: quote.timeWhenInactive,
76
- correlationId: response.correlationId
77
- };
112
+ response = await fetch(`${backendUrl}/api/quote`, {
113
+ method: "POST",
114
+ headers: { "Content-Type": "application/json" },
115
+ signal: requestSignal,
116
+ body: JSON.stringify({
117
+ dry,
118
+ swapType,
119
+ slippageTolerance,
120
+ originAsset: originToken.assetId,
121
+ destinationAsset: destinationToken.assetId,
122
+ amount: amountInSmallestUnits,
123
+ refundTo,
124
+ recipient,
125
+ deadline: deadline?.toISOString() || generateDeadline(1),
126
+ referral
127
+ })
128
+ });
78
129
  } catch (error) {
79
- if (error instanceof ApiError) {
80
- throw new Error(
81
- `Quote failed (${error.status}): ${JSON.stringify(error.body)}`
82
- );
130
+ cleanup();
131
+ if (isAbortError(error)) {
132
+ if (signal?.aborted && !didTimeout()) {
133
+ throw error;
134
+ }
135
+ throw new UniportError({
136
+ code: "REQUEST_TIMEOUT",
137
+ message: "Quote request timed out"
138
+ });
83
139
  }
84
140
  throw error;
85
141
  }
142
+ cleanup();
143
+ if (!response.ok) {
144
+ const errorBody = await response.json().catch(() => ({}));
145
+ throw toUniportError(errorBody, {
146
+ code: "QUOTE_FAILED",
147
+ message: "Quote failed.",
148
+ status: response.status
149
+ });
150
+ }
151
+ const data = await response.json();
152
+ const quote = data.quote;
153
+ return {
154
+ depositAddress: quote.depositAddress || "",
155
+ memo: quote.depositMemo,
156
+ amountIn: quote.amountIn,
157
+ amountOut: quote.amountOut,
158
+ amountOutFormatted: quote.amountOutFormatted,
159
+ amountOutUsd: quote.amountOutUsd,
160
+ deadline: quote.deadline,
161
+ timeWhenInactive: quote.timeWhenInactive,
162
+ correlationId: data.correlationId
163
+ };
86
164
  }
87
165
  async function getExecutionStatus(depositAddress, memo) {
88
- ensureInitialized();
166
+ const { backendUrl, requestTimeoutMs } = getUniportConfig();
167
+ const url = new URL(
168
+ `${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
169
+ );
170
+ if (memo) {
171
+ url.searchParams.set("memo", memo);
172
+ }
173
+ const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
174
+ let response;
89
175
  try {
90
- const response = await OneClickService.getExecutionStatus(
91
- depositAddress,
92
- memo
93
- );
94
- const status = response.status;
95
- const isComplete = ["SUCCESS", "REFUNDED", "FAILED"].includes(status);
96
- const isSuccess = status === "SUCCESS";
97
- const swapDetails = response.swapDetails;
98
- const destinationTxHashes = swapDetails?.destinationChainTxHashes?.map((tx) => tx.hash);
99
- const originTxHashes = swapDetails?.originChainTxHashes?.map(
100
- (tx) => tx.hash
101
- );
102
- return {
103
- status,
104
- isComplete,
105
- isSuccess,
106
- correlationId: response.correlationId,
107
- destinationTxHashes,
108
- originTxHashes
109
- };
176
+ response = await fetch(url.toString(), { signal });
110
177
  } catch (error) {
111
- if (error instanceof ApiError) {
112
- throw new Error(
113
- `Status check failed (${error.status}): ${JSON.stringify(error.body)}`
114
- );
178
+ cleanup();
179
+ if (isAbortError(error)) {
180
+ throw new UniportError({
181
+ code: "REQUEST_TIMEOUT",
182
+ message: "Status check timed out"
183
+ });
115
184
  }
116
185
  throw error;
117
186
  }
187
+ cleanup();
188
+ if (!response.ok) {
189
+ const errorBody = await response.json().catch(() => ({}));
190
+ throw toUniportError(errorBody, {
191
+ code: "STATUS_CHECK_FAILED",
192
+ message: "Status check failed.",
193
+ status: response.status
194
+ });
195
+ }
196
+ return await response.json();
118
197
  }
119
198
 
120
199
  // src/core/tokens.ts
@@ -122,7 +201,7 @@ var TOKEN_ICONS = {
122
201
  // Stablecoins
123
202
  USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
124
203
  USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
125
- DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EesdfdsfdC495271d0F/logo.png",
204
+ DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeEC495271d0F/logo.png",
126
205
  // Major tokens
127
206
  ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
128
207
  WETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
@@ -155,16 +234,16 @@ var TOKEN_ICONS = {
155
234
  SHIB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE/logo.png",
156
235
  PEPE: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6982508145454Ce325dDbE47a25d4ec3d2311933/logo.png",
157
236
  // Ecosystem tokens
158
- STRK: "https://assets.coingecko.com/coins/images/26433/standard/starknet.png",
159
- BERA: "https://assets.coingecko.com/coins/images/34286/standard/bera.png",
237
+ STRK: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png",
238
+ BERA: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png",
160
239
  GNO: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6810e776880C02933D47DB1b9fc05908e5386b96/logo.png",
161
- MON: "https://assets.coingecko.com/coins/images/35887/standard/monad.png",
240
+ MON: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png",
162
241
  ZEC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png",
163
242
  // Meme coins
164
- TRUMP: "https://assets.coingecko.com/coins/images/53746/standard/trump.jpg",
165
- WIF: "https://assets.coingecko.com/coins/images/33566/standard/dogwifhat.jpg",
166
- BRETT: "https://assets.coingecko.com/coins/images/35529/standard/brett.png",
167
- TURBO: "https://assets.coingecko.com/coins/images/30116/standard/turbo.png",
243
+ TRUMP: "https://s2.coinmarketcap.com/static/img/coins/64x64/35336.png",
244
+ WIF: "https://s2.coinmarketcap.com/static/img/coins/64x64/28752.png",
245
+ BRETT: "https://s2.coinmarketcap.com/static/img/coins/64x64/29743.png",
246
+ TURBO: "https://s2.coinmarketcap.com/static/img/coins/64x64/24911.png",
168
247
  // Default fallback
169
248
  DEFAULT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png"
170
249
  };
@@ -186,21 +265,29 @@ var CHAIN_ICONS = {
186
265
  cardano: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/cardano/info/logo.png",
187
266
  aptos: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aptos/info/logo.png",
188
267
  gnosis: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/xdai/info/logo.png",
189
- starknet: "https://assets.coingecko.com/coins/images/26433/standard/starknet.png",
190
- bera: "https://assets.coingecko.com/coins/images/34286/standard/bera.png",
191
- monad: "https://assets.coingecko.com/coins/images/35887/standard/monad.png",
268
+ starknet: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png",
269
+ bera: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png",
270
+ monad: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png",
192
271
  doge: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/doge/info/logo.png",
193
272
  ltc: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/litecoin/info/logo.png",
194
273
  bch: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoincash/info/logo.png",
195
274
  xrp: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ripple/info/logo.png",
196
275
  zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png"
197
276
  };
198
- function createToken(chain, symbol, assetId, decimals, contractAddress) {
199
- const name = `${chain}${symbol.replace("$", "").replace(" ", "")}`;
277
+ function createToken(chain, symbol, assetId, decimals, contractAddress, options) {
278
+ const normalizedSymbol = symbol.replace("$", "").replace(" ", "");
279
+ const canonicalPrefix = TOKEN_NAME_PREFIXES[chain] || chain;
280
+ const legacyName = `${chain}${normalizedSymbol}`;
281
+ const name = options?.name || `${canonicalPrefix}${normalizedSymbol}`;
200
282
  const icon = TOKEN_ICONS[symbol] || TOKEN_ICONS.DEFAULT;
201
283
  const chainIcon = CHAIN_ICONS[chain];
284
+ const aliases = new Set(options?.aliases || []);
285
+ if (legacyName !== name) {
286
+ aliases.add(legacyName);
287
+ }
202
288
  return {
203
289
  name,
290
+ aliases: aliases.size > 0 ? Array.from(aliases) : void 0,
204
291
  symbol,
205
292
  assetId,
206
293
  chain,
@@ -210,6 +297,20 @@ function createToken(chain, symbol, assetId, decimals, contractAddress) {
210
297
  contractAddress
211
298
  };
212
299
  }
300
+ var TOKEN_NAME_PREFIXES = {
301
+ eth: "ethereum",
302
+ arb: "arbitrum",
303
+ op: "optimism",
304
+ sol: "solana",
305
+ btc: "bitcoin",
306
+ pol: "polygon",
307
+ avax: "avalanche",
308
+ doge: "dogecoin",
309
+ ltc: "litecoin",
310
+ bch: "bitcoinCash",
311
+ bera: "berachain",
312
+ zec: "zcash"
313
+ };
213
314
  var suiSUI = createToken("sui", "SUI", "nep141:sui.omft.near", 9);
214
315
  var suiUSDC = createToken("sui", "USDC", "nep141:sui-c1b81ecaf27933252d31a963bc5e9458f13c18ce.omft.near", 6, "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC");
215
316
  var ethereumETH = createToken("eth", "ETH", "nep141:eth.omft.near", 18);
@@ -231,7 +332,7 @@ var arbitrumARB = createToken("arb", "ARB", "nep141:arb-0x912ce59144191c1204e645
231
332
  var arbitrumGMX = createToken("arb", "GMX", "nep141:arb-0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a.omft.near", 18, "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a");
232
333
  var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
233
334
  var baseUSDC = createToken("base", "USDC", "nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near", 6, "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913");
234
- var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf");
335
+ var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
235
336
  var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
236
337
  var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
237
338
  var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
@@ -266,7 +367,10 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
266
367
  var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
267
368
  var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
268
369
  var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
269
- var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near");
370
+ var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
371
+ name: "nearNEAR",
372
+ aliases: ["nearwNEAR"]
373
+ });
270
374
  var nearUSDC = createToken("near", "USDC", "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6, "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1");
271
375
  var nearUSDT = createToken("near", "USDT", "nep141:usdt.tether-token.near", 6, "usdt.tether-token.near");
272
376
  var CHAINS = {
@@ -421,77 +525,124 @@ var CHAINS = {
421
525
  tokens: []
422
526
  }
423
527
  };
424
- Object.values(CHAINS).flatMap((chain) => chain.tokens);
528
+ var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
529
+ function getToken(name) {
530
+ return ALL_TOKENS.find(
531
+ (token) => token.name === name || token.aliases?.includes(name)
532
+ );
533
+ }
425
534
  function getSupportedChains() {
426
535
  return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
427
536
  }
428
- function getSuiDestinationTokens() {
429
- return CHAINS.sui.tokens;
430
- }
431
537
 
432
538
  // src/hooks/useUniportPayment.ts
433
539
  function useUniportPayment(options) {
434
- const { recipient, refundAddress, destinationToken, onSuccess, onError } = options;
435
- const destToken = destinationToken === "suiSUI" ? suiSUI : suiUSDC;
540
+ const {
541
+ recipient,
542
+ refundAddress: initialRefundAddress,
543
+ destinationToken,
544
+ amount: initialAmount,
545
+ onSuccess,
546
+ onError
547
+ } = options;
548
+ const destToken = getToken(destinationToken);
549
+ if (!destToken) {
550
+ throw new Error(
551
+ `Invalid destinationToken: "${destinationToken}". Use a valid token name like "suiUSDC", "arbitrumUSDC", "ethereumUSDC", or "baseETH". See the supported tokens table in the README.`
552
+ );
553
+ }
436
554
  const [paymentState, setPaymentState] = useState("idle");
437
555
  const [quote, setQuote] = useState(null);
438
556
  const [previewQuote, setPreviewQuote] = useState(null);
557
+ const [previewError, setPreviewError] = useState(null);
439
558
  const [isLoadingPreview, setIsLoadingPreview] = useState(false);
440
559
  const [status, setStatus] = useState(null);
441
560
  const [error, setError] = useState(null);
442
561
  const [selectedChain, setSelectedChain] = useState(null);
443
562
  const [selectedToken, setSelectedToken] = useState(null);
444
- const [amount, setAmountState] = useState("");
563
+ const [amount, setAmountState] = useState(initialAmount ?? "");
564
+ const [refundAddress, setRefundAddressState] = useState(
565
+ initialRefundAddress ?? ""
566
+ );
445
567
  const pollingRef = useRef(null);
446
568
  const lastStatusRef = useRef(null);
447
569
  const previewDebounceRef = useRef(null);
448
- const chains = getSupportedChains().filter((c) => c.id !== "sui");
570
+ const previewAbortRef = useRef(null);
571
+ const chains = getSupportedChains().filter((c) => c.id !== destToken.chain);
449
572
  const tokens = selectedChain?.tokens || [];
450
- const destinationTokens = getSuiDestinationTokens();
451
- const setAmount = useCallback(
452
- (newAmount) => {
453
- setAmountState(newAmount);
573
+ const schedulePreviewQuote = useCallback(
574
+ (nextAmount, nextRefundAddress, nextSelectedToken) => {
454
575
  setPreviewQuote(null);
576
+ setPreviewError(null);
455
577
  if (previewDebounceRef.current) {
456
578
  clearTimeout(previewDebounceRef.current);
457
579
  }
458
- if (newAmount && selectedToken && refundAddress) {
459
- setIsLoadingPreview(true);
460
- previewDebounceRef.current = setTimeout(async () => {
461
- try {
462
- const result = await getQuote({
463
- originToken: selectedToken,
464
- destinationToken: destToken,
465
- amount: newAmount,
466
- recipient,
467
- refundTo: refundAddress,
468
- dry: true
469
- // Dry run for preview
470
- });
471
- setPreviewQuote(result);
472
- } catch (err) {
473
- console.warn("Preview quote failed:", err);
474
- } finally {
475
- setIsLoadingPreview(false);
476
- }
477
- }, 3e3);
478
- } else {
580
+ if (previewAbortRef.current) {
581
+ previewAbortRef.current.abort();
582
+ previewAbortRef.current = null;
583
+ }
584
+ if (!nextAmount || !nextSelectedToken || !nextRefundAddress) {
479
585
  setIsLoadingPreview(false);
586
+ return;
480
587
  }
588
+ setIsLoadingPreview(true);
589
+ previewDebounceRef.current = setTimeout(async () => {
590
+ const controller = new AbortController();
591
+ previewAbortRef.current = controller;
592
+ try {
593
+ const result = await getQuote({
594
+ originToken: nextSelectedToken,
595
+ destinationToken: destToken,
596
+ amount: nextAmount,
597
+ recipient,
598
+ refundTo: nextRefundAddress,
599
+ dry: true,
600
+ signal: controller.signal
601
+ });
602
+ setPreviewQuote(result);
603
+ } catch (err) {
604
+ if (err instanceof Error && err.name === "AbortError") {
605
+ return;
606
+ }
607
+ const previewFailure = err instanceof Error ? err : new Error("Failed to fetch estimate");
608
+ setPreviewError(previewFailure);
609
+ console.warn("Preview quote failed:", previewFailure);
610
+ } finally {
611
+ if (previewAbortRef.current === controller) {
612
+ previewAbortRef.current = null;
613
+ }
614
+ setIsLoadingPreview(false);
615
+ }
616
+ }, 250);
617
+ },
618
+ [destToken, recipient]
619
+ );
620
+ const setAmount = useCallback(
621
+ (newAmount) => {
622
+ setAmountState(newAmount);
623
+ schedulePreviewQuote(newAmount, refundAddress, selectedToken);
624
+ },
625
+ [refundAddress, schedulePreviewQuote, selectedToken]
626
+ );
627
+ const setRefundAddress = useCallback(
628
+ (newRefundAddress) => {
629
+ setRefundAddressState(newRefundAddress);
630
+ schedulePreviewQuote(amount, newRefundAddress, selectedToken);
481
631
  },
482
- [selectedToken, refundAddress, recipient, destToken]
632
+ [amount, schedulePreviewQuote, selectedToken]
483
633
  );
484
634
  const handleChainSelect = useCallback((chain) => {
635
+ const nextToken = chain.tokens[0] || null;
485
636
  setSelectedChain(chain);
486
- setSelectedToken(chain.tokens[0] || null);
637
+ setSelectedToken(nextToken);
487
638
  setPaymentState("selecting");
488
- setPreviewQuote(null);
489
- }, []);
639
+ schedulePreviewQuote(amount, refundAddress, nextToken);
640
+ }, [amount, refundAddress, schedulePreviewQuote]);
490
641
  const handleTokenSelect = useCallback((token) => {
491
642
  setSelectedToken(token);
492
643
  setPaymentState("selecting");
493
- setPreviewQuote(null);
494
- }, []);
644
+ schedulePreviewQuote(amount, refundAddress, token);
645
+ }, [amount, refundAddress, schedulePreviewQuote]);
495
646
  const fetchQuote = useCallback(async () => {
496
647
  if (!selectedToken || !amount || !refundAddress) {
497
648
  setError(new Error("Missing required fields"));
@@ -524,6 +675,12 @@ function useUniportPayment(options) {
524
675
  destToken,
525
676
  onError
526
677
  ]);
678
+ const stopPolling = useCallback(() => {
679
+ if (pollingRef.current) {
680
+ clearInterval(pollingRef.current);
681
+ pollingRef.current = null;
682
+ }
683
+ }, []);
527
684
  const pollStatus = useCallback(async () => {
528
685
  if (!quote?.depositAddress) return;
529
686
  try {
@@ -543,10 +700,12 @@ function useUniportPayment(options) {
543
700
  txHash: result.destinationTxHashes?.[0] || "",
544
701
  amount: quote.amountOut
545
702
  });
546
- } else if (result.status === "FAILED") {
703
+ } else if (result.isComplete) {
547
704
  setPaymentState("error");
548
705
  stopPolling();
549
- const err = new Error("Payment failed");
706
+ const err = new Error(
707
+ result.status === "REFUNDED" ? "Payment was refunded" : "Payment failed"
708
+ );
550
709
  setError(err);
551
710
  onError?.(err);
552
711
  }
@@ -554,18 +713,12 @@ function useUniportPayment(options) {
554
713
  } catch (err) {
555
714
  console.error("Status poll error:", err);
556
715
  }
557
- }, [quote, onSuccess, onError]);
716
+ }, [quote, onSuccess, onError, stopPolling]);
558
717
  const startPolling = useCallback(() => {
559
718
  if (pollingRef.current) return;
560
719
  pollStatus();
561
720
  pollingRef.current = setInterval(pollStatus, 3e3);
562
721
  }, [pollStatus]);
563
- const stopPolling = useCallback(() => {
564
- if (pollingRef.current) {
565
- clearInterval(pollingRef.current);
566
- pollingRef.current = null;
567
- }
568
- }, []);
569
722
  const copyToClipboard = useCallback(async (text) => {
570
723
  try {
571
724
  await navigator.clipboard.writeText(text);
@@ -579,15 +732,29 @@ function useUniportPayment(options) {
579
732
  if (previewDebounceRef.current) {
580
733
  clearTimeout(previewDebounceRef.current);
581
734
  }
735
+ if (previewAbortRef.current) {
736
+ previewAbortRef.current.abort();
737
+ previewAbortRef.current = null;
738
+ }
582
739
  setPaymentState("idle");
583
740
  setQuote(null);
584
741
  setPreviewQuote(null);
585
742
  setIsLoadingPreview(false);
586
743
  setStatus(null);
587
744
  setError(null);
745
+ setPreviewError(null);
588
746
  setSelectedChain(null);
589
747
  setSelectedToken(null);
590
- setAmountState("");
748
+ setAmountState(initialAmount ?? "");
749
+ setRefundAddressState(initialRefundAddress ?? "");
750
+ lastStatusRef.current = null;
751
+ }, [initialAmount, initialRefundAddress, stopPolling]);
752
+ const cancelQuote = useCallback(() => {
753
+ stopPolling();
754
+ setPaymentState("selecting");
755
+ setQuote(null);
756
+ setStatus(null);
757
+ setError(null);
591
758
  lastStatusRef.current = null;
592
759
  }, [stopPolling]);
593
760
  useEffect(() => {
@@ -596,293 +763,90 @@ function useUniportPayment(options) {
596
763
  if (previewDebounceRef.current) {
597
764
  clearTimeout(previewDebounceRef.current);
598
765
  }
766
+ if (previewAbortRef.current) {
767
+ previewAbortRef.current.abort();
768
+ previewAbortRef.current = null;
769
+ }
599
770
  };
600
771
  }, [stopPolling]);
601
772
  return {
602
773
  paymentState,
603
774
  quote,
604
775
  previewQuote,
776
+ previewError,
605
777
  isLoadingPreview,
606
778
  status,
607
779
  error,
608
780
  selectedChain,
609
781
  selectedToken,
610
782
  amount,
783
+ refundAddress,
611
784
  destinationToken: destToken,
612
785
  chains,
613
786
  tokens,
614
- destinationTokens,
615
787
  setSelectedChain: handleChainSelect,
616
788
  setSelectedToken: handleTokenSelect,
617
789
  setAmount,
790
+ setRefundAddress,
618
791
  fetchQuote,
619
792
  startPolling,
620
793
  stopPolling,
794
+ cancelQuote,
621
795
  reset,
622
796
  copyToClipboard
623
797
  };
624
798
  }
625
- var styles = {
626
- overlay: {
627
- position: "fixed",
628
- inset: 0,
629
- backgroundColor: "rgba(0, 0, 0, 0.8)",
630
- backdropFilter: "blur(8px)",
631
- display: "flex",
632
- alignItems: "center",
633
- justifyContent: "center",
634
- zIndex: 9999,
635
- padding: "16px",
636
- animation: "uniport-fade-in 0.2s ease"
637
- },
638
- modal: {
639
- position: "relative",
640
- width: "100%",
641
- maxWidth: "380px",
642
- background: "rgba(22, 22, 30, 0.95)",
643
- backdropFilter: "blur(24px)",
644
- border: "1px solid rgba(255, 255, 255, 0.08)",
645
- borderRadius: "24px",
646
- padding: "24px",
647
- boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.05)",
648
- fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
649
- animation: "uniport-slide-up 0.3s ease"
650
- },
651
- header: {
652
- display: "flex",
653
- flexDirection: "column",
654
- alignItems: "center",
655
- marginBottom: "24px"
656
- },
657
- headerIcon: {
658
- width: "48px",
659
- height: "48px",
660
- borderRadius: "16px",
661
- background: "linear-gradient(135deg, rgba(255,255,255,0.1), transparent)",
662
- border: "1px solid rgba(255,255,255,0.05)",
663
- display: "flex",
664
- alignItems: "center",
665
- justifyContent: "center",
666
- marginBottom: "16px"
667
- },
668
- title: {
669
- fontSize: "18px",
670
- fontWeight: 500,
671
- color: "white",
672
- margin: 0,
673
- textShadow: "0 0 15px rgba(255,255,255,0.3)"
674
- },
675
- subtitle: {
676
- fontSize: "12px",
677
- color: "rgba(255,255,255,0.4)",
678
- marginTop: "4px",
679
- fontWeight: 300,
680
- letterSpacing: "0.5px"
681
- },
682
- closeButton: {
683
- position: "absolute",
684
- top: "16px",
685
- right: "16px",
686
- width: "32px",
687
- height: "32px",
688
- borderRadius: "8px",
689
- background: "rgba(255,255,255,0.05)",
690
- border: "1px solid rgba(255,255,255,0.1)",
691
- color: "rgba(255,255,255,0.6)",
692
- cursor: "pointer",
693
- display: "flex",
694
- alignItems: "center",
695
- justifyContent: "center",
696
- transition: "all 0.2s"
697
- },
698
- selectorsRow: {
699
- display: "grid",
700
- gridTemplateColumns: "1fr 1fr",
701
- gap: "12px",
702
- marginBottom: "24px"
703
- },
704
- selector: {
705
- display: "flex",
706
- alignItems: "center",
707
- justifyContent: "space-between",
708
- padding: "12px",
709
- background: "rgba(255,255,255,0.05)",
710
- border: "1px solid rgba(255,255,255,0.05)",
711
- borderRadius: "16px",
712
- cursor: "pointer",
713
- transition: "all 0.2s"
714
- },
715
- selectorIcon: {
716
- width: "32px",
717
- height: "32px",
718
- borderRadius: "50%",
719
- background: "#1c1c26",
720
- border: "1px solid rgba(255,255,255,0.1)",
721
- display: "flex",
722
- alignItems: "center",
723
- justifyContent: "center",
724
- overflow: "hidden"
725
- },
726
- selectorLabel: {
727
- fontSize: "10px",
728
- textTransform: "uppercase",
729
- letterSpacing: "1.5px",
730
- color: "rgba(255,255,255,0.3)",
731
- fontWeight: 500
732
- },
733
- selectorValue: {
734
- fontSize: "14px",
735
- color: "rgba(255,255,255,0.9)",
736
- fontWeight: 500
737
- },
738
- amountInput: {
739
- width: "100%",
740
- textAlign: "center",
741
- fontSize: "48px",
742
- fontWeight: 500,
743
- color: "white",
744
- background: "transparent",
745
- border: "none",
746
- outline: "none",
747
- marginBottom: "24px",
748
- caretColor: "#4F46E5"
749
- },
750
- details: {
751
- marginBottom: "20px",
752
- padding: "0 4px"
753
- },
754
- detailRow: {
755
- display: "flex",
756
- justifyContent: "space-between",
757
- alignItems: "center",
758
- fontSize: "12px",
759
- color: "rgba(255,255,255,0.4)",
760
- marginBottom: "8px"
761
- },
762
- detailValue: {
763
- fontWeight: 500,
764
- color: "rgba(255,255,255,0.7)",
765
- display: "flex",
766
- alignItems: "center",
767
- gap: "6px"
768
- },
769
- button: {
770
- width: "100%",
771
- position: "relative",
772
- overflow: "hidden",
773
- borderRadius: "16px",
774
- padding: "2px",
775
- background: "linear-gradient(90deg, #4F46E5, #7C3AED, #4F46E5)",
776
- backgroundSize: "200% 200%",
777
- animation: "uniport-gradient 3s ease infinite",
778
- border: "none",
779
- cursor: "pointer"
780
- },
781
- buttonInner: {
782
- display: "flex",
783
- alignItems: "center",
784
- justifyContent: "center",
785
- gap: "8px",
786
- height: "48px",
787
- borderRadius: "14px",
788
- background: "#0A0A0F",
789
- color: "white",
790
- fontSize: "14px",
791
- fontWeight: 500,
792
- transition: "background 0.3s"
793
- },
794
- buttonDisabled: {
795
- opacity: 0.5,
796
- cursor: "not-allowed"
797
- },
798
- // QR container - dark background, no white box
799
- qrContainer: {
800
- display: "flex",
801
- flexDirection: "column",
802
- alignItems: "center",
803
- padding: "24px",
804
- background: "transparent",
805
- marginBottom: "16px"
806
- },
807
- // Address with copy button
808
- addressContainer: {
809
- display: "flex",
810
- alignItems: "center",
811
- justifyContent: "center",
812
- gap: "8px",
813
- marginTop: "16px"
814
- },
815
- addressText: {
816
- fontSize: "12px",
817
- color: "rgba(255,255,255,0.6)",
818
- wordBreak: "break-all",
819
- textAlign: "center",
820
- fontFamily: "monospace"
821
- },
822
- copyButton: {
823
- display: "flex",
824
- alignItems: "center",
825
- justifyContent: "center",
826
- width: "32px",
827
- height: "32px",
828
- borderRadius: "8px",
829
- background: "rgba(255,255,255,0.1)",
830
- border: "1px solid rgba(255,255,255,0.15)",
831
- cursor: "pointer",
832
- transition: "all 0.2s",
833
- flexShrink: 0
834
- },
835
- statusBadge: {
836
- display: "inline-flex",
837
- alignItems: "center",
838
- gap: "6px",
839
- padding: "6px 12px",
840
- borderRadius: "20px",
841
- fontSize: "12px",
842
- fontWeight: 500
843
- },
844
- processingBadge: {
845
- background: "rgba(79, 70, 229, 0.2)",
846
- color: "#818CF8"
847
- },
848
- dropdown: {
849
- position: "absolute",
850
- top: "calc(100% + 8px)",
851
- left: 0,
852
- right: 0,
853
- background: "rgba(22, 22, 30, 0.98)",
854
- border: "1px solid rgba(255,255,255,0.1)",
855
- borderRadius: "16px",
856
- maxHeight: "200px",
857
- overflowY: "auto",
858
- zIndex: 10,
859
- boxShadow: "0 20px 40px rgba(0,0,0,0.5)"
860
- },
861
- dropdownItem: {
862
- display: "flex",
863
- alignItems: "center",
864
- gap: "12px",
865
- padding: "12px 16px",
866
- cursor: "pointer",
867
- transition: "background 0.2s"
868
- },
869
- loadingDot: {
870
- width: "8px",
871
- height: "8px",
872
- borderRadius: "50%",
873
- background: "#818CF8",
874
- animation: "uniport-pulse 1s ease infinite"
875
- },
876
- tokenBadge: {
877
- display: "inline-flex",
878
- alignItems: "center",
879
- gap: "4px",
880
- padding: "2px 8px",
881
- borderRadius: "12px",
882
- background: "rgba(255,255,255,0.08)",
883
- fontSize: "11px"
884
- }
799
+ var LIGHT = {
800
+ overlay: "rgba(0, 0, 0, 0.42)",
801
+ modalBg: "#ffffff",
802
+ rowHover: "#f5f5f7",
803
+ inputBg: "#f5f5f7",
804
+ warningBg: "#fffbeb",
805
+ warningBorder: "rgba(245, 158, 11, 0.25)",
806
+ text: "#1c1c1e",
807
+ textSecondary: "#3a3a3c",
808
+ textMuted: "#8e8e93",
809
+ border: "#e5e5ea",
810
+ accent: "#6366f1",
811
+ success: "#30d158",
812
+ error: "#ff3b30",
813
+ warning: "#d97706",
814
+ warningText: "#92400e",
815
+ btnBg: "#1c1c1e",
816
+ btnText: "#ffffff",
817
+ btnDisabledBg: "#e5e5ea",
818
+ btnDisabledText: "#8e8e93",
819
+ iconBtnBg: "#f5f5f7",
820
+ iconBtnHover: "#e5e5ea",
821
+ iconBtnColor: "#3a3a3c"
822
+ };
823
+ var DARK = {
824
+ overlay: "rgba(0, 0, 0, 0.65)",
825
+ modalBg: "#1c1c1e",
826
+ rowHover: "#2c2c2e",
827
+ inputBg: "#2c2c2e",
828
+ warningBg: "rgba(245, 158, 11, 0.1)",
829
+ warningBorder: "rgba(245, 158, 11, 0.2)",
830
+ text: "#ffffff",
831
+ textSecondary: "rgba(235, 235, 245, 0.85)",
832
+ textMuted: "#8e8e93",
833
+ border: "#38383a",
834
+ accent: "#818cf8",
835
+ success: "#30d158",
836
+ error: "#ff453a",
837
+ warning: "#ffd60a",
838
+ warningText: "#ffd60a",
839
+ btnBg: "#6366f1",
840
+ btnText: "#ffffff",
841
+ btnDisabledBg: "#3a3a3c",
842
+ btnDisabledText: "#636366",
843
+ iconBtnBg: "#2c2c2e",
844
+ iconBtnHover: "#3a3a3c",
845
+ iconBtnColor: "rgba(235, 235, 245, 0.8)"
885
846
  };
847
+ function getTheme(mode) {
848
+ return mode === "dark" ? DARK : LIGHT;
849
+ }
886
850
  var injectStyles = () => {
887
851
  if (typeof document === "undefined") return;
888
852
  if (document.getElementById("uniport-styles")) return;
@@ -891,643 +855,917 @@ var injectStyles = () => {
891
855
  style.textContent = `
892
856
  @keyframes uniport-fade-in {
893
857
  from { opacity: 0; }
894
- to { opacity: 1; }
858
+ to { opacity: 1; }
895
859
  }
896
860
  @keyframes uniport-slide-up {
897
- from { opacity: 0; transform: translateY(20px) scale(0.95); }
898
- to { opacity: 1; transform: translateY(0) scale(1); }
861
+ from { opacity: 0; transform: translateY(14px) scale(0.98); }
862
+ to { opacity: 1; transform: translateY(0) scale(1); }
899
863
  }
900
- @keyframes uniport-gradient {
901
- 0% { background-position: 0% 50%; }
902
- 50% { background-position: 100% 50%; }
903
- 100% { background-position: 0% 50%; }
864
+ @keyframes uniport-spin {
865
+ from { transform: rotate(0deg); }
866
+ to { transform: rotate(360deg); }
904
867
  }
905
868
  @keyframes uniport-pulse {
906
869
  0%, 100% { opacity: 1; }
907
- 50% { opacity: 0.3; }
870
+ 50% { opacity: 0.35; }
908
871
  }
909
872
  `;
910
873
  document.head.appendChild(style);
911
874
  };
875
+ var AVATAR_COLORS = [
876
+ "#6366f1",
877
+ "#8b5cf6",
878
+ "#06b6d4",
879
+ "#10b981",
880
+ "#f59e0b",
881
+ "#ef4444",
882
+ "#ec4899",
883
+ "#3b82f6",
884
+ "#14b8a6",
885
+ "#f97316"
886
+ ];
887
+ function charColor(name) {
888
+ let h = 0;
889
+ for (let i = 0; i < name.length; i++) {
890
+ h = name.charCodeAt(i) + ((h << 5) - h);
891
+ }
892
+ return AVATAR_COLORS[Math.abs(h) % AVATAR_COLORS.length];
893
+ }
894
+ function TokenAvatar({ src, name, size = 40 }) {
895
+ const [failed, setFailed] = useState(false);
896
+ if (failed || !src) {
897
+ return /* @__PURE__ */ jsx(
898
+ "div",
899
+ {
900
+ "aria-label": name,
901
+ style: {
902
+ width: size,
903
+ height: size,
904
+ borderRadius: "50%",
905
+ background: charColor(name),
906
+ display: "flex",
907
+ alignItems: "center",
908
+ justifyContent: "center",
909
+ fontSize: Math.round(size * 0.4),
910
+ fontWeight: 700,
911
+ color: "#fff",
912
+ flexShrink: 0,
913
+ userSelect: "none",
914
+ letterSpacing: "-0.01em"
915
+ },
916
+ children: name.charAt(0).toUpperCase()
917
+ }
918
+ );
919
+ }
920
+ return /* @__PURE__ */ jsx(
921
+ "img",
922
+ {
923
+ src,
924
+ alt: name,
925
+ width: size,
926
+ height: size,
927
+ style: { borderRadius: "50%", objectFit: "cover", flexShrink: 0, display: "block" },
928
+ onError: () => setFailed(true)
929
+ }
930
+ );
931
+ }
932
+ function BackArrow({ color }) {
933
+ return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M19 12H5M5 12l7 7M5 12l7-7", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) });
934
+ }
935
+ function XMark({ color }) {
936
+ return /* @__PURE__ */ jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12", stroke: color, strokeWidth: "2.5", strokeLinecap: "round" }) });
937
+ }
938
+ function ChevronRight({ color }) {
939
+ return /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M9 18l6-6-6-6", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) });
940
+ }
941
+ function Spinner({ color }) {
942
+ return /* @__PURE__ */ jsxs(
943
+ "svg",
944
+ {
945
+ width: "18",
946
+ height: "18",
947
+ viewBox: "0 0 24 24",
948
+ fill: "none",
949
+ style: { animation: "uniport-spin 0.75s linear infinite", display: "block", flexShrink: 0 },
950
+ children: [
951
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10", stroke: color, strokeWidth: "3", strokeOpacity: "0.2" }),
952
+ /* @__PURE__ */ jsx("path", { d: "M12 2a10 10 0 019.95 9", stroke: color, strokeWidth: "3", strokeLinecap: "round" })
953
+ ]
954
+ }
955
+ );
956
+ }
957
+ function CopyIcon({ color }) {
958
+ return /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", children: [
959
+ /* @__PURE__ */ jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", stroke: color, strokeWidth: "2" }),
960
+ /* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1", stroke: color, strokeWidth: "2" })
961
+ ] });
962
+ }
963
+ function CheckMark({ color }) {
964
+ return /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M20 6L9 17l-5-5", stroke: color, strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
965
+ }
966
+ function WarningTriangle({ color }) {
967
+ return /* @__PURE__ */ jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", style: { flexShrink: 0, marginTop: 1 }, children: [
968
+ /* @__PURE__ */ jsx(
969
+ "path",
970
+ {
971
+ d: "M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z",
972
+ stroke: color,
973
+ strokeWidth: "2",
974
+ strokeLinecap: "round",
975
+ strokeLinejoin: "round"
976
+ }
977
+ ),
978
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "9", x2: "12", y2: "13", stroke: color, strokeWidth: "2", strokeLinecap: "round" }),
979
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "17", x2: "12.01", y2: "17", stroke: color, strokeWidth: "2", strokeLinecap: "round" })
980
+ ] });
981
+ }
982
+ function formatPreviewError(error) {
983
+ if (error.name === "AbortError") {
984
+ return "Estimate request was cancelled. Try again.";
985
+ }
986
+ if (error.message === "Quote request timed out") {
987
+ return "Could not fetch estimate. Please try again.";
988
+ }
989
+ const normalized = error.message.toLowerCase();
990
+ if (normalized.includes("recipient is not valid")) {
991
+ return "Recipient address does not match the selected destination chain.";
992
+ }
993
+ if (normalized.includes("refund") && normalized.includes("valid")) {
994
+ return "Refund address does not match the source chain.";
995
+ }
996
+ if (normalized.includes("amount")) {
997
+ return "Enter a valid amount to fetch an estimate.";
998
+ }
999
+ return "Could not fetch estimate. Check the details and try again.";
1000
+ }
1001
+ function formatChainLabel(chainId) {
1002
+ const labels = {
1003
+ sui: "Sui",
1004
+ eth: "Ethereum",
1005
+ sol: "Solana",
1006
+ arb: "Arbitrum",
1007
+ base: "Base",
1008
+ op: "Optimism",
1009
+ pol: "Polygon",
1010
+ avax: "Avalanche",
1011
+ bsc: "BNB Chain",
1012
+ near: "NEAR",
1013
+ btc: "Bitcoin",
1014
+ ton: "TON",
1015
+ tron: "Tron",
1016
+ stellar: "Stellar",
1017
+ cardano: "Cardano",
1018
+ xrp: "XRP Ledger",
1019
+ doge: "Dogecoin",
1020
+ ltc: "Litecoin",
1021
+ bch: "Bitcoin Cash",
1022
+ aptos: "Aptos",
1023
+ starknet: "Starknet",
1024
+ bera: "Berachain",
1025
+ zec: "Zcash",
1026
+ gnosis: "Gnosis",
1027
+ monad: "Monad"
1028
+ };
1029
+ return labels[chainId] || chainId.toUpperCase();
1030
+ }
912
1031
  function UniportModal({
913
1032
  open,
914
1033
  onClose,
915
1034
  recipient,
916
1035
  refundAddress,
917
- destinationToken = "suiUSDC",
1036
+ destinationToken,
918
1037
  amount: initialAmount,
1038
+ theme: themeMode = "light",
919
1039
  onSuccess,
920
1040
  onError
921
1041
  }) {
1042
+ const t = getTheme(themeMode);
922
1043
  const payment = useUniportPayment({
923
1044
  recipient,
924
1045
  refundAddress,
925
1046
  destinationToken,
1047
+ amount: initialAmount,
926
1048
  onSuccess,
927
1049
  onError
928
1050
  });
929
- const [chainDropdownOpen, setChainDropdownOpen] = React.useState(false);
930
- const [tokenDropdownOpen, setTokenDropdownOpen] = React.useState(false);
1051
+ const [modalStep, setModalStep] = useState("chain");
931
1052
  const [copied, setCopied] = useState(false);
932
1053
  const [showReceipt, setShowReceipt] = useState(false);
1054
+ const [portalRoot, setPortalRoot] = useState(null);
933
1055
  useEffect(() => {
1056
+ setPortalRoot(document.body);
934
1057
  injectStyles();
935
1058
  }, []);
936
1059
  useEffect(() => {
937
- if (payment.paymentState === "awaiting_deposit") {
938
- payment.startPolling();
939
- }
1060
+ if (payment.paymentState === "awaiting_deposit") payment.startPolling();
940
1061
  }, [payment.paymentState]);
941
1062
  useEffect(() => {
942
1063
  return () => payment.stopPolling();
943
1064
  }, []);
944
1065
  const handleClose = useCallback(() => {
945
1066
  payment.reset();
1067
+ setModalStep("chain");
1068
+ setShowReceipt(false);
946
1069
  onClose();
947
1070
  }, [payment, onClose]);
948
1071
  useEffect(() => {
949
- const handleEscape = (e) => {
1072
+ const onKey = (e) => {
950
1073
  if (e.key === "Escape") handleClose();
951
1074
  };
952
1075
  if (open) {
953
- document.addEventListener("keydown", handleEscape);
954
- return () => document.removeEventListener("keydown", handleEscape);
1076
+ document.addEventListener("keydown", onKey);
1077
+ document.body.style.overflow = "hidden";
1078
+ return () => {
1079
+ document.removeEventListener("keydown", onKey);
1080
+ document.body.style.overflow = "";
1081
+ };
955
1082
  }
956
1083
  }, [open, handleClose]);
957
1084
  const handleCopy = useCallback(async () => {
958
1085
  if (payment.quote?.depositAddress) {
959
- const success = await payment.copyToClipboard(payment.quote.depositAddress);
960
- if (success) {
1086
+ const ok = await payment.copyToClipboard(payment.quote.depositAddress);
1087
+ if (ok) {
961
1088
  setCopied(true);
962
1089
  setTimeout(() => setCopied(false), 2e3);
963
1090
  }
964
1091
  }
965
1092
  }, [payment]);
966
- if (!open) return null;
967
- const canSubmit = payment.selectedToken && payment.amount && refundAddress;
968
- const isProcessing = payment.paymentState === "quoting" || payment.paymentState === "processing";
969
- const showQR = payment.paymentState === "awaiting_deposit" || payment.paymentState === "processing";
970
- const isSuccess = payment.paymentState === "success";
971
- return /* @__PURE__ */ jsx("div", { style: styles.overlay, onClick: handleClose, children: /* @__PURE__ */ jsxs("div", { style: styles.modal, onClick: (e) => e.stopPropagation(), children: [
972
- /* @__PURE__ */ jsx(
973
- "button",
974
- {
975
- style: styles.closeButton,
976
- onClick: handleClose,
977
- onMouseEnter: (e) => {
978
- e.currentTarget.style.background = "rgba(255,255,255,0.1)";
979
- },
980
- onMouseLeave: (e) => {
981
- e.currentTarget.style.background = "rgba(255,255,255,0.05)";
1093
+ if (!open || !portalRoot) return null;
1094
+ const { paymentState } = payment;
1095
+ const showQR = paymentState === "awaiting_deposit" || paymentState === "processing";
1096
+ const isSuccess = paymentState === "success";
1097
+ const isError = paymentState === "error";
1098
+ const isQuoting = paymentState === "quoting";
1099
+ const canSubmit = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1100
+ const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1101
+ const showBack = !isSuccess && !isError && (showQR || modalStep !== "chain");
1102
+ const iconBtn = {
1103
+ width: 36,
1104
+ height: 36,
1105
+ borderRadius: "50%",
1106
+ background: t.iconBtnBg,
1107
+ border: "none",
1108
+ cursor: "pointer",
1109
+ display: "flex",
1110
+ alignItems: "center",
1111
+ justifyContent: "center",
1112
+ transition: "background 0.15s",
1113
+ flexShrink: 0,
1114
+ padding: 0
1115
+ };
1116
+ const primaryBtn = (disabled) => ({
1117
+ width: "100%",
1118
+ height: 52,
1119
+ borderRadius: "14px",
1120
+ border: "none",
1121
+ background: disabled ? t.btnDisabledBg : t.btnBg,
1122
+ color: disabled ? t.btnDisabledText : t.btnText,
1123
+ fontSize: "15px",
1124
+ fontWeight: 600,
1125
+ cursor: disabled ? "not-allowed" : "pointer",
1126
+ display: "flex",
1127
+ alignItems: "center",
1128
+ justifyContent: "center",
1129
+ gap: "8px",
1130
+ fontFamily: "inherit",
1131
+ letterSpacing: "-0.01em"
1132
+ });
1133
+ const warningBox = {
1134
+ display: "flex",
1135
+ gap: "9px",
1136
+ alignItems: "flex-start",
1137
+ padding: "11px 13px",
1138
+ background: t.warningBg,
1139
+ border: `1px solid ${t.warningBorder}`,
1140
+ borderRadius: "10px"
1141
+ };
1142
+ const renderHeader = (title) => /* @__PURE__ */ jsxs("div", { style: {
1143
+ display: "flex",
1144
+ alignItems: "center",
1145
+ justifyContent: "space-between",
1146
+ padding: "18px 18px 0",
1147
+ marginBottom: "12px"
1148
+ }, children: [
1149
+ /* @__PURE__ */ jsx("div", { style: { width: 36, display: "flex" }, children: showBack && /* @__PURE__ */ jsx(
1150
+ "button",
1151
+ {
1152
+ style: iconBtn,
1153
+ onClick: () => {
1154
+ if (showQR) {
1155
+ payment.cancelQuote();
1156
+ setModalStep("amount");
1157
+ } else if (modalStep === "token") setModalStep("chain");
1158
+ else if (modalStep === "amount") setModalStep("token");
1159
+ },
1160
+ onMouseEnter: (e) => {
1161
+ e.currentTarget.style.background = t.iconBtnHover;
1162
+ },
1163
+ onMouseLeave: (e) => {
1164
+ e.currentTarget.style.background = t.iconBtnBg;
982
1165
  },
983
- children: /* @__PURE__ */ jsx(CloseIcon, {})
1166
+ children: /* @__PURE__ */ jsx(BackArrow, { color: t.iconBtnColor })
984
1167
  }
985
- ),
986
- isSuccess ? /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", paddingTop: "20px" }, children: [
987
- /* @__PURE__ */ jsx("h2", { style: { ...styles.title, marginBottom: "32px", fontSize: "20px" }, children: "Payment Successful" }),
988
- /* @__PURE__ */ jsx(
989
- "div",
990
- {
991
- style: {
992
- width: "100px",
993
- height: "100px",
994
- borderRadius: "50%",
995
- background: "rgba(22, 22, 30, 0.9)",
996
- border: "3px solid #10B981",
997
- display: "flex",
998
- alignItems: "center",
999
- justifyContent: "center",
1000
- margin: "0 auto 24px",
1001
- boxShadow: "0 0 30px rgba(16, 185, 129, 0.3)"
1002
- },
1003
- children: /* @__PURE__ */ jsx("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", stroke: "#10B981", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" }) })
1004
- }
1005
- ),
1006
- /* @__PURE__ */ jsx("p", { style: { color: "white", fontSize: "18px", fontWeight: 500, marginBottom: "8px" }, children: "Payment Completed" }),
1007
- /* @__PURE__ */ jsxs("p", { style: { color: "rgba(255,255,255,0.5)", fontSize: "14px", marginBottom: "32px" }, children: [
1008
- payment.amount,
1009
- " ",
1010
- payment.selectedToken?.symbol,
1011
- " \u2192 ~",
1012
- payment.quote?.amountOutFormatted || "",
1013
- " ",
1014
- payment.destinationToken.symbol,
1015
- " on Sui"
1016
- ] }),
1017
- /* @__PURE__ */ jsx(
1018
- "button",
1019
- {
1020
- onClick: () => setShowReceipt(!showReceipt),
1021
- style: { background: "transparent", border: "none", color: "rgba(255,255,255,0.6)", fontSize: "14px", cursor: "pointer", textDecoration: "underline", marginBottom: showReceipt ? "16px" : "0" },
1022
- children: showReceipt ? "Hide receipt" : "Show receipt"
1023
- }
1024
- ),
1025
- showReceipt && /* @__PURE__ */ jsxs("div", { style: { background: "rgba(255,255,255,0.05)", borderRadius: "12px", padding: "16px", textAlign: "left", marginTop: "8px" }, children: [
1026
- payment.status?.originTxHashes?.map((hash, i) => /* @__PURE__ */ jsxs("div", { style: { marginBottom: "12px" }, children: [
1027
- /* @__PURE__ */ jsxs("p", { style: { color: "rgba(255,255,255,0.5)", fontSize: "12px", marginBottom: "4px" }, children: [
1028
- "Source TX (",
1029
- payment.selectedChain?.name,
1030
- ")"
1168
+ ) }),
1169
+ /* @__PURE__ */ jsx("h2", { style: { margin: 0, fontSize: "16px", fontWeight: 600, color: t.text, letterSpacing: "-0.015em" }, children: title }),
1170
+ /* @__PURE__ */ jsx(
1171
+ "button",
1172
+ {
1173
+ style: iconBtn,
1174
+ onClick: handleClose,
1175
+ onMouseEnter: (e) => {
1176
+ e.currentTarget.style.background = t.iconBtnHover;
1177
+ },
1178
+ onMouseLeave: (e) => {
1179
+ e.currentTarget.style.background = t.iconBtnBg;
1180
+ },
1181
+ children: /* @__PURE__ */ jsx(XMark, { color: t.iconBtnColor })
1182
+ }
1183
+ )
1184
+ ] });
1185
+ const renderChainStep = () => /* @__PURE__ */ jsxs(Fragment, { children: [
1186
+ renderHeader("Select network"),
1187
+ /* @__PURE__ */ jsx("div", { style: { overflowY: "auto", maxHeight: 420 }, children: payment.chains.map((chain, i) => /* @__PURE__ */ jsxs(
1188
+ "button",
1189
+ {
1190
+ onClick: () => {
1191
+ payment.setSelectedChain(chain);
1192
+ setModalStep("token");
1193
+ },
1194
+ style: {
1195
+ display: "flex",
1196
+ alignItems: "center",
1197
+ gap: "14px",
1198
+ width: "100%",
1199
+ padding: "13px 20px",
1200
+ background: "transparent",
1201
+ border: "none",
1202
+ borderBottom: i < payment.chains.length - 1 ? `1px solid ${t.border}` : "none",
1203
+ cursor: "pointer",
1204
+ textAlign: "left",
1205
+ transition: "background 0.1s",
1206
+ fontFamily: "inherit"
1207
+ },
1208
+ onMouseEnter: (e) => {
1209
+ e.currentTarget.style.background = t.rowHover;
1210
+ },
1211
+ onMouseLeave: (e) => {
1212
+ e.currentTarget.style.background = "transparent";
1213
+ },
1214
+ children: [
1215
+ /* @__PURE__ */ jsx(TokenAvatar, { src: chain.icon, name: chain.name, size: 40 }),
1216
+ /* @__PURE__ */ jsx("span", { style: { flex: 1, fontSize: "15px", fontWeight: 500, color: t.text }, children: chain.name }),
1217
+ /* @__PURE__ */ jsx(ChevronRight, { color: t.textMuted })
1218
+ ]
1219
+ },
1220
+ chain.id
1221
+ )) })
1222
+ ] });
1223
+ const renderTokenStep = () => /* @__PURE__ */ jsxs(Fragment, { children: [
1224
+ renderHeader("Select token"),
1225
+ /* @__PURE__ */ jsx("div", { style: { overflowY: "auto", maxHeight: 420 }, children: payment.tokens.map((token, i) => /* @__PURE__ */ jsxs(
1226
+ "button",
1227
+ {
1228
+ onClick: () => {
1229
+ payment.setSelectedToken(token);
1230
+ setModalStep("amount");
1231
+ },
1232
+ style: {
1233
+ display: "flex",
1234
+ alignItems: "center",
1235
+ gap: "14px",
1236
+ width: "100%",
1237
+ padding: "13px 20px",
1238
+ background: "transparent",
1239
+ border: "none",
1240
+ borderBottom: i < payment.tokens.length - 1 ? `1px solid ${t.border}` : "none",
1241
+ cursor: "pointer",
1242
+ textAlign: "left",
1243
+ transition: "background 0.1s",
1244
+ fontFamily: "inherit"
1245
+ },
1246
+ onMouseEnter: (e) => {
1247
+ e.currentTarget.style.background = t.rowHover;
1248
+ },
1249
+ onMouseLeave: (e) => {
1250
+ e.currentTarget.style.background = "transparent";
1251
+ },
1252
+ children: [
1253
+ /* @__PURE__ */ jsx(TokenAvatar, { src: token.icon, name: token.symbol, size: 40 }),
1254
+ /* @__PURE__ */ jsx("span", { style: { flex: 1, fontSize: "15px", fontWeight: 500, color: t.text }, children: token.symbol }),
1255
+ /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.textMuted, fontWeight: 500 }, children: payment.selectedChain?.name })
1256
+ ]
1257
+ },
1258
+ token.assetId
1259
+ )) })
1260
+ ] });
1261
+ const renderAmountStep = () => {
1262
+ const tok = payment.selectedToken;
1263
+ const ch = payment.selectedChain;
1264
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1265
+ renderHeader("Enter amount"),
1266
+ /* @__PURE__ */ jsxs("div", { style: { padding: "4px 20px 24px" }, children: [
1267
+ /* @__PURE__ */ jsxs("div", { style: {
1268
+ display: "flex",
1269
+ alignItems: "center",
1270
+ gap: "10px",
1271
+ padding: "10px 13px",
1272
+ background: t.inputBg,
1273
+ borderRadius: "12px",
1274
+ marginBottom: "24px"
1275
+ }, children: [
1276
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [
1277
+ tok && /* @__PURE__ */ jsx(TokenAvatar, { src: tok.icon, name: tok.symbol, size: 30 }),
1278
+ /* @__PURE__ */ jsx("div", { style: { marginLeft: -8, marginTop: 12 }, children: /* @__PURE__ */ jsx(TokenAvatar, { src: payment.destinationToken.icon, name: payment.destinationToken.symbol, size: 20 }) })
1031
1279
  ] }),
1032
- /* @__PURE__ */ jsxs("a", { href: payment.selectedChain?.id === "base" ? `https://basescan.org/tx/${hash}` : payment.selectedChain?.id === "arb" ? `https://arbiscan.io/tx/${hash}` : `https://etherscan.io/tx/${hash}`, target: "_blank", rel: "noopener noreferrer", style: { color: "#60A5FA", fontSize: "13px", textDecoration: "none", fontFamily: "monospace" }, children: [
1033
- hash.slice(0, 10),
1034
- "...",
1035
- hash.slice(-8),
1036
- " \u2197"
1280
+ /* @__PURE__ */ jsxs("div", { children: [
1281
+ /* @__PURE__ */ jsxs("div", { style: { fontSize: "13px", fontWeight: 600, color: t.text }, children: [
1282
+ tok?.symbol,
1283
+ " on ",
1284
+ ch?.name
1285
+ ] }),
1286
+ /* @__PURE__ */ jsxs("div", { style: { fontSize: "12px", color: t.textMuted, marginTop: 1 }, children: [
1287
+ "\u2192 ",
1288
+ payment.destinationToken.symbol,
1289
+ " on ",
1290
+ payment.destinationToken.chain.toUpperCase()
1291
+ ] })
1037
1292
  ] })
1038
- ] }, `origin-${i}`)),
1039
- payment.status?.destinationTxHashes?.map((hash, i) => /* @__PURE__ */ jsxs("div", { children: [
1040
- /* @__PURE__ */ jsx("p", { style: { color: "rgba(255,255,255,0.5)", fontSize: "12px", marginBottom: "4px" }, children: "Destination TX (Sui)" }),
1041
- /* @__PURE__ */ jsxs("a", { href: `https://suiscan.xyz/mainnet/tx/${hash}`, target: "_blank", rel: "noopener noreferrer", style: { color: "#60A5FA", fontSize: "13px", textDecoration: "none", fontFamily: "monospace" }, children: [
1042
- hash.slice(0, 10),
1043
- "...",
1044
- hash.slice(-8),
1045
- " \u2197"
1293
+ ] }),
1294
+ /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", marginBottom: "6px" }, children: [
1295
+ /* @__PURE__ */ jsx(
1296
+ "input",
1297
+ {
1298
+ type: "text",
1299
+ inputMode: "decimal",
1300
+ placeholder: "0.00",
1301
+ value: payment.amount,
1302
+ onChange: (e) => payment.setAmount(e.target.value),
1303
+ style: {
1304
+ width: "100%",
1305
+ textAlign: "center",
1306
+ fontSize: "54px",
1307
+ fontWeight: 600,
1308
+ color: payment.amount ? t.text : t.textMuted,
1309
+ background: "transparent",
1310
+ border: "none",
1311
+ outline: "none",
1312
+ caretColor: t.accent,
1313
+ fontFamily: "inherit",
1314
+ letterSpacing: "-0.04em",
1315
+ lineHeight: 1,
1316
+ padding: 0
1317
+ },
1318
+ autoFocus: true
1319
+ }
1320
+ ),
1321
+ /* @__PURE__ */ jsx("div", { style: { fontSize: "14px", color: t.textMuted, marginTop: 8 }, children: tok?.symbol })
1322
+ ] }),
1323
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "18px" }, children: [
1324
+ /* @__PURE__ */ jsxs(
1325
+ "label",
1326
+ {
1327
+ style: {
1328
+ display: "block",
1329
+ fontSize: "13px",
1330
+ fontWeight: 600,
1331
+ color: t.text,
1332
+ marginBottom: "8px"
1333
+ },
1334
+ children: [
1335
+ "Refund address on ",
1336
+ ch?.name || "the source chain"
1337
+ ]
1338
+ }
1339
+ ),
1340
+ /* @__PURE__ */ jsx(
1341
+ "input",
1342
+ {
1343
+ type: "text",
1344
+ value: payment.refundAddress,
1345
+ onChange: (e) => payment.setRefundAddress(e.target.value),
1346
+ placeholder: `Enter a ${ch?.name || "source chain"} refund address`,
1347
+ spellCheck: false,
1348
+ autoCapitalize: "off",
1349
+ autoCorrect: "off",
1350
+ style: {
1351
+ width: "100%",
1352
+ padding: "13px 14px",
1353
+ fontSize: "14px",
1354
+ color: payment.refundAddress ? t.text : t.textMuted,
1355
+ background: t.inputBg,
1356
+ border: `1px solid ${t.border}`,
1357
+ borderRadius: "12px",
1358
+ outline: "none",
1359
+ fontFamily: "inherit"
1360
+ }
1361
+ }
1362
+ ),
1363
+ /* @__PURE__ */ jsx(
1364
+ "p",
1365
+ {
1366
+ style: {
1367
+ margin: "8px 0 0",
1368
+ fontSize: "12px",
1369
+ color: t.textMuted,
1370
+ lineHeight: 1.5
1371
+ },
1372
+ children: "Used only if the swap fails. This address must live on the chain the payer is sending from."
1373
+ }
1374
+ )
1375
+ ] }),
1376
+ /* @__PURE__ */ jsxs("div", { style: {
1377
+ textAlign: "center",
1378
+ height: 32,
1379
+ display: "flex",
1380
+ alignItems: "center",
1381
+ justifyContent: "center",
1382
+ gap: 5,
1383
+ marginBottom: "20px"
1384
+ }, children: [
1385
+ canPreviewEstimate && payment.isLoadingPreview && [0, 0.2, 0.4].map((delay, i) => /* @__PURE__ */ jsx("div", { style: {
1386
+ width: 6,
1387
+ height: 6,
1388
+ borderRadius: "50%",
1389
+ background: t.accent,
1390
+ animation: `uniport-pulse 1s ease infinite ${delay}s`
1391
+ } }, i)),
1392
+ canPreviewEstimate && !payment.isLoadingPreview && payment.previewQuote && /* @__PURE__ */ jsxs("span", { style: { fontSize: "15px", color: t.textSecondary }, children: [
1393
+ "You will receive",
1394
+ " ",
1395
+ /* @__PURE__ */ jsxs("strong", { style: { color: t.text }, children: [
1396
+ payment.previewQuote.amountOutFormatted,
1397
+ " ",
1398
+ payment.destinationToken.symbol
1399
+ ] }),
1400
+ " ",
1401
+ "on",
1402
+ " ",
1403
+ /* @__PURE__ */ jsx("strong", { style: { color: t.text }, children: formatChainLabel(payment.destinationToken.chain) })
1404
+ ] }),
1405
+ canPreviewEstimate && !payment.isLoadingPreview && payment.previewError && /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.error }, children: formatPreviewError(payment.previewError) }),
1406
+ canPreviewEstimate && !payment.isLoadingPreview && !payment.previewQuote && !payment.previewError && /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "Fetching estimate\u2026" })
1407
+ ] }),
1408
+ !!payment.amount && /* @__PURE__ */ jsxs("div", { style: { ...warningBox, marginBottom: "20px" }, children: [
1409
+ /* @__PURE__ */ jsx(WarningTriangle, { color: t.warning }),
1410
+ /* @__PURE__ */ jsxs("p", { style: { margin: 0, fontSize: "13px", color: t.warningText, lineHeight: 1.55 }, children: [
1411
+ "You must send",
1412
+ " ",
1413
+ /* @__PURE__ */ jsxs("strong", { children: [
1414
+ "exactly ",
1415
+ payment.amount,
1416
+ " ",
1417
+ tok?.symbol
1418
+ ] }),
1419
+ " ",
1420
+ "on ",
1421
+ /* @__PURE__ */ jsx("strong", { children: ch?.name }),
1422
+ ". Sending a different amount or asset may result in loss of funds."
1046
1423
  ] })
1047
- ] }, `dest-${i}`)),
1048
- !payment.status?.originTxHashes?.length && !payment.status?.destinationTxHashes?.length && /* @__PURE__ */ jsx("p", { style: { color: "rgba(255,255,255,0.4)", fontSize: "13px" }, children: "Transaction details loading..." })
1049
- ] }),
1050
- /* @__PURE__ */ jsx("button", { onClick: handleClose, style: { ...styles.button, marginTop: "24px", background: "linear-gradient(135deg, #10B981, #059669)" }, children: "Done" })
1051
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1052
- /* @__PURE__ */ jsxs("div", { style: styles.header, children: [
1053
- /* @__PURE__ */ jsx("div", { style: styles.headerIcon, children: /* @__PURE__ */ jsx(CardIcon, {}) }),
1054
- /* @__PURE__ */ jsx("h2", { style: styles.title, children: showQR ? "Send Payment" : "Pay with any token" }),
1055
- /* @__PURE__ */ jsx("p", { style: styles.subtitle, children: showQR ? "Scan QR or copy address below" : "Secure, gasless transactions" })
1056
- ] }),
1057
- showQR && payment.quote && /* @__PURE__ */ jsxs(Fragment, { children: [
1058
- /* @__PURE__ */ jsx("div", { style: styles.qrContainer, children: /* @__PURE__ */ jsx(
1424
+ ] }),
1425
+ /* @__PURE__ */ jsx(
1426
+ "button",
1427
+ {
1428
+ disabled: !canSubmit || isQuoting,
1429
+ onClick: () => payment.fetchQuote(),
1430
+ style: primaryBtn(!canSubmit || isQuoting),
1431
+ children: isQuoting ? /* @__PURE__ */ jsxs(Fragment, { children: [
1432
+ /* @__PURE__ */ jsx(Spinner, { color: t.btnText }),
1433
+ " Getting quote\u2026"
1434
+ ] }) : "Confirm Payment"
1435
+ }
1436
+ ),
1437
+ !payment.refundAddress.trim() && /* @__PURE__ */ jsxs("p", { style: { textAlign: "center", fontSize: "12px", color: t.error, margin: "10px 0 0" }, children: [
1438
+ "Enter a refund address on ",
1439
+ ch?.name || "the source chain",
1440
+ " to continue."
1441
+ ] })
1442
+ ] })
1443
+ ] });
1444
+ };
1445
+ const renderPaymentStep = () => {
1446
+ const { quote } = payment;
1447
+ const isProcessing = paymentState === "processing";
1448
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1449
+ renderHeader(`Send ${payment.amount} ${payment.selectedToken?.symbol ?? ""} on ${payment.selectedChain?.name ?? ""}`),
1450
+ /* @__PURE__ */ jsx("div", { style: { padding: "4px 20px 24px" }, children: quote && /* @__PURE__ */ jsxs(Fragment, { children: [
1451
+ /* @__PURE__ */ jsx("div", { style: {
1452
+ background: "#ffffff",
1453
+ borderRadius: "16px",
1454
+ padding: "20px",
1455
+ display: "flex",
1456
+ alignItems: "center",
1457
+ justifyContent: "center",
1458
+ border: `1px solid ${t.border}`,
1459
+ marginBottom: "14px"
1460
+ }, children: /* @__PURE__ */ jsx(
1059
1461
  QRCodeSVG,
1060
1462
  {
1061
- value: payment.quote.depositAddress,
1062
- size: 180,
1463
+ value: quote.depositAddress,
1464
+ size: 200,
1063
1465
  level: "M",
1064
- bgColor: "transparent",
1065
- fgColor: "white"
1466
+ bgColor: "#ffffff",
1467
+ fgColor: "#000000"
1066
1468
  }
1067
1469
  ) }),
1068
- /* @__PURE__ */ jsxs("div", { style: styles.addressContainer, children: [
1069
- /* @__PURE__ */ jsxs("span", { style: styles.addressText, children: [
1070
- payment.quote.depositAddress.slice(0, 8),
1071
- "...",
1072
- payment.quote.depositAddress.slice(-8)
1073
- ] }),
1470
+ /* @__PURE__ */ jsxs("div", { style: {
1471
+ display: "flex",
1472
+ alignItems: "center",
1473
+ gap: "10px",
1474
+ padding: "11px 13px",
1475
+ background: t.inputBg,
1476
+ borderRadius: "10px",
1477
+ marginBottom: "14px",
1478
+ border: `1px solid ${t.border}`
1479
+ }, children: [
1480
+ /* @__PURE__ */ jsx("span", { style: {
1481
+ flex: 1,
1482
+ fontSize: "11px",
1483
+ color: t.textSecondary,
1484
+ fontFamily: "monospace",
1485
+ wordBreak: "break-all",
1486
+ lineHeight: 1.5
1487
+ }, children: quote.depositAddress }),
1074
1488
  /* @__PURE__ */ jsx(
1075
1489
  "button",
1076
1490
  {
1077
- style: styles.copyButton,
1078
1491
  onClick: handleCopy,
1079
- onMouseEnter: (e) => {
1080
- e.currentTarget.style.background = "rgba(255,255,255,0.2)";
1492
+ title: "Copy address",
1493
+ style: {
1494
+ flexShrink: 0,
1495
+ width: 34,
1496
+ height: 34,
1497
+ borderRadius: "8px",
1498
+ background: copied ? `${t.success}18` : t.iconBtnBg,
1499
+ border: `1px solid ${copied ? t.success + "44" : t.border}`,
1500
+ cursor: "pointer",
1501
+ display: "flex",
1502
+ alignItems: "center",
1503
+ justifyContent: "center",
1504
+ transition: "all 0.2s"
1081
1505
  },
1082
- onMouseLeave: (e) => {
1083
- e.currentTarget.style.background = "rgba(255,255,255,0.1)";
1084
- },
1085
- children: copied ? /* @__PURE__ */ jsx(CheckSmallIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {})
1506
+ children: copied ? /* @__PURE__ */ jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsx(CopyIcon, { color: t.textMuted })
1086
1507
  }
1087
1508
  )
1088
1509
  ] }),
1089
- /* @__PURE__ */ jsxs("div", { style: { ...styles.details, marginTop: "20px" }, children: [
1090
- /* @__PURE__ */ jsxs("div", { style: styles.detailRow, children: [
1091
- /* @__PURE__ */ jsx("span", { children: "Status" }),
1092
- /* @__PURE__ */ jsxs(
1093
- "span",
1094
- {
1095
- style: {
1096
- ...styles.statusBadge,
1097
- ...styles.processingBadge
1098
- },
1099
- children: [
1100
- /* @__PURE__ */ jsx(PulseIcon, {}),
1101
- " ",
1102
- payment.paymentState === "processing" ? "Processing deposit..." : "Waiting for deposit"
1103
- ]
1104
- }
1105
- )
1106
- ] }),
1107
- /* @__PURE__ */ jsxs("div", { style: styles.detailRow, children: [
1108
- /* @__PURE__ */ jsx("span", { children: "Amount to send" }),
1109
- /* @__PURE__ */ jsxs("span", { style: styles.detailValue, children: [
1510
+ /* @__PURE__ */ jsxs("div", { style: { ...warningBox, marginBottom: "14px" }, children: [
1511
+ /* @__PURE__ */ jsx(WarningTriangle, { color: t.warning }),
1512
+ /* @__PURE__ */ jsxs("p", { style: { margin: 0, fontSize: "13px", color: t.warningText, lineHeight: 1.55 }, children: [
1513
+ "Only send",
1514
+ " ",
1515
+ /* @__PURE__ */ jsxs("strong", { children: [
1110
1516
  payment.amount,
1111
1517
  " ",
1112
- payment.selectedToken?.symbol,
1113
- /* @__PURE__ */ jsx("span", { style: styles.tokenBadge, children: payment.selectedChain?.name })
1114
- ] })
1115
- ] }),
1116
- /* @__PURE__ */ jsxs("div", { style: styles.detailRow, children: [
1117
- /* @__PURE__ */ jsx("span", { children: "You receive" }),
1118
- /* @__PURE__ */ jsxs("span", { style: styles.detailValue, children: [
1119
- "~",
1120
- payment.quote.amountOutFormatted,
1121
- " ",
1122
- payment.destinationToken.symbol,
1123
- /* @__PURE__ */ jsx("span", { style: styles.tokenBadge, children: "Sui" })
1124
- ] })
1125
- ] })
1126
- ] })
1127
- ] }),
1128
- !showQR && !isSuccess && /* @__PURE__ */ jsxs(Fragment, { children: [
1129
- /* @__PURE__ */ jsxs("div", { style: styles.selectorsRow, children: [
1130
- /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
1131
- /* @__PURE__ */ jsxs(
1132
- "div",
1133
- {
1134
- style: styles.selector,
1135
- onClick: () => {
1136
- setChainDropdownOpen(!chainDropdownOpen);
1137
- setTokenDropdownOpen(false);
1138
- },
1139
- children: [
1140
- /* @__PURE__ */ jsxs(
1141
- "div",
1142
- {
1143
- style: {
1144
- display: "flex",
1145
- alignItems: "center",
1146
- gap: "12px"
1147
- },
1148
- children: [
1149
- /* @__PURE__ */ jsx("div", { style: styles.selectorIcon, children: payment.selectedChain ? /* @__PURE__ */ jsx(
1150
- "img",
1151
- {
1152
- src: payment.selectedChain.icon,
1153
- alt: "",
1154
- style: {
1155
- width: "100%",
1156
- height: "100%"
1157
- }
1158
- }
1159
- ) : /* @__PURE__ */ jsx(GlobeIcon, {}) }),
1160
- /* @__PURE__ */ jsxs("div", { children: [
1161
- /* @__PURE__ */ jsx("div", { style: styles.selectorLabel, children: "Chain" }),
1162
- /* @__PURE__ */ jsx("div", { style: styles.selectorValue, children: payment.selectedChain?.name || "Select" })
1163
- ] })
1164
- ]
1165
- }
1166
- ),
1167
- /* @__PURE__ */ jsx(ChevronIcon, {})
1168
- ]
1169
- }
1170
- ),
1171
- chainDropdownOpen && /* @__PURE__ */ jsx("div", { style: styles.dropdown, children: payment.chains.map((chain) => /* @__PURE__ */ jsxs(
1172
- "div",
1173
- {
1174
- style: styles.dropdownItem,
1175
- onClick: () => {
1176
- payment.setSelectedChain(chain);
1177
- setChainDropdownOpen(false);
1178
- },
1179
- onMouseEnter: (e) => {
1180
- e.currentTarget.style.background = "rgba(255,255,255,0.1)";
1181
- },
1182
- onMouseLeave: (e) => {
1183
- e.currentTarget.style.background = "transparent";
1184
- },
1185
- children: [
1186
- /* @__PURE__ */ jsx(
1187
- "img",
1188
- {
1189
- src: chain.icon,
1190
- alt: "",
1191
- style: {
1192
- width: "24px",
1193
- height: "24px",
1194
- borderRadius: "50%"
1195
- }
1196
- }
1197
- ),
1198
- /* @__PURE__ */ jsx(
1199
- "span",
1200
- {
1201
- style: {
1202
- color: "white",
1203
- fontSize: "14px"
1204
- },
1205
- children: chain.name
1206
- }
1207
- )
1208
- ]
1209
- },
1210
- chain.id
1211
- )) })
1212
- ] }),
1213
- /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
1214
- /* @__PURE__ */ jsxs(
1215
- "div",
1216
- {
1217
- style: {
1218
- ...styles.selector,
1219
- opacity: payment.selectedChain ? 1 : 0.5,
1220
- pointerEvents: payment.selectedChain ? "auto" : "none"
1221
- },
1222
- onClick: () => {
1223
- if (payment.selectedChain) {
1224
- setTokenDropdownOpen(!tokenDropdownOpen);
1225
- setChainDropdownOpen(false);
1226
- }
1227
- },
1228
- children: [
1229
- /* @__PURE__ */ jsxs(
1230
- "div",
1231
- {
1232
- style: {
1233
- display: "flex",
1234
- alignItems: "center",
1235
- gap: "12px"
1236
- },
1237
- children: [
1238
- /* @__PURE__ */ jsx("div", { style: styles.selectorIcon, children: payment.selectedToken ? /* @__PURE__ */ jsx(
1239
- "img",
1240
- {
1241
- src: payment.selectedToken.icon,
1242
- alt: "",
1243
- style: {
1244
- width: "100%",
1245
- height: "100%"
1246
- }
1247
- }
1248
- ) : /* @__PURE__ */ jsx(DollarIcon, {}) }),
1249
- /* @__PURE__ */ jsxs("div", { children: [
1250
- /* @__PURE__ */ jsx("div", { style: styles.selectorLabel, children: "Token" }),
1251
- /* @__PURE__ */ jsx("div", { style: styles.selectorValue, children: payment.selectedToken?.symbol || "Select" })
1252
- ] })
1253
- ]
1254
- }
1255
- ),
1256
- /* @__PURE__ */ jsx(ChevronIcon, {})
1257
- ]
1258
- }
1259
- ),
1260
- tokenDropdownOpen && /* @__PURE__ */ jsx("div", { style: styles.dropdown, children: payment.tokens.map((token) => /* @__PURE__ */ jsxs(
1261
- "div",
1262
- {
1263
- style: styles.dropdownItem,
1264
- onClick: () => {
1265
- payment.setSelectedToken(token);
1266
- setTokenDropdownOpen(false);
1267
- },
1268
- onMouseEnter: (e) => {
1269
- e.currentTarget.style.background = "rgba(255,255,255,0.1)";
1270
- },
1271
- onMouseLeave: (e) => {
1272
- e.currentTarget.style.background = "transparent";
1273
- },
1274
- children: [
1275
- /* @__PURE__ */ jsx(
1276
- "img",
1277
- {
1278
- src: token.icon,
1279
- alt: "",
1280
- style: {
1281
- width: "24px",
1282
- height: "24px",
1283
- borderRadius: "50%"
1284
- }
1285
- }
1286
- ),
1287
- /* @__PURE__ */ jsx(
1288
- "span",
1289
- {
1290
- style: {
1291
- color: "white",
1292
- fontSize: "14px"
1293
- },
1294
- children: token.symbol
1295
- }
1296
- )
1297
- ]
1298
- },
1299
- token.assetId
1300
- )) })
1518
+ payment.selectedToken?.symbol
1519
+ ] }),
1520
+ " ",
1521
+ "on ",
1522
+ /* @__PURE__ */ jsx("strong", { children: payment.selectedChain?.name }),
1523
+ " to this address. Other assets may be permanently lost."
1301
1524
  ] })
1302
1525
  ] }),
1303
- /* @__PURE__ */ jsx(
1304
- "input",
1305
- {
1306
- type: "text",
1307
- inputMode: "decimal",
1308
- placeholder: "0.00",
1309
- value: payment.amount,
1310
- onChange: (e) => payment.setAmount(e.target.value),
1311
- style: styles.amountInput
1312
- }
1313
- ),
1314
- /* @__PURE__ */ jsxs("div", { style: styles.details, children: [
1315
- payment.amount && /* @__PURE__ */ jsxs("div", { style: styles.detailRow, children: [
1316
- /* @__PURE__ */ jsx("span", { children: "You receive" }),
1317
- payment.isLoadingPreview ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "4px" }, children: [
1318
- /* @__PURE__ */ jsx("div", { style: styles.loadingDot }),
1319
- /* @__PURE__ */ jsx("div", { style: { ...styles.loadingDot, animationDelay: "0.2s" } }),
1320
- /* @__PURE__ */ jsx("div", { style: { ...styles.loadingDot, animationDelay: "0.4s" } })
1321
- ] }) : payment.previewQuote ? /* @__PURE__ */ jsxs("span", { style: styles.detailValue, children: [
1322
- "~",
1323
- payment.previewQuote.amountOutFormatted,
1526
+ /* @__PURE__ */ jsxs("div", { style: { borderTop: `1px solid ${t.border}`, paddingTop: "12px" }, children: [
1527
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", marginBottom: "10px" }, children: [
1528
+ /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "You'll receive" }),
1529
+ /* @__PURE__ */ jsxs("span", { style: { fontSize: "13px", fontWeight: 600, color: t.text }, children: [
1530
+ "\u2248",
1531
+ quote.amountOutFormatted,
1324
1532
  " ",
1325
1533
  payment.destinationToken.symbol
1326
- ] }) : /* @__PURE__ */ jsx("span", { style: { color: "rgba(255,255,255,0.3)" }, children: "Enter amount..." })
1327
- ] }),
1328
- /* @__PURE__ */ jsxs("div", { style: styles.detailRow, children: [
1329
- /* @__PURE__ */ jsx("span", { children: "Destination" }),
1330
- /* @__PURE__ */ jsxs("span", { style: styles.detailValue, children: [
1331
- payment.destinationToken.symbol,
1332
- " on Sui"
1333
1534
  ] })
1334
- ] })
1335
- ] }),
1336
- /* @__PURE__ */ jsx(
1337
- "button",
1338
- {
1339
- style: {
1340
- ...styles.button,
1341
- ...!canSubmit || isProcessing ? styles.buttonDisabled : {}
1342
- },
1343
- disabled: !canSubmit || isProcessing,
1344
- onClick: () => payment.fetchQuote(),
1345
- children: /* @__PURE__ */ jsx("div", { style: styles.buttonInner, children: isProcessing ? /* @__PURE__ */ jsxs(Fragment, { children: [
1346
- /* @__PURE__ */ jsx(SpinnerIcon, {}),
1347
- " Processing..."
1535
+ ] }),
1536
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
1537
+ /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "Status" }),
1538
+ /* @__PURE__ */ jsx("span", { style: {
1539
+ fontSize: "13px",
1540
+ fontWeight: 600,
1541
+ color: isProcessing ? t.accent : t.warning,
1542
+ display: "flex",
1543
+ alignItems: "center",
1544
+ gap: "6px"
1545
+ }, children: isProcessing ? /* @__PURE__ */ jsxs(Fragment, { children: [
1546
+ /* @__PURE__ */ jsx(Spinner, { color: t.accent }),
1547
+ " Processing\u2026"
1348
1548
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1349
- "Confirm Payment",
1350
- /* @__PURE__ */ jsx(ArrowIcon, {})
1549
+ /* @__PURE__ */ jsx("div", { style: {
1550
+ width: 8,
1551
+ height: 8,
1552
+ borderRadius: "50%",
1553
+ background: t.warning,
1554
+ animation: "uniport-pulse 1.5s ease infinite"
1555
+ } }),
1556
+ "Waiting for deposit"
1351
1557
  ] }) })
1352
- }
1353
- )
1354
- ] })
1355
- ] }),
1558
+ ] })
1559
+ ] })
1560
+ ] }) })
1561
+ ] });
1562
+ };
1563
+ const renderSuccessStep = () => /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
1356
1564
  /* @__PURE__ */ jsx(
1357
- "p",
1565
+ "button",
1358
1566
  {
1359
- style: {
1360
- textAlign: "center",
1361
- fontSize: "10px",
1362
- color: "rgba(255,255,255,0.3)",
1363
- marginTop: "16px"
1567
+ style: { ...iconBtn, position: "absolute", top: 18, right: 18 },
1568
+ onClick: handleClose,
1569
+ onMouseEnter: (e) => {
1570
+ e.currentTarget.style.background = t.iconBtnHover;
1571
+ },
1572
+ onMouseLeave: (e) => {
1573
+ e.currentTarget.style.background = t.iconBtnBg;
1364
1574
  },
1365
- children: "Powered by Uniport \u2022 NEAR Intents"
1575
+ children: /* @__PURE__ */ jsx(XMark, { color: t.iconBtnColor })
1366
1576
  }
1367
- )
1368
- ] }) });
1369
- }
1370
- function CloseIcon() {
1371
- return /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx(
1372
- "path",
1373
- {
1374
- d: "M18 6L6 18M6 6L18 18",
1375
- stroke: "currentColor",
1376
- strokeWidth: "2",
1377
- strokeLinecap: "round"
1378
- }
1379
- ) });
1380
- }
1381
- function CardIcon() {
1382
- return /* @__PURE__ */ jsx(
1383
- "svg",
1384
- {
1385
- width: "24",
1386
- height: "24",
1387
- viewBox: "0 0 24 24",
1388
- fill: "none",
1389
- stroke: "rgba(255,255,255,0.9)",
1390
- strokeWidth: "1.5",
1391
- children: /* @__PURE__ */ jsx("path", { d: "M3 10h18M7 15h2m4 0h4M6 19h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" })
1392
- }
1393
- );
1394
- }
1395
- function GlobeIcon() {
1396
- return /* @__PURE__ */ jsxs(
1397
- "svg",
1398
- {
1399
- width: "18",
1400
- height: "18",
1401
- viewBox: "0 0 24 24",
1402
- fill: "none",
1403
- stroke: "#818CF8",
1404
- strokeWidth: "1.5",
1405
- children: [
1406
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
1407
- /* @__PURE__ */ jsx("path", { d: "M2 12h20M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z" })
1408
- ]
1409
- }
1410
- );
1411
- }
1412
- function DollarIcon() {
1413
- return /* @__PURE__ */ jsxs(
1414
- "svg",
1415
- {
1416
- width: "18",
1417
- height: "18",
1418
- viewBox: "0 0 24 24",
1419
- fill: "none",
1420
- stroke: "#22D3EE",
1421
- strokeWidth: "1.5",
1422
- children: [
1423
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
1424
- /* @__PURE__ */ jsx("path", { d: "M12 6v12M15 9.5a3 3 0 00-3-2.5h-1a2.5 2.5 0 000 5h2a2.5 2.5 0 010 5H12a3 3 0 01-3-2.5" })
1425
- ]
1426
- }
1427
- );
1428
- }
1429
- function ChevronIcon() {
1430
- return /* @__PURE__ */ jsx(
1431
- "svg",
1432
- {
1433
- width: "16",
1434
- height: "16",
1435
- viewBox: "0 0 24 24",
1436
- fill: "none",
1437
- stroke: "rgba(255,255,255,0.4)",
1438
- strokeWidth: "2",
1439
- children: /* @__PURE__ */ jsx("path", { d: "M6 9l6 6 6-6" })
1440
- }
1441
- );
1442
- }
1443
- function CheckSmallIcon() {
1444
- return /* @__PURE__ */ jsx(
1445
- "svg",
1446
- {
1447
- width: "16",
1448
- height: "16",
1449
- viewBox: "0 0 24 24",
1450
- fill: "none",
1451
- stroke: "#10B981",
1452
- strokeWidth: "2",
1453
- children: /* @__PURE__ */ jsx("path", { d: "M20 6L9 17l-5-5" })
1454
- }
1455
- );
1456
- }
1457
- function CopyIcon() {
1458
- return /* @__PURE__ */ jsxs(
1459
- "svg",
1460
- {
1461
- width: "16",
1462
- height: "16",
1463
- viewBox: "0 0 24 24",
1464
- fill: "none",
1465
- stroke: "rgba(255,255,255,0.7)",
1466
- strokeWidth: "2",
1467
- children: [
1468
- /* @__PURE__ */ jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
1469
- /* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" })
1470
- ]
1471
- }
1472
- );
1473
- }
1474
- function PulseIcon() {
1475
- return /* @__PURE__ */ jsx("svg", { width: "8", height: "8", viewBox: "0 0 8 8", children: /* @__PURE__ */ jsx(
1476
- "circle",
1477
- {
1478
- cx: "4",
1479
- cy: "4",
1480
- r: "4",
1481
- fill: "#818CF8",
1482
- style: { animation: "uniport-pulse 1s ease infinite" }
1483
- }
1484
- ) });
1485
- }
1486
- function SpinnerIcon() {
1487
- return /* @__PURE__ */ jsxs(
1488
- "svg",
1489
- {
1490
- width: "16",
1491
- height: "16",
1492
- viewBox: "0 0 24 24",
1493
- fill: "none",
1494
- style: { animation: "spin 1s linear infinite" },
1495
- children: [
1496
- /* @__PURE__ */ jsx(
1497
- "circle",
1498
- {
1499
- cx: "12",
1500
- cy: "12",
1501
- r: "10",
1502
- stroke: "rgba(255,255,255,0.2)",
1503
- strokeWidth: "3"
1504
- }
1505
- ),
1506
- /* @__PURE__ */ jsx(
1507
- "path",
1577
+ ),
1578
+ /* @__PURE__ */ jsxs("div", { style: { padding: "44px 24px 28px", textAlign: "center" }, children: [
1579
+ /* @__PURE__ */ jsx("div", { style: {
1580
+ width: 72,
1581
+ height: 72,
1582
+ borderRadius: "50%",
1583
+ background: `${t.success}18`,
1584
+ border: `2px solid ${t.success}55`,
1585
+ display: "flex",
1586
+ alignItems: "center",
1587
+ justifyContent: "center",
1588
+ margin: "0 auto 20px"
1589
+ }, children: /* @__PURE__ */ jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx(
1590
+ "path",
1591
+ {
1592
+ d: "M20 6L9 17l-5-5",
1593
+ stroke: t.success,
1594
+ strokeWidth: "2.5",
1595
+ strokeLinecap: "round",
1596
+ strokeLinejoin: "round"
1597
+ }
1598
+ ) }) }),
1599
+ /* @__PURE__ */ jsx("h2", { style: { margin: "0 0 8px", fontSize: "20px", fontWeight: 700, color: t.text, letterSpacing: "-0.02em" }, children: "Payment sent!" }),
1600
+ /* @__PURE__ */ jsxs("p", { style: { margin: "0 0 24px", fontSize: "14px", color: t.textMuted, lineHeight: 1.6 }, children: [
1601
+ payment.amount,
1602
+ " ",
1603
+ payment.selectedToken?.symbol,
1604
+ " \u2192 ",
1605
+ "\u2248",
1606
+ payment.quote?.amountOutFormatted,
1607
+ " ",
1608
+ payment.destinationToken.symbol
1609
+ ] }),
1610
+ /* @__PURE__ */ jsx(
1611
+ "button",
1612
+ {
1613
+ onClick: () => setShowReceipt((p) => !p),
1614
+ style: {
1615
+ background: "transparent",
1616
+ border: "none",
1617
+ color: t.accent,
1618
+ fontSize: "14px",
1619
+ cursor: "pointer",
1620
+ textDecoration: "underline",
1621
+ marginBottom: showReceipt ? 14 : 0,
1622
+ fontFamily: "inherit"
1623
+ },
1624
+ children: showReceipt ? "Hide receipt" : "View receipt"
1625
+ }
1626
+ ),
1627
+ showReceipt && /* @__PURE__ */ jsxs("div", { style: { background: t.inputBg, borderRadius: "12px", padding: "14px", textAlign: "left", marginBottom: "20px" }, children: [
1628
+ payment.status?.originTxHashes?.map((hash, i) => /* @__PURE__ */ jsxs("div", { style: { marginBottom: 10 }, children: [
1629
+ /* @__PURE__ */ jsxs("p", { style: { color: t.textMuted, fontSize: "11px", margin: "0 0 3px", textTransform: "uppercase", letterSpacing: "0.05em" }, children: [
1630
+ "Source TX \xB7 ",
1631
+ payment.selectedChain?.name
1632
+ ] }),
1633
+ /* @__PURE__ */ jsxs(
1634
+ "a",
1635
+ {
1636
+ href: `https://etherscan.io/tx/${hash}`,
1637
+ target: "_blank",
1638
+ rel: "noopener noreferrer",
1639
+ style: { color: t.accent, fontSize: "12px", fontFamily: "monospace", textDecoration: "none" },
1640
+ children: [
1641
+ hash.slice(0, 12),
1642
+ "\u2026",
1643
+ hash.slice(-8),
1644
+ " \u2197"
1645
+ ]
1646
+ }
1647
+ )
1648
+ ] }, `o${i}`)),
1649
+ payment.status?.destinationTxHashes?.map((hash, i) => /* @__PURE__ */ jsxs("div", { children: [
1650
+ /* @__PURE__ */ jsx("p", { style: { color: t.textMuted, fontSize: "11px", margin: "0 0 3px", textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Destination TX" }),
1651
+ /* @__PURE__ */ jsxs("span", { style: { color: t.textSecondary, fontSize: "12px", fontFamily: "monospace" }, children: [
1652
+ hash.slice(0, 12),
1653
+ "\u2026",
1654
+ hash.slice(-8)
1655
+ ] })
1656
+ ] }, `d${i}`)),
1657
+ !payment.status?.originTxHashes?.length && !payment.status?.destinationTxHashes?.length && /* @__PURE__ */ jsx("p", { style: { color: t.textMuted, fontSize: "13px", margin: 0 }, children: "Loading transaction details\u2026" })
1658
+ ] }),
1659
+ /* @__PURE__ */ jsx("button", { onClick: handleClose, style: primaryBtn(false), children: "Done" })
1660
+ ] })
1661
+ ] });
1662
+ const renderErrorStep = () => /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
1663
+ /* @__PURE__ */ jsx(
1664
+ "button",
1665
+ {
1666
+ style: { ...iconBtn, position: "absolute", top: 18, right: 18 },
1667
+ onClick: handleClose,
1668
+ onMouseEnter: (e) => {
1669
+ e.currentTarget.style.background = t.iconBtnHover;
1670
+ },
1671
+ onMouseLeave: (e) => {
1672
+ e.currentTarget.style.background = t.iconBtnBg;
1673
+ },
1674
+ children: /* @__PURE__ */ jsx(XMark, { color: t.iconBtnColor })
1675
+ }
1676
+ ),
1677
+ /* @__PURE__ */ jsxs("div", { style: { padding: "44px 24px 28px", textAlign: "center" }, children: [
1678
+ /* @__PURE__ */ jsx("div", { style: {
1679
+ width: 72,
1680
+ height: 72,
1681
+ borderRadius: "50%",
1682
+ background: `${t.error}18`,
1683
+ border: `2px solid ${t.error}44`,
1684
+ display: "flex",
1685
+ alignItems: "center",
1686
+ justifyContent: "center",
1687
+ margin: "0 auto 20px"
1688
+ }, children: /* @__PURE__ */ jsx(XMark, { color: t.error }) }),
1689
+ /* @__PURE__ */ jsx("h2", { style: { margin: "0 0 8px", fontSize: "20px", fontWeight: 700, color: t.text, letterSpacing: "-0.02em" }, children: "Payment failed" }),
1690
+ /* @__PURE__ */ jsx("p", { style: { margin: "0 0 28px", fontSize: "14px", color: t.textMuted, lineHeight: 1.6 }, children: payment.error?.message || "Something went wrong. Please try again." }),
1691
+ /* @__PURE__ */ jsx(
1692
+ "button",
1693
+ {
1694
+ onClick: () => {
1695
+ payment.reset();
1696
+ setModalStep("chain");
1697
+ },
1698
+ style: { ...primaryBtn(false), background: "transparent", border: `1.5px solid ${t.border}`, color: t.text },
1699
+ children: "Try again"
1700
+ }
1701
+ )
1702
+ ] })
1703
+ ] });
1704
+ const renderContent = () => {
1705
+ if (isSuccess) return renderSuccessStep();
1706
+ if (isError) return renderErrorStep();
1707
+ if (showQR) return renderPaymentStep();
1708
+ if (modalStep === "chain") return renderChainStep();
1709
+ if (modalStep === "token") return renderTokenStep();
1710
+ return renderAmountStep();
1711
+ };
1712
+ return ReactDOM.createPortal(
1713
+ /* @__PURE__ */ jsx(
1714
+ "div",
1715
+ {
1716
+ style: {
1717
+ // This overlay must live at the top of the DOM stacking order.
1718
+ // By portaling into document.body we escape any parent element that
1719
+ // has transform, filter, or backdrop-filter (all of which would
1720
+ // otherwise break position:fixed, making it relative to that element
1721
+ // rather than the viewport).
1722
+ position: "fixed",
1723
+ top: 0,
1724
+ left: 0,
1725
+ right: 0,
1726
+ bottom: 0,
1727
+ zIndex: 2147483647,
1728
+ // max z-index
1729
+ display: "flex",
1730
+ alignItems: "center",
1731
+ justifyContent: "center",
1732
+ padding: "16px",
1733
+ // Overlay colour + frosted effect applied here (on the backdrop),
1734
+ // NOT on the modal card itself.
1735
+ backgroundColor: t.overlay,
1736
+ backdropFilter: "blur(18px) saturate(180%)",
1737
+ WebkitBackdropFilter: "blur(18px) saturate(180%)",
1738
+ animation: "uniport-fade-in 0.18s ease"
1739
+ },
1740
+ onClick: handleClose,
1741
+ children: /* @__PURE__ */ jsx(
1742
+ "div",
1508
1743
  {
1509
- d: "M12 2a10 10 0 019.95 9",
1510
- stroke: "white",
1511
- strokeWidth: "3",
1512
- strokeLinecap: "round"
1744
+ onClick: (e) => e.stopPropagation(),
1745
+ style: {
1746
+ position: "relative",
1747
+ width: "100%",
1748
+ maxWidth: "440px",
1749
+ // Solid card — no glassmorphism on the card itself
1750
+ background: t.modalBg,
1751
+ borderRadius: "20px",
1752
+ boxShadow: themeMode === "light" ? "0 24px 64px rgba(0,0,0,0.14), 0 0 0 1px rgba(0,0,0,0.06)" : "0 24px 64px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06)",
1753
+ fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
1754
+ // Only the initial modal mount gets the slide-up animation.
1755
+ // Content transitions (chain→token→amount) use plain renders,
1756
+ // not component remounts, so polling re-renders don't re-trigger it.
1757
+ animation: "uniport-slide-up 0.22s ease",
1758
+ overflow: "hidden",
1759
+ maxHeight: "90vh",
1760
+ display: "flex",
1761
+ flexDirection: "column"
1762
+ },
1763
+ children: renderContent()
1513
1764
  }
1514
1765
  )
1515
- ]
1516
- }
1517
- );
1518
- }
1519
- function ArrowIcon() {
1520
- return /* @__PURE__ */ jsx(
1521
- "svg",
1522
- {
1523
- width: "16",
1524
- height: "16",
1525
- viewBox: "0 0 24 24",
1526
- fill: "none",
1527
- stroke: "currentColor",
1528
- strokeWidth: "2",
1529
- children: /* @__PURE__ */ jsx("path", { d: "M5 12h14M12 5l7 7-7 7" })
1530
- }
1766
+ }
1767
+ ),
1768
+ portalRoot
1531
1769
  );
1532
1770
  }
1533
1771
  var buttonStyles = {
@@ -1589,12 +1827,13 @@ var buttonStyles = {
1589
1827
  function UniportButton({
1590
1828
  recipient,
1591
1829
  refundAddress,
1592
- destinationToken = "suiUSDC",
1830
+ destinationToken,
1593
1831
  amount,
1594
1832
  label = "Pay with Crypto",
1595
1833
  variant = "default",
1596
1834
  disabled = false,
1597
1835
  className,
1836
+ theme = "light",
1598
1837
  onSuccess,
1599
1838
  onError,
1600
1839
  onOpenChange
@@ -1638,6 +1877,7 @@ function UniportButton({
1638
1877
  refundAddress,
1639
1878
  destinationToken,
1640
1879
  amount,
1880
+ theme,
1641
1881
  onSuccess,
1642
1882
  onError
1643
1883
  }