uniport-sdk 0.0.1 → 0.0.2

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