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/README.md CHANGED
@@ -25,22 +25,7 @@ import { UniportButton } from 'uniport-sdk'
25
25
  />
26
26
  ```
27
27
 
28
- The SDK uses Uniport's hosted backend by default. No API key or backend URL is required for standard integration.
29
-
30
- ## Backend Configuration
31
-
32
- If you want to self-host or point the SDK at staging, configure it explicitly:
33
-
34
- ```tsx
35
- import { configureUniport } from 'uniport-sdk'
36
-
37
- configureUniport({
38
- backendUrl: 'https://your-backend.example.com',
39
- requestTimeoutMs: 20000,
40
- })
41
- ```
42
-
43
- `NEXT_PUBLIC_UNIPORT_BACKEND_URL` is still supported as a legacy override, but `configureUniport()` is the preferred integration path.
28
+ The SDK uses Uniport's hosted backend. No API key or backend URL is required for standard integration.
44
29
 
45
30
  ## UniportButton Props
46
31
 
@@ -141,7 +126,6 @@ The package exports:
141
126
  - `UniportButton`
142
127
  - `UniportModal`
143
128
  - `useUniportPayment`
144
- - `configureUniport`
145
129
  - `getQuote`
146
130
  - `submitDepositTx`
147
131
  - `getExecutionStatus`
@@ -17,13 +17,8 @@ var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
17
17
  function normalizeBackendUrl(url) {
18
18
  return url.replace(/\/+$/, "");
19
19
  }
20
- function getLegacyBackendOverride() {
21
- const envBackendUrl = typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_UNIPORT_BACKEND_URL : void 0;
22
- const windowBackendUrl = typeof window !== "undefined" ? window.__UNIPORT_BACKEND_URL__ : void 0;
23
- return envBackendUrl || windowBackendUrl;
24
- }
25
20
  function getUniportConfig() {
26
- const backendUrl = getLegacyBackendOverride() || DEFAULT_HOSTED_BACKEND_URL;
21
+ const backendUrl = DEFAULT_HOSTED_BACKEND_URL;
27
22
  return {
28
23
  backendUrl: normalizeBackendUrl(backendUrl),
29
24
  requestTimeoutMs: DEFAULT_REQUEST_TIMEOUT_MS
@@ -43,10 +38,27 @@ var UniportError = class extends Error {
43
38
  function isAbortError(error) {
44
39
  return error instanceof Error && error.name === "AbortError";
45
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
+ }
46
57
  function toUniportError(body, fallback) {
58
+ const detailMessage = extractDetailMessage(body.details);
47
59
  return new UniportError({
48
60
  code: body.code || fallback.code,
49
- message: body.message || fallback.message,
61
+ message: detailMessage || body.message || fallback.message,
50
62
  details: body.details,
51
63
  status: fallback.status
52
64
  });
@@ -297,6 +309,7 @@ var TOKEN_NAME_PREFIXES = {
297
309
  op: "optimism",
298
310
  sol: "solana",
299
311
  btc: "bitcoin",
312
+ pol: "polygon",
300
313
  avax: "avalanche",
301
314
  doge: "dogecoin",
302
315
  ltc: "litecoin",
@@ -547,6 +560,7 @@ function useUniportPayment(options) {
547
560
  const [paymentState, setPaymentState] = react.useState("idle");
548
561
  const [quote, setQuote] = react.useState(null);
549
562
  const [previewQuote, setPreviewQuote] = react.useState(null);
563
+ const [previewError, setPreviewError] = react.useState(null);
550
564
  const [isLoadingPreview, setIsLoadingPreview] = react.useState(false);
551
565
  const [status, setStatus] = react.useState(null);
552
566
  const [error, setError] = react.useState(null);
@@ -565,6 +579,7 @@ function useUniportPayment(options) {
565
579
  const schedulePreviewQuote = react.useCallback(
566
580
  (nextAmount, nextRefundAddress, nextSelectedToken) => {
567
581
  setPreviewQuote(null);
582
+ setPreviewError(null);
568
583
  if (previewDebounceRef.current) {
569
584
  clearTimeout(previewDebounceRef.current);
570
585
  }
@@ -595,7 +610,9 @@ function useUniportPayment(options) {
595
610
  if (err instanceof Error && err.name === "AbortError") {
596
611
  return;
597
612
  }
598
- console.warn("Preview quote failed:", err);
613
+ const previewFailure = err instanceof Error ? err : new Error("Failed to fetch estimate");
614
+ setPreviewError(previewFailure);
615
+ console.warn("Preview quote failed:", previewFailure);
599
616
  } finally {
600
617
  if (previewAbortRef.current === controller) {
601
618
  previewAbortRef.current = null;
@@ -731,6 +748,7 @@ function useUniportPayment(options) {
731
748
  setIsLoadingPreview(false);
732
749
  setStatus(null);
733
750
  setError(null);
751
+ setPreviewError(null);
734
752
  setSelectedChain(null);
735
753
  setSelectedToken(null);
736
754
  setAmountState(initialAmount ?? "");
@@ -761,6 +779,7 @@ function useUniportPayment(options) {
761
779
  paymentState,
762
780
  quote,
763
781
  previewQuote,
782
+ previewError,
764
783
  isLoadingPreview,
765
784
  status,
766
785
  error,
@@ -966,6 +985,55 @@ function WarningTriangle({ color }) {
966
985
  /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "17", x2: "12.01", y2: "17", stroke: color, strokeWidth: "2", strokeLinecap: "round" })
967
986
  ] });
968
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
+ }
969
1037
  function UniportModal({
970
1038
  open,
971
1039
  onClose,
@@ -1035,6 +1103,7 @@ function UniportModal({
1035
1103
  const isError = paymentState === "error";
1036
1104
  const isQuoting = paymentState === "quoting";
1037
1105
  const canSubmit = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1106
+ const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
1038
1107
  const showBack = !isSuccess && !isError && (showQR || modalStep !== "chain");
1039
1108
  const iconBtn = {
1040
1109
  width: 36,
@@ -1319,22 +1388,28 @@ function UniportModal({
1319
1388
  gap: 5,
1320
1389
  marginBottom: "20px"
1321
1390
  }, children: [
1322
- payment.amount && payment.isLoadingPreview && [0, 0.2, 0.4].map((delay, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1391
+ canPreviewEstimate && payment.isLoadingPreview && [0, 0.2, 0.4].map((delay, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1323
1392
  width: 6,
1324
1393
  height: 6,
1325
1394
  borderRadius: "50%",
1326
1395
  background: t.accent,
1327
1396
  animation: `uniport-pulse 1s ease infinite ${delay}s`
1328
1397
  } }, i)),
1329
- payment.amount && !payment.isLoadingPreview && payment.previewQuote && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontSize: "15px", color: t.textSecondary }, children: [
1330
- "\u2248 ",
1398
+ canPreviewEstimate && !payment.isLoadingPreview && payment.previewQuote && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontSize: "15px", color: t.textSecondary }, children: [
1399
+ "You will receive",
1400
+ " ",
1331
1401
  /* @__PURE__ */ jsxRuntime.jsxs("strong", { style: { color: t.text }, children: [
1332
1402
  payment.previewQuote.amountOutFormatted,
1333
1403
  " ",
1334
1404
  payment.destinationToken.symbol
1335
- ] })
1405
+ ] }),
1406
+ " ",
1407
+ "on",
1408
+ " ",
1409
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { style: { color: t.text }, children: formatChainLabel(payment.destinationToken.chain) })
1336
1410
  ] }),
1337
- payment.amount && !payment.isLoadingPreview && !payment.previewQuote && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "Fetching estimate\u2026" })
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" })
1338
1413
  ] }),
1339
1414
  !!payment.amount && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...warningBox, marginBottom: "20px" }, children: [
1340
1415
  /* @__PURE__ */ jsxRuntime.jsx(WarningTriangle, { color: t.warning }),