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/dist/index.cjs
CHANGED
|
@@ -116,6 +116,7 @@ var TOKEN_NAME_PREFIXES = {
|
|
|
116
116
|
op: "optimism",
|
|
117
117
|
sol: "solana",
|
|
118
118
|
btc: "bitcoin",
|
|
119
|
+
pol: "polygon",
|
|
119
120
|
avax: "avalanche",
|
|
120
121
|
doge: "dogecoin",
|
|
121
122
|
ltc: "litecoin",
|
|
@@ -361,11 +362,6 @@ var configuredRequestTimeoutMs;
|
|
|
361
362
|
function normalizeBackendUrl(url) {
|
|
362
363
|
return url.replace(/\/+$/, "");
|
|
363
364
|
}
|
|
364
|
-
function getLegacyBackendOverride() {
|
|
365
|
-
const envBackendUrl = typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_UNIPORT_BACKEND_URL : void 0;
|
|
366
|
-
const windowBackendUrl = typeof window !== "undefined" ? window.__UNIPORT_BACKEND_URL__ : void 0;
|
|
367
|
-
return envBackendUrl || windowBackendUrl;
|
|
368
|
-
}
|
|
369
365
|
function configureUniport(config) {
|
|
370
366
|
if (config.backendUrl !== void 0) {
|
|
371
367
|
configuredBackendUrl = config.backendUrl ? normalizeBackendUrl(config.backendUrl) : void 0;
|
|
@@ -375,7 +371,7 @@ function configureUniport(config) {
|
|
|
375
371
|
}
|
|
376
372
|
}
|
|
377
373
|
function getUniportConfig() {
|
|
378
|
-
const backendUrl = configuredBackendUrl ||
|
|
374
|
+
const backendUrl = configuredBackendUrl || DEFAULT_HOSTED_BACKEND_URL;
|
|
379
375
|
return {
|
|
380
376
|
backendUrl: normalizeBackendUrl(backendUrl),
|
|
381
377
|
requestTimeoutMs: configuredRequestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
|
|
@@ -395,10 +391,27 @@ var UniportError = class extends Error {
|
|
|
395
391
|
function isAbortError(error) {
|
|
396
392
|
return error instanceof Error && error.name === "AbortError";
|
|
397
393
|
}
|
|
394
|
+
function extractDetailMessage(details) {
|
|
395
|
+
if (typeof details === "string" && details.trim()) {
|
|
396
|
+
return details;
|
|
397
|
+
}
|
|
398
|
+
if (Array.isArray(details)) {
|
|
399
|
+
const firstString = details.find(
|
|
400
|
+
(detail) => typeof detail === "string" && detail.trim().length > 0
|
|
401
|
+
);
|
|
402
|
+
return firstString;
|
|
403
|
+
}
|
|
404
|
+
if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
|
|
405
|
+
const message = details.message.trim();
|
|
406
|
+
return message || void 0;
|
|
407
|
+
}
|
|
408
|
+
return void 0;
|
|
409
|
+
}
|
|
398
410
|
function toUniportError(body, fallback) {
|
|
411
|
+
const detailMessage = extractDetailMessage(body.details);
|
|
399
412
|
return new UniportError({
|
|
400
413
|
code: body.code || fallback.code,
|
|
401
|
-
message: body.message || fallback.message,
|
|
414
|
+
message: detailMessage || body.message || fallback.message,
|
|
402
415
|
details: body.details,
|
|
403
416
|
status: fallback.status
|
|
404
417
|
});
|
|
@@ -618,6 +631,7 @@ function useUniportPayment(options) {
|
|
|
618
631
|
const [paymentState, setPaymentState] = react.useState("idle");
|
|
619
632
|
const [quote, setQuote] = react.useState(null);
|
|
620
633
|
const [previewQuote, setPreviewQuote] = react.useState(null);
|
|
634
|
+
const [previewError, setPreviewError] = react.useState(null);
|
|
621
635
|
const [isLoadingPreview, setIsLoadingPreview] = react.useState(false);
|
|
622
636
|
const [status, setStatus] = react.useState(null);
|
|
623
637
|
const [error, setError] = react.useState(null);
|
|
@@ -636,6 +650,7 @@ function useUniportPayment(options) {
|
|
|
636
650
|
const schedulePreviewQuote = react.useCallback(
|
|
637
651
|
(nextAmount, nextRefundAddress, nextSelectedToken) => {
|
|
638
652
|
setPreviewQuote(null);
|
|
653
|
+
setPreviewError(null);
|
|
639
654
|
if (previewDebounceRef.current) {
|
|
640
655
|
clearTimeout(previewDebounceRef.current);
|
|
641
656
|
}
|
|
@@ -666,7 +681,9 @@ function useUniportPayment(options) {
|
|
|
666
681
|
if (err instanceof Error && err.name === "AbortError") {
|
|
667
682
|
return;
|
|
668
683
|
}
|
|
669
|
-
|
|
684
|
+
const previewFailure = err instanceof Error ? err : new Error("Failed to fetch estimate");
|
|
685
|
+
setPreviewError(previewFailure);
|
|
686
|
+
console.warn("Preview quote failed:", previewFailure);
|
|
670
687
|
} finally {
|
|
671
688
|
if (previewAbortRef.current === controller) {
|
|
672
689
|
previewAbortRef.current = null;
|
|
@@ -802,6 +819,7 @@ function useUniportPayment(options) {
|
|
|
802
819
|
setIsLoadingPreview(false);
|
|
803
820
|
setStatus(null);
|
|
804
821
|
setError(null);
|
|
822
|
+
setPreviewError(null);
|
|
805
823
|
setSelectedChain(null);
|
|
806
824
|
setSelectedToken(null);
|
|
807
825
|
setAmountState(initialAmount ?? "");
|
|
@@ -832,6 +850,7 @@ function useUniportPayment(options) {
|
|
|
832
850
|
paymentState,
|
|
833
851
|
quote,
|
|
834
852
|
previewQuote,
|
|
853
|
+
previewError,
|
|
835
854
|
isLoadingPreview,
|
|
836
855
|
status,
|
|
837
856
|
error,
|
|
@@ -1037,6 +1056,55 @@ function WarningTriangle({ color }) {
|
|
|
1037
1056
|
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "17", x2: "12.01", y2: "17", stroke: color, strokeWidth: "2", strokeLinecap: "round" })
|
|
1038
1057
|
] });
|
|
1039
1058
|
}
|
|
1059
|
+
function formatPreviewError(error) {
|
|
1060
|
+
if (error.name === "AbortError") {
|
|
1061
|
+
return "Estimate request was cancelled. Try again.";
|
|
1062
|
+
}
|
|
1063
|
+
if (error.message === "Quote request timed out") {
|
|
1064
|
+
return "Could not fetch estimate. Please try again.";
|
|
1065
|
+
}
|
|
1066
|
+
const normalized = error.message.toLowerCase();
|
|
1067
|
+
if (normalized.includes("recipient is not valid")) {
|
|
1068
|
+
return "Recipient address does not match the selected destination chain.";
|
|
1069
|
+
}
|
|
1070
|
+
if (normalized.includes("refund") && normalized.includes("valid")) {
|
|
1071
|
+
return "Refund address does not match the source chain.";
|
|
1072
|
+
}
|
|
1073
|
+
if (normalized.includes("amount")) {
|
|
1074
|
+
return "Enter a valid amount to fetch an estimate.";
|
|
1075
|
+
}
|
|
1076
|
+
return "Could not fetch estimate. Check the details and try again.";
|
|
1077
|
+
}
|
|
1078
|
+
function formatChainLabel(chainId) {
|
|
1079
|
+
const labels = {
|
|
1080
|
+
sui: "Sui",
|
|
1081
|
+
eth: "Ethereum",
|
|
1082
|
+
sol: "Solana",
|
|
1083
|
+
arb: "Arbitrum",
|
|
1084
|
+
base: "Base",
|
|
1085
|
+
op: "Optimism",
|
|
1086
|
+
pol: "Polygon",
|
|
1087
|
+
avax: "Avalanche",
|
|
1088
|
+
bsc: "BNB Chain",
|
|
1089
|
+
near: "NEAR",
|
|
1090
|
+
btc: "Bitcoin",
|
|
1091
|
+
ton: "TON",
|
|
1092
|
+
tron: "Tron",
|
|
1093
|
+
stellar: "Stellar",
|
|
1094
|
+
cardano: "Cardano",
|
|
1095
|
+
xrp: "XRP Ledger",
|
|
1096
|
+
doge: "Dogecoin",
|
|
1097
|
+
ltc: "Litecoin",
|
|
1098
|
+
bch: "Bitcoin Cash",
|
|
1099
|
+
aptos: "Aptos",
|
|
1100
|
+
starknet: "Starknet",
|
|
1101
|
+
bera: "Berachain",
|
|
1102
|
+
zec: "Zcash",
|
|
1103
|
+
gnosis: "Gnosis",
|
|
1104
|
+
monad: "Monad"
|
|
1105
|
+
};
|
|
1106
|
+
return labels[chainId] || chainId.toUpperCase();
|
|
1107
|
+
}
|
|
1040
1108
|
function UniportModal({
|
|
1041
1109
|
open,
|
|
1042
1110
|
onClose,
|
|
@@ -1106,6 +1174,7 @@ function UniportModal({
|
|
|
1106
1174
|
const isError = paymentState === "error";
|
|
1107
1175
|
const isQuoting = paymentState === "quoting";
|
|
1108
1176
|
const canSubmit = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
|
|
1177
|
+
const canPreviewEstimate = !!(payment.selectedToken && payment.amount && payment.refundAddress.trim());
|
|
1109
1178
|
const showBack = !isSuccess && !isError && (showQR || modalStep !== "chain");
|
|
1110
1179
|
const iconBtn = {
|
|
1111
1180
|
width: 36,
|
|
@@ -1390,22 +1459,28 @@ function UniportModal({
|
|
|
1390
1459
|
gap: 5,
|
|
1391
1460
|
marginBottom: "20px"
|
|
1392
1461
|
}, children: [
|
|
1393
|
-
|
|
1462
|
+
canPreviewEstimate && payment.isLoadingPreview && [0, 0.2, 0.4].map((delay, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
1394
1463
|
width: 6,
|
|
1395
1464
|
height: 6,
|
|
1396
1465
|
borderRadius: "50%",
|
|
1397
1466
|
background: t.accent,
|
|
1398
1467
|
animation: `uniport-pulse 1s ease infinite ${delay}s`
|
|
1399
1468
|
} }, i)),
|
|
1400
|
-
|
|
1401
|
-
"
|
|
1469
|
+
canPreviewEstimate && !payment.isLoadingPreview && payment.previewQuote && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontSize: "15px", color: t.textSecondary }, children: [
|
|
1470
|
+
"You will receive",
|
|
1471
|
+
" ",
|
|
1402
1472
|
/* @__PURE__ */ jsxRuntime.jsxs("strong", { style: { color: t.text }, children: [
|
|
1403
1473
|
payment.previewQuote.amountOutFormatted,
|
|
1404
1474
|
" ",
|
|
1405
1475
|
payment.destinationToken.symbol
|
|
1406
|
-
] })
|
|
1476
|
+
] }),
|
|
1477
|
+
" ",
|
|
1478
|
+
"on",
|
|
1479
|
+
" ",
|
|
1480
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { style: { color: t.text }, children: formatChainLabel(payment.destinationToken.chain) })
|
|
1407
1481
|
] }),
|
|
1408
|
-
|
|
1482
|
+
canPreviewEstimate && !payment.isLoadingPreview && payment.previewError && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "13px", color: t.error }, children: formatPreviewError(payment.previewError) }),
|
|
1483
|
+
canPreviewEstimate && !payment.isLoadingPreview && !payment.previewQuote && !payment.previewError && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "Fetching estimate\u2026" })
|
|
1409
1484
|
] }),
|
|
1410
1485
|
!!payment.amount && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...warningBox, marginBottom: "20px" }, children: [
|
|
1411
1486
|
/* @__PURE__ */ jsxRuntime.jsx(WarningTriangle, { color: t.warning }),
|
|
@@ -1770,62 +1845,101 @@ function UniportModal({
|
|
|
1770
1845
|
portalRoot
|
|
1771
1846
|
);
|
|
1772
1847
|
}
|
|
1848
|
+
var sharedButtonStyle = {
|
|
1849
|
+
display: "inline-flex",
|
|
1850
|
+
alignItems: "center",
|
|
1851
|
+
justifyContent: "center",
|
|
1852
|
+
cursor: "pointer",
|
|
1853
|
+
transition: "all 0.2s ease",
|
|
1854
|
+
fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1855
|
+
};
|
|
1773
1856
|
var buttonStyles = {
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
alignItems: "center",
|
|
1811
|
-
justifyContent: "center",
|
|
1812
|
-
gap: "8px",
|
|
1813
|
-
padding: "12px 24px",
|
|
1814
|
-
fontSize: "14px",
|
|
1815
|
-
fontWeight: 500,
|
|
1816
|
-
color: "#4F46E5",
|
|
1817
|
-
background: "transparent",
|
|
1818
|
-
border: "2px solid #4F46E5",
|
|
1819
|
-
borderRadius: "12px",
|
|
1820
|
-
cursor: "pointer",
|
|
1821
|
-
transition: "all 0.2s ease",
|
|
1822
|
-
fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1857
|
+
light: {
|
|
1858
|
+
default: {
|
|
1859
|
+
...sharedButtonStyle,
|
|
1860
|
+
gap: "8px",
|
|
1861
|
+
padding: "12px 24px",
|
|
1862
|
+
fontSize: "14px",
|
|
1863
|
+
fontWeight: 600,
|
|
1864
|
+
color: "#ffffff",
|
|
1865
|
+
background: "#1c1c1e",
|
|
1866
|
+
border: "1px solid #1c1c1e",
|
|
1867
|
+
borderRadius: "12px",
|
|
1868
|
+
boxShadow: "0 8px 24px rgba(28, 28, 30, 0.18)"
|
|
1869
|
+
},
|
|
1870
|
+
compact: {
|
|
1871
|
+
...sharedButtonStyle,
|
|
1872
|
+
gap: "6px",
|
|
1873
|
+
padding: "8px 16px",
|
|
1874
|
+
fontSize: "13px",
|
|
1875
|
+
fontWeight: 600,
|
|
1876
|
+
color: "#ffffff",
|
|
1877
|
+
background: "#1c1c1e",
|
|
1878
|
+
border: "1px solid #1c1c1e",
|
|
1879
|
+
borderRadius: "8px",
|
|
1880
|
+
boxShadow: "0 6px 18px rgba(28, 28, 30, 0.16)"
|
|
1881
|
+
},
|
|
1882
|
+
outline: {
|
|
1883
|
+
...sharedButtonStyle,
|
|
1884
|
+
gap: "8px",
|
|
1885
|
+
padding: "12px 24px",
|
|
1886
|
+
fontSize: "14px",
|
|
1887
|
+
fontWeight: 600,
|
|
1888
|
+
color: "#1c1c1e",
|
|
1889
|
+
background: "transparent",
|
|
1890
|
+
border: "1px solid #1c1c1e",
|
|
1891
|
+
borderRadius: "12px"
|
|
1892
|
+
}
|
|
1823
1893
|
},
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1894
|
+
dark: {
|
|
1895
|
+
default: {
|
|
1896
|
+
...sharedButtonStyle,
|
|
1897
|
+
gap: "8px",
|
|
1898
|
+
padding: "12px 24px",
|
|
1899
|
+
fontSize: "14px",
|
|
1900
|
+
fontWeight: 600,
|
|
1901
|
+
color: "#111113",
|
|
1902
|
+
background: "#ffffff",
|
|
1903
|
+
border: "1px solid rgba(255, 255, 255, 0.9)",
|
|
1904
|
+
borderRadius: "12px",
|
|
1905
|
+
boxShadow: "0 8px 24px rgba(0, 0, 0, 0.32)"
|
|
1906
|
+
},
|
|
1907
|
+
compact: {
|
|
1908
|
+
...sharedButtonStyle,
|
|
1909
|
+
gap: "6px",
|
|
1910
|
+
padding: "8px 16px",
|
|
1911
|
+
fontSize: "13px",
|
|
1912
|
+
fontWeight: 600,
|
|
1913
|
+
color: "#111113",
|
|
1914
|
+
background: "#ffffff",
|
|
1915
|
+
border: "1px solid rgba(255, 255, 255, 0.9)",
|
|
1916
|
+
borderRadius: "8px",
|
|
1917
|
+
boxShadow: "0 6px 18px rgba(0, 0, 0, 0.28)"
|
|
1918
|
+
},
|
|
1919
|
+
outline: {
|
|
1920
|
+
...sharedButtonStyle,
|
|
1921
|
+
gap: "8px",
|
|
1922
|
+
padding: "12px 24px",
|
|
1923
|
+
fontSize: "14px",
|
|
1924
|
+
fontWeight: 600,
|
|
1925
|
+
color: "#ffffff",
|
|
1926
|
+
background: "transparent",
|
|
1927
|
+
border: "1px solid rgba(255, 255, 255, 0.72)",
|
|
1928
|
+
borderRadius: "12px"
|
|
1929
|
+
}
|
|
1827
1930
|
}
|
|
1828
1931
|
};
|
|
1932
|
+
var disabledButtonStyle = {
|
|
1933
|
+
opacity: 0.5,
|
|
1934
|
+
cursor: "not-allowed",
|
|
1935
|
+
boxShadow: "none"
|
|
1936
|
+
};
|
|
1937
|
+
function getButtonStyle(variant, theme, disabled) {
|
|
1938
|
+
return {
|
|
1939
|
+
...buttonStyles[theme][variant],
|
|
1940
|
+
...disabled ? disabledButtonStyle : {}
|
|
1941
|
+
};
|
|
1942
|
+
}
|
|
1829
1943
|
function UniportButton({
|
|
1830
1944
|
recipient,
|
|
1831
1945
|
refundAddress,
|
|
@@ -1851,10 +1965,7 @@ function UniportButton({
|
|
|
1851
1965
|
setIsOpen(false);
|
|
1852
1966
|
onOpenChange?.(false);
|
|
1853
1967
|
};
|
|
1854
|
-
const style =
|
|
1855
|
-
...buttonStyles[variant],
|
|
1856
|
-
...disabled ? buttonStyles.disabled : {}
|
|
1857
|
-
};
|
|
1968
|
+
const style = getButtonStyle(variant, theme, disabled);
|
|
1858
1969
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1859
1970
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1860
1971
|
"button",
|