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/README.md +1 -17
- package/dist/components/index.cjs +180 -69
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +180 -69
- package/dist/components/index.js.map +1 -1
- package/dist/core/index.cjs +20 -7
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +3 -4
- package/dist/core/index.d.ts +3 -4
- package/dist/core/index.js +20 -7
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +180 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +180 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1330
|
-
"
|
|
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
|
-
|
|
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 }),
|
|
@@ -1699,62 +1774,101 @@ function UniportModal({
|
|
|
1699
1774
|
portalRoot
|
|
1700
1775
|
);
|
|
1701
1776
|
}
|
|
1777
|
+
var sharedButtonStyle = {
|
|
1778
|
+
display: "inline-flex",
|
|
1779
|
+
alignItems: "center",
|
|
1780
|
+
justifyContent: "center",
|
|
1781
|
+
cursor: "pointer",
|
|
1782
|
+
transition: "all 0.2s ease",
|
|
1783
|
+
fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1784
|
+
};
|
|
1702
1785
|
var buttonStyles = {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
alignItems: "center",
|
|
1740
|
-
justifyContent: "center",
|
|
1741
|
-
gap: "8px",
|
|
1742
|
-
padding: "12px 24px",
|
|
1743
|
-
fontSize: "14px",
|
|
1744
|
-
fontWeight: 500,
|
|
1745
|
-
color: "#4F46E5",
|
|
1746
|
-
background: "transparent",
|
|
1747
|
-
border: "2px solid #4F46E5",
|
|
1748
|
-
borderRadius: "12px",
|
|
1749
|
-
cursor: "pointer",
|
|
1750
|
-
transition: "all 0.2s ease",
|
|
1751
|
-
fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1786
|
+
light: {
|
|
1787
|
+
default: {
|
|
1788
|
+
...sharedButtonStyle,
|
|
1789
|
+
gap: "8px",
|
|
1790
|
+
padding: "12px 24px",
|
|
1791
|
+
fontSize: "14px",
|
|
1792
|
+
fontWeight: 600,
|
|
1793
|
+
color: "#ffffff",
|
|
1794
|
+
background: "#1c1c1e",
|
|
1795
|
+
border: "1px solid #1c1c1e",
|
|
1796
|
+
borderRadius: "12px",
|
|
1797
|
+
boxShadow: "0 8px 24px rgba(28, 28, 30, 0.18)"
|
|
1798
|
+
},
|
|
1799
|
+
compact: {
|
|
1800
|
+
...sharedButtonStyle,
|
|
1801
|
+
gap: "6px",
|
|
1802
|
+
padding: "8px 16px",
|
|
1803
|
+
fontSize: "13px",
|
|
1804
|
+
fontWeight: 600,
|
|
1805
|
+
color: "#ffffff",
|
|
1806
|
+
background: "#1c1c1e",
|
|
1807
|
+
border: "1px solid #1c1c1e",
|
|
1808
|
+
borderRadius: "8px",
|
|
1809
|
+
boxShadow: "0 6px 18px rgba(28, 28, 30, 0.16)"
|
|
1810
|
+
},
|
|
1811
|
+
outline: {
|
|
1812
|
+
...sharedButtonStyle,
|
|
1813
|
+
gap: "8px",
|
|
1814
|
+
padding: "12px 24px",
|
|
1815
|
+
fontSize: "14px",
|
|
1816
|
+
fontWeight: 600,
|
|
1817
|
+
color: "#1c1c1e",
|
|
1818
|
+
background: "transparent",
|
|
1819
|
+
border: "1px solid #1c1c1e",
|
|
1820
|
+
borderRadius: "12px"
|
|
1821
|
+
}
|
|
1752
1822
|
},
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1823
|
+
dark: {
|
|
1824
|
+
default: {
|
|
1825
|
+
...sharedButtonStyle,
|
|
1826
|
+
gap: "8px",
|
|
1827
|
+
padding: "12px 24px",
|
|
1828
|
+
fontSize: "14px",
|
|
1829
|
+
fontWeight: 600,
|
|
1830
|
+
color: "#111113",
|
|
1831
|
+
background: "#ffffff",
|
|
1832
|
+
border: "1px solid rgba(255, 255, 255, 0.9)",
|
|
1833
|
+
borderRadius: "12px",
|
|
1834
|
+
boxShadow: "0 8px 24px rgba(0, 0, 0, 0.32)"
|
|
1835
|
+
},
|
|
1836
|
+
compact: {
|
|
1837
|
+
...sharedButtonStyle,
|
|
1838
|
+
gap: "6px",
|
|
1839
|
+
padding: "8px 16px",
|
|
1840
|
+
fontSize: "13px",
|
|
1841
|
+
fontWeight: 600,
|
|
1842
|
+
color: "#111113",
|
|
1843
|
+
background: "#ffffff",
|
|
1844
|
+
border: "1px solid rgba(255, 255, 255, 0.9)",
|
|
1845
|
+
borderRadius: "8px",
|
|
1846
|
+
boxShadow: "0 6px 18px rgba(0, 0, 0, 0.28)"
|
|
1847
|
+
},
|
|
1848
|
+
outline: {
|
|
1849
|
+
...sharedButtonStyle,
|
|
1850
|
+
gap: "8px",
|
|
1851
|
+
padding: "12px 24px",
|
|
1852
|
+
fontSize: "14px",
|
|
1853
|
+
fontWeight: 600,
|
|
1854
|
+
color: "#ffffff",
|
|
1855
|
+
background: "transparent",
|
|
1856
|
+
border: "1px solid rgba(255, 255, 255, 0.72)",
|
|
1857
|
+
borderRadius: "12px"
|
|
1858
|
+
}
|
|
1756
1859
|
}
|
|
1757
1860
|
};
|
|
1861
|
+
var disabledButtonStyle = {
|
|
1862
|
+
opacity: 0.5,
|
|
1863
|
+
cursor: "not-allowed",
|
|
1864
|
+
boxShadow: "none"
|
|
1865
|
+
};
|
|
1866
|
+
function getButtonStyle(variant, theme, disabled) {
|
|
1867
|
+
return {
|
|
1868
|
+
...buttonStyles[theme][variant],
|
|
1869
|
+
...disabled ? disabledButtonStyle : {}
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1758
1872
|
function UniportButton({
|
|
1759
1873
|
recipient,
|
|
1760
1874
|
refundAddress,
|
|
@@ -1780,10 +1894,7 @@ function UniportButton({
|
|
|
1780
1894
|
setIsOpen(false);
|
|
1781
1895
|
onOpenChange?.(false);
|
|
1782
1896
|
};
|
|
1783
|
-
const style =
|
|
1784
|
-
...buttonStyles[variant],
|
|
1785
|
-
...disabled ? buttonStyles.disabled : {}
|
|
1786
|
-
};
|
|
1897
|
+
const style = getButtonStyle(variant, theme, disabled);
|
|
1787
1898
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1788
1899
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1789
1900
|
"button",
|