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