uniport-sdk 0.0.3 → 0.0.5

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.
@@ -274,6 +274,51 @@ var CHAIN_ICONS = {
274
274
  xrp: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ripple/info/logo.png",
275
275
  zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png"
276
276
  };
277
+ var EVM_CHAINS = [
278
+ "eth",
279
+ "arb",
280
+ "base",
281
+ "op",
282
+ "pol",
283
+ "avax",
284
+ "bsc",
285
+ "gnosis",
286
+ "bera",
287
+ "monad"
288
+ ];
289
+ function isEvmChain(chain) {
290
+ return EVM_CHAINS.includes(chain);
291
+ }
292
+ var EXPLORER_TX_URLS = {
293
+ eth: (h) => `https://etherscan.io/tx/${h}`,
294
+ arb: (h) => `https://arbiscan.io/tx/${h}`,
295
+ base: (h) => `https://basescan.org/tx/${h}`,
296
+ op: (h) => `https://optimistic.etherscan.io/tx/${h}`,
297
+ pol: (h) => `https://polygonscan.com/tx/${h}`,
298
+ avax: (h) => `https://snowtrace.io/tx/${h}`,
299
+ bsc: (h) => `https://bscscan.com/tx/${h}`,
300
+ gnosis: (h) => `https://gnosisscan.io/tx/${h}`,
301
+ bera: (h) => `https://berascan.com/tx/${h}`,
302
+ monad: (h) => `https://monadvision.com/tx/${h}`,
303
+ sui: (h) => `https://suivision.xyz/txblock/${h}`,
304
+ sol: (h) => `https://solscan.io/tx/${h}`,
305
+ btc: (h) => `https://mempool.space/tx/${h}`,
306
+ near: (h) => `https://nearblocks.io/txns/${h}`,
307
+ ton: (h) => `https://tonviewer.com/transaction/${h}`,
308
+ tron: (h) => `https://tronscan.org/#/transaction/${h}`,
309
+ stellar: (h) => `https://stellar.expert/explorer/public/tx/${h}`,
310
+ cardano: (h) => `https://cardanoscan.io/transaction/${h}`,
311
+ aptos: (h) => `https://explorer.aptoslabs.com/txn/${h}?network=mainnet`,
312
+ starknet: (h) => `https://voyager.online/tx/${h}`,
313
+ doge: (h) => `https://dogechain.info/tx/${h}`,
314
+ ltc: (h) => `https://litecoinspace.org/tx/${h}`,
315
+ bch: (h) => `https://blockchair.com/bitcoin-cash/transaction/${h}`,
316
+ xrp: (h) => `https://xrpscan.com/tx/${h}`,
317
+ zec: (h) => `https://blockchair.com/zcash/transaction/${h}`
318
+ };
319
+ function getExplorerTxUrl(chain, hash) {
320
+ return EXPLORER_TX_URLS[chain]?.(hash);
321
+ }
277
322
  function createToken(chain, symbol, assetId, decimals, contractAddress, options) {
278
323
  const normalizedSymbol = symbol.replace("$", "").replace(" ", "");
279
324
  const canonicalPrefix = TOKEN_NAME_PREFIXES[chain] || chain;
@@ -535,6 +580,46 @@ function getSupportedChains() {
535
580
  return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
536
581
  }
537
582
 
583
+ // src/core/ens.ts
584
+ var ENSIDEAS_BASE_URL = "https://api.ensideas.com/ens/resolve";
585
+ var UNIPORT_ENS_NAME = "uniport.eth";
586
+ var UNIPORT_FALLBACK_REFUND_ADDRESS = "0x2f43A54f931b95053c3DDa5f4637065AA0c3c494";
587
+ async function resolveEnsName(name, options) {
588
+ const controller = new AbortController();
589
+ const timeoutId = setTimeout(
590
+ () => controller.abort(),
591
+ 1e4
592
+ );
593
+ try {
594
+ const response = await fetch(
595
+ `${ENSIDEAS_BASE_URL}/${encodeURIComponent(name)}`,
596
+ { signal: controller.signal }
597
+ );
598
+ if (!response.ok) return null;
599
+ const data = await response.json();
600
+ if (!data.address) return null;
601
+ return {
602
+ address: data.address,
603
+ name: data.name ?? name,
604
+ displayName: data.displayName ?? name,
605
+ avatar: data.avatar ?? null
606
+ };
607
+ } catch {
608
+ return null;
609
+ } finally {
610
+ clearTimeout(timeoutId);
611
+ }
612
+ }
613
+ var uniportRefundAddressPromise = null;
614
+ function getUniportDefaultRefundAddress() {
615
+ if (!uniportRefundAddressPromise) {
616
+ uniportRefundAddressPromise = resolveEnsName(UNIPORT_ENS_NAME).then(
617
+ (result) => result?.address ?? UNIPORT_FALLBACK_REFUND_ADDRESS
618
+ );
619
+ }
620
+ return uniportRefundAddressPromise;
621
+ }
622
+
538
623
  // src/hooks/useUniportPayment.ts
539
624
  function useUniportPayment(options) {
540
625
  const {
@@ -564,6 +649,19 @@ function useUniportPayment(options) {
564
649
  const [refundAddress, setRefundAddressState] = useState(
565
650
  initialRefundAddress ?? ""
566
651
  );
652
+ const [evmDefaultRefundAddress, setEvmDefaultRefundAddress] = useState(
653
+ UNIPORT_FALLBACK_REFUND_ADDRESS
654
+ );
655
+ useEffect(() => {
656
+ let cancelled = false;
657
+ getUniportDefaultRefundAddress().then((address) => {
658
+ if (!cancelled) setEvmDefaultRefundAddress(address);
659
+ });
660
+ return () => {
661
+ cancelled = true;
662
+ };
663
+ }, []);
664
+ const effectiveRefundAddress = refundAddress.trim() || (selectedChain && isEvmChain(selectedChain.id) ? evmDefaultRefundAddress : "");
567
665
  const pollingRef = useRef(null);
568
666
  const lastStatusRef = useRef(null);
569
667
  const previewDebounceRef = useRef(null);
@@ -620,31 +718,33 @@ function useUniportPayment(options) {
620
718
  const setAmount = useCallback(
621
719
  (newAmount) => {
622
720
  setAmountState(newAmount);
623
- schedulePreviewQuote(newAmount, refundAddress, selectedToken);
721
+ schedulePreviewQuote(newAmount, effectiveRefundAddress, selectedToken);
624
722
  },
625
- [refundAddress, schedulePreviewQuote, selectedToken]
723
+ [effectiveRefundAddress, schedulePreviewQuote, selectedToken]
626
724
  );
627
725
  const setRefundAddress = useCallback(
628
726
  (newRefundAddress) => {
629
727
  setRefundAddressState(newRefundAddress);
630
- schedulePreviewQuote(amount, newRefundAddress, selectedToken);
728
+ const nextEffective = newRefundAddress.trim() || (selectedChain && isEvmChain(selectedChain.id) ? evmDefaultRefundAddress : "");
729
+ schedulePreviewQuote(amount, nextEffective, selectedToken);
631
730
  },
632
- [amount, schedulePreviewQuote, selectedToken]
731
+ [amount, evmDefaultRefundAddress, schedulePreviewQuote, selectedChain, selectedToken]
633
732
  );
634
733
  const handleChainSelect = useCallback((chain) => {
635
734
  const nextToken = chain.tokens[0] || null;
636
735
  setSelectedChain(chain);
637
736
  setSelectedToken(nextToken);
638
737
  setPaymentState("selecting");
639
- schedulePreviewQuote(amount, refundAddress, nextToken);
640
- }, [amount, refundAddress, schedulePreviewQuote]);
738
+ const nextEffective = refundAddress.trim() || (isEvmChain(chain.id) ? evmDefaultRefundAddress : "");
739
+ schedulePreviewQuote(amount, nextEffective, nextToken);
740
+ }, [amount, evmDefaultRefundAddress, refundAddress, schedulePreviewQuote]);
641
741
  const handleTokenSelect = useCallback((token) => {
642
742
  setSelectedToken(token);
643
743
  setPaymentState("selecting");
644
- schedulePreviewQuote(amount, refundAddress, token);
645
- }, [amount, refundAddress, schedulePreviewQuote]);
744
+ schedulePreviewQuote(amount, effectiveRefundAddress, token);
745
+ }, [amount, effectiveRefundAddress, schedulePreviewQuote]);
646
746
  const fetchQuote = useCallback(async () => {
647
- if (!selectedToken || !amount || !refundAddress) {
747
+ if (!selectedToken || !amount || !effectiveRefundAddress) {
648
748
  setError(new Error("Missing required fields"));
649
749
  return;
650
750
  }
@@ -656,7 +756,7 @@ function useUniportPayment(options) {
656
756
  destinationToken: destToken,
657
757
  amount,
658
758
  recipient,
659
- refundTo: refundAddress,
759
+ refundTo: effectiveRefundAddress,
660
760
  dry: false
661
761
  });
662
762
  setQuote(result);
@@ -670,7 +770,7 @@ function useUniportPayment(options) {
670
770
  }, [
671
771
  selectedToken,
672
772
  amount,
673
- refundAddress,
773
+ effectiveRefundAddress,
674
774
  recipient,
675
775
  destToken,
676
776
  onError
@@ -781,6 +881,8 @@ function useUniportPayment(options) {
781
881
  selectedToken,
782
882
  amount,
783
883
  refundAddress,
884
+ effectiveRefundAddress,
885
+ isUsingDefaultRefundAddress: !refundAddress.trim() && !!effectiveRefundAddress,
784
886
  destinationToken: destToken,
785
887
  chains,
786
888
  tokens,
@@ -1096,8 +1198,8 @@ function UniportModal({
1096
1198
  const isSuccess = paymentState === "success";
1097
1199
  const isError = paymentState === "error";
1098
1200
  const isQuoting = paymentState === "quoting";
1099
- const canSubmit = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1100
- const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1201
+ const canSubmit = !!(payment.selectedToken && payment.amount && payment.effectiveRefundAddress);
1202
+ const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.effectiveRefundAddress);
1101
1203
  const showBack = !isSuccess && !isError && (showQR || modalStep !== "chain");
1102
1204
  const iconBtn = {
1103
1205
  width: 36,
@@ -1333,7 +1435,8 @@ function UniportModal({
1333
1435
  },
1334
1436
  children: [
1335
1437
  "Refund address on ",
1336
- ch?.name || "the source chain"
1438
+ ch?.name || "the source chain",
1439
+ ch && isEvmChain(ch.id) && /* @__PURE__ */ jsx("span", { style: { fontWeight: 400, color: t.textMuted }, children: " (optional)" })
1337
1440
  ]
1338
1441
  }
1339
1442
  ),
@@ -1343,7 +1446,7 @@ function UniportModal({
1343
1446
  type: "text",
1344
1447
  value: payment.refundAddress,
1345
1448
  onChange: (e) => payment.setRefundAddress(e.target.value),
1346
- placeholder: `Enter a ${ch?.name || "source chain"} refund address`,
1449
+ placeholder: ch && isEvmChain(ch.id) ? `Optional \u2014 defaults to ${UNIPORT_ENS_NAME}` : `Enter a ${ch?.name || "source chain"} refund address`,
1347
1450
  spellCheck: false,
1348
1451
  autoCapitalize: "off",
1349
1452
  autoCorrect: "off",
@@ -1369,7 +1472,7 @@ function UniportModal({
1369
1472
  color: t.textMuted,
1370
1473
  lineHeight: 1.5
1371
1474
  },
1372
- children: "Used only if the swap fails. This address must live on the chain the payer is sending from."
1475
+ 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."
1373
1476
  }
1374
1477
  )
1375
1478
  ] }),
@@ -1434,7 +1537,7 @@ function UniportModal({
1434
1537
  ] }) : "Confirm Payment"
1435
1538
  }
1436
1539
  ),
1437
- !payment.refundAddress.trim() && /* @__PURE__ */ jsxs("p", { style: { textAlign: "center", fontSize: "12px", color: t.error, margin: "10px 0 0" }, children: [
1540
+ !payment.effectiveRefundAddress && /* @__PURE__ */ jsxs("p", { style: { textAlign: "center", fontSize: "12px", color: t.error, margin: "10px 0 0" }, children: [
1438
1541
  "Enter a refund address on ",
1439
1542
  ch?.name || "the source chain",
1440
1543
  " to continue."
@@ -1560,6 +1663,25 @@ function UniportModal({
1560
1663
  ] }) })
1561
1664
  ] });
1562
1665
  };
1666
+ const renderTxHash = (hash, url) => url ? /* @__PURE__ */ jsxs(
1667
+ "a",
1668
+ {
1669
+ href: url,
1670
+ target: "_blank",
1671
+ rel: "noopener noreferrer",
1672
+ style: { color: t.accent, fontSize: "12px", fontFamily: "monospace", textDecoration: "none" },
1673
+ children: [
1674
+ hash.slice(0, 12),
1675
+ "\u2026",
1676
+ hash.slice(-8),
1677
+ " \u2197"
1678
+ ]
1679
+ }
1680
+ ) : /* @__PURE__ */ jsxs("span", { style: { color: t.textSecondary, fontSize: "12px", fontFamily: "monospace" }, children: [
1681
+ hash.slice(0, 12),
1682
+ "\u2026",
1683
+ hash.slice(-8)
1684
+ ] });
1563
1685
  const renderSuccessStep = () => /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
1564
1686
  /* @__PURE__ */ jsx(
1565
1687
  "button",
@@ -1630,29 +1752,14 @@ function UniportModal({
1630
1752
  "Source TX \xB7 ",
1631
1753
  payment.selectedChain?.name
1632
1754
  ] }),
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
- )
1755
+ renderTxHash(hash, payment.selectedChain ? getExplorerTxUrl(payment.selectedChain.id, hash) : void 0)
1648
1756
  ] }, `o${i}`)),
1649
1757
  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
- ] })
1758
+ /* @__PURE__ */ jsxs("p", { style: { color: t.textMuted, fontSize: "11px", margin: "0 0 3px", textTransform: "uppercase", letterSpacing: "0.05em" }, children: [
1759
+ "Destination TX \xB7 ",
1760
+ CHAINS[payment.destinationToken.chain].name
1761
+ ] }),
1762
+ renderTxHash(hash, getExplorerTxUrl(payment.destinationToken.chain, hash))
1656
1763
  ] }, `d${i}`)),
1657
1764
  !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
1765
  ] }),
@@ -1768,62 +1875,101 @@ function UniportModal({
1768
1875
  portalRoot
1769
1876
  );
1770
1877
  }
1878
+ var sharedButtonStyle = {
1879
+ display: "inline-flex",
1880
+ alignItems: "center",
1881
+ justifyContent: "center",
1882
+ cursor: "pointer",
1883
+ transition: "all 0.2s ease",
1884
+ fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1885
+ };
1771
1886
  var buttonStyles = {
1772
- default: {
1773
- display: "inline-flex",
1774
- alignItems: "center",
1775
- justifyContent: "center",
1776
- gap: "8px",
1777
- padding: "12px 24px",
1778
- fontSize: "14px",
1779
- fontWeight: 500,
1780
- color: "white",
1781
- background: "linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%)",
1782
- border: "none",
1783
- borderRadius: "12px",
1784
- cursor: "pointer",
1785
- transition: "all 0.2s ease",
1786
- boxShadow: "0 4px 14px rgba(79, 70, 229, 0.3)",
1787
- fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1788
- },
1789
- compact: {
1790
- display: "inline-flex",
1791
- alignItems: "center",
1792
- justifyContent: "center",
1793
- gap: "6px",
1794
- padding: "8px 16px",
1795
- fontSize: "13px",
1796
- fontWeight: 500,
1797
- color: "white",
1798
- background: "linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%)",
1799
- border: "none",
1800
- borderRadius: "8px",
1801
- cursor: "pointer",
1802
- transition: "all 0.2s ease",
1803
- boxShadow: "0 2px 8px rgba(79, 70, 229, 0.25)",
1804
- fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1805
- },
1806
- outline: {
1807
- display: "inline-flex",
1808
- alignItems: "center",
1809
- justifyContent: "center",
1810
- gap: "8px",
1811
- padding: "12px 24px",
1812
- fontSize: "14px",
1813
- fontWeight: 500,
1814
- color: "#4F46E5",
1815
- background: "transparent",
1816
- border: "2px solid #4F46E5",
1817
- borderRadius: "12px",
1818
- cursor: "pointer",
1819
- transition: "all 0.2s ease",
1820
- fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1887
+ light: {
1888
+ default: {
1889
+ ...sharedButtonStyle,
1890
+ gap: "8px",
1891
+ padding: "12px 24px",
1892
+ fontSize: "14px",
1893
+ fontWeight: 600,
1894
+ color: "#ffffff",
1895
+ background: "#1c1c1e",
1896
+ border: "1px solid #1c1c1e",
1897
+ borderRadius: "12px",
1898
+ boxShadow: "0 8px 24px rgba(28, 28, 30, 0.18)"
1899
+ },
1900
+ compact: {
1901
+ ...sharedButtonStyle,
1902
+ gap: "6px",
1903
+ padding: "8px 16px",
1904
+ fontSize: "13px",
1905
+ fontWeight: 600,
1906
+ color: "#ffffff",
1907
+ background: "#1c1c1e",
1908
+ border: "1px solid #1c1c1e",
1909
+ borderRadius: "8px",
1910
+ boxShadow: "0 6px 18px rgba(28, 28, 30, 0.16)"
1911
+ },
1912
+ outline: {
1913
+ ...sharedButtonStyle,
1914
+ gap: "8px",
1915
+ padding: "12px 24px",
1916
+ fontSize: "14px",
1917
+ fontWeight: 600,
1918
+ color: "#1c1c1e",
1919
+ background: "transparent",
1920
+ border: "1px solid #1c1c1e",
1921
+ borderRadius: "12px"
1922
+ }
1821
1923
  },
1822
- disabled: {
1823
- opacity: 0.5,
1824
- cursor: "not-allowed"
1924
+ dark: {
1925
+ default: {
1926
+ ...sharedButtonStyle,
1927
+ gap: "8px",
1928
+ padding: "12px 24px",
1929
+ fontSize: "14px",
1930
+ fontWeight: 600,
1931
+ color: "#111113",
1932
+ background: "#ffffff",
1933
+ border: "1px solid rgba(255, 255, 255, 0.9)",
1934
+ borderRadius: "12px",
1935
+ boxShadow: "0 8px 24px rgba(0, 0, 0, 0.32)"
1936
+ },
1937
+ compact: {
1938
+ ...sharedButtonStyle,
1939
+ gap: "6px",
1940
+ padding: "8px 16px",
1941
+ fontSize: "13px",
1942
+ fontWeight: 600,
1943
+ color: "#111113",
1944
+ background: "#ffffff",
1945
+ border: "1px solid rgba(255, 255, 255, 0.9)",
1946
+ borderRadius: "8px",
1947
+ boxShadow: "0 6px 18px rgba(0, 0, 0, 0.28)"
1948
+ },
1949
+ outline: {
1950
+ ...sharedButtonStyle,
1951
+ gap: "8px",
1952
+ padding: "12px 24px",
1953
+ fontSize: "14px",
1954
+ fontWeight: 600,
1955
+ color: "#ffffff",
1956
+ background: "transparent",
1957
+ border: "1px solid rgba(255, 255, 255, 0.72)",
1958
+ borderRadius: "12px"
1959
+ }
1825
1960
  }
1826
1961
  };
1962
+ var disabledButtonStyle = {
1963
+ opacity: 0.5,
1964
+ cursor: "not-allowed",
1965
+ boxShadow: "none"
1966
+ };
1967
+ function getButtonStyle(variant, theme, disabled) {
1968
+ return {
1969
+ ...buttonStyles[theme][variant],
1970
+ ...disabled ? disabledButtonStyle : {}
1971
+ };
1972
+ }
1827
1973
  function UniportButton({
1828
1974
  recipient,
1829
1975
  refundAddress,
@@ -1849,10 +1995,7 @@ function UniportButton({
1849
1995
  setIsOpen(false);
1850
1996
  onOpenChange?.(false);
1851
1997
  };
1852
- const style = {
1853
- ...buttonStyles[variant],
1854
- ...disabled ? buttonStyles.disabled : {}
1855
- };
1998
+ const style = getButtonStyle(variant, theme, disabled);
1856
1999
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1857
2000
  /* @__PURE__ */ jsxs(
1858
2001
  "button",