uniport-sdk 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,197 +5,6 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
 
6
6
  // src/components/UniportButton.tsx
7
7
 
8
- // src/core/config.ts
9
- var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
10
- var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
11
- function normalizeBackendUrl(url) {
12
- return url.replace(/\/+$/, "");
13
- }
14
- function getUniportConfig() {
15
- const backendUrl = DEFAULT_HOSTED_BACKEND_URL;
16
- return {
17
- backendUrl: normalizeBackendUrl(backendUrl),
18
- requestTimeoutMs: DEFAULT_REQUEST_TIMEOUT_MS
19
- };
20
- }
21
-
22
- // src/core/intents.ts
23
- var UniportError = class extends Error {
24
- constructor(params) {
25
- super(params.message);
26
- this.name = "UniportError";
27
- this.code = params.code;
28
- this.details = params.details;
29
- this.status = params.status;
30
- }
31
- };
32
- function isAbortError(error) {
33
- return error instanceof Error && error.name === "AbortError";
34
- }
35
- function extractDetailMessage(details) {
36
- if (typeof details === "string" && details.trim()) {
37
- return details;
38
- }
39
- if (Array.isArray(details)) {
40
- const firstString = details.find(
41
- (detail) => typeof detail === "string" && detail.trim().length > 0
42
- );
43
- return firstString;
44
- }
45
- if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
46
- const message = details.message.trim();
47
- return message || void 0;
48
- }
49
- return void 0;
50
- }
51
- function toUniportError(body, fallback) {
52
- const detailMessage = extractDetailMessage(body.details);
53
- return new UniportError({
54
- code: body.code || fallback.code,
55
- message: detailMessage || body.message || fallback.message,
56
- details: body.details,
57
- status: fallback.status
58
- });
59
- }
60
- function createTimeoutSignal(timeoutMs, externalSignal) {
61
- const controller = new AbortController();
62
- let timedOut = false;
63
- const timeoutId = setTimeout(() => {
64
- timedOut = true;
65
- controller.abort();
66
- }, timeoutMs);
67
- const abortFromExternal = () => controller.abort();
68
- externalSignal?.addEventListener("abort", abortFromExternal, {
69
- once: true
70
- });
71
- return {
72
- signal: controller.signal,
73
- didTimeout: () => timedOut,
74
- cleanup: () => {
75
- clearTimeout(timeoutId);
76
- externalSignal?.removeEventListener("abort", abortFromExternal);
77
- }
78
- };
79
- }
80
- function toSmallestUnits(amount, decimals) {
81
- const [whole, fraction = ""] = amount.split(".");
82
- const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
83
- return `${whole}${paddedFraction}`.replace(/^0+/, "") || "0";
84
- }
85
- function generateDeadline(hoursFromNow = 1) {
86
- const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
87
- return deadline.toISOString();
88
- }
89
- async function getQuote(options) {
90
- const {
91
- originToken,
92
- destinationToken,
93
- amount,
94
- recipient,
95
- refundTo,
96
- slippageTolerance = 100,
97
- // 1% default
98
- swapType = "EXACT_INPUT",
99
- deadline,
100
- dry = false,
101
- referral = "uniport",
102
- signal
103
- } = options;
104
- const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
105
- const { backendUrl, requestTimeoutMs } = getUniportConfig();
106
- const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
107
- requestTimeoutMs,
108
- signal
109
- );
110
- let response;
111
- try {
112
- response = await fetch(`${backendUrl}/api/quote`, {
113
- method: "POST",
114
- headers: { "Content-Type": "application/json" },
115
- signal: requestSignal,
116
- body: JSON.stringify({
117
- dry,
118
- swapType,
119
- slippageTolerance,
120
- originAsset: originToken.assetId,
121
- destinationAsset: destinationToken.assetId,
122
- amount: amountInSmallestUnits,
123
- refundTo,
124
- recipient,
125
- deadline: deadline?.toISOString() || generateDeadline(1),
126
- referral
127
- })
128
- });
129
- } catch (error) {
130
- cleanup();
131
- if (isAbortError(error)) {
132
- if (signal?.aborted && !didTimeout()) {
133
- throw error;
134
- }
135
- throw new UniportError({
136
- code: "REQUEST_TIMEOUT",
137
- message: "Quote request timed out"
138
- });
139
- }
140
- throw error;
141
- }
142
- cleanup();
143
- if (!response.ok) {
144
- const errorBody = await response.json().catch(() => ({}));
145
- throw toUniportError(errorBody, {
146
- code: "QUOTE_FAILED",
147
- message: "Quote failed.",
148
- status: response.status
149
- });
150
- }
151
- const data = await response.json();
152
- const quote = data.quote;
153
- return {
154
- depositAddress: quote.depositAddress || "",
155
- memo: quote.depositMemo,
156
- amountIn: quote.amountIn,
157
- amountOut: quote.amountOut,
158
- amountOutFormatted: quote.amountOutFormatted,
159
- amountOutUsd: quote.amountOutUsd,
160
- deadline: quote.deadline,
161
- timeWhenInactive: quote.timeWhenInactive,
162
- correlationId: data.correlationId
163
- };
164
- }
165
- async function getExecutionStatus(depositAddress, memo) {
166
- const { backendUrl, requestTimeoutMs } = getUniportConfig();
167
- const url = new URL(
168
- `${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
169
- );
170
- if (memo) {
171
- url.searchParams.set("memo", memo);
172
- }
173
- const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
174
- let response;
175
- try {
176
- response = await fetch(url.toString(), { signal });
177
- } catch (error) {
178
- cleanup();
179
- if (isAbortError(error)) {
180
- throw new UniportError({
181
- code: "REQUEST_TIMEOUT",
182
- message: "Status check timed out"
183
- });
184
- }
185
- throw error;
186
- }
187
- cleanup();
188
- if (!response.ok) {
189
- const errorBody = await response.json().catch(() => ({}));
190
- throw toUniportError(errorBody, {
191
- code: "STATUS_CHECK_FAILED",
192
- message: "Status check failed.",
193
- status: response.status
194
- });
195
- }
196
- return await response.json();
197
- }
198
-
199
8
  // src/core/tokens.ts
200
9
  var TOKEN_ICONS = {
201
10
  // Stablecoins
@@ -272,8 +81,60 @@ var CHAIN_ICONS = {
272
81
  ltc: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/litecoin/info/logo.png",
273
82
  bch: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoincash/info/logo.png",
274
83
  xrp: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ripple/info/logo.png",
275
- zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png"
84
+ zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png",
85
+ scroll: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/scroll/info/logo.png"
276
86
  };
87
+ var EVM_CHAINS = [
88
+ "eth",
89
+ "arb",
90
+ "base",
91
+ "op",
92
+ "pol",
93
+ "avax",
94
+ "bsc",
95
+ "gnosis",
96
+ "bera",
97
+ "monad",
98
+ "scroll"
99
+ ];
100
+ function isEvmChain(chain) {
101
+ return EVM_CHAINS.includes(chain);
102
+ }
103
+ var CHAINS_REQUIRING_MEMO = ["stellar"];
104
+ function needsMemoDeposit(chain) {
105
+ return CHAINS_REQUIRING_MEMO.includes(chain);
106
+ }
107
+ var EXPLORER_TX_URLS = {
108
+ eth: (h) => `https://etherscan.io/tx/${h}`,
109
+ arb: (h) => `https://arbiscan.io/tx/${h}`,
110
+ base: (h) => `https://basescan.org/tx/${h}`,
111
+ op: (h) => `https://optimistic.etherscan.io/tx/${h}`,
112
+ pol: (h) => `https://polygonscan.com/tx/${h}`,
113
+ avax: (h) => `https://snowtrace.io/tx/${h}`,
114
+ bsc: (h) => `https://bscscan.com/tx/${h}`,
115
+ gnosis: (h) => `https://gnosisscan.io/tx/${h}`,
116
+ bera: (h) => `https://berascan.com/tx/${h}`,
117
+ monad: (h) => `https://monadvision.com/tx/${h}`,
118
+ sui: (h) => `https://suivision.xyz/txblock/${h}`,
119
+ sol: (h) => `https://solscan.io/tx/${h}`,
120
+ btc: (h) => `https://mempool.space/tx/${h}`,
121
+ near: (h) => `https://nearblocks.io/txns/${h}`,
122
+ ton: (h) => `https://tonviewer.com/transaction/${h}`,
123
+ tron: (h) => `https://tronscan.org/#/transaction/${h}`,
124
+ stellar: (h) => `https://stellar.expert/explorer/public/tx/${h}`,
125
+ cardano: (h) => `https://cardanoscan.io/transaction/${h}`,
126
+ aptos: (h) => `https://explorer.aptoslabs.com/txn/${h}?network=mainnet`,
127
+ starknet: (h) => `https://voyager.online/tx/${h}`,
128
+ doge: (h) => `https://dogechain.info/tx/${h}`,
129
+ ltc: (h) => `https://litecoinspace.org/tx/${h}`,
130
+ bch: (h) => `https://blockchair.com/bitcoin-cash/transaction/${h}`,
131
+ xrp: (h) => `https://xrpscan.com/tx/${h}`,
132
+ zec: (h) => `https://blockchair.com/zcash/transaction/${h}`,
133
+ scroll: (h) => `https://scrollscan.com/tx/${h}`
134
+ };
135
+ function getExplorerTxUrl(chain, hash) {
136
+ return EXPLORER_TX_URLS[chain]?.(hash);
137
+ }
277
138
  function createToken(chain, symbol, assetId, decimals, contractAddress, options) {
278
139
  const normalizedSymbol = symbol.replace("$", "").replace(" ", "");
279
140
  const canonicalPrefix = TOKEN_NAME_PREFIXES[chain] || chain;
@@ -334,6 +195,8 @@ var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
334
195
  var baseUSDC = createToken("base", "USDC", "nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near", 6, "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913");
335
196
  var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
336
197
  var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
198
+ var scrollETH = createToken("scroll", "ETH", "nep245:v2_1.omni.hot.tg:534352_11111111111111111111", 18);
199
+ var scrollUSDT = createToken("scroll", "USDT", "nep245:v2_1.omni.hot.tg:534352_4RG3Q2wFsMQmd45m5m89RjsLfupA", 6, "0xf55bec9cafdbe8730f096aa55dad6d22d44099df");
337
200
  var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
338
201
  var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
339
202
  var optimismUSDT = createToken("op", "USDT", "nep245:v2_1.omni.hot.tg:10_359RPSJVdTxwTJT9TyGssr2rFoWo", 6, "0x94b008aa00579c1307b0ef2c499ad98a8ce58e58");
@@ -367,6 +230,8 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
367
230
  var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
368
231
  var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
369
232
  var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
233
+ var stellarXLM = createToken("stellar", "XLM", "nep245:v2_1.omni.hot.tg:1100_111bzQBB5v7AhLyPMDwS8uJgQV24KaAPXtwyVWu2KXbbfQU6NXRCz", 7);
234
+ var stellarUSDC = createToken("stellar", "USDC", "nep245:v2_1.omni.hot.tg:1100_111bzQBB65GxAPAVoxqmMcgYo5oS3txhqs1Uh1cgahKQUeTUq1TJu", 7, "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN");
370
235
  var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
371
236
  name: "nearNEAR",
372
237
  aliases: ["nearwNEAR"]
@@ -398,6 +263,12 @@ var CHAINS = {
398
263
  icon: CHAIN_ICONS.base,
399
264
  tokens: [baseETH, baseUSDC, baseCbBTC, baseBRETT]
400
265
  },
266
+ scroll: {
267
+ id: "scroll",
268
+ name: "Scroll",
269
+ icon: CHAIN_ICONS.scroll,
270
+ tokens: [scrollETH, scrollUSDT]
271
+ },
401
272
  op: {
402
273
  id: "op",
403
274
  name: "Optimism",
@@ -522,7 +393,7 @@ var CHAINS = {
522
393
  id: "stellar",
523
394
  name: "Stellar",
524
395
  icon: CHAIN_ICONS.stellar,
525
- tokens: []
396
+ tokens: [stellarXLM, stellarUSDC]
526
397
  }
527
398
  };
528
399
  var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
@@ -535,6 +406,249 @@ function getSupportedChains() {
535
406
  return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
536
407
  }
537
408
 
409
+ // src/core/config.ts
410
+ var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
411
+ var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
412
+ function normalizeBackendUrl(url) {
413
+ return url.replace(/\/+$/, "");
414
+ }
415
+ function getUniportConfig() {
416
+ const backendUrl = DEFAULT_HOSTED_BACKEND_URL;
417
+ return {
418
+ backendUrl: normalizeBackendUrl(backendUrl),
419
+ requestTimeoutMs: DEFAULT_REQUEST_TIMEOUT_MS
420
+ };
421
+ }
422
+
423
+ // src/core/intents.ts
424
+ var UniportError = class extends Error {
425
+ constructor(params) {
426
+ super(params.message);
427
+ this.name = "UniportError";
428
+ this.code = params.code;
429
+ this.details = params.details;
430
+ this.status = params.status;
431
+ }
432
+ };
433
+ function isAbortError(error) {
434
+ return error instanceof Error && error.name === "AbortError";
435
+ }
436
+ function extractDetailMessage(details) {
437
+ if (typeof details === "string" && details.trim()) {
438
+ return details;
439
+ }
440
+ if (Array.isArray(details)) {
441
+ const firstString = details.find(
442
+ (detail) => typeof detail === "string" && detail.trim().length > 0
443
+ );
444
+ return firstString;
445
+ }
446
+ if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
447
+ const message = details.message.trim();
448
+ return message || void 0;
449
+ }
450
+ return void 0;
451
+ }
452
+ function toUniportError(body, fallback) {
453
+ const detailMessage = extractDetailMessage(body.details);
454
+ return new UniportError({
455
+ code: body.code || fallback.code,
456
+ message: detailMessage || body.message || fallback.message,
457
+ details: body.details,
458
+ status: fallback.status
459
+ });
460
+ }
461
+ function createTimeoutSignal(timeoutMs, externalSignal) {
462
+ const controller = new AbortController();
463
+ let timedOut = false;
464
+ const timeoutId = setTimeout(() => {
465
+ timedOut = true;
466
+ controller.abort();
467
+ }, timeoutMs);
468
+ const abortFromExternal = () => controller.abort();
469
+ externalSignal?.addEventListener("abort", abortFromExternal, {
470
+ once: true
471
+ });
472
+ return {
473
+ signal: controller.signal,
474
+ didTimeout: () => timedOut,
475
+ cleanup: () => {
476
+ clearTimeout(timeoutId);
477
+ externalSignal?.removeEventListener("abort", abortFromExternal);
478
+ }
479
+ };
480
+ }
481
+ function toSmallestUnits(amount, decimals) {
482
+ const [whole, fraction = ""] = amount.split(".");
483
+ const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
484
+ return `${whole}${paddedFraction}`.replace(/^0+/, "") || "0";
485
+ }
486
+ function generateDeadline(hoursFromNow = 1) {
487
+ const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
488
+ return deadline.toISOString();
489
+ }
490
+ function formatDisplayAmount(amount, significantDigits = 6) {
491
+ if (!amount) return amount ?? "";
492
+ const num = Number(amount);
493
+ if (!Number.isFinite(num) || num === 0) return amount;
494
+ const abs = Math.abs(num);
495
+ if (abs < 1e-6 || abs >= 1e21) return amount;
496
+ return new Intl.NumberFormat("en-US", {
497
+ maximumSignificantDigits: significantDigits,
498
+ useGrouping: false
499
+ }).format(num);
500
+ }
501
+ async function getQuote(options) {
502
+ const {
503
+ originToken,
504
+ destinationToken,
505
+ amount,
506
+ recipient,
507
+ refundTo,
508
+ slippageTolerance = 100,
509
+ // 1% default
510
+ swapType = "EXACT_INPUT",
511
+ deadline,
512
+ dry = false,
513
+ referral = "uniport",
514
+ signal
515
+ } = options;
516
+ const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
517
+ const { backendUrl, requestTimeoutMs } = getUniportConfig();
518
+ const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
519
+ requestTimeoutMs,
520
+ signal
521
+ );
522
+ let response;
523
+ try {
524
+ response = await fetch(`${backendUrl}/api/quote`, {
525
+ method: "POST",
526
+ headers: { "Content-Type": "application/json" },
527
+ signal: requestSignal,
528
+ body: JSON.stringify({
529
+ dry,
530
+ swapType,
531
+ slippageTolerance,
532
+ depositMode: needsMemoDeposit(originToken.chain) ? "MEMO" : void 0,
533
+ originAsset: originToken.assetId,
534
+ destinationAsset: destinationToken.assetId,
535
+ amount: amountInSmallestUnits,
536
+ refundTo,
537
+ recipient,
538
+ deadline: deadline?.toISOString() || generateDeadline(1),
539
+ referral
540
+ })
541
+ });
542
+ } catch (error) {
543
+ cleanup();
544
+ if (isAbortError(error)) {
545
+ if (signal?.aborted && !didTimeout()) {
546
+ throw error;
547
+ }
548
+ throw new UniportError({
549
+ code: "REQUEST_TIMEOUT",
550
+ message: "Quote request timed out"
551
+ });
552
+ }
553
+ throw error;
554
+ }
555
+ cleanup();
556
+ if (!response.ok) {
557
+ const errorBody = await response.json().catch(() => ({}));
558
+ throw toUniportError(errorBody, {
559
+ code: "QUOTE_FAILED",
560
+ message: "Quote failed.",
561
+ status: response.status
562
+ });
563
+ }
564
+ const data = await response.json();
565
+ const quote = data.quote;
566
+ return {
567
+ depositAddress: quote.depositAddress || "",
568
+ memo: quote.depositMemo,
569
+ amountIn: quote.amountIn,
570
+ amountOut: quote.amountOut,
571
+ amountOutFormatted: quote.amountOutFormatted,
572
+ amountOutUsd: quote.amountOutUsd,
573
+ deadline: quote.deadline,
574
+ timeWhenInactive: quote.timeWhenInactive,
575
+ correlationId: data.correlationId
576
+ };
577
+ }
578
+ async function getExecutionStatus(depositAddress, memo) {
579
+ const { backendUrl, requestTimeoutMs } = getUniportConfig();
580
+ const url = new URL(
581
+ `${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
582
+ );
583
+ if (memo) {
584
+ url.searchParams.set("memo", memo);
585
+ }
586
+ const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
587
+ let response;
588
+ try {
589
+ response = await fetch(url.toString(), { signal });
590
+ } catch (error) {
591
+ cleanup();
592
+ if (isAbortError(error)) {
593
+ throw new UniportError({
594
+ code: "REQUEST_TIMEOUT",
595
+ message: "Status check timed out"
596
+ });
597
+ }
598
+ throw error;
599
+ }
600
+ cleanup();
601
+ if (!response.ok) {
602
+ const errorBody = await response.json().catch(() => ({}));
603
+ throw toUniportError(errorBody, {
604
+ code: "STATUS_CHECK_FAILED",
605
+ message: "Status check failed.",
606
+ status: response.status
607
+ });
608
+ }
609
+ return await response.json();
610
+ }
611
+
612
+ // src/core/ens.ts
613
+ var ENSIDEAS_BASE_URL = "https://api.ensideas.com/ens/resolve";
614
+ var UNIPORT_ENS_NAME = "uniport.eth";
615
+ var UNIPORT_FALLBACK_REFUND_ADDRESS = "0x2f43A54f931b95053c3DDa5f4637065AA0c3c494";
616
+ async function resolveEnsName(name, options) {
617
+ const controller = new AbortController();
618
+ const timeoutId = setTimeout(
619
+ () => controller.abort(),
620
+ 1e4
621
+ );
622
+ try {
623
+ const response = await fetch(
624
+ `${ENSIDEAS_BASE_URL}/${encodeURIComponent(name)}`,
625
+ { signal: controller.signal }
626
+ );
627
+ if (!response.ok) return null;
628
+ const data = await response.json();
629
+ if (!data.address) return null;
630
+ return {
631
+ address: data.address,
632
+ name: data.name ?? name,
633
+ displayName: data.displayName ?? name,
634
+ avatar: data.avatar ?? null
635
+ };
636
+ } catch {
637
+ return null;
638
+ } finally {
639
+ clearTimeout(timeoutId);
640
+ }
641
+ }
642
+ var uniportRefundAddressPromise = null;
643
+ function getUniportDefaultRefundAddress() {
644
+ if (!uniportRefundAddressPromise) {
645
+ uniportRefundAddressPromise = resolveEnsName(UNIPORT_ENS_NAME).then(
646
+ (result) => result?.address ?? UNIPORT_FALLBACK_REFUND_ADDRESS
647
+ );
648
+ }
649
+ return uniportRefundAddressPromise;
650
+ }
651
+
538
652
  // src/hooks/useUniportPayment.ts
539
653
  function useUniportPayment(options) {
540
654
  const {
@@ -564,6 +678,19 @@ function useUniportPayment(options) {
564
678
  const [refundAddress, setRefundAddressState] = useState(
565
679
  initialRefundAddress ?? ""
566
680
  );
681
+ const [evmDefaultRefundAddress, setEvmDefaultRefundAddress] = useState(
682
+ UNIPORT_FALLBACK_REFUND_ADDRESS
683
+ );
684
+ useEffect(() => {
685
+ let cancelled = false;
686
+ getUniportDefaultRefundAddress().then((address) => {
687
+ if (!cancelled) setEvmDefaultRefundAddress(address);
688
+ });
689
+ return () => {
690
+ cancelled = true;
691
+ };
692
+ }, []);
693
+ const effectiveRefundAddress = refundAddress.trim() || (selectedChain && isEvmChain(selectedChain.id) ? evmDefaultRefundAddress : "");
567
694
  const pollingRef = useRef(null);
568
695
  const lastStatusRef = useRef(null);
569
696
  const previewDebounceRef = useRef(null);
@@ -620,31 +747,33 @@ function useUniportPayment(options) {
620
747
  const setAmount = useCallback(
621
748
  (newAmount) => {
622
749
  setAmountState(newAmount);
623
- schedulePreviewQuote(newAmount, refundAddress, selectedToken);
750
+ schedulePreviewQuote(newAmount, effectiveRefundAddress, selectedToken);
624
751
  },
625
- [refundAddress, schedulePreviewQuote, selectedToken]
752
+ [effectiveRefundAddress, schedulePreviewQuote, selectedToken]
626
753
  );
627
754
  const setRefundAddress = useCallback(
628
755
  (newRefundAddress) => {
629
756
  setRefundAddressState(newRefundAddress);
630
- schedulePreviewQuote(amount, newRefundAddress, selectedToken);
757
+ const nextEffective = newRefundAddress.trim() || (selectedChain && isEvmChain(selectedChain.id) ? evmDefaultRefundAddress : "");
758
+ schedulePreviewQuote(amount, nextEffective, selectedToken);
631
759
  },
632
- [amount, schedulePreviewQuote, selectedToken]
760
+ [amount, evmDefaultRefundAddress, schedulePreviewQuote, selectedChain, selectedToken]
633
761
  );
634
762
  const handleChainSelect = useCallback((chain) => {
635
763
  const nextToken = chain.tokens[0] || null;
636
764
  setSelectedChain(chain);
637
765
  setSelectedToken(nextToken);
638
766
  setPaymentState("selecting");
639
- schedulePreviewQuote(amount, refundAddress, nextToken);
640
- }, [amount, refundAddress, schedulePreviewQuote]);
767
+ const nextEffective = refundAddress.trim() || (isEvmChain(chain.id) ? evmDefaultRefundAddress : "");
768
+ schedulePreviewQuote(amount, nextEffective, nextToken);
769
+ }, [amount, evmDefaultRefundAddress, refundAddress, schedulePreviewQuote]);
641
770
  const handleTokenSelect = useCallback((token) => {
642
771
  setSelectedToken(token);
643
772
  setPaymentState("selecting");
644
- schedulePreviewQuote(amount, refundAddress, token);
645
- }, [amount, refundAddress, schedulePreviewQuote]);
773
+ schedulePreviewQuote(amount, effectiveRefundAddress, token);
774
+ }, [amount, effectiveRefundAddress, schedulePreviewQuote]);
646
775
  const fetchQuote = useCallback(async () => {
647
- if (!selectedToken || !amount || !refundAddress) {
776
+ if (!selectedToken || !amount || !effectiveRefundAddress) {
648
777
  setError(new Error("Missing required fields"));
649
778
  return;
650
779
  }
@@ -656,7 +785,7 @@ function useUniportPayment(options) {
656
785
  destinationToken: destToken,
657
786
  amount,
658
787
  recipient,
659
- refundTo: refundAddress,
788
+ refundTo: effectiveRefundAddress,
660
789
  dry: false
661
790
  });
662
791
  setQuote(result);
@@ -670,7 +799,7 @@ function useUniportPayment(options) {
670
799
  }, [
671
800
  selectedToken,
672
801
  amount,
673
- refundAddress,
802
+ effectiveRefundAddress,
674
803
  recipient,
675
804
  destToken,
676
805
  onError
@@ -781,6 +910,8 @@ function useUniportPayment(options) {
781
910
  selectedToken,
782
911
  amount,
783
912
  refundAddress,
913
+ effectiveRefundAddress,
914
+ isUsingDefaultRefundAddress: !refundAddress.trim() && !!effectiveRefundAddress,
784
915
  destinationToken: destToken,
785
916
  chains,
786
917
  tokens,
@@ -1049,7 +1180,7 @@ function UniportModal({
1049
1180
  onError
1050
1181
  });
1051
1182
  const [modalStep, setModalStep] = useState("chain");
1052
- const [copied, setCopied] = useState(false);
1183
+ const [copiedField, setCopiedField] = useState(null);
1053
1184
  const [showReceipt, setShowReceipt] = useState(false);
1054
1185
  const [portalRoot, setPortalRoot] = useState(null);
1055
1186
  useEffect(() => {
@@ -1081,13 +1212,11 @@ function UniportModal({
1081
1212
  };
1082
1213
  }
1083
1214
  }, [open, handleClose]);
1084
- const handleCopy = useCallback(async () => {
1085
- if (payment.quote?.depositAddress) {
1086
- const ok = await payment.copyToClipboard(payment.quote.depositAddress);
1087
- if (ok) {
1088
- setCopied(true);
1089
- setTimeout(() => setCopied(false), 2e3);
1090
- }
1215
+ const handleCopy = useCallback(async (field, text) => {
1216
+ const ok = await payment.copyToClipboard(text);
1217
+ if (ok) {
1218
+ setCopiedField(field);
1219
+ setTimeout(() => setCopiedField(null), 2e3);
1091
1220
  }
1092
1221
  }, [payment]);
1093
1222
  if (!open || !portalRoot) return null;
@@ -1096,8 +1225,8 @@ function UniportModal({
1096
1225
  const isSuccess = paymentState === "success";
1097
1226
  const isError = paymentState === "error";
1098
1227
  const isQuoting = paymentState === "quoting";
1099
- const canSubmit = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1100
- const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1228
+ const canSubmit = !!(payment.selectedToken && payment.amount && payment.effectiveRefundAddress);
1229
+ const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.effectiveRefundAddress);
1101
1230
  const showBack = !isSuccess && !isError && (showQR || modalStep !== "chain");
1102
1231
  const iconBtn = {
1103
1232
  width: 36,
@@ -1333,7 +1462,8 @@ function UniportModal({
1333
1462
  },
1334
1463
  children: [
1335
1464
  "Refund address on ",
1336
- ch?.name || "the source chain"
1465
+ ch?.name || "the source chain",
1466
+ ch && isEvmChain(ch.id) && /* @__PURE__ */ jsx("span", { style: { fontWeight: 400, color: t.textMuted }, children: " (optional)" })
1337
1467
  ]
1338
1468
  }
1339
1469
  ),
@@ -1343,7 +1473,7 @@ function UniportModal({
1343
1473
  type: "text",
1344
1474
  value: payment.refundAddress,
1345
1475
  onChange: (e) => payment.setRefundAddress(e.target.value),
1346
- placeholder: `Enter a ${ch?.name || "source chain"} refund address`,
1476
+ placeholder: ch && isEvmChain(ch.id) ? `Optional \u2014 defaults to ${UNIPORT_ENS_NAME}` : `Enter a ${ch?.name || "source chain"} refund address`,
1347
1477
  spellCheck: false,
1348
1478
  autoCapitalize: "off",
1349
1479
  autoCorrect: "off",
@@ -1369,7 +1499,23 @@ function UniportModal({
1369
1499
  color: t.textMuted,
1370
1500
  lineHeight: 1.5
1371
1501
  },
1372
- children: "Used only if the swap fails. This address must live on the chain the payer is sending from."
1502
+ children: payment.isUsingDefaultRefundAddress ? `Used only if the swap fails. You can enter your own address, or leave blank to use Uniport's default (${UNIPORT_ENS_NAME}).` : "Used only if the swap fails. This address must live on the chain the payer is sending from."
1503
+ }
1504
+ ),
1505
+ ch?.id === "stellar" && tok?.symbol !== "XLM" && /* @__PURE__ */ jsxs(
1506
+ "p",
1507
+ {
1508
+ style: {
1509
+ margin: "6px 0 0",
1510
+ fontSize: "12px",
1511
+ color: t.warning,
1512
+ lineHeight: 1.5
1513
+ },
1514
+ children: [
1515
+ "This refund address must already have a trustline for ",
1516
+ tok?.symbol,
1517
+ " on Stellar, or a refund cannot be delivered to it."
1518
+ ]
1373
1519
  }
1374
1520
  )
1375
1521
  ] }),
@@ -1393,7 +1539,7 @@ function UniportModal({
1393
1539
  "You will receive",
1394
1540
  " ",
1395
1541
  /* @__PURE__ */ jsxs("strong", { style: { color: t.text }, children: [
1396
- payment.previewQuote.amountOutFormatted,
1542
+ formatDisplayAmount(payment.previewQuote.amountOutFormatted),
1397
1543
  " ",
1398
1544
  payment.destinationToken.symbol
1399
1545
  ] }),
@@ -1434,7 +1580,7 @@ function UniportModal({
1434
1580
  ] }) : "Confirm Payment"
1435
1581
  }
1436
1582
  ),
1437
- !payment.refundAddress.trim() && /* @__PURE__ */ jsxs("p", { style: { textAlign: "center", fontSize: "12px", color: t.error, margin: "10px 0 0" }, children: [
1583
+ !payment.effectiveRefundAddress && /* @__PURE__ */ jsxs("p", { style: { textAlign: "center", fontSize: "12px", color: t.error, margin: "10px 0 0" }, children: [
1438
1584
  "Enter a refund address on ",
1439
1585
  ch?.name || "the source chain",
1440
1586
  " to continue."
@@ -1474,7 +1620,7 @@ function UniportModal({
1474
1620
  padding: "11px 13px",
1475
1621
  background: t.inputBg,
1476
1622
  borderRadius: "10px",
1477
- marginBottom: "14px",
1623
+ marginBottom: quote.memo ? "10px" : "14px",
1478
1624
  border: `1px solid ${t.border}`
1479
1625
  }, children: [
1480
1626
  /* @__PURE__ */ jsx("span", { style: {
@@ -1488,22 +1634,64 @@ function UniportModal({
1488
1634
  /* @__PURE__ */ jsx(
1489
1635
  "button",
1490
1636
  {
1491
- onClick: handleCopy,
1637
+ onClick: () => handleCopy("address", quote.depositAddress),
1492
1638
  title: "Copy address",
1493
1639
  style: {
1494
1640
  flexShrink: 0,
1495
1641
  width: 34,
1496
1642
  height: 34,
1497
1643
  borderRadius: "8px",
1498
- background: copied ? `${t.success}18` : t.iconBtnBg,
1499
- border: `1px solid ${copied ? t.success + "44" : t.border}`,
1644
+ background: copiedField === "address" ? `${t.success}18` : t.iconBtnBg,
1645
+ border: `1px solid ${copiedField === "address" ? t.success + "44" : t.border}`,
1500
1646
  cursor: "pointer",
1501
1647
  display: "flex",
1502
1648
  alignItems: "center",
1503
1649
  justifyContent: "center",
1504
1650
  transition: "all 0.2s"
1505
1651
  },
1506
- children: copied ? /* @__PURE__ */ jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsx(CopyIcon, { color: t.textMuted })
1652
+ children: copiedField === "address" ? /* @__PURE__ */ jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsx(CopyIcon, { color: t.textMuted })
1653
+ }
1654
+ )
1655
+ ] }),
1656
+ quote.memo && /* @__PURE__ */ jsxs("div", { style: {
1657
+ display: "flex",
1658
+ alignItems: "center",
1659
+ gap: "10px",
1660
+ padding: "11px 13px",
1661
+ background: `${t.warning}0f`,
1662
+ borderRadius: "10px",
1663
+ marginBottom: "14px",
1664
+ border: `1px solid ${t.warning}44`
1665
+ }, children: [
1666
+ /* @__PURE__ */ jsxs("div", { style: { flex: 1 }, children: [
1667
+ /* @__PURE__ */ jsx("p", { style: { margin: "0 0 3px", fontSize: "11px", color: t.warning, fontWeight: 600, textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Memo required" }),
1668
+ /* @__PURE__ */ jsx("span", { style: {
1669
+ fontSize: "13px",
1670
+ color: t.text,
1671
+ fontFamily: "monospace",
1672
+ wordBreak: "break-all",
1673
+ lineHeight: 1.4
1674
+ }, children: quote.memo })
1675
+ ] }),
1676
+ /* @__PURE__ */ jsx(
1677
+ "button",
1678
+ {
1679
+ onClick: () => handleCopy("memo", quote.memo),
1680
+ title: "Copy memo",
1681
+ style: {
1682
+ flexShrink: 0,
1683
+ width: 34,
1684
+ height: 34,
1685
+ borderRadius: "8px",
1686
+ background: copiedField === "memo" ? `${t.success}18` : t.iconBtnBg,
1687
+ border: `1px solid ${copiedField === "memo" ? t.success + "44" : t.border}`,
1688
+ cursor: "pointer",
1689
+ display: "flex",
1690
+ alignItems: "center",
1691
+ justifyContent: "center",
1692
+ transition: "all 0.2s"
1693
+ },
1694
+ children: copiedField === "memo" ? /* @__PURE__ */ jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsx(CopyIcon, { color: t.textMuted })
1507
1695
  }
1508
1696
  )
1509
1697
  ] }),
@@ -1520,7 +1708,14 @@ function UniportModal({
1520
1708
  " ",
1521
1709
  "on ",
1522
1710
  /* @__PURE__ */ jsx("strong", { children: payment.selectedChain?.name }),
1523
- " to this address. Other assets may be permanently lost."
1711
+ " to this address",
1712
+ quote.memo && /* @__PURE__ */ jsxs(Fragment, { children: [
1713
+ " ",
1714
+ /* @__PURE__ */ jsx("strong", { children: "with the memo above" })
1715
+ ] }),
1716
+ ". Other assets may be permanently lost",
1717
+ quote.memo && /* @__PURE__ */ jsx(Fragment, { children: ", and omitting the memo may make your deposit unrecoverable" }),
1718
+ "."
1524
1719
  ] })
1525
1720
  ] }),
1526
1721
  /* @__PURE__ */ jsxs("div", { style: { borderTop: `1px solid ${t.border}`, paddingTop: "12px" }, children: [
@@ -1528,7 +1723,7 @@ function UniportModal({
1528
1723
  /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "You'll receive" }),
1529
1724
  /* @__PURE__ */ jsxs("span", { style: { fontSize: "13px", fontWeight: 600, color: t.text }, children: [
1530
1725
  "\u2248",
1531
- quote.amountOutFormatted,
1726
+ formatDisplayAmount(quote.amountOutFormatted),
1532
1727
  " ",
1533
1728
  payment.destinationToken.symbol
1534
1729
  ] })
@@ -1560,6 +1755,25 @@ function UniportModal({
1560
1755
  ] }) })
1561
1756
  ] });
1562
1757
  };
1758
+ const renderTxHash = (hash, url) => url ? /* @__PURE__ */ jsxs(
1759
+ "a",
1760
+ {
1761
+ href: url,
1762
+ target: "_blank",
1763
+ rel: "noopener noreferrer",
1764
+ style: { color: t.accent, fontSize: "12px", fontFamily: "monospace", textDecoration: "none" },
1765
+ children: [
1766
+ hash.slice(0, 12),
1767
+ "\u2026",
1768
+ hash.slice(-8),
1769
+ " \u2197"
1770
+ ]
1771
+ }
1772
+ ) : /* @__PURE__ */ jsxs("span", { style: { color: t.textSecondary, fontSize: "12px", fontFamily: "monospace" }, children: [
1773
+ hash.slice(0, 12),
1774
+ "\u2026",
1775
+ hash.slice(-8)
1776
+ ] });
1563
1777
  const renderSuccessStep = () => /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
1564
1778
  /* @__PURE__ */ jsx(
1565
1779
  "button",
@@ -1603,7 +1817,7 @@ function UniportModal({
1603
1817
  payment.selectedToken?.symbol,
1604
1818
  " \u2192 ",
1605
1819
  "\u2248",
1606
- payment.quote?.amountOutFormatted,
1820
+ formatDisplayAmount(payment.quote?.amountOutFormatted),
1607
1821
  " ",
1608
1822
  payment.destinationToken.symbol
1609
1823
  ] }),
@@ -1630,29 +1844,14 @@ function UniportModal({
1630
1844
  "Source TX \xB7 ",
1631
1845
  payment.selectedChain?.name
1632
1846
  ] }),
1633
- /* @__PURE__ */ jsxs(
1634
- "a",
1635
- {
1636
- href: `https://etherscan.io/tx/${hash}`,
1637
- target: "_blank",
1638
- rel: "noopener noreferrer",
1639
- style: { color: t.accent, fontSize: "12px", fontFamily: "monospace", textDecoration: "none" },
1640
- children: [
1641
- hash.slice(0, 12),
1642
- "\u2026",
1643
- hash.slice(-8),
1644
- " \u2197"
1645
- ]
1646
- }
1647
- )
1847
+ renderTxHash(hash, payment.selectedChain ? getExplorerTxUrl(payment.selectedChain.id, hash) : void 0)
1648
1848
  ] }, `o${i}`)),
1649
1849
  payment.status?.destinationTxHashes?.map((hash, i) => /* @__PURE__ */ jsxs("div", { children: [
1650
- /* @__PURE__ */ jsx("p", { style: { color: t.textMuted, fontSize: "11px", margin: "0 0 3px", textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Destination TX" }),
1651
- /* @__PURE__ */ jsxs("span", { style: { color: t.textSecondary, fontSize: "12px", fontFamily: "monospace" }, children: [
1652
- hash.slice(0, 12),
1653
- "\u2026",
1654
- hash.slice(-8)
1655
- ] })
1850
+ /* @__PURE__ */ jsxs("p", { style: { color: t.textMuted, fontSize: "11px", margin: "0 0 3px", textTransform: "uppercase", letterSpacing: "0.05em" }, children: [
1851
+ "Destination TX \xB7 ",
1852
+ CHAINS[payment.destinationToken.chain].name
1853
+ ] }),
1854
+ renderTxHash(hash, getExplorerTxUrl(payment.destinationToken.chain, hash))
1656
1855
  ] }, `d${i}`)),
1657
1856
  !payment.status?.originTxHashes?.length && !payment.status?.destinationTxHashes?.length && /* @__PURE__ */ jsx("p", { style: { color: t.textMuted, fontSize: "13px", margin: 0 }, children: "Loading transaction details\u2026" })
1658
1857
  ] }),