uniport-sdk 0.0.2 → 0.0.4

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.
package/dist/index.d.cts CHANGED
@@ -26,6 +26,7 @@ interface UseUniportPaymentReturn {
26
26
  paymentState: PaymentState;
27
27
  quote: QuoteResult | null;
28
28
  previewQuote: QuoteResult | null;
29
+ previewError: Error | null;
29
30
  isLoadingPreview: boolean;
30
31
  status: StatusResult | null;
31
32
  error: Error | null;
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ interface UseUniportPaymentReturn {
26
26
  paymentState: PaymentState;
27
27
  quote: QuoteResult | null;
28
28
  previewQuote: QuoteResult | null;
29
+ previewError: Error | null;
29
30
  isLoadingPreview: boolean;
30
31
  status: StatusResult | null;
31
32
  error: Error | null;
package/dist/index.js CHANGED
@@ -110,6 +110,7 @@ var TOKEN_NAME_PREFIXES = {
110
110
  op: "optimism",
111
111
  sol: "solana",
112
112
  btc: "bitcoin",
113
+ pol: "polygon",
113
114
  avax: "avalanche",
114
115
  doge: "dogecoin",
115
116
  ltc: "litecoin",
@@ -355,11 +356,6 @@ var configuredRequestTimeoutMs;
355
356
  function normalizeBackendUrl(url) {
356
357
  return url.replace(/\/+$/, "");
357
358
  }
358
- function getLegacyBackendOverride() {
359
- const envBackendUrl = typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_UNIPORT_BACKEND_URL : void 0;
360
- const windowBackendUrl = typeof window !== "undefined" ? window.__UNIPORT_BACKEND_URL__ : void 0;
361
- return envBackendUrl || windowBackendUrl;
362
- }
363
359
  function configureUniport(config) {
364
360
  if (config.backendUrl !== void 0) {
365
361
  configuredBackendUrl = config.backendUrl ? normalizeBackendUrl(config.backendUrl) : void 0;
@@ -369,7 +365,7 @@ function configureUniport(config) {
369
365
  }
370
366
  }
371
367
  function getUniportConfig() {
372
- const backendUrl = configuredBackendUrl || getLegacyBackendOverride() || DEFAULT_HOSTED_BACKEND_URL;
368
+ const backendUrl = configuredBackendUrl || DEFAULT_HOSTED_BACKEND_URL;
373
369
  return {
374
370
  backendUrl: normalizeBackendUrl(backendUrl),
375
371
  requestTimeoutMs: configuredRequestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
@@ -389,10 +385,27 @@ var UniportError = class extends Error {
389
385
  function isAbortError(error) {
390
386
  return error instanceof Error && error.name === "AbortError";
391
387
  }
388
+ function extractDetailMessage(details) {
389
+ if (typeof details === "string" && details.trim()) {
390
+ return details;
391
+ }
392
+ if (Array.isArray(details)) {
393
+ const firstString = details.find(
394
+ (detail) => typeof detail === "string" && detail.trim().length > 0
395
+ );
396
+ return firstString;
397
+ }
398
+ if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
399
+ const message = details.message.trim();
400
+ return message || void 0;
401
+ }
402
+ return void 0;
403
+ }
392
404
  function toUniportError(body, fallback) {
405
+ const detailMessage = extractDetailMessage(body.details);
393
406
  return new UniportError({
394
407
  code: body.code || fallback.code,
395
- message: body.message || fallback.message,
408
+ message: detailMessage || body.message || fallback.message,
396
409
  details: body.details,
397
410
  status: fallback.status
398
411
  });
@@ -612,6 +625,7 @@ function useUniportPayment(options) {
612
625
  const [paymentState, setPaymentState] = useState("idle");
613
626
  const [quote, setQuote] = useState(null);
614
627
  const [previewQuote, setPreviewQuote] = useState(null);
628
+ const [previewError, setPreviewError] = useState(null);
615
629
  const [isLoadingPreview, setIsLoadingPreview] = useState(false);
616
630
  const [status, setStatus] = useState(null);
617
631
  const [error, setError] = useState(null);
@@ -630,6 +644,7 @@ function useUniportPayment(options) {
630
644
  const schedulePreviewQuote = useCallback(
631
645
  (nextAmount, nextRefundAddress, nextSelectedToken) => {
632
646
  setPreviewQuote(null);
647
+ setPreviewError(null);
633
648
  if (previewDebounceRef.current) {
634
649
  clearTimeout(previewDebounceRef.current);
635
650
  }
@@ -660,7 +675,9 @@ function useUniportPayment(options) {
660
675
  if (err instanceof Error && err.name === "AbortError") {
661
676
  return;
662
677
  }
663
- console.warn("Preview quote failed:", err);
678
+ const previewFailure = err instanceof Error ? err : new Error("Failed to fetch estimate");
679
+ setPreviewError(previewFailure);
680
+ console.warn("Preview quote failed:", previewFailure);
664
681
  } finally {
665
682
  if (previewAbortRef.current === controller) {
666
683
  previewAbortRef.current = null;
@@ -796,6 +813,7 @@ function useUniportPayment(options) {
796
813
  setIsLoadingPreview(false);
797
814
  setStatus(null);
798
815
  setError(null);
816
+ setPreviewError(null);
799
817
  setSelectedChain(null);
800
818
  setSelectedToken(null);
801
819
  setAmountState(initialAmount ?? "");
@@ -826,6 +844,7 @@ function useUniportPayment(options) {
826
844
  paymentState,
827
845
  quote,
828
846
  previewQuote,
847
+ previewError,
829
848
  isLoadingPreview,
830
849
  status,
831
850
  error,
@@ -1031,6 +1050,55 @@ function WarningTriangle({ color }) {
1031
1050
  /* @__PURE__ */ jsx("line", { x1: "12", y1: "17", x2: "12.01", y2: "17", stroke: color, strokeWidth: "2", strokeLinecap: "round" })
1032
1051
  ] });
1033
1052
  }
1053
+ function formatPreviewError(error) {
1054
+ if (error.name === "AbortError") {
1055
+ return "Estimate request was cancelled. Try again.";
1056
+ }
1057
+ if (error.message === "Quote request timed out") {
1058
+ return "Could not fetch estimate. Please try again.";
1059
+ }
1060
+ const normalized = error.message.toLowerCase();
1061
+ if (normalized.includes("recipient is not valid")) {
1062
+ return "Recipient address does not match the selected destination chain.";
1063
+ }
1064
+ if (normalized.includes("refund") && normalized.includes("valid")) {
1065
+ return "Refund address does not match the source chain.";
1066
+ }
1067
+ if (normalized.includes("amount")) {
1068
+ return "Enter a valid amount to fetch an estimate.";
1069
+ }
1070
+ return "Could not fetch estimate. Check the details and try again.";
1071
+ }
1072
+ function formatChainLabel(chainId) {
1073
+ const labels = {
1074
+ sui: "Sui",
1075
+ eth: "Ethereum",
1076
+ sol: "Solana",
1077
+ arb: "Arbitrum",
1078
+ base: "Base",
1079
+ op: "Optimism",
1080
+ pol: "Polygon",
1081
+ avax: "Avalanche",
1082
+ bsc: "BNB Chain",
1083
+ near: "NEAR",
1084
+ btc: "Bitcoin",
1085
+ ton: "TON",
1086
+ tron: "Tron",
1087
+ stellar: "Stellar",
1088
+ cardano: "Cardano",
1089
+ xrp: "XRP Ledger",
1090
+ doge: "Dogecoin",
1091
+ ltc: "Litecoin",
1092
+ bch: "Bitcoin Cash",
1093
+ aptos: "Aptos",
1094
+ starknet: "Starknet",
1095
+ bera: "Berachain",
1096
+ zec: "Zcash",
1097
+ gnosis: "Gnosis",
1098
+ monad: "Monad"
1099
+ };
1100
+ return labels[chainId] || chainId.toUpperCase();
1101
+ }
1034
1102
  function UniportModal({
1035
1103
  open,
1036
1104
  onClose,
@@ -1100,6 +1168,7 @@ function UniportModal({
1100
1168
  const isError = paymentState === "error";
1101
1169
  const isQuoting = paymentState === "quoting";
1102
1170
  const canSubmit = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1171
+ const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1103
1172
  const showBack = !isSuccess && !isError && (showQR || modalStep !== "chain");
1104
1173
  const iconBtn = {
1105
1174
  width: 36,
@@ -1384,22 +1453,28 @@ function UniportModal({
1384
1453
  gap: 5,
1385
1454
  marginBottom: "20px"
1386
1455
  }, children: [
1387
- payment.amount && payment.isLoadingPreview && [0, 0.2, 0.4].map((delay, i) => /* @__PURE__ */ jsx("div", { style: {
1456
+ canPreviewEstimate && payment.isLoadingPreview && [0, 0.2, 0.4].map((delay, i) => /* @__PURE__ */ jsx("div", { style: {
1388
1457
  width: 6,
1389
1458
  height: 6,
1390
1459
  borderRadius: "50%",
1391
1460
  background: t.accent,
1392
1461
  animation: `uniport-pulse 1s ease infinite ${delay}s`
1393
1462
  } }, i)),
1394
- payment.amount && !payment.isLoadingPreview && payment.previewQuote && /* @__PURE__ */ jsxs("span", { style: { fontSize: "15px", color: t.textSecondary }, children: [
1395
- "\u2248 ",
1463
+ canPreviewEstimate && !payment.isLoadingPreview && payment.previewQuote && /* @__PURE__ */ jsxs("span", { style: { fontSize: "15px", color: t.textSecondary }, children: [
1464
+ "You will receive",
1465
+ " ",
1396
1466
  /* @__PURE__ */ jsxs("strong", { style: { color: t.text }, children: [
1397
1467
  payment.previewQuote.amountOutFormatted,
1398
1468
  " ",
1399
1469
  payment.destinationToken.symbol
1400
- ] })
1470
+ ] }),
1471
+ " ",
1472
+ "on",
1473
+ " ",
1474
+ /* @__PURE__ */ jsx("strong", { style: { color: t.text }, children: formatChainLabel(payment.destinationToken.chain) })
1401
1475
  ] }),
1402
- payment.amount && !payment.isLoadingPreview && !payment.previewQuote && /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "Fetching estimate\u2026" })
1476
+ canPreviewEstimate && !payment.isLoadingPreview && payment.previewError && /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.error }, children: formatPreviewError(payment.previewError) }),
1477
+ canPreviewEstimate && !payment.isLoadingPreview && !payment.previewQuote && !payment.previewError && /* @__PURE__ */ jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "Fetching estimate\u2026" })
1403
1478
  ] }),
1404
1479
  !!payment.amount && /* @__PURE__ */ jsxs("div", { style: { ...warningBox, marginBottom: "20px" }, children: [
1405
1480
  /* @__PURE__ */ jsx(WarningTriangle, { color: t.warning }),
@@ -1764,62 +1839,101 @@ function UniportModal({
1764
1839
  portalRoot
1765
1840
  );
1766
1841
  }
1842
+ var sharedButtonStyle = {
1843
+ display: "inline-flex",
1844
+ alignItems: "center",
1845
+ justifyContent: "center",
1846
+ cursor: "pointer",
1847
+ transition: "all 0.2s ease",
1848
+ fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1849
+ };
1767
1850
  var buttonStyles = {
1768
- default: {
1769
- display: "inline-flex",
1770
- alignItems: "center",
1771
- justifyContent: "center",
1772
- gap: "8px",
1773
- padding: "12px 24px",
1774
- fontSize: "14px",
1775
- fontWeight: 500,
1776
- color: "white",
1777
- background: "linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%)",
1778
- border: "none",
1779
- borderRadius: "12px",
1780
- cursor: "pointer",
1781
- transition: "all 0.2s ease",
1782
- boxShadow: "0 4px 14px rgba(79, 70, 229, 0.3)",
1783
- fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1784
- },
1785
- compact: {
1786
- display: "inline-flex",
1787
- alignItems: "center",
1788
- justifyContent: "center",
1789
- gap: "6px",
1790
- padding: "8px 16px",
1791
- fontSize: "13px",
1792
- fontWeight: 500,
1793
- color: "white",
1794
- background: "linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%)",
1795
- border: "none",
1796
- borderRadius: "8px",
1797
- cursor: "pointer",
1798
- transition: "all 0.2s ease",
1799
- boxShadow: "0 2px 8px rgba(79, 70, 229, 0.25)",
1800
- fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1801
- },
1802
- outline: {
1803
- display: "inline-flex",
1804
- alignItems: "center",
1805
- justifyContent: "center",
1806
- gap: "8px",
1807
- padding: "12px 24px",
1808
- fontSize: "14px",
1809
- fontWeight: 500,
1810
- color: "#4F46E5",
1811
- background: "transparent",
1812
- border: "2px solid #4F46E5",
1813
- borderRadius: "12px",
1814
- cursor: "pointer",
1815
- transition: "all 0.2s ease",
1816
- fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
1851
+ light: {
1852
+ default: {
1853
+ ...sharedButtonStyle,
1854
+ gap: "8px",
1855
+ padding: "12px 24px",
1856
+ fontSize: "14px",
1857
+ fontWeight: 600,
1858
+ color: "#ffffff",
1859
+ background: "#1c1c1e",
1860
+ border: "1px solid #1c1c1e",
1861
+ borderRadius: "12px",
1862
+ boxShadow: "0 8px 24px rgba(28, 28, 30, 0.18)"
1863
+ },
1864
+ compact: {
1865
+ ...sharedButtonStyle,
1866
+ gap: "6px",
1867
+ padding: "8px 16px",
1868
+ fontSize: "13px",
1869
+ fontWeight: 600,
1870
+ color: "#ffffff",
1871
+ background: "#1c1c1e",
1872
+ border: "1px solid #1c1c1e",
1873
+ borderRadius: "8px",
1874
+ boxShadow: "0 6px 18px rgba(28, 28, 30, 0.16)"
1875
+ },
1876
+ outline: {
1877
+ ...sharedButtonStyle,
1878
+ gap: "8px",
1879
+ padding: "12px 24px",
1880
+ fontSize: "14px",
1881
+ fontWeight: 600,
1882
+ color: "#1c1c1e",
1883
+ background: "transparent",
1884
+ border: "1px solid #1c1c1e",
1885
+ borderRadius: "12px"
1886
+ }
1817
1887
  },
1818
- disabled: {
1819
- opacity: 0.5,
1820
- cursor: "not-allowed"
1888
+ dark: {
1889
+ default: {
1890
+ ...sharedButtonStyle,
1891
+ gap: "8px",
1892
+ padding: "12px 24px",
1893
+ fontSize: "14px",
1894
+ fontWeight: 600,
1895
+ color: "#111113",
1896
+ background: "#ffffff",
1897
+ border: "1px solid rgba(255, 255, 255, 0.9)",
1898
+ borderRadius: "12px",
1899
+ boxShadow: "0 8px 24px rgba(0, 0, 0, 0.32)"
1900
+ },
1901
+ compact: {
1902
+ ...sharedButtonStyle,
1903
+ gap: "6px",
1904
+ padding: "8px 16px",
1905
+ fontSize: "13px",
1906
+ fontWeight: 600,
1907
+ color: "#111113",
1908
+ background: "#ffffff",
1909
+ border: "1px solid rgba(255, 255, 255, 0.9)",
1910
+ borderRadius: "8px",
1911
+ boxShadow: "0 6px 18px rgba(0, 0, 0, 0.28)"
1912
+ },
1913
+ outline: {
1914
+ ...sharedButtonStyle,
1915
+ gap: "8px",
1916
+ padding: "12px 24px",
1917
+ fontSize: "14px",
1918
+ fontWeight: 600,
1919
+ color: "#ffffff",
1920
+ background: "transparent",
1921
+ border: "1px solid rgba(255, 255, 255, 0.72)",
1922
+ borderRadius: "12px"
1923
+ }
1821
1924
  }
1822
1925
  };
1926
+ var disabledButtonStyle = {
1927
+ opacity: 0.5,
1928
+ cursor: "not-allowed",
1929
+ boxShadow: "none"
1930
+ };
1931
+ function getButtonStyle(variant, theme, disabled) {
1932
+ return {
1933
+ ...buttonStyles[theme][variant],
1934
+ ...disabled ? disabledButtonStyle : {}
1935
+ };
1936
+ }
1823
1937
  function UniportButton({
1824
1938
  recipient,
1825
1939
  refundAddress,
@@ -1845,10 +1959,7 @@ function UniportButton({
1845
1959
  setIsOpen(false);
1846
1960
  onOpenChange?.(false);
1847
1961
  };
1848
- const style = {
1849
- ...buttonStyles[variant],
1850
- ...disabled ? buttonStyles.disabled : {}
1851
- };
1962
+ const style = getButtonStyle(variant, theme, disabled);
1852
1963
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1853
1964
  /* @__PURE__ */ jsxs(
1854
1965
  "button",