uniport-sdk 0.0.2 → 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.
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 }),