uniport-sdk 0.0.5 → 0.0.7
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 +34 -0
- package/dist/components/index.cjs +313 -221
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +313 -221
- package/dist/components/index.js.map +1 -1
- package/dist/core/index.cjs +49 -13
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +30 -1
- package/dist/core/index.d.ts +30 -1
- package/dist/core/index.js +43 -14
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +129 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +123 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,197 +11,6 @@ var ReactDOM__default = /*#__PURE__*/_interopDefault(ReactDOM);
|
|
|
11
11
|
|
|
12
12
|
// src/components/UniportButton.tsx
|
|
13
13
|
|
|
14
|
-
// src/core/config.ts
|
|
15
|
-
var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
|
|
16
|
-
var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
|
|
17
|
-
function normalizeBackendUrl(url) {
|
|
18
|
-
return url.replace(/\/+$/, "");
|
|
19
|
-
}
|
|
20
|
-
function getUniportConfig() {
|
|
21
|
-
const backendUrl = DEFAULT_HOSTED_BACKEND_URL;
|
|
22
|
-
return {
|
|
23
|
-
backendUrl: normalizeBackendUrl(backendUrl),
|
|
24
|
-
requestTimeoutMs: DEFAULT_REQUEST_TIMEOUT_MS
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// src/core/intents.ts
|
|
29
|
-
var UniportError = class extends Error {
|
|
30
|
-
constructor(params) {
|
|
31
|
-
super(params.message);
|
|
32
|
-
this.name = "UniportError";
|
|
33
|
-
this.code = params.code;
|
|
34
|
-
this.details = params.details;
|
|
35
|
-
this.status = params.status;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
function isAbortError(error) {
|
|
39
|
-
return error instanceof Error && error.name === "AbortError";
|
|
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
|
-
}
|
|
57
|
-
function toUniportError(body, fallback) {
|
|
58
|
-
const detailMessage = extractDetailMessage(body.details);
|
|
59
|
-
return new UniportError({
|
|
60
|
-
code: body.code || fallback.code,
|
|
61
|
-
message: detailMessage || body.message || fallback.message,
|
|
62
|
-
details: body.details,
|
|
63
|
-
status: fallback.status
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function createTimeoutSignal(timeoutMs, externalSignal) {
|
|
67
|
-
const controller = new AbortController();
|
|
68
|
-
let timedOut = false;
|
|
69
|
-
const timeoutId = setTimeout(() => {
|
|
70
|
-
timedOut = true;
|
|
71
|
-
controller.abort();
|
|
72
|
-
}, timeoutMs);
|
|
73
|
-
const abortFromExternal = () => controller.abort();
|
|
74
|
-
externalSignal?.addEventListener("abort", abortFromExternal, {
|
|
75
|
-
once: true
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
signal: controller.signal,
|
|
79
|
-
didTimeout: () => timedOut,
|
|
80
|
-
cleanup: () => {
|
|
81
|
-
clearTimeout(timeoutId);
|
|
82
|
-
externalSignal?.removeEventListener("abort", abortFromExternal);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function toSmallestUnits(amount, decimals) {
|
|
87
|
-
const [whole, fraction = ""] = amount.split(".");
|
|
88
|
-
const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
|
|
89
|
-
return `${whole}${paddedFraction}`.replace(/^0+/, "") || "0";
|
|
90
|
-
}
|
|
91
|
-
function generateDeadline(hoursFromNow = 1) {
|
|
92
|
-
const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
|
|
93
|
-
return deadline.toISOString();
|
|
94
|
-
}
|
|
95
|
-
async function getQuote(options) {
|
|
96
|
-
const {
|
|
97
|
-
originToken,
|
|
98
|
-
destinationToken,
|
|
99
|
-
amount,
|
|
100
|
-
recipient,
|
|
101
|
-
refundTo,
|
|
102
|
-
slippageTolerance = 100,
|
|
103
|
-
// 1% default
|
|
104
|
-
swapType = "EXACT_INPUT",
|
|
105
|
-
deadline,
|
|
106
|
-
dry = false,
|
|
107
|
-
referral = "uniport",
|
|
108
|
-
signal
|
|
109
|
-
} = options;
|
|
110
|
-
const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
|
|
111
|
-
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
112
|
-
const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
|
|
113
|
-
requestTimeoutMs,
|
|
114
|
-
signal
|
|
115
|
-
);
|
|
116
|
-
let response;
|
|
117
|
-
try {
|
|
118
|
-
response = await fetch(`${backendUrl}/api/quote`, {
|
|
119
|
-
method: "POST",
|
|
120
|
-
headers: { "Content-Type": "application/json" },
|
|
121
|
-
signal: requestSignal,
|
|
122
|
-
body: JSON.stringify({
|
|
123
|
-
dry,
|
|
124
|
-
swapType,
|
|
125
|
-
slippageTolerance,
|
|
126
|
-
originAsset: originToken.assetId,
|
|
127
|
-
destinationAsset: destinationToken.assetId,
|
|
128
|
-
amount: amountInSmallestUnits,
|
|
129
|
-
refundTo,
|
|
130
|
-
recipient,
|
|
131
|
-
deadline: deadline?.toISOString() || generateDeadline(1),
|
|
132
|
-
referral
|
|
133
|
-
})
|
|
134
|
-
});
|
|
135
|
-
} catch (error) {
|
|
136
|
-
cleanup();
|
|
137
|
-
if (isAbortError(error)) {
|
|
138
|
-
if (signal?.aborted && !didTimeout()) {
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
throw new UniportError({
|
|
142
|
-
code: "REQUEST_TIMEOUT",
|
|
143
|
-
message: "Quote request timed out"
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
cleanup();
|
|
149
|
-
if (!response.ok) {
|
|
150
|
-
const errorBody = await response.json().catch(() => ({}));
|
|
151
|
-
throw toUniportError(errorBody, {
|
|
152
|
-
code: "QUOTE_FAILED",
|
|
153
|
-
message: "Quote failed.",
|
|
154
|
-
status: response.status
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
const data = await response.json();
|
|
158
|
-
const quote = data.quote;
|
|
159
|
-
return {
|
|
160
|
-
depositAddress: quote.depositAddress || "",
|
|
161
|
-
memo: quote.depositMemo,
|
|
162
|
-
amountIn: quote.amountIn,
|
|
163
|
-
amountOut: quote.amountOut,
|
|
164
|
-
amountOutFormatted: quote.amountOutFormatted,
|
|
165
|
-
amountOutUsd: quote.amountOutUsd,
|
|
166
|
-
deadline: quote.deadline,
|
|
167
|
-
timeWhenInactive: quote.timeWhenInactive,
|
|
168
|
-
correlationId: data.correlationId
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
async function getExecutionStatus(depositAddress, memo) {
|
|
172
|
-
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
173
|
-
const url = new URL(
|
|
174
|
-
`${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
|
|
175
|
-
);
|
|
176
|
-
if (memo) {
|
|
177
|
-
url.searchParams.set("memo", memo);
|
|
178
|
-
}
|
|
179
|
-
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
180
|
-
let response;
|
|
181
|
-
try {
|
|
182
|
-
response = await fetch(url.toString(), { signal });
|
|
183
|
-
} catch (error) {
|
|
184
|
-
cleanup();
|
|
185
|
-
if (isAbortError(error)) {
|
|
186
|
-
throw new UniportError({
|
|
187
|
-
code: "REQUEST_TIMEOUT",
|
|
188
|
-
message: "Status check timed out"
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
throw error;
|
|
192
|
-
}
|
|
193
|
-
cleanup();
|
|
194
|
-
if (!response.ok) {
|
|
195
|
-
const errorBody = await response.json().catch(() => ({}));
|
|
196
|
-
throw toUniportError(errorBody, {
|
|
197
|
-
code: "STATUS_CHECK_FAILED",
|
|
198
|
-
message: "Status check failed.",
|
|
199
|
-
status: response.status
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
return await response.json();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
14
|
// src/core/tokens.ts
|
|
206
15
|
var TOKEN_ICONS = {
|
|
207
16
|
// Stablecoins
|
|
@@ -278,7 +87,8 @@ var CHAIN_ICONS = {
|
|
|
278
87
|
ltc: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/litecoin/info/logo.png",
|
|
279
88
|
bch: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoincash/info/logo.png",
|
|
280
89
|
xrp: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ripple/info/logo.png",
|
|
281
|
-
zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png"
|
|
90
|
+
zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png",
|
|
91
|
+
scroll: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/scroll/info/logo.png"
|
|
282
92
|
};
|
|
283
93
|
var EVM_CHAINS = [
|
|
284
94
|
"eth",
|
|
@@ -290,11 +100,16 @@ var EVM_CHAINS = [
|
|
|
290
100
|
"bsc",
|
|
291
101
|
"gnosis",
|
|
292
102
|
"bera",
|
|
293
|
-
"monad"
|
|
103
|
+
"monad",
|
|
104
|
+
"scroll"
|
|
294
105
|
];
|
|
295
106
|
function isEvmChain(chain) {
|
|
296
107
|
return EVM_CHAINS.includes(chain);
|
|
297
108
|
}
|
|
109
|
+
var CHAINS_REQUIRING_MEMO = ["stellar"];
|
|
110
|
+
function needsMemoDeposit(chain) {
|
|
111
|
+
return CHAINS_REQUIRING_MEMO.includes(chain);
|
|
112
|
+
}
|
|
298
113
|
var EXPLORER_TX_URLS = {
|
|
299
114
|
eth: (h) => `https://etherscan.io/tx/${h}`,
|
|
300
115
|
arb: (h) => `https://arbiscan.io/tx/${h}`,
|
|
@@ -320,7 +135,8 @@ var EXPLORER_TX_URLS = {
|
|
|
320
135
|
ltc: (h) => `https://litecoinspace.org/tx/${h}`,
|
|
321
136
|
bch: (h) => `https://blockchair.com/bitcoin-cash/transaction/${h}`,
|
|
322
137
|
xrp: (h) => `https://xrpscan.com/tx/${h}`,
|
|
323
|
-
zec: (h) => `https://blockchair.com/zcash/transaction/${h}
|
|
138
|
+
zec: (h) => `https://blockchair.com/zcash/transaction/${h}`,
|
|
139
|
+
scroll: (h) => `https://scrollscan.com/tx/${h}`
|
|
324
140
|
};
|
|
325
141
|
function getExplorerTxUrl(chain, hash) {
|
|
326
142
|
return EXPLORER_TX_URLS[chain]?.(hash);
|
|
@@ -385,6 +201,8 @@ var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
|
|
|
385
201
|
var baseUSDC = createToken("base", "USDC", "nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near", 6, "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913");
|
|
386
202
|
var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
|
|
387
203
|
var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
|
|
204
|
+
var scrollETH = createToken("scroll", "ETH", "nep245:v2_1.omni.hot.tg:534352_11111111111111111111", 18);
|
|
205
|
+
var scrollUSDT = createToken("scroll", "USDT", "nep245:v2_1.omni.hot.tg:534352_4RG3Q2wFsMQmd45m5m89RjsLfupA", 6, "0xf55bec9cafdbe8730f096aa55dad6d22d44099df");
|
|
388
206
|
var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
|
|
389
207
|
var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
|
|
390
208
|
var optimismUSDT = createToken("op", "USDT", "nep245:v2_1.omni.hot.tg:10_359RPSJVdTxwTJT9TyGssr2rFoWo", 6, "0x94b008aa00579c1307b0ef2c499ad98a8ce58e58");
|
|
@@ -418,6 +236,8 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
|
|
|
418
236
|
var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
|
|
419
237
|
var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
|
|
420
238
|
var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
|
|
239
|
+
var stellarXLM = createToken("stellar", "XLM", "nep245:v2_1.omni.hot.tg:1100_111bzQBB5v7AhLyPMDwS8uJgQV24KaAPXtwyVWu2KXbbfQU6NXRCz", 7);
|
|
240
|
+
var stellarUSDC = createToken("stellar", "USDC", "nep245:v2_1.omni.hot.tg:1100_111bzQBB65GxAPAVoxqmMcgYo5oS3txhqs1Uh1cgahKQUeTUq1TJu", 7, "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN");
|
|
421
241
|
var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
|
|
422
242
|
name: "nearNEAR",
|
|
423
243
|
aliases: ["nearwNEAR"]
|
|
@@ -425,11 +245,11 @@ var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near",
|
|
|
425
245
|
var nearUSDC = createToken("near", "USDC", "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6, "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1");
|
|
426
246
|
var nearUSDT = createToken("near", "USDT", "nep141:usdt.tether-token.near", 6, "usdt.tether-token.near");
|
|
427
247
|
var CHAINS = {
|
|
428
|
-
|
|
429
|
-
id: "
|
|
430
|
-
name: "
|
|
431
|
-
icon: CHAIN_ICONS.
|
|
432
|
-
tokens: [
|
|
248
|
+
stellar: {
|
|
249
|
+
id: "stellar",
|
|
250
|
+
name: "Stellar",
|
|
251
|
+
icon: CHAIN_ICONS.stellar,
|
|
252
|
+
tokens: [stellarXLM, stellarUSDC]
|
|
433
253
|
},
|
|
434
254
|
eth: {
|
|
435
255
|
id: "eth",
|
|
@@ -449,6 +269,12 @@ var CHAINS = {
|
|
|
449
269
|
icon: CHAIN_ICONS.base,
|
|
450
270
|
tokens: [baseETH, baseUSDC, baseCbBTC, baseBRETT]
|
|
451
271
|
},
|
|
272
|
+
sui: {
|
|
273
|
+
id: "sui",
|
|
274
|
+
name: "Sui",
|
|
275
|
+
icon: CHAIN_ICONS.sui,
|
|
276
|
+
tokens: [suiSUI, suiUSDC]
|
|
277
|
+
},
|
|
452
278
|
op: {
|
|
453
279
|
id: "op",
|
|
454
280
|
name: "Optimism",
|
|
@@ -569,11 +395,11 @@ var CHAINS = {
|
|
|
569
395
|
icon: CHAIN_ICONS.monad,
|
|
570
396
|
tokens: []
|
|
571
397
|
},
|
|
572
|
-
|
|
573
|
-
id: "
|
|
574
|
-
name: "
|
|
575
|
-
icon: CHAIN_ICONS.
|
|
576
|
-
tokens: []
|
|
398
|
+
scroll: {
|
|
399
|
+
id: "scroll",
|
|
400
|
+
name: "Scroll",
|
|
401
|
+
icon: CHAIN_ICONS.scroll,
|
|
402
|
+
tokens: [scrollETH, scrollUSDT]
|
|
577
403
|
}
|
|
578
404
|
};
|
|
579
405
|
var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
|
|
@@ -586,6 +412,209 @@ function getSupportedChains() {
|
|
|
586
412
|
return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
|
|
587
413
|
}
|
|
588
414
|
|
|
415
|
+
// src/core/config.ts
|
|
416
|
+
var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
|
|
417
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
|
|
418
|
+
function normalizeBackendUrl(url) {
|
|
419
|
+
return url.replace(/\/+$/, "");
|
|
420
|
+
}
|
|
421
|
+
function getUniportConfig() {
|
|
422
|
+
const backendUrl = DEFAULT_HOSTED_BACKEND_URL;
|
|
423
|
+
return {
|
|
424
|
+
backendUrl: normalizeBackendUrl(backendUrl),
|
|
425
|
+
requestTimeoutMs: DEFAULT_REQUEST_TIMEOUT_MS
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/core/intents.ts
|
|
430
|
+
var UniportError = class extends Error {
|
|
431
|
+
constructor(params) {
|
|
432
|
+
super(params.message);
|
|
433
|
+
this.name = "UniportError";
|
|
434
|
+
this.code = params.code;
|
|
435
|
+
this.details = params.details;
|
|
436
|
+
this.status = params.status;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
function isAbortError(error) {
|
|
440
|
+
return error instanceof Error && error.name === "AbortError";
|
|
441
|
+
}
|
|
442
|
+
function extractDetailMessage(details) {
|
|
443
|
+
if (typeof details === "string" && details.trim()) {
|
|
444
|
+
return details;
|
|
445
|
+
}
|
|
446
|
+
if (Array.isArray(details)) {
|
|
447
|
+
const firstString = details.find(
|
|
448
|
+
(detail) => typeof detail === "string" && detail.trim().length > 0
|
|
449
|
+
);
|
|
450
|
+
return firstString;
|
|
451
|
+
}
|
|
452
|
+
if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
|
|
453
|
+
const message = details.message.trim();
|
|
454
|
+
return message || void 0;
|
|
455
|
+
}
|
|
456
|
+
return void 0;
|
|
457
|
+
}
|
|
458
|
+
function toUniportError(body, fallback) {
|
|
459
|
+
const detailMessage = extractDetailMessage(body.details);
|
|
460
|
+
return new UniportError({
|
|
461
|
+
code: body.code || fallback.code,
|
|
462
|
+
message: detailMessage || body.message || fallback.message,
|
|
463
|
+
details: body.details,
|
|
464
|
+
status: fallback.status
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
function createTimeoutSignal(timeoutMs, externalSignal) {
|
|
468
|
+
const controller = new AbortController();
|
|
469
|
+
let timedOut = false;
|
|
470
|
+
const timeoutId = setTimeout(() => {
|
|
471
|
+
timedOut = true;
|
|
472
|
+
controller.abort();
|
|
473
|
+
}, timeoutMs);
|
|
474
|
+
const abortFromExternal = () => controller.abort();
|
|
475
|
+
externalSignal?.addEventListener("abort", abortFromExternal, {
|
|
476
|
+
once: true
|
|
477
|
+
});
|
|
478
|
+
return {
|
|
479
|
+
signal: controller.signal,
|
|
480
|
+
didTimeout: () => timedOut,
|
|
481
|
+
cleanup: () => {
|
|
482
|
+
clearTimeout(timeoutId);
|
|
483
|
+
externalSignal?.removeEventListener("abort", abortFromExternal);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function toSmallestUnits(amount, decimals) {
|
|
488
|
+
const [whole, fraction = ""] = amount.split(".");
|
|
489
|
+
const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
|
|
490
|
+
return `${whole}${paddedFraction}`.replace(/^0+/, "") || "0";
|
|
491
|
+
}
|
|
492
|
+
function generateDeadline(hoursFromNow = 1) {
|
|
493
|
+
const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
|
|
494
|
+
return deadline.toISOString();
|
|
495
|
+
}
|
|
496
|
+
function formatDisplayAmount(amount, significantDigits = 6) {
|
|
497
|
+
if (!amount) return amount ?? "";
|
|
498
|
+
const num = Number(amount);
|
|
499
|
+
if (!Number.isFinite(num) || num === 0) return amount;
|
|
500
|
+
const abs = Math.abs(num);
|
|
501
|
+
if (abs < 1e-6 || abs >= 1e21) return amount;
|
|
502
|
+
return new Intl.NumberFormat("en-US", {
|
|
503
|
+
maximumSignificantDigits: significantDigits,
|
|
504
|
+
useGrouping: false
|
|
505
|
+
}).format(num);
|
|
506
|
+
}
|
|
507
|
+
async function getQuote(options) {
|
|
508
|
+
const {
|
|
509
|
+
originToken,
|
|
510
|
+
destinationToken,
|
|
511
|
+
amount,
|
|
512
|
+
recipient,
|
|
513
|
+
refundTo,
|
|
514
|
+
slippageTolerance = 100,
|
|
515
|
+
// 1% default
|
|
516
|
+
swapType = "EXACT_INPUT",
|
|
517
|
+
deadline,
|
|
518
|
+
dry = false,
|
|
519
|
+
referral = "uniport",
|
|
520
|
+
signal
|
|
521
|
+
} = options;
|
|
522
|
+
const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
|
|
523
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
524
|
+
const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
|
|
525
|
+
requestTimeoutMs,
|
|
526
|
+
signal
|
|
527
|
+
);
|
|
528
|
+
let response;
|
|
529
|
+
try {
|
|
530
|
+
response = await fetch(`${backendUrl}/api/quote`, {
|
|
531
|
+
method: "POST",
|
|
532
|
+
headers: { "Content-Type": "application/json" },
|
|
533
|
+
signal: requestSignal,
|
|
534
|
+
body: JSON.stringify({
|
|
535
|
+
dry,
|
|
536
|
+
swapType,
|
|
537
|
+
slippageTolerance,
|
|
538
|
+
depositMode: needsMemoDeposit(originToken.chain) ? "MEMO" : void 0,
|
|
539
|
+
originAsset: originToken.assetId,
|
|
540
|
+
destinationAsset: destinationToken.assetId,
|
|
541
|
+
amount: amountInSmallestUnits,
|
|
542
|
+
refundTo,
|
|
543
|
+
recipient,
|
|
544
|
+
deadline: deadline?.toISOString() || generateDeadline(1),
|
|
545
|
+
referral
|
|
546
|
+
})
|
|
547
|
+
});
|
|
548
|
+
} catch (error) {
|
|
549
|
+
cleanup();
|
|
550
|
+
if (isAbortError(error)) {
|
|
551
|
+
if (signal?.aborted && !didTimeout()) {
|
|
552
|
+
throw error;
|
|
553
|
+
}
|
|
554
|
+
throw new UniportError({
|
|
555
|
+
code: "REQUEST_TIMEOUT",
|
|
556
|
+
message: "Quote request timed out"
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
cleanup();
|
|
562
|
+
if (!response.ok) {
|
|
563
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
564
|
+
throw toUniportError(errorBody, {
|
|
565
|
+
code: "QUOTE_FAILED",
|
|
566
|
+
message: "Quote failed.",
|
|
567
|
+
status: response.status
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
const data = await response.json();
|
|
571
|
+
const quote = data.quote;
|
|
572
|
+
return {
|
|
573
|
+
depositAddress: quote.depositAddress || "",
|
|
574
|
+
memo: quote.depositMemo,
|
|
575
|
+
amountIn: quote.amountIn,
|
|
576
|
+
amountOut: quote.amountOut,
|
|
577
|
+
amountOutFormatted: quote.amountOutFormatted,
|
|
578
|
+
amountOutUsd: quote.amountOutUsd,
|
|
579
|
+
deadline: quote.deadline,
|
|
580
|
+
timeWhenInactive: quote.timeWhenInactive,
|
|
581
|
+
correlationId: data.correlationId
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
async function getExecutionStatus(depositAddress, memo) {
|
|
585
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
586
|
+
const url = new URL(
|
|
587
|
+
`${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
|
|
588
|
+
);
|
|
589
|
+
if (memo) {
|
|
590
|
+
url.searchParams.set("memo", memo);
|
|
591
|
+
}
|
|
592
|
+
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
593
|
+
let response;
|
|
594
|
+
try {
|
|
595
|
+
response = await fetch(url.toString(), { signal });
|
|
596
|
+
} catch (error) {
|
|
597
|
+
cleanup();
|
|
598
|
+
if (isAbortError(error)) {
|
|
599
|
+
throw new UniportError({
|
|
600
|
+
code: "REQUEST_TIMEOUT",
|
|
601
|
+
message: "Status check timed out"
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
throw error;
|
|
605
|
+
}
|
|
606
|
+
cleanup();
|
|
607
|
+
if (!response.ok) {
|
|
608
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
609
|
+
throw toUniportError(errorBody, {
|
|
610
|
+
code: "STATUS_CHECK_FAILED",
|
|
611
|
+
message: "Status check failed.",
|
|
612
|
+
status: response.status
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
return await response.json();
|
|
616
|
+
}
|
|
617
|
+
|
|
589
618
|
// src/core/ens.ts
|
|
590
619
|
var ENSIDEAS_BASE_URL = "https://api.ensideas.com/ens/resolve";
|
|
591
620
|
var UNIPORT_ENS_NAME = "uniport.eth";
|
|
@@ -1157,7 +1186,7 @@ function UniportModal({
|
|
|
1157
1186
|
onError
|
|
1158
1187
|
});
|
|
1159
1188
|
const [modalStep, setModalStep] = react.useState("chain");
|
|
1160
|
-
const [
|
|
1189
|
+
const [copiedField, setCopiedField] = react.useState(null);
|
|
1161
1190
|
const [showReceipt, setShowReceipt] = react.useState(false);
|
|
1162
1191
|
const [portalRoot, setPortalRoot] = react.useState(null);
|
|
1163
1192
|
react.useEffect(() => {
|
|
@@ -1189,13 +1218,11 @@ function UniportModal({
|
|
|
1189
1218
|
};
|
|
1190
1219
|
}
|
|
1191
1220
|
}, [open, handleClose]);
|
|
1192
|
-
const handleCopy = react.useCallback(async () => {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
1198
|
-
}
|
|
1221
|
+
const handleCopy = react.useCallback(async (field, text) => {
|
|
1222
|
+
const ok = await payment.copyToClipboard(text);
|
|
1223
|
+
if (ok) {
|
|
1224
|
+
setCopiedField(field);
|
|
1225
|
+
setTimeout(() => setCopiedField(null), 2e3);
|
|
1199
1226
|
}
|
|
1200
1227
|
}, [payment]);
|
|
1201
1228
|
if (!open || !portalRoot) return null;
|
|
@@ -1480,6 +1507,22 @@ function UniportModal({
|
|
|
1480
1507
|
},
|
|
1481
1508
|
children: payment.isUsingDefaultRefundAddress ? `Used only if the swap fails. You can enter your own address, or leave blank to use Uniport's default (${UNIPORT_ENS_NAME}).` : "Used only if the swap fails. This address must live on the chain the payer is sending from."
|
|
1482
1509
|
}
|
|
1510
|
+
),
|
|
1511
|
+
ch?.id === "stellar" && tok?.symbol !== "XLM" && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1512
|
+
"p",
|
|
1513
|
+
{
|
|
1514
|
+
style: {
|
|
1515
|
+
margin: "6px 0 0",
|
|
1516
|
+
fontSize: "12px",
|
|
1517
|
+
color: t.warning,
|
|
1518
|
+
lineHeight: 1.5
|
|
1519
|
+
},
|
|
1520
|
+
children: [
|
|
1521
|
+
"This refund address must already have a trustline for ",
|
|
1522
|
+
tok?.symbol,
|
|
1523
|
+
" on Stellar, or a refund cannot be delivered to it."
|
|
1524
|
+
]
|
|
1525
|
+
}
|
|
1483
1526
|
)
|
|
1484
1527
|
] }),
|
|
1485
1528
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
@@ -1502,7 +1545,7 @@ function UniportModal({
|
|
|
1502
1545
|
"You will receive",
|
|
1503
1546
|
" ",
|
|
1504
1547
|
/* @__PURE__ */ jsxRuntime.jsxs("strong", { style: { color: t.text }, children: [
|
|
1505
|
-
payment.previewQuote.amountOutFormatted,
|
|
1548
|
+
formatDisplayAmount(payment.previewQuote.amountOutFormatted),
|
|
1506
1549
|
" ",
|
|
1507
1550
|
payment.destinationToken.symbol
|
|
1508
1551
|
] }),
|
|
@@ -1583,7 +1626,7 @@ function UniportModal({
|
|
|
1583
1626
|
padding: "11px 13px",
|
|
1584
1627
|
background: t.inputBg,
|
|
1585
1628
|
borderRadius: "10px",
|
|
1586
|
-
marginBottom: "14px",
|
|
1629
|
+
marginBottom: quote.memo ? "10px" : "14px",
|
|
1587
1630
|
border: `1px solid ${t.border}`
|
|
1588
1631
|
}, children: [
|
|
1589
1632
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: {
|
|
@@ -1597,22 +1640,64 @@ function UniportModal({
|
|
|
1597
1640
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1598
1641
|
"button",
|
|
1599
1642
|
{
|
|
1600
|
-
onClick: handleCopy,
|
|
1643
|
+
onClick: () => handleCopy("address", quote.depositAddress),
|
|
1601
1644
|
title: "Copy address",
|
|
1602
1645
|
style: {
|
|
1603
1646
|
flexShrink: 0,
|
|
1604
1647
|
width: 34,
|
|
1605
1648
|
height: 34,
|
|
1606
1649
|
borderRadius: "8px",
|
|
1607
|
-
background:
|
|
1608
|
-
border: `1px solid ${
|
|
1650
|
+
background: copiedField === "address" ? `${t.success}18` : t.iconBtnBg,
|
|
1651
|
+
border: `1px solid ${copiedField === "address" ? t.success + "44" : t.border}`,
|
|
1609
1652
|
cursor: "pointer",
|
|
1610
1653
|
display: "flex",
|
|
1611
1654
|
alignItems: "center",
|
|
1612
1655
|
justifyContent: "center",
|
|
1613
1656
|
transition: "all 0.2s"
|
|
1614
1657
|
},
|
|
1615
|
-
children:
|
|
1658
|
+
children: copiedField === "address" ? /* @__PURE__ */ jsxRuntime.jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { color: t.textMuted })
|
|
1659
|
+
}
|
|
1660
|
+
)
|
|
1661
|
+
] }),
|
|
1662
|
+
quote.memo && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
1663
|
+
display: "flex",
|
|
1664
|
+
alignItems: "center",
|
|
1665
|
+
gap: "10px",
|
|
1666
|
+
padding: "11px 13px",
|
|
1667
|
+
background: `${t.warning}0f`,
|
|
1668
|
+
borderRadius: "10px",
|
|
1669
|
+
marginBottom: "14px",
|
|
1670
|
+
border: `1px solid ${t.warning}44`
|
|
1671
|
+
}, children: [
|
|
1672
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1 }, children: [
|
|
1673
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 3px", fontSize: "11px", color: t.warning, fontWeight: 600, textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Memo required" }),
|
|
1674
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: {
|
|
1675
|
+
fontSize: "13px",
|
|
1676
|
+
color: t.text,
|
|
1677
|
+
fontFamily: "monospace",
|
|
1678
|
+
wordBreak: "break-all",
|
|
1679
|
+
lineHeight: 1.4
|
|
1680
|
+
}, children: quote.memo })
|
|
1681
|
+
] }),
|
|
1682
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1683
|
+
"button",
|
|
1684
|
+
{
|
|
1685
|
+
onClick: () => handleCopy("memo", quote.memo),
|
|
1686
|
+
title: "Copy memo",
|
|
1687
|
+
style: {
|
|
1688
|
+
flexShrink: 0,
|
|
1689
|
+
width: 34,
|
|
1690
|
+
height: 34,
|
|
1691
|
+
borderRadius: "8px",
|
|
1692
|
+
background: copiedField === "memo" ? `${t.success}18` : t.iconBtnBg,
|
|
1693
|
+
border: `1px solid ${copiedField === "memo" ? t.success + "44" : t.border}`,
|
|
1694
|
+
cursor: "pointer",
|
|
1695
|
+
display: "flex",
|
|
1696
|
+
alignItems: "center",
|
|
1697
|
+
justifyContent: "center",
|
|
1698
|
+
transition: "all 0.2s"
|
|
1699
|
+
},
|
|
1700
|
+
children: copiedField === "memo" ? /* @__PURE__ */ jsxRuntime.jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { color: t.textMuted })
|
|
1616
1701
|
}
|
|
1617
1702
|
)
|
|
1618
1703
|
] }),
|
|
@@ -1629,7 +1714,14 @@ function UniportModal({
|
|
|
1629
1714
|
" ",
|
|
1630
1715
|
"on ",
|
|
1631
1716
|
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: payment.selectedChain?.name }),
|
|
1632
|
-
" to this address
|
|
1717
|
+
" to this address",
|
|
1718
|
+
quote.memo && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1719
|
+
" ",
|
|
1720
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "with the memo above" })
|
|
1721
|
+
] }),
|
|
1722
|
+
". Other assets may be permanently lost",
|
|
1723
|
+
quote.memo && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: ", and omitting the memo may make your deposit unrecoverable" }),
|
|
1724
|
+
"."
|
|
1633
1725
|
] })
|
|
1634
1726
|
] }),
|
|
1635
1727
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { borderTop: `1px solid ${t.border}`, paddingTop: "12px" }, children: [
|
|
@@ -1637,7 +1729,7 @@ function UniportModal({
|
|
|
1637
1729
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "You'll receive" }),
|
|
1638
1730
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontSize: "13px", fontWeight: 600, color: t.text }, children: [
|
|
1639
1731
|
"\u2248",
|
|
1640
|
-
quote.amountOutFormatted,
|
|
1732
|
+
formatDisplayAmount(quote.amountOutFormatted),
|
|
1641
1733
|
" ",
|
|
1642
1734
|
payment.destinationToken.symbol
|
|
1643
1735
|
] })
|
|
@@ -1731,7 +1823,7 @@ function UniportModal({
|
|
|
1731
1823
|
payment.selectedToken?.symbol,
|
|
1732
1824
|
" \u2192 ",
|
|
1733
1825
|
"\u2248",
|
|
1734
|
-
payment.quote?.amountOutFormatted,
|
|
1826
|
+
formatDisplayAmount(payment.quote?.amountOutFormatted),
|
|
1735
1827
|
" ",
|
|
1736
1828
|
payment.destinationToken.symbol
|
|
1737
1829
|
] }),
|