@embarkai/ui-kit 0.4.25 → 0.4.26

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.
@@ -1,980 +0,0 @@
1
- import {
2
- Badge,
3
- BnbIcon,
4
- Button,
5
- EthereumIcon,
6
- Highlight,
7
- Input,
8
- LumiaIcon,
9
- TOKENS_ICONS,
10
- cn,
11
- formatPrice,
12
- sendUserOperation,
13
- useBlockscoutAssets,
14
- useBridgeStore,
15
- useFlowSelectorStore,
16
- useLayoutStore,
17
- useSession,
18
- useT
19
- } from "./chunk-YW3BCDPE.js";
20
- import "./chunk-7G3OIJGJ.js";
21
- import "./chunk-MLUPZCC3.js";
22
- import "./chunk-DBFKMKYT.js";
23
-
24
- // src/internal/components/SendMenu/hyperbridge/HyperlaneBridge.tsx
25
- import { useEffect as useEffect4 } from "react";
26
-
27
- // src/internal/components/SendMenu/hyperbridge/components/TokenSelector.tsx
28
- import { toPairs } from "lodash-es";
29
- import { ArrowLeftRightIcon } from "lucide-react";
30
- import { Fragment, useCallback } from "react";
31
-
32
- // src/internal/components/SendMenu/hyperbridge/lib/chains.ts
33
- import { lumiaMainnetChain as lumiaprism } from "@embarkai/core/read";
34
- import { bsc, mainnet as ethereum } from "wagmi/chains";
35
- var CHAINS_META = {
36
- lumiaprism: {
37
- chainID: lumiaprism.id,
38
- chainLabel: lumiaprism.name,
39
- chainName: "lumiaprism",
40
- // exact hyperlane registry chain name
41
- Icon: LumiaIcon
42
- },
43
- bsc: {
44
- chainID: bsc.id,
45
- chainLabel: bsc.name,
46
- chainName: "bsc",
47
- // exact hyperlane registry chain name
48
- Icon: BnbIcon
49
- },
50
- ethereum: {
51
- chainID: ethereum.id,
52
- chainLabel: ethereum.name,
53
- chainName: "ethereum",
54
- // exact hyperlane registry chain name
55
- Icon: EthereumIcon
56
- }
57
- // base: {
58
- // chainID: base.id,
59
- // chainLabel: base.name,
60
- // chainName: 'ethereum', // exact hyperlane registry chain name
61
- // Icon: EthereumIcon
62
- // },
63
- };
64
-
65
- // src/internal/components/SendMenu/hyperbridge/lib/warp.ts
66
- import { lumiaMainnetChain as lumiaprism2 } from "@embarkai/core/read";
67
- import { chainMetadata, warpRouteConfigs } from "@hyperlane-xyz/registry";
68
- import {
69
- MultiProtocolProvider,
70
- WarpCore
71
- } from "@hyperlane-xyz/sdk";
72
- import { bsc as bsc2, base as ethereum2 } from "wagmi/chains";
73
- var WARP_ROUTES = [
74
- {
75
- symbol: "LUMIA",
76
- icon: TOKENS_ICONS.LUMIA,
77
- id: "LUMIA/arbitrum-avalanche-base-bsc-ethereum-lumiaprism-optimism-polygon",
78
- // Canonical LUMIA warp route (includes BSC + Lumia Prism).
79
- name: "bsc-lumiaprism",
80
- chainPair: [
81
- {
82
- chainID: bsc2.id,
83
- chainLabel: bsc2.name,
84
- chainName: "bsc",
85
- Icon: BnbIcon
86
- },
87
- {
88
- chainID: lumiaprism2.id,
89
- chainLabel: lumiaprism2.name,
90
- chainName: "lumiaprism",
91
- Icon: LumiaIcon
92
- }
93
- ]
94
- },
95
- {
96
- symbol: "USDT",
97
- icon: TOKENS_ICONS.USDT,
98
- id: "USDT/ethereum-lumiaprism",
99
- name: "ethereum-lumiaprism",
100
- chainPair: [
101
- {
102
- chainID: ethereum2.id,
103
- chainLabel: ethereum2.name,
104
- chainName: "ethereum",
105
- Icon: EthereumIcon
106
- },
107
- {
108
- chainID: lumiaprism2.id,
109
- chainLabel: lumiaprism2.name,
110
- chainName: "lumiaprism",
111
- Icon: LumiaIcon
112
- }
113
- ]
114
- },
115
- {
116
- symbol: "USDC",
117
- icon: TOKENS_ICONS.USDC,
118
- id: "USDC/lumia",
119
- name: "ethereum-lumiaprism",
120
- chainPair: [
121
- {
122
- chainID: ethereum2.id,
123
- chainLabel: ethereum2.name,
124
- chainName: "ethereum",
125
- Icon: EthereumIcon
126
- },
127
- {
128
- chainID: lumiaprism2.id,
129
- chainLabel: lumiaprism2.name,
130
- chainName: "lumiaprism",
131
- Icon: LumiaIcon
132
- }
133
- ]
134
- }
135
- ];
136
- function buildLumiaWarpConfig(warpRouteId) {
137
- const config = warpRouteConfigs[warpRouteId];
138
- if (!config) {
139
- console.warn(`[HYPERLANE SDK] Warp route ${warpRouteId} not found in @hyperlane-xyz/registry`);
140
- return null;
141
- }
142
- return config;
143
- }
144
- function tokenConnectionId(chainName, addressOrDenom) {
145
- return `ethereum|${chainName}|${addressOrDenom}`.toLowerCase();
146
- }
147
- function filterWarpConfigForChains(config, chains) {
148
- const chainSet = new Set(chains);
149
- const tokens = config.tokens.filter((t) => chainSet.has(t.chainName) && t.addressOrDenom);
150
- const allowedConnectionIds = new Set(tokens.map((t) => tokenConnectionId(t.chainName, t.addressOrDenom)));
151
- const prunedTokens = tokens.map((token) => ({
152
- ...token,
153
- connections: (token.connections ?? []).filter((c) => allowedConnectionIds.has(c.token.toLowerCase()))
154
- }));
155
- return { ...config, tokens: prunedTokens };
156
- }
157
- function isDirectRouteAvailable(config, originChain, destinationChain) {
158
- const originTokens = config.tokens.find((t) => t.chainName === originChain);
159
- const destinationTokens = config.tokens.find((t) => t.chainName === destinationChain);
160
- if (!originTokens || !destinationTokens) return false;
161
- const destinationTokensId = `ethereum|${destinationChain}|${destinationTokens.addressOrDenom}`.toLowerCase();
162
- return (originTokens.connections ?? []).some((c) => c.token.toLowerCase() === destinationTokensId);
163
- }
164
- function createMultiProtocolProvider(chainNames) {
165
- const metadata = {};
166
- for (const name of chainNames) {
167
- const meta = chainMetadata[name];
168
- if (meta) metadata[name] = meta;
169
- }
170
- return new MultiProtocolProvider(metadata);
171
- }
172
- function createWarpCore(config, chainNames) {
173
- const multiProvider = createMultiProtocolProvider(chainNames);
174
- return WarpCore.FromConfig(multiProvider, config);
175
- }
176
-
177
- // src/internal/components/SendMenu/hyperbridge/components/TokenSelector.tsx
178
- import { jsx, jsxs } from "react/jsx-runtime";
179
- var BRIDGE_CHAINS_LIST = toPairs(CHAINS_META).map(([chainName]) => chainName);
180
- function RouteItem(props) {
181
- const { id, icon: Icon, chainPair, symbol } = props;
182
- const hyperRouteID = useBridgeStore((st) => st.hyperRoute);
183
- const selectRoute = useCallback((routeId) => {
184
- const {
185
- //
186
- setHyperRoute,
187
- setBridgeStep,
188
- setWarpCore,
189
- setWarpCoreConfig,
190
- setOriginChain,
191
- setDestinationChain
192
- } = useBridgeStore.getState();
193
- setHyperRoute(routeId);
194
- const warpConfig = buildLumiaWarpConfig(routeId);
195
- if (!warpConfig) {
196
- useFlowSelectorStore.getState().setError(`Warp route ${routeId} not found in @hyperlane-xyz/registry`);
197
- setBridgeStep("select");
198
- return;
199
- }
200
- console.log("[HYPERLANE SDK] Selecting route", routeId);
201
- const filteredConfig = filterWarpConfigForChains(warpConfig, BRIDGE_CHAINS_LIST);
202
- const warpCore = createWarpCore(filteredConfig, BRIDGE_CHAINS_LIST);
203
- setWarpCore(warpCore);
204
- setWarpCoreConfig(filteredConfig);
205
- setOriginChain(chainPair[0].chainName);
206
- setDestinationChain(chainPair[1].chainName);
207
- setBridgeStep("select");
208
- }, []);
209
- return /* @__PURE__ */ jsxs(
210
- Button,
211
- {
212
- size: "large",
213
- variant: hyperRouteID === id ? "default" : "outline",
214
- className: "justify-between",
215
- onClick: () => selectRoute(id),
216
- children: [
217
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[var(--ui-kit-gap)]", children: [
218
- /* @__PURE__ */ jsx(Icon, { className: "w-6 h-6" }),
219
- /* @__PURE__ */ jsx("span", { children: symbol.toUpperCase() })
220
- ] }),
221
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-[var(--ui-kit-gap)]", children: chainPair.map((chain, chIdx) => /* @__PURE__ */ jsxs(Fragment, { children: [
222
- chIdx > 0 && /* @__PURE__ */ jsx(ArrowLeftRightIcon, { className: "w-4 h-4" }),
223
- /* @__PURE__ */ jsx(chain.Icon, { className: "w-4 h-4" })
224
- ] }, `${id}-icon-${chain.chainID}-${chIdx}`)) })
225
- ]
226
- }
227
- );
228
- }
229
- function TokenSelector() {
230
- return /* @__PURE__ */ jsx("div", { className: "w-full flex flex-col gap-[var(--ui-kit-gap)]", children: WARP_ROUTES.map((hyperRoute) => /* @__PURE__ */ jsx(RouteItem, { ...hyperRoute }, hyperRoute.id)) });
231
- }
232
-
233
- // src/internal/components/SendMenu/hyperbridge/hooks/useBridge.ts
234
- import { toWei } from "@hyperlane-xyz/utils";
235
- import { useMutation } from "@tanstack/react-query";
236
- import { debounce } from "lodash-es";
237
- import { useCallback as useCallback2, useEffect as useEffect2 } from "react";
238
-
239
- // src/internal/components/SendMenu/hyperbridge/lib/executeWarpTxs.ts
240
- import { ProviderType, WarpTxCategory } from "@hyperlane-xyz/sdk";
241
- async function executeWarpTransactions(txs) {
242
- const { publicClient, session } = useSession.getState();
243
- if (!session) {
244
- throw new Error("No active session");
245
- }
246
- if (!publicClient) {
247
- throw new Error("No public client available");
248
- }
249
- const hashes = [];
250
- for (const tx of txs) {
251
- if (tx.type !== ProviderType.EthersV5) {
252
- throw new Error(`Unsupported transaction provider: ${tx.type}`);
253
- }
254
- const populated = tx.transaction;
255
- if (!populated.to) {
256
- throw new Error("Transaction missing `to` address");
257
- }
258
- const hash = await sendUserOperation(session, {
259
- to: populated.to,
260
- data: populated.data ?? "0x",
261
- value: (populated.value ? BigInt(populated.value.toString()) : 0n).toString(),
262
- chainId: publicClient.chain.id
263
- });
264
- hashes.push(hash);
265
- }
266
- return hashes;
267
- }
268
-
269
- // src/internal/components/SendMenu/hyperbridge/hooks/useWarpCore.ts
270
- import { toPairs as toPairs2 } from "lodash-es";
271
- import { useEffect } from "react";
272
- var BRIDGE_CHAINS_LIST2 = toPairs2(CHAINS_META).map(([chainName]) => chainName);
273
- var DEFAULT_WARP_ROUTE_ID = "USDT/ethereum-lumiaprism";
274
- function useWarpCore() {
275
- useEffect(() => {
276
- const existingWarpCore = useBridgeStore.getState().warpCore;
277
- if (!!existingWarpCore) return;
278
- const {
279
- hyperRoute,
280
- originChain,
281
- destinationChain,
282
- setWarpCore,
283
- setWarpCoreConfig,
284
- setBridgeStep,
285
- setHyperRoute,
286
- setOriginChain,
287
- setDestinationChain
288
- } = useBridgeStore.getState();
289
- const hyperRouteID = hyperRoute || DEFAULT_WARP_ROUTE_ID;
290
- console.debug("[HYPERLANE SDK] Initializing WarpCore...", hyperRouteID);
291
- const fullConfig = buildLumiaWarpConfig(hyperRouteID);
292
- if (!fullConfig) {
293
- useFlowSelectorStore.getState().setError(`Warp route ${hyperRouteID} not found in @hyperlane-xyz/registry`);
294
- setBridgeStep("select");
295
- return;
296
- }
297
- const filteredConfig = filterWarpConfigForChains(fullConfig, BRIDGE_CHAINS_LIST2);
298
- const warpCore = createWarpCore(filteredConfig, BRIDGE_CHAINS_LIST2);
299
- setWarpCore(warpCore);
300
- setWarpCoreConfig(filteredConfig);
301
- if (hyperRoute !== hyperRouteID) setHyperRoute(hyperRouteID);
302
- const chainsPair = WARP_ROUTES.find((warpRoute) => warpRoute.id === hyperRouteID)?.chainPair;
303
- if (!!chainsPair) {
304
- console.debug(`[HYPERLANE SDK] chain pair ${chainsPair.map((c) => c.chainName).join(" - ")}`);
305
- const persistedOrigin = originChain && chainsPair.find((c) => c.chainName === originChain);
306
- const persistedDestination = destinationChain && chainsPair.find((c) => c.chainName === destinationChain);
307
- setOriginChain(persistedOrigin?.chainName || chainsPair[0].chainName);
308
- setDestinationChain(persistedDestination?.chainName || chainsPair[1].chainName);
309
- }
310
- return () => {
311
- setWarpCore(null);
312
- setWarpCoreConfig(null);
313
- };
314
- }, []);
315
- }
316
-
317
- // src/internal/components/SendMenu/hyperbridge/hooks/useBridge.ts
318
- function findToken(warpCore, chain) {
319
- return warpCore.tokens.find((t) => t.chainName === chain);
320
- }
321
- function findDestinationToken(warpCore, origin, destination) {
322
- if (!origin.getConnectionForChain(destination)) return void 0;
323
- return warpCore.tokens.find((t) => t.chainName === destination);
324
- }
325
- function useBridge() {
326
- const { t } = useT();
327
- useWarpCore();
328
- const address = useSession((st) => st.address);
329
- const currentChainId = useSession((st) => st.activeChainId);
330
- const warpCore = useBridgeStore((st) => st.warpCore);
331
- const amountToBridge = useBridgeStore((st) => st.amount);
332
- const swapDirection = useCallback2(() => {
333
- const {
334
- bridgeStep,
335
- originChain,
336
- destinationChain,
337
- amount,
338
- //
339
- setOriginChain,
340
- setDestinationChain,
341
- setAmount,
342
- setQuote
343
- } = useBridgeStore.getState();
344
- useFlowSelectorStore.getState().setError(null);
345
- useFlowSelectorStore.getState().setRenderKey(`${bridgeStep}-swaped-${Date.now()}`);
346
- setOriginChain(destinationChain);
347
- setDestinationChain(originChain);
348
- const cacheAmount = amount;
349
- setAmount("0");
350
- setQuote(null);
351
- setTimeout(() => setAmount(cacheAmount), 500);
352
- }, []);
353
- const { mutate: estimateQuote } = useMutation({
354
- mutationFn: async (amountToBridge2) => {
355
- useFlowSelectorStore.getState().setError(null);
356
- useFlowSelectorStore.getState().setIsUiLocked(true);
357
- const {
358
- //
359
- bridgeStep,
360
- originChain,
361
- destinationChain,
362
- recipient,
363
- // setQuote,
364
- setIsQuoteEstimating
365
- } = useBridgeStore.getState();
366
- useFlowSelectorStore.getState().setRenderKey(`${bridgeStep}-quoted-${Date.now()}`);
367
- setIsQuoteEstimating(true);
368
- const originToken = findToken(warpCore, originChain);
369
- const destToken = originToken ? findDestinationToken(warpCore, originToken, destinationChain) : void 0;
370
- if (!originToken || !destToken) {
371
- throw new Error(
372
- // @ts-expect-error i18n typing
373
- t("passport:bridgeMenu.errors.noConnections", { originChain, destinationChain })
374
- );
375
- }
376
- const wei = toWei(amountToBridge2, originToken.decimals);
377
- const originTokenAmount = originToken.amount(wei);
378
- const { igpQuote, tokenFeeQuote } = await warpCore.getInterchainTransferFee({
379
- originTokenAmount,
380
- destination: destinationChain,
381
- sender: address,
382
- recipient: recipient || address,
383
- destinationToken: destToken
384
- });
385
- const localQuote = await warpCore.getLocalTransferFeeAmount({
386
- originToken,
387
- destination: destinationChain,
388
- sender: address,
389
- interchainFee: igpQuote,
390
- tokenFeeQuote,
391
- amount: BigInt(wei.toString()),
392
- destinationToken: destToken
393
- });
394
- return {
395
- amount: amountToBridge2,
396
- igpFee: String(igpQuote.getDecimalFormattedAmount()),
397
- localFee: String(localQuote.getDecimalFormattedAmount()),
398
- tokenFee: tokenFeeQuote ? String(tokenFeeQuote.getDecimalFormattedAmount()) : void 0,
399
- igpSymbol: igpQuote.token.symbol,
400
- localSymbol: localQuote.token.symbol
401
- };
402
- },
403
- onSuccess: (quote) => {
404
- const { bridgeStep, setQuote, setIsQuoteEstimating } = useBridgeStore.getState();
405
- setQuote(quote);
406
- setIsQuoteEstimating(false);
407
- useFlowSelectorStore.getState().setIsUiLocked(false);
408
- useFlowSelectorStore.getState().setRenderKey(`${bridgeStep}-quoted-${Date.now()}`);
409
- },
410
- onError: (error) => {
411
- const { setQuote, setIsQuoteEstimating } = useBridgeStore.getState();
412
- console.error("[HYPERLANE SDK] Quote estimation error", error);
413
- setQuote(null);
414
- setIsQuoteEstimating(false);
415
- useFlowSelectorStore.getState().setIsUiLocked(false);
416
- useFlowSelectorStore.getState().setError(error instanceof Error ? error.message : String(error));
417
- }
418
- });
419
- const defferedQuoteEstimation = useCallback2(
420
- debounce((amountToBridge2) => {
421
- estimateQuote(amountToBridge2);
422
- }, 600),
423
- []
424
- );
425
- useEffect2(() => {
426
- if (!amountToBridge || !Number(amountToBridge)) return;
427
- const { originChain, destinationChain } = useBridgeStore.getState();
428
- if (!originChain || !destinationChain) return;
429
- const warpCoreConfig = useBridgeStore.getState().warpCoreConfig;
430
- const routeReady = isDirectRouteAvailable(warpCoreConfig, originChain, destinationChain);
431
- if (!routeReady) {
432
- console.warn("[HYPERLANE SDK] route not ready");
433
- useFlowSelectorStore.getState().setError(
434
- // @ts-expect-error i18n typing
435
- t("passport:bridgeMenu.errors.routeUnavailable", { originChain, destinationChain })
436
- );
437
- return;
438
- }
439
- defferedQuoteEstimation(amountToBridge);
440
- }, [amountToBridge]);
441
- const { mutate: bridgeAsset, isPending: isAssetBridging } = useMutation({
442
- mutationFn: async () => {
443
- const {
444
- //
445
- originChain,
446
- destinationChain,
447
- amount,
448
- recipient,
449
- setBridgeTxStatus,
450
- setLastTxHashes
451
- } = useBridgeStore.getState();
452
- useLayoutStore.getState().setIsDialogForced(true);
453
- useFlowSelectorStore.getState().setIsUiLocked(true);
454
- useFlowSelectorStore.getState().setError(null);
455
- setBridgeTxStatus(null);
456
- setLastTxHashes([]);
457
- const expectedChainId = warpCore.multiProvider.getChainId(originChain);
458
- console.warn("[HYPERLANE SDK] expectedChainId", expectedChainId, "currentChainId", currentChainId);
459
- if (currentChainId !== expectedChainId) {
460
- throw new Error(t("passport:bridgeMenu.errors.wrongNetwork"));
461
- }
462
- const originToken = findToken(warpCore, originChain);
463
- const destToken = originToken ? findDestinationToken(warpCore, originToken, destinationChain) : void 0;
464
- if (!originToken || !destToken) {
465
- throw new Error(
466
- // @ts-expect-error i18n typing
467
- t("passport:bridgeMenu.errors.noConnections", { originChain, destinationChain })
468
- );
469
- }
470
- setBridgeTxStatus(t("passport:bridgeMenu.statuses.txPrepare"));
471
- const wei = toWei(amount, originToken.decimals);
472
- const originTokenAmount = originToken.amount(wei);
473
- const to = recipient || address;
474
- console.log("[HYPERLANE SDK] tokens:\n", originToken, "->", destToken);
475
- const { igpQuote, tokenFeeQuote } = await warpCore.getInterchainTransferFee({
476
- originTokenAmount,
477
- destination: destinationChain,
478
- sender: address,
479
- recipient: to,
480
- destinationToken: destToken
481
- });
482
- const txs = await warpCore.getTransferRemoteTxs({
483
- originTokenAmount,
484
- destination: destinationChain,
485
- sender: address,
486
- recipient: to,
487
- interchainFee: igpQuote,
488
- tokenFeeQuote,
489
- destinationToken: destToken
490
- });
491
- setBridgeTxStatus(
492
- // @ts-expect-error i18n typing
493
- t("passport:bridgeMenu.statuses.txSending", { txCount: txs.length })
494
- );
495
- return await executeWarpTransactions(txs);
496
- },
497
- onSuccess: (hashes) => {
498
- const { setBridgeStep, setBridgeTxStatus, setLastTxHashes, destinationChain } = useBridgeStore.getState();
499
- setLastTxHashes(hashes);
500
- setBridgeTxStatus(
501
- // @ts-expect-error i18n typing
502
- t("passport:bridgeMenu.statuses.txSent", { destination: destinationChain })
503
- );
504
- useLayoutStore.getState().setIsDialogForced(false);
505
- useFlowSelectorStore.getState().setIsUiLocked(false);
506
- setBridgeStep("success");
507
- },
508
- onError: (error) => {
509
- console.error("[HYPERLANE SDK] Bridge execution error", error);
510
- const { setBridgeTxStatus } = useBridgeStore.getState();
511
- setBridgeTxStatus(null);
512
- useLayoutStore.getState().setIsDialogForced(false);
513
- useFlowSelectorStore.getState().setIsUiLocked(false);
514
- useFlowSelectorStore.getState().setError(error instanceof Error ? error.message : String(error));
515
- }
516
- });
517
- return {
518
- swapDirection,
519
- bridgeAsset,
520
- isAssetBridging
521
- };
522
- }
523
-
524
- // src/internal/components/SendMenu/hyperbridge/hooks/useMenuTitle.ts
525
- import { useEffect as useEffect3 } from "react";
526
- function useMenuTitle() {
527
- const { t } = useT();
528
- const bridgeStep = useBridgeStore((st) => st.bridgeStep);
529
- const hyperRouteMeta = useBridgeStore((st) => WARP_ROUTES.find((route) => route.id === st.hyperRoute));
530
- useEffect3(() => {
531
- const updateMenuTitle = useFlowSelectorStore.getState().setMenuTitle;
532
- switch (true) {
533
- case bridgeStep === "select-token":
534
- updateMenuTitle(t("passport:bridgeMenu.labels.selectToken"));
535
- break;
536
- case bridgeStep === "confirm":
537
- updateMenuTitle(t("passport:bridgeMenu.labels.confirm"));
538
- break;
539
- case bridgeStep === "success":
540
- updateMenuTitle(t("passport:bridgeMenu.labels.bridgeTransactions"));
541
- break;
542
- default:
543
- updateMenuTitle(
544
- // @ts-expect-error i18n typings
545
- t("passport:bridgeMenu.labels.bridgeAsset", {
546
- asset: hyperRouteMeta?.symbol || "Asset"
547
- })
548
- );
549
- break;
550
- }
551
- }, [bridgeStep, hyperRouteMeta, t]);
552
- }
553
-
554
- // src/internal/components/SendMenu/hyperbridge/steps/SelectStep.tsx
555
- import { ArrowLeftRightIcon as ArrowLeftRightIcon2, ArrowRightLeftIcon, LoaderIcon, Wallet2Icon, XIcon } from "lucide-react";
556
- import { Fragment as Fragment2 } from "react";
557
-
558
- // src/internal/components/SendMenu/hyperbridge/utils.ts
559
- import { formatUnits } from "viem";
560
- function isNftAsset(asset) {
561
- if (!asset) return false;
562
- return asset.type === "erc721" || asset.type === "erc1155";
563
- }
564
- function getAssetBalance(asset) {
565
- if (!asset) return 0;
566
- if (isNftAsset(asset)) return 1;
567
- return Number(formatUnits(BigInt(asset.balance || "0"), asset.decimals || 18));
568
- }
569
-
570
- // src/internal/components/SendMenu/hyperbridge/steps/SelectStep.tsx
571
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
572
- function SelectStep({ swapChains }) {
573
- const address = useSession((st) => st.address);
574
- const { t } = useT();
575
- const {
576
- originChain,
577
- destinationChain,
578
- hyperRoute,
579
- amount,
580
- isQuoteEstimating,
581
- quote,
582
- recipient,
583
- setBridgeStep,
584
- setAmount,
585
- setRecipient
586
- } = useBridgeStore();
587
- const {
588
- assets,
589
- refreshBalances,
590
- isLoading: isAssetsLoading
591
- } = useBlockscoutAssets({
592
- address
593
- });
594
- const selectedWarpRoute = WARP_ROUTES.find((route) => route.id === hyperRoute);
595
- const routeTokenBalanace = assets.find((a) => a.symbol === selectedWarpRoute.symbol);
596
- const balance = routeTokenBalanace ? getAssetBalance(routeTokenBalanace) : null;
597
- const isError = useFlowSelectorStore((st) => !!st.error);
598
- const OriginChainIcon = originChain ? CHAINS_META[originChain]?.Icon : null;
599
- const DestinationChainIcon = destinationChain ? CHAINS_META[destinationChain]?.Icon : null;
600
- return /* @__PURE__ */ jsxs2("div", { className: "w-full flex flex-col gap-[var(--ui-kit-gap)] items-center", children: [
601
- /* @__PURE__ */ jsxs2("div", { className: "w-full flex flex-col gap-[var(--ui-kit-gap)]", children: [
602
- /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between gap-[var(--ui-kit-gap)] text-[10px]", children: [
603
- /* @__PURE__ */ jsx2("span", { className: "text-[var(--ui-kit-fg-muted)]", children: t("passport:bridgeMenu.labels.selectToken") }),
604
- /* @__PURE__ */ jsx2("span", { className: "w-4 h-4" }),
605
- /* @__PURE__ */ jsxs2("span", { className: "flex items-center gap-[var(--ui-kit-gap)] leading-4", children: [
606
- isAssetsLoading && /* @__PURE__ */ jsx2(LoaderIcon, { className: "w-4 h-4 animate-spin" }),
607
- /* @__PURE__ */ jsxs2("span", { className: "text-[var(--ui-kit-fg-muted)]", children: [
608
- t("passport:common.balance"),
609
- ": "
610
- ] }),
611
- !isAssetsLoading && /* @__PURE__ */ jsxs2("span", { className: "font-semibold", children: [
612
- formatPrice(balance || 0),
613
- " ",
614
- selectedWarpRoute?.symbol
615
- ] })
616
- ] })
617
- ] }),
618
- /* @__PURE__ */ jsxs2(
619
- Button,
620
- {
621
- disabled: isQuoteEstimating,
622
- variant: "outline",
623
- className: "w-full justify-between",
624
- onClick: () => {
625
- useFlowSelectorStore.getState().setError(null);
626
- setBridgeStep("select-token");
627
- refreshBalances();
628
- },
629
- children: [
630
- selectedWarpRoute && /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-[var(--ui-kit-gap)]", children: [
631
- /* @__PURE__ */ jsx2(selectedWarpRoute.icon, { className: "w-6 h-6" }),
632
- /* @__PURE__ */ jsx2("span", { children: selectedWarpRoute.symbol })
633
- ] }),
634
- /* @__PURE__ */ jsx2("div", { className: "flex items-center gap-[var(--ui-kit-gap)]", children: selectedWarpRoute?.chainPair?.map((chain, chIdx) => /* @__PURE__ */ jsxs2(Fragment2, { children: [
635
- chIdx > 0 && /* @__PURE__ */ jsx2(ArrowLeftRightIcon2, { className: "w-4 h-4 opacity-50" }),
636
- /* @__PURE__ */ jsx2(chain.Icon, { className: "w-4 h-4 opacity-50" })
637
- ] }, `${selectedWarpRoute.id}-icon-${chain.chainID}-${chIdx}`)) })
638
- ]
639
- }
640
- ),
641
- /* @__PURE__ */ jsxs2(
642
- "div",
643
- {
644
- className: cn(
645
- "flex items-center justify-between gap-[var(--ui-kit-gap)]",
646
- "text-[10px] text-[var(--ui-kit-fg-muted)] leading-4"
647
- ),
648
- children: [
649
- /* @__PURE__ */ jsx2("span", { className: "block text-[10px] text-[var(--ui-kit-fg-muted)]", children: t("passport:bridgeMenu.labels.fromChain") }),
650
- /* @__PURE__ */ jsx2("span", { className: "block text-[10px] text-[var(--ui-kit-fg-muted)]", children: t("passport:bridgeMenu.labels.toChain") })
651
- ]
652
- }
653
- ),
654
- /* @__PURE__ */ jsxs2("div", { className: "w-full flex items-center justify-center", children: [
655
- /* @__PURE__ */ jsxs2(
656
- Badge,
657
- {
658
- variant: "outline",
659
- size: "large",
660
- className: "block flex-1 flex gap-[var(--ui-kit-gap)] justify-center",
661
- children: [
662
- OriginChainIcon && /* @__PURE__ */ jsx2(OriginChainIcon, { className: "w-6 h-6" }),
663
- originChain && /* @__PURE__ */ jsx2("span", { className: "block max-w-[100px] truncate", children: CHAINS_META[originChain]?.chainLabel })
664
- ]
665
- }
666
- ),
667
- /* @__PURE__ */ jsx2(
668
- Button,
669
- {
670
- size: "icon",
671
- disabled: isQuoteEstimating,
672
- variant: "ghost",
673
- onClick: swapChains,
674
- children: /* @__PURE__ */ jsx2(ArrowRightLeftIcon, { className: "w-4 h-4 " })
675
- }
676
- ),
677
- /* @__PURE__ */ jsxs2(
678
- Badge,
679
- {
680
- variant: "outline",
681
- size: "large",
682
- className: "block flex-1 flex gap-[var(--ui-kit-gap)] justify-center",
683
- children: [
684
- DestinationChainIcon && /* @__PURE__ */ jsx2(DestinationChainIcon, { className: "w-6 h-6" }),
685
- destinationChain && /* @__PURE__ */ jsx2("span", { className: "block max-w-[100px] truncate", children: CHAINS_META[destinationChain]?.chainLabel })
686
- ]
687
- }
688
- )
689
- ] }),
690
- /* @__PURE__ */ jsxs2(
691
- "div",
692
- {
693
- className: cn(
694
- //
695
- "w-full flex flex-col",
696
- "text-[10px]",
697
- "gap-[var(--ui-kit-gap)]"
698
- ),
699
- children: [
700
- /* @__PURE__ */ jsx2("span", { className: "text-[var(--ui-kit-fg-muted)] leading-4", children: t("passport:common.amount") }),
701
- /* @__PURE__ */ jsx2(
702
- Input,
703
- {
704
- type: "text",
705
- disabled: isQuoteEstimating || !originChain || !destinationChain || !hyperRoute,
706
- placeholder: t("passport:common.amount"),
707
- onChange: (e) => {
708
- useFlowSelectorStore.getState().setError(null);
709
- let { value } = e.target;
710
- const regex = /^(0|[1-9]\d*)(\.\d{0,5})?$/;
711
- if (value.length > 1 && value.startsWith("0") && !value.startsWith("0.")) {
712
- value = value.slice(1);
713
- }
714
- if (regex.test(value) || value === "") {
715
- if (value === "") {
716
- setAmount("0");
717
- } else {
718
- setAmount(value);
719
- }
720
- }
721
- },
722
- value: amount
723
- }
724
- )
725
- ]
726
- }
727
- ),
728
- /* @__PURE__ */ jsxs2(
729
- "div",
730
- {
731
- className: cn(
732
- //
733
- "w-full flex flex-col",
734
- "text-[10px]",
735
- "gap-[var(--ui-kit-gap)] pb-[var(--ui-kit-pd)]"
736
- ),
737
- children: [
738
- /* @__PURE__ */ jsx2("span", { className: "text-[var(--ui-kit-fg-muted)] leading-4", children: t("passport:bridgeMenu.labels.optionalRecipient") }),
739
- /* @__PURE__ */ jsx2(
740
- Input,
741
- {
742
- type: "text",
743
- disabled: isQuoteEstimating || !originChain || !destinationChain || !hyperRoute,
744
- placeholder: t("passport:bridgeMenu.labels.optionalRecipient") + " (ex: 0x...)",
745
- value: recipient || "",
746
- Icon: Wallet2Icon,
747
- onChange: (e) => {
748
- useFlowSelectorStore.getState().setError(null);
749
- setRecipient(e.target.value);
750
- },
751
- element: /* @__PURE__ */ jsx2(
752
- Button,
753
- {
754
- size: "icon",
755
- disabled: isQuoteEstimating,
756
- variant: "ghost",
757
- onClick: (e) => {
758
- e.stopPropagation();
759
- setRecipient(null);
760
- },
761
- children: /* @__PURE__ */ jsx2(XIcon, { className: "w-4 h-4" })
762
- }
763
- )
764
- }
765
- )
766
- ]
767
- }
768
- )
769
- ] }),
770
- quote && /* @__PURE__ */ jsxs2(Highlight, { type: "info", className: "flex flex-col gap-[var(--ui-kit-gap)] w-full", children: [
771
- /* @__PURE__ */ jsxs2("p", { className: "flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
772
- /* @__PURE__ */ jsx2("span", { children: t("passport:bridgeMenu.quote.amount") }),
773
- /* @__PURE__ */ jsx2("strong", { children: formatPrice(Number(quote.amount)) })
774
- ] }),
775
- /* @__PURE__ */ jsxs2("p", { className: "flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
776
- /* @__PURE__ */ jsx2("span", { children: t("passport:bridgeMenu.quote.igpFee") }),
777
- /* @__PURE__ */ jsxs2("strong", { children: [
778
- /* @__PURE__ */ jsx2("span", { children: formatPrice(Number(quote.igpFee)) }),
779
- /* @__PURE__ */ jsxs2("span", { children: [
780
- " ",
781
- quote.igpSymbol
782
- ] })
783
- ] })
784
- ] }),
785
- /* @__PURE__ */ jsxs2("p", { className: "flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
786
- /* @__PURE__ */ jsx2("span", { children: t("passport:bridgeMenu.quote.localFee") }),
787
- /* @__PURE__ */ jsxs2("strong", { children: [
788
- /* @__PURE__ */ jsx2("span", { children: formatPrice(Number(quote.localFee)) }),
789
- /* @__PURE__ */ jsxs2("span", { children: [
790
- " ",
791
- quote.localSymbol
792
- ] })
793
- ] })
794
- ] }),
795
- quote.tokenFee && /* @__PURE__ */ jsxs2("p", { className: "flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
796
- /* @__PURE__ */ jsx2("span", { children: t("passport:bridgeMenu.quote.tokenFee") }),
797
- /* @__PURE__ */ jsx2("strong", { children: formatPrice(Number(quote.tokenFee)) })
798
- ] })
799
- ] }),
800
- /* @__PURE__ */ jsxs2(
801
- Button,
802
- {
803
- size: "large",
804
- variant: "default",
805
- className: "w-full",
806
- disabled: isQuoteEstimating || isError || !quote,
807
- onClick: () => useBridgeStore.getState().setBridgeStep("confirm"),
808
- children: [
809
- isQuoteEstimating && /* @__PURE__ */ jsx2(LoaderIcon, { className: "h-4 w-4 animate-spin" }),
810
- /* @__PURE__ */ jsx2("span", { children: t(
811
- (() => {
812
- switch (true) {
813
- // case isWalletChainConnecting:
814
- // return 'passport:bridgeMenu.statuses.switchingWalletChain'
815
- case isQuoteEstimating:
816
- return "passport:bridgeMenu.statuses.qouteEstimating";
817
- default:
818
- return "passport:bridgeMenu.actions.confirmBridge";
819
- }
820
- })()
821
- ).toUpperCase() })
822
- ]
823
- }
824
- )
825
- ] });
826
- }
827
-
828
- // src/internal/components/SendMenu/hyperbridge/steps/ConfirmStep.tsx
829
- import { LoaderIcon as LoaderIcon2 } from "lucide-react";
830
- import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
831
- var P_CN = "flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]";
832
- function ConfirmStep(props) {
833
- const { isAssetBridging, bridgeAsset } = props;
834
- const { t } = useT();
835
- const address = useSession((st) => st.address);
836
- const isError = useFlowSelectorStore((st) => !!st.error);
837
- const quote = useBridgeStore((st) => st.quote);
838
- const originChain = useBridgeStore((st) => st.originChain);
839
- const destinationChain = useBridgeStore((st) => st.destinationChain);
840
- const recipient = useBridgeStore((st) => st.recipient);
841
- const bridgeTxStatus = useBridgeStore((st) => st.bridgeTxStatus);
842
- const recipientAddress = (recipient || address).slice(0, 6) + "..." + (recipient || address).slice(-4);
843
- return /* @__PURE__ */ jsxs3(Fragment3, { children: [
844
- /* @__PURE__ */ jsxs3(Highlight, { type: "info", className: "flex flex-col gap-[var(--ui-kit-gap)] w-full", children: [
845
- /* @__PURE__ */ jsxs3("p", { className: P_CN, children: [
846
- /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.quote.recipient") }),
847
- /* @__PURE__ */ jsx3("strong", { children: recipientAddress })
848
- ] }),
849
- /* @__PURE__ */ jsxs3("p", { className: P_CN, children: [
850
- /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.labels.fromChain") }),
851
- /* @__PURE__ */ jsx3("strong", { children: CHAINS_META[originChain].chainLabel })
852
- ] }),
853
- /* @__PURE__ */ jsxs3("p", { className: P_CN, children: [
854
- /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.labels.toChain") }),
855
- /* @__PURE__ */ jsx3("strong", { children: CHAINS_META[destinationChain].chainLabel })
856
- ] }),
857
- /* @__PURE__ */ jsxs3("p", { className: P_CN, children: [
858
- /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.quote.amount") }),
859
- /* @__PURE__ */ jsx3("strong", { children: formatPrice(Number(quote.amount)) })
860
- ] }),
861
- /* @__PURE__ */ jsxs3("p", { className: "flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
862
- /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.quote.igpFee") }),
863
- /* @__PURE__ */ jsxs3("strong", { children: [
864
- /* @__PURE__ */ jsx3("span", { children: formatPrice(Number(quote.igpFee)) }),
865
- /* @__PURE__ */ jsxs3("span", { children: [
866
- " ",
867
- quote.igpSymbol
868
- ] })
869
- ] })
870
- ] }),
871
- /* @__PURE__ */ jsxs3("p", { className: "flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
872
- /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.quote.localFee") }),
873
- /* @__PURE__ */ jsxs3("strong", { children: [
874
- /* @__PURE__ */ jsx3("span", { children: formatPrice(Number(quote.localFee)) }),
875
- /* @__PURE__ */ jsxs3("span", { children: [
876
- " ",
877
- quote.localSymbol
878
- ] })
879
- ] })
880
- ] }),
881
- quote.tokenFee && /* @__PURE__ */ jsxs3("p", { className: P_CN, children: [
882
- /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.quote.tokenFee") }),
883
- /* @__PURE__ */ jsx3("strong", { children: formatPrice(Number(quote.tokenFee)) })
884
- ] })
885
- ] }),
886
- !isError && /* @__PURE__ */ jsxs3(
887
- Button,
888
- {
889
- size: "large",
890
- variant: "default",
891
- disabled: isAssetBridging,
892
- onClick: () => bridgeAsset(),
893
- className: "w-full",
894
- children: [
895
- isAssetBridging && /* @__PURE__ */ jsx3(LoaderIcon2, { className: "h-4 w-4 animate-spin" }),
896
- isAssetBridging ? /* @__PURE__ */ jsx3("span", { children: t("passport:bridgeMenu.statuses.txExecuting").toUpperCase() }) : /* @__PURE__ */ jsx3("span", { children: (bridgeTxStatus || t("passport:common.continue")).toUpperCase() })
897
- ]
898
- }
899
- )
900
- ] });
901
- }
902
-
903
- // src/internal/components/SendMenu/hyperbridge/steps/SuccessStep.tsx
904
- import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
905
- var P_CN2 = "w-full flex-1 flex items-center justify-between gap-[var(--ui-kit-gap)]";
906
- function SuccessStep() {
907
- const { t } = useT();
908
- const address = useSession((st) => st.address);
909
- const amount = useBridgeStore((st) => st.amount);
910
- const originChain = useBridgeStore((st) => st.originChain);
911
- const destinationChain = useBridgeStore((st) => st.destinationChain);
912
- const recipient = useBridgeStore((st) => st.recipient);
913
- const lastTxHashes = useBridgeStore((st) => st.lastTxHashes);
914
- const bridgeTxStatus = useBridgeStore((st) => st.bridgeTxStatus);
915
- const recipientAddress = (recipient || address).slice(0, 6) + "..." + (recipient || address).slice(-4);
916
- return /* @__PURE__ */ jsxs4(Fragment4, { children: [
917
- /* @__PURE__ */ jsxs4(Highlight, { type: "success", className: "flex flex-col gap-[var(--ui-kit-gap)] w-full", children: [
918
- /* @__PURE__ */ jsxs4("p", { className: P_CN2, children: [
919
- /* @__PURE__ */ jsx4("span", { children: t("passport:bridgeMenu.quote.status") }),
920
- /* @__PURE__ */ jsx4("strong", { children: bridgeTxStatus })
921
- ] }),
922
- /* @__PURE__ */ jsxs4("p", { className: P_CN2, children: [
923
- /* @__PURE__ */ jsx4("span", { children: t("passport:bridgeMenu.quote.recipient") }),
924
- /* @__PURE__ */ jsx4("strong", { children: recipientAddress })
925
- ] }),
926
- /* @__PURE__ */ jsxs4("p", { className: P_CN2, children: [
927
- /* @__PURE__ */ jsx4("span", { children: t("passport:bridgeMenu.labels.fromChain") }),
928
- /* @__PURE__ */ jsx4("strong", { children: CHAINS_META[originChain].chainLabel })
929
- ] }),
930
- /* @__PURE__ */ jsxs4("p", { className: P_CN2, children: [
931
- /* @__PURE__ */ jsx4("span", { children: t("passport:bridgeMenu.labels.toChain") }),
932
- /* @__PURE__ */ jsx4("strong", { children: CHAINS_META[destinationChain].chainLabel })
933
- ] }),
934
- /* @__PURE__ */ jsxs4("p", { className: P_CN2, children: [
935
- /* @__PURE__ */ jsx4("span", { children: t("passport:bridgeMenu.quote.amount") }),
936
- /* @__PURE__ */ jsx4("strong", { children: formatPrice(Number(amount)) })
937
- ] }),
938
- /* @__PURE__ */ jsx4("p", { className: "mt-[var(--ui-kit-gap)]", children: t("passport:bridgeMenu.labels.bridgeTransactions") + ":" }),
939
- lastTxHashes.map((hash) => /* @__PURE__ */ jsx4("p", { className: "truncate max-w-full font-mono! text-sm", children: hash }, hash))
940
- ] }),
941
- /* @__PURE__ */ jsx4(
942
- Button,
943
- {
944
- size: "large",
945
- variant: "default",
946
- className: "w-full",
947
- onClick: () => {
948
- useFlowSelectorStore.getState().setError(null);
949
- useBridgeStore.getState().setBridgeTxStatus(null);
950
- useBridgeStore.getState().setLastTxHashes([]);
951
- useBridgeStore.getState().setBridgeStep("select");
952
- },
953
- children: /* @__PURE__ */ jsx4("span", { children: `${t("passport:common.continue")}`.toUpperCase() })
954
- }
955
- )
956
- ] });
957
- }
958
-
959
- // src/internal/components/SendMenu/hyperbridge/HyperlaneBridge.tsx
960
- import { Fragment as Fragment5, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
961
- function HyperlaneBridge() {
962
- const { swapDirection, bridgeAsset, isAssetBridging } = useBridge();
963
- useMenuTitle();
964
- const bridgeStep = useBridgeStore((st) => st.bridgeStep);
965
- useEffect4(() => () => useBridgeStore.getState().resetSelections(), []);
966
- return /* @__PURE__ */ jsxs5(Fragment5, { children: [
967
- bridgeStep === "select-token" && /* @__PURE__ */ jsx5(TokenSelector, {}),
968
- bridgeStep === "select" && /* @__PURE__ */ jsx5(SelectStep, { swapChains: swapDirection }),
969
- bridgeStep === "confirm" && /* @__PURE__ */ jsx5(ConfirmStep, { isAssetBridging, bridgeAsset }),
970
- bridgeStep === "success" && /* @__PURE__ */ jsx5(SuccessStep, {})
971
- ] });
972
- }
973
-
974
- // src/internal/components/SendMenu/hyperbridge/index.ts
975
- var hyperbridge_default = HyperlaneBridge;
976
- export {
977
- hyperbridge_default as default,
978
- useBridgeStore
979
- };
980
- //# sourceMappingURL=hyperbridge-ISLQLJ65.js.map