@multiversx/sdk-dapp-liquidity 1.1.7 → 2.0.0-alpha.0

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.
Files changed (81) hide show
  1. package/index.js +7 -0
  2. package/index.mjs +8 -1
  3. package/package.json +19 -16
  4. package/reactjs/adapters/SuiAdapter.d.ts +60 -0
  5. package/reactjs/adapters/SuiAdapter.js +350 -0
  6. package/reactjs/adapters/SuiAdapter.mjs +349 -0
  7. package/reactjs/components/AmountInput/AmountInput.js +1 -1
  8. package/reactjs/components/AmountInput/AmountInput.mjs +1 -1
  9. package/reactjs/components/BridgeForm/Deposit.js +57 -18
  10. package/reactjs/components/BridgeForm/Deposit.mjs +57 -18
  11. package/reactjs/components/BridgeForm/Transfer.js +17 -10
  12. package/reactjs/components/BridgeForm/Transfer.mjs +17 -10
  13. package/reactjs/components/BridgeForm/hooks/useBridgeTokenSelection.js +31 -9
  14. package/reactjs/components/BridgeForm/hooks/useBridgeTokenSelection.mjs +31 -9
  15. package/reactjs/components/BridgeForm/utils/bridgeFormHelpers.d.ts +6 -0
  16. package/reactjs/components/BridgeForm/utils/bridgeFormHelpers.js +18 -0
  17. package/reactjs/components/BridgeForm/utils/bridgeFormHelpers.mjs +18 -0
  18. package/reactjs/components/BridgeHistory/BridgeHistory.js +2 -2
  19. package/reactjs/components/BridgeHistory/BridgeHistory.mjs +2 -2
  20. package/reactjs/components/Connect/BridgeAccountDisplay.js +77 -25
  21. package/reactjs/components/Connect/BridgeAccountDisplay.mjs +77 -25
  22. package/reactjs/components/Connect/BridgeConnectButton.js +1 -1
  23. package/reactjs/components/Connect/BridgeConnectButton.mjs +1 -1
  24. package/reactjs/components/Connect/ChainSelectConnect.d.ts +7 -0
  25. package/reactjs/components/Connect/ChainSelectConnect.js +144 -0
  26. package/reactjs/components/Connect/ChainSelectConnect.mjs +143 -0
  27. package/reactjs/components/Connect/MvxAccountDisplay.js +17 -3
  28. package/reactjs/components/Connect/MvxAccountDisplay.mjs +17 -3
  29. package/reactjs/components/Connect/MvxConnectButton.js +2 -2
  30. package/reactjs/components/Connect/MvxConnectButton.mjs +2 -2
  31. package/reactjs/components/Connect/index.d.ts +1 -0
  32. package/reactjs/components/Connect/index.js +2 -0
  33. package/reactjs/components/Connect/index.mjs +2 -0
  34. package/reactjs/components/TokenSelector/components/TokenItem.js +11 -1
  35. package/reactjs/components/TokenSelector/components/TokenItem.mjs +11 -1
  36. package/reactjs/components/TrimAddress/TrimAddress.js +1 -1
  37. package/reactjs/components/TrimAddress/TrimAddress.mjs +1 -1
  38. package/reactjs/components/index.js +2 -0
  39. package/reactjs/components/index.mjs +2 -0
  40. package/reactjs/constants/chains.d.ts +7 -1
  41. package/reactjs/constants/chains.js +6 -0
  42. package/reactjs/constants/chains.mjs +6 -0
  43. package/reactjs/helpers/index.d.ts +1 -0
  44. package/reactjs/helpers/index.js +7 -0
  45. package/reactjs/helpers/index.mjs +6 -0
  46. package/reactjs/helpers/resolveBridgeApiChainId.d.ts +18 -0
  47. package/reactjs/helpers/resolveBridgeApiChainId.js +41 -0
  48. package/reactjs/helpers/resolveBridgeApiChainId.mjs +40 -0
  49. package/reactjs/hooks/index.d.ts +2 -0
  50. package/reactjs/hooks/index.js +4 -0
  51. package/reactjs/hooks/index.mjs +4 -0
  52. package/reactjs/hooks/useBridgeApiChainId.d.ts +2 -0
  53. package/reactjs/hooks/useBridgeApiChainId.js +14 -0
  54. package/reactjs/hooks/useBridgeApiChainId.mjs +13 -0
  55. package/reactjs/hooks/useFetchTokens.js +17 -17
  56. package/reactjs/hooks/useFetchTokens.mjs +17 -17
  57. package/reactjs/hooks/useGenericSignMessage.d.ts +1 -1
  58. package/reactjs/hooks/useGenericSignMessage.js +14 -0
  59. package/reactjs/hooks/useGenericSignMessage.mjs +14 -0
  60. package/reactjs/hooks/useSignTransaction.d.ts +418 -3
  61. package/reactjs/hooks/useSignTransaction.js +28 -0
  62. package/reactjs/hooks/useSignTransaction.mjs +28 -0
  63. package/reactjs/hooks/useSuiConnect.d.ts +8 -0
  64. package/reactjs/hooks/useSuiConnect.js +87 -0
  65. package/reactjs/hooks/useSuiConnect.mjs +86 -0
  66. package/reactjs/index.js +7 -0
  67. package/reactjs/index.mjs +8 -1
  68. package/reactjs/init/index.js +1 -0
  69. package/reactjs/init/index.mjs +2 -1
  70. package/reactjs/init/init.d.ts +9 -30
  71. package/reactjs/init/init.js +90 -9
  72. package/reactjs/init/init.mjs +91 -10
  73. package/reactjs/queries/useCheckAccount.query.js +4 -14
  74. package/reactjs/queries/useCheckAccount.query.mjs +4 -14
  75. package/reactjs/queries/useGetNonMvxTokensBalances.query.js +1 -0
  76. package/reactjs/queries/useGetNonMvxTokensBalances.query.mjs +1 -0
  77. package/style.css +51 -0
  78. package/types/chainType.d.ts +2 -1
  79. package/types/chainType.js +1 -0
  80. package/types/chainType.mjs +1 -0
  81. package/types/transaction.d.ts +5 -0
@@ -8,11 +8,14 @@ import debounce from "lodash/debounce";
8
8
  import { useRef, useState, useMemo, useCallback, useEffect } from "react";
9
9
  import { toast } from "react-toastify";
10
10
  import { useBridgeTokenSelection } from "./hooks/useBridgeTokenSelection.mjs";
11
+ import { resolveSigningChainType } from "./utils/bridgeFormHelpers.mjs";
11
12
  import { MVX_CHAIN_IDS } from "../../../constants/index.mjs";
12
13
  import { getApiURL } from "../../../helpers/getApiURL.mjs";
13
14
  import { ChainType } from "../../../types/chainType.mjs";
14
15
  import { useWeb3App } from "../../context/useWeb3App.mjs";
16
+ import { sameBridgeApiChainId, toBridgeApiChainId } from "../../helpers/resolveBridgeApiChainId.mjs";
15
17
  import { useAccount } from "../../hooks/useAccount.mjs";
18
+ import { useBridgeApiChainId } from "../../hooks/useBridgeApiChainId.mjs";
16
19
  import { useBridgeFormik, BridgeFormikValuesEnum } from "../../hooks/useBridgeFormik.mjs";
17
20
  import { useFetchBridgeData } from "../../hooks/useFetchBridgeData.mjs";
18
21
  import { useGetChainId } from "../../hooks/useGetChainId.mjs";
@@ -39,6 +42,7 @@ import "wagmi";
39
42
  import { MvxConnectButton } from "../Connect/MvxConnectButton.mjs";
40
43
  import { BridgeAccountDisplay } from "../Connect/BridgeAccountDisplay.mjs";
41
44
  import { MvxAccountDisplay } from "../Connect/MvxAccountDisplay.mjs";
45
+ import "@reown/appkit-controllers";
42
46
  import { ToggleDirection } from "../ToggleDirection/ToggleDirection.mjs";
43
47
  import { TokenSelector } from "../TokenSelector/TokenSelector.mjs";
44
48
  let fetchRateInterval;
@@ -78,6 +82,7 @@ const Deposit = ({
78
82
  bridgeOnly
79
83
  } = useWeb3App();
80
84
  const chainId = useGetChainId();
85
+ const bridgeApiChainId = useBridgeApiChainId();
81
86
  const {
82
87
  evmTokensWithBalances,
83
88
  mvxTokensWithBalances,
@@ -93,16 +98,14 @@ const Deposit = ({
93
98
  });
94
99
  const isTokensLoading = tokensLoading || isLoadingEvmTokensBalances || isLoadingMvxTokensBalances || isChainsLoading;
95
100
  const activeChain = useMemo(() => {
96
- return sdkChains.find(
97
- (chain) => chain.id.toString() === (chainId == null ? void 0 : chainId.toString())
98
- );
101
+ return sdkChains.find((chain) => sameBridgeApiChainId(chain.id, chainId));
99
102
  }, [chainId, sdkChains]);
100
103
  const mvxChain = useMemo(() => {
101
104
  return chains.find(
102
105
  (chain) => chain.chainId.toString() === mvxChainId.toString()
103
106
  );
104
107
  }, [chainId, chains]);
105
- const { evm, solana, bitcoin } = useSignTransaction();
108
+ const { evm, solana, bitcoin, sui } = useSignTransaction();
106
109
  const sendTransactions = useSendTransactions();
107
110
  const {
108
111
  mutate: getRate,
@@ -114,7 +117,7 @@ const Deposit = ({
114
117
  const handleSwitchNetwork = useCallback(
115
118
  (chain) => {
116
119
  const sdkChain = sdkChains.find(
117
- (c) => c.id.toString() === chain.id.toString()
120
+ (c) => sameBridgeApiChainId(c.id, chain.id)
118
121
  );
119
122
  if (sdkChain) {
120
123
  switchNetwork(sdkChain);
@@ -158,15 +161,19 @@ const Deposit = ({
158
161
  return selectedChainOption;
159
162
  }
160
163
  return chains.find(
161
- (chain) => chain.chainId.toString() === firstToken.chainId.toString()
164
+ (chain) => sameBridgeApiChainId(chain.chainId, firstToken.chainId)
162
165
  ) ?? selectedChainOption;
163
166
  }, [firstToken == null ? void 0 : firstToken.chainId, chains, selectedChainOption]);
167
+ const bridgeFromChainId = useMemo(
168
+ () => toBridgeApiChainId(firstToken == null ? void 0 : firstToken.chainId) ?? bridgeApiChainId,
169
+ [firstToken == null ? void 0 : firstToken.chainId, bridgeApiChainId]
170
+ );
164
171
  const bridgeAddress = account.address;
165
172
  const isAuthenticated = account.isConnected && Boolean(bridgeAddress);
166
173
  const hasAmounts = firstAmount !== "" && secondAmount !== "";
167
174
  const fetchRateDebounced = useCallback(
168
175
  debounce(async (amount) => {
169
- if (!amount || !Number(amount) || !account.address || !(firstToken == null ? void 0 : firstToken.address) || !(secondToken == null ? void 0 : secondToken.address) || !selectedChainOption || !chainId) {
176
+ if (!amount || !Number(amount) || !account.address || !(firstToken == null ? void 0 : firstToken.address) || !(secondToken == null ? void 0 : secondToken.address) || !selectedChainOption || !bridgeFromChainId) {
170
177
  return;
171
178
  }
172
179
  getRate({
@@ -174,7 +181,7 @@ const Deposit = ({
174
181
  body: {
175
182
  tokenIn: firstToken.address,
176
183
  amountIn: amount,
177
- fromChainId: chainId.toString(),
184
+ fromChainId: bridgeFromChainId,
178
185
  tokenOut: secondToken.address,
179
186
  toChainId: mvxChainId
180
187
  }
@@ -182,6 +189,7 @@ const Deposit = ({
182
189
  }, 500),
183
190
  [
184
191
  account.address,
192
+ bridgeFromChainId,
185
193
  firstToken == null ? void 0 : firstToken.address,
186
194
  secondToken == null ? void 0 : secondToken.address,
187
195
  selectedChainOption
@@ -240,6 +248,7 @@ const Deposit = ({
240
248
  transactions,
241
249
  provider
242
250
  }) => {
251
+ var _a2, _b2, _c;
243
252
  const signedTransactions = [];
244
253
  setPendingSigning(true);
245
254
  setSigningTransactionsCount(() => transactions.length);
@@ -248,8 +257,8 @@ const Deposit = ({
248
257
  for (const transaction of transactions) {
249
258
  ++txIndex;
250
259
  try {
251
- switch (selectedChainOption == null ? void 0 : selectedChainOption.chainType) {
252
- case ChainType.evm:
260
+ switch (resolveSigningChainType(transaction, firstTokenChain)) {
261
+ case ChainType.evm: {
253
262
  const hash = await evm.signTransaction({
254
263
  ...transaction,
255
264
  value: BigInt(transaction.value),
@@ -278,6 +287,7 @@ const Deposit = ({
278
287
  hash
279
288
  });
280
289
  break;
290
+ }
281
291
  case ChainType.sol:
282
292
  if (!transaction.instructions || !transaction.feePayer) {
283
293
  break;
@@ -308,6 +318,29 @@ const Deposit = ({
308
318
  txHash: psbt
309
319
  });
310
320
  break;
321
+ case ChainType.sui: {
322
+ const serializedTx = (_a2 = transaction.suiParams) == null ? void 0 : _a2.transactionBytes;
323
+ const sender = (_b2 = transaction.suiParams) == null ? void 0 : _b2.sender;
324
+ if (!serializedTx || !sender) {
325
+ console.error("No Sui transaction bytes or sender address");
326
+ break;
327
+ }
328
+ const signature = await sui.signTransaction({
329
+ transaction: serializedTx,
330
+ address: sender
331
+ });
332
+ if (!signature) {
333
+ break;
334
+ }
335
+ signedTransactions.push({
336
+ ...transaction,
337
+ suiParams: {
338
+ ...transaction.suiParams,
339
+ signature
340
+ }
341
+ });
342
+ break;
343
+ }
311
344
  default:
312
345
  toast.error("Provider not supported");
313
346
  setPendingSigning(false);
@@ -324,13 +357,15 @@ const Deposit = ({
324
357
  return;
325
358
  }
326
359
  }
327
- await sendTransactions({
360
+ const { data: batch } = await sendTransactions({
328
361
  transactions: signedTransactions,
329
362
  provider,
330
363
  url: getApiURL() ?? "",
331
364
  token: nativeAuthToken ?? ""
332
365
  });
333
- const txHashes = signedTransactions.map((tx) => tx.txHash);
366
+ const apiHashes = ((_c = batch.transactions) == null ? void 0 : _c.map((tx) => tx.txHash).filter((h) => Boolean(h))) ?? [];
367
+ const localHashes = signedTransactions.map((tx) => tx.txHash).filter((h) => Boolean(h));
368
+ const txHashes = apiHashes.length > 0 ? apiHashes : localHashes.length > 0 ? localHashes : batch.batchId ? [batch.batchId] : [];
334
369
  onSuccess(txHashes);
335
370
  setPendingSigning(false);
336
371
  } catch (e) {
@@ -346,14 +381,18 @@ const Deposit = ({
346
381
  }
347
382
  },
348
383
  [
349
- selectedChainOption,
384
+ firstTokenChain == null ? void 0 : firstTokenChain.chainType,
350
385
  bridgeAddress,
386
+ config,
351
387
  handleOnChangeFirstAmount,
352
388
  handleOnChangeSecondAmount,
353
389
  nativeAuthToken,
354
390
  onSuccess,
355
391
  sendTransactions,
356
- evm.signTransaction
392
+ bitcoin.signTransaction,
393
+ evm.signTransaction,
394
+ solana.signTransaction,
395
+ sui.signTransaction
357
396
  ]
358
397
  );
359
398
  const {
@@ -372,7 +411,7 @@ const Deposit = ({
372
411
  receiver: mvxAddress ?? "",
373
412
  firstToken,
374
413
  firstAmount,
375
- fromChainId: chainId == null ? void 0 : chainId.toString(),
414
+ fromChainId: bridgeFromChainId,
376
415
  toChainId: mvxChainId,
377
416
  secondToken,
378
417
  secondAmount,
@@ -580,14 +619,14 @@ const Deposit = ({
580
619
  className: "liq-w-full disabled:liq-bg-neutral-850/50 liq-py-3 hover:enabled:liq-bg-primary !liq-text-primary-200",
581
620
  disabled: !hasAmounts || isPendingRate || !mvxAddress || !account.address || hasError || pendingSigning,
582
621
  children: [
583
- hasAmounts && !pendingSigning && /* @__PURE__ */ jsxs("div", { className: "liq-flex liq-justify-center liq-gap-2", children: [
622
+ hasAmounts && !pendingSigning && /* @__PURE__ */ jsxs("div", { className: "liq-flex liq-justify-center liq-items-center liq-gap-2", children: [
584
623
  /* @__PURE__ */ jsx("div", { children: "Deposit on " }),
585
624
  /* @__PURE__ */ jsx(
586
625
  "img",
587
626
  {
588
627
  src: (mvxChain == null ? void 0 : mvxChain.pngUrl) ?? "",
589
628
  alt: "",
590
- className: "liq-h-[1.5rem] liq-w-[1.5rem]"
629
+ className: "liq-h-[1.5rem] liq-w-[1.5rem] liq-rounded-lg"
591
630
  }
592
631
  ),
593
632
  /* @__PURE__ */ jsx("div", { children: "MultiversX" })
@@ -608,7 +647,7 @@ const Deposit = ({
608
647
  {
609
648
  src: (mvxChain == null ? void 0 : mvxChain.pngUrl) ?? "",
610
649
  alt: "",
611
- className: "liq-h-[1.5rem] liq-w-[1.5rem]"
650
+ className: "liq-h-[1.5rem] liq-w-[1.5rem] liq-rounded-lg"
612
651
  }
613
652
  ),
614
653
  /* @__PURE__ */ jsx("div", { children: "MultiversX" })
@@ -12,6 +12,7 @@ const constants_index = require("../../../constants/index.js");
12
12
  const helpers_getApiURL = require("../../../helpers/getApiURL.js");
13
13
  const types_providerType = require("../../../types/providerType.js");
14
14
  const reactjs_context_useWeb3App = require("../../context/useWeb3App.js");
15
+ const reactjs_helpers_resolveBridgeApiChainId = require("../../helpers/resolveBridgeApiChainId.js");
15
16
  require("yup");
16
17
  require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount");
17
18
  require("bignumber.js");
@@ -19,6 +20,7 @@ const reactjs_hooks_useAccount = require("../../hooks/useAccount.js");
19
20
  require("axios");
20
21
  const reactjs_hooks_useBridgeFormik = require("../../hooks/useBridgeFormik.js");
21
22
  const reactjs_hooks_useFetchBridgeData = require("../../hooks/useFetchBridgeData.js");
23
+ const reactjs_hooks_useBridgeApiChainId = require("../../hooks/useBridgeApiChainId.js");
22
24
  require("@tanstack/react-query");
23
25
  const reactjs_hooks_useGetChainId = require("../../hooks/useGetChainId.js");
24
26
  require("../../constants/index.js");
@@ -26,6 +28,7 @@ const reactjs_hooks_useSendTransactions = require("../../hooks/useSendTransactio
26
28
  require("@reown/appkit-adapter-solana/react");
27
29
  require("@solana/web3.js");
28
30
  require("wagmi");
31
+ require("@reown/appkit-controllers");
29
32
  const reactjs_queries_useGetHistory_query = require("../../queries/useGetHistory.query.js");
30
33
  const reactjs_queries_useGetRate_mutation = require("../../queries/useGetRate.mutation.js");
31
34
  const reactjs_utils_mxClsx = require("../../utils/mxClsx.js");
@@ -84,6 +87,7 @@ const Transfer = ({
84
87
  bridgeOnly
85
88
  } = reactjs_context_useWeb3App.useWeb3App();
86
89
  const chainId = reactjs_hooks_useGetChainId.useGetChainId();
90
+ const bridgeApiChainId = reactjs_hooks_useBridgeApiChainId.useBridgeApiChainId();
87
91
  const sendTransactions = reactjs_hooks_useSendTransactions.useSendTransactions();
88
92
  const {
89
93
  signMvxTransactions,
@@ -105,9 +109,7 @@ const Transfer = ({
105
109
  });
106
110
  const isTokensLoading = tokensLoading || isLoadingEvmTokensBalances || isLoadingMvxTokensBalances || isChainsLoading;
107
111
  const activeChain = React.useMemo(() => {
108
- return sdkChains.find(
109
- (chain) => chain.id.toString() === (chainId == null ? void 0 : chainId.toString())
110
- );
112
+ return sdkChains.find((chain) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(chain.id, chainId));
111
113
  }, [chainId, sdkChains]);
112
114
  const mvxChain = React.useMemo(() => {
113
115
  return chains.find(
@@ -124,7 +126,7 @@ const Transfer = ({
124
126
  const handleSwitchNetwork = React.useCallback(
125
127
  (chain) => {
126
128
  const sdkChain = sdkChains.find(
127
- (c) => c.id.toString() === chain.id.toString()
129
+ (c) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(c.id, chain.id)
128
130
  );
129
131
  if (sdkChain) {
130
132
  switchNetwork(sdkChain);
@@ -173,15 +175,19 @@ const Transfer = ({
173
175
  return selectedChainOption;
174
176
  }
175
177
  return chains.find(
176
- (chain) => chain.chainId.toString() === secondToken.chainId.toString()
178
+ (chain) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(chain.chainId, secondToken.chainId)
177
179
  ) ?? selectedChainOption;
178
180
  }, [secondToken == null ? void 0 : secondToken.chainId, chains, selectedChainOption]);
181
+ const bridgeToChainId = React.useMemo(
182
+ () => reactjs_helpers_resolveBridgeApiChainId.toBridgeApiChainId(secondToken == null ? void 0 : secondToken.chainId) ?? bridgeApiChainId,
183
+ [secondToken == null ? void 0 : secondToken.chainId, bridgeApiChainId]
184
+ );
179
185
  const bridgeAddress = account.address;
180
186
  const isAuthenticated = account.isConnected && Boolean(bridgeAddress);
181
187
  const hasAmounts = firstAmount !== "" && secondAmount !== "";
182
188
  const fetchRateDebounced = React.useCallback(
183
189
  debounce(async (amount) => {
184
- if (!amount || !Number(amount) || !account.address || !(firstToken == null ? void 0 : firstToken.address) || !(secondToken == null ? void 0 : secondToken.address) || !selectedChainOption || !chainId) {
190
+ if (!amount || !Number(amount) || !account.address || !(firstToken == null ? void 0 : firstToken.address) || !(secondToken == null ? void 0 : secondToken.address) || !selectedChainOption || !bridgeToChainId) {
185
191
  return;
186
192
  }
187
193
  getRate({
@@ -191,12 +197,13 @@ const Transfer = ({
191
197
  amountIn: amount,
192
198
  fromChainId: mvxChainId,
193
199
  tokenOut: secondToken.address,
194
- toChainId: chainId.toString()
200
+ toChainId: bridgeToChainId
195
201
  }
196
202
  });
197
203
  }, 500),
198
204
  [
199
205
  account.address,
206
+ bridgeToChainId,
200
207
  firstToken == null ? void 0 : firstToken.address,
201
208
  secondToken == null ? void 0 : secondToken.address,
202
209
  selectedChainOption
@@ -281,7 +288,7 @@ const Transfer = ({
281
288
  firstToken,
282
289
  firstAmount,
283
290
  fromChainId: mvxChainId,
284
- toChainId: chainId == null ? void 0 : chainId.toString(),
291
+ toChainId: bridgeToChainId,
285
292
  secondToken,
286
293
  secondAmount,
287
294
  setForceRefetchRate,
@@ -521,14 +528,14 @@ const Transfer = ({
521
528
  className: "liq-w-full disabled:liq-bg-neutral-850/50 liq-py-3 hover:enabled:liq-bg-primary !liq-text-primary-200",
522
529
  disabled: !hasAmounts || isPendingRate || !mvxAddress || !account.address || hasError,
523
530
  children: [
524
- hasAmounts && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "liq-flex liq-justify-center liq-gap-2", children: [
531
+ hasAmounts && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "liq-flex liq-justify-center liq-items-center liq-gap-2", children: [
525
532
  /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Transfer to " }),
526
533
  /* @__PURE__ */ jsxRuntime.jsx(
527
534
  "img",
528
535
  {
529
536
  src: (secondTokenChain == null ? void 0 : secondTokenChain.pngUrl) ?? "",
530
537
  alt: "",
531
- className: "liq-h-[1.5rem] liq-w-[1.5rem]"
538
+ className: "liq-h-[1.5rem] liq-w-[1.5rem] liq-rounded-lg"
532
539
  }
533
540
  ),
534
541
  /* @__PURE__ */ jsxRuntime.jsx("div", { children: secondTokenChain == null ? void 0 : secondTokenChain.networkName })
@@ -9,6 +9,7 @@ import { MVX_CHAIN_IDS } from "../../../constants/index.mjs";
9
9
  import { getApiURL } from "../../../helpers/getApiURL.mjs";
10
10
  import { ProviderType } from "../../../types/providerType.mjs";
11
11
  import { useWeb3App } from "../../context/useWeb3App.mjs";
12
+ import { sameBridgeApiChainId, toBridgeApiChainId } from "../../helpers/resolveBridgeApiChainId.mjs";
12
13
  import "yup";
13
14
  import "@multiversx/sdk-dapp-utils/out/helpers/parseAmount";
14
15
  import "bignumber.js";
@@ -16,6 +17,7 @@ import { useAccount } from "../../hooks/useAccount.mjs";
16
17
  import "axios";
17
18
  import { useBridgeFormik, BridgeFormikValuesEnum } from "../../hooks/useBridgeFormik.mjs";
18
19
  import { useFetchBridgeData } from "../../hooks/useFetchBridgeData.mjs";
20
+ import { useBridgeApiChainId } from "../../hooks/useBridgeApiChainId.mjs";
19
21
  import "@tanstack/react-query";
20
22
  import { useGetChainId } from "../../hooks/useGetChainId.mjs";
21
23
  import "../../constants/index.mjs";
@@ -23,6 +25,7 @@ import { useSendTransactions } from "../../hooks/useSendTransactions.mjs";
23
25
  import "@reown/appkit-adapter-solana/react";
24
26
  import "@solana/web3.js";
25
27
  import "wagmi";
28
+ import "@reown/appkit-controllers";
26
29
  import { invalidateHistoryQuery } from "../../queries/useGetHistory.query.mjs";
27
30
  import { useGetRateMutation } from "../../queries/useGetRate.mutation.mjs";
28
31
  import { mxClsx } from "../../utils/mxClsx.mjs";
@@ -81,6 +84,7 @@ const Transfer = ({
81
84
  bridgeOnly
82
85
  } = useWeb3App();
83
86
  const chainId = useGetChainId();
87
+ const bridgeApiChainId = useBridgeApiChainId();
84
88
  const sendTransactions = useSendTransactions();
85
89
  const {
86
90
  signMvxTransactions,
@@ -102,9 +106,7 @@ const Transfer = ({
102
106
  });
103
107
  const isTokensLoading = tokensLoading || isLoadingEvmTokensBalances || isLoadingMvxTokensBalances || isChainsLoading;
104
108
  const activeChain = useMemo(() => {
105
- return sdkChains.find(
106
- (chain) => chain.id.toString() === (chainId == null ? void 0 : chainId.toString())
107
- );
109
+ return sdkChains.find((chain) => sameBridgeApiChainId(chain.id, chainId));
108
110
  }, [chainId, sdkChains]);
109
111
  const mvxChain = useMemo(() => {
110
112
  return chains.find(
@@ -121,7 +123,7 @@ const Transfer = ({
121
123
  const handleSwitchNetwork = useCallback(
122
124
  (chain) => {
123
125
  const sdkChain = sdkChains.find(
124
- (c) => c.id.toString() === chain.id.toString()
126
+ (c) => sameBridgeApiChainId(c.id, chain.id)
125
127
  );
126
128
  if (sdkChain) {
127
129
  switchNetwork(sdkChain);
@@ -170,15 +172,19 @@ const Transfer = ({
170
172
  return selectedChainOption;
171
173
  }
172
174
  return chains.find(
173
- (chain) => chain.chainId.toString() === secondToken.chainId.toString()
175
+ (chain) => sameBridgeApiChainId(chain.chainId, secondToken.chainId)
174
176
  ) ?? selectedChainOption;
175
177
  }, [secondToken == null ? void 0 : secondToken.chainId, chains, selectedChainOption]);
178
+ const bridgeToChainId = useMemo(
179
+ () => toBridgeApiChainId(secondToken == null ? void 0 : secondToken.chainId) ?? bridgeApiChainId,
180
+ [secondToken == null ? void 0 : secondToken.chainId, bridgeApiChainId]
181
+ );
176
182
  const bridgeAddress = account.address;
177
183
  const isAuthenticated = account.isConnected && Boolean(bridgeAddress);
178
184
  const hasAmounts = firstAmount !== "" && secondAmount !== "";
179
185
  const fetchRateDebounced = useCallback(
180
186
  debounce(async (amount) => {
181
- if (!amount || !Number(amount) || !account.address || !(firstToken == null ? void 0 : firstToken.address) || !(secondToken == null ? void 0 : secondToken.address) || !selectedChainOption || !chainId) {
187
+ if (!amount || !Number(amount) || !account.address || !(firstToken == null ? void 0 : firstToken.address) || !(secondToken == null ? void 0 : secondToken.address) || !selectedChainOption || !bridgeToChainId) {
182
188
  return;
183
189
  }
184
190
  getRate({
@@ -188,12 +194,13 @@ const Transfer = ({
188
194
  amountIn: amount,
189
195
  fromChainId: mvxChainId,
190
196
  tokenOut: secondToken.address,
191
- toChainId: chainId.toString()
197
+ toChainId: bridgeToChainId
192
198
  }
193
199
  });
194
200
  }, 500),
195
201
  [
196
202
  account.address,
203
+ bridgeToChainId,
197
204
  firstToken == null ? void 0 : firstToken.address,
198
205
  secondToken == null ? void 0 : secondToken.address,
199
206
  selectedChainOption
@@ -278,7 +285,7 @@ const Transfer = ({
278
285
  firstToken,
279
286
  firstAmount,
280
287
  fromChainId: mvxChainId,
281
- toChainId: chainId == null ? void 0 : chainId.toString(),
288
+ toChainId: bridgeToChainId,
282
289
  secondToken,
283
290
  secondAmount,
284
291
  setForceRefetchRate,
@@ -518,14 +525,14 @@ const Transfer = ({
518
525
  className: "liq-w-full disabled:liq-bg-neutral-850/50 liq-py-3 hover:enabled:liq-bg-primary !liq-text-primary-200",
519
526
  disabled: !hasAmounts || isPendingRate || !mvxAddress || !account.address || hasError,
520
527
  children: [
521
- hasAmounts && /* @__PURE__ */ jsxs("div", { className: "liq-flex liq-justify-center liq-gap-2", children: [
528
+ hasAmounts && /* @__PURE__ */ jsxs("div", { className: "liq-flex liq-justify-center liq-items-center liq-gap-2", children: [
522
529
  /* @__PURE__ */ jsx("div", { children: "Transfer to " }),
523
530
  /* @__PURE__ */ jsx(
524
531
  "img",
525
532
  {
526
533
  src: (secondTokenChain == null ? void 0 : secondTokenChain.pngUrl) ?? "",
527
534
  alt: "",
528
- className: "liq-h-[1.5rem] liq-w-[1.5rem]"
535
+ className: "liq-h-[1.5rem] liq-w-[1.5rem] liq-rounded-lg"
529
536
  }
530
537
  ),
531
538
  /* @__PURE__ */ jsx("div", { children: secondTokenChain == null ? void 0 : secondTokenChain.networkName })
@@ -2,6 +2,7 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
4
  const React = require("react");
5
+ const reactjs_helpers_resolveBridgeApiChainId = require("../../../helpers/resolveBridgeApiChainId.js");
5
6
  const reactjs_utils_getInitialTokens = require("../../../utils/getInitialTokens.js");
6
7
  const reactjs_components_BridgeForm_utils_bridgeFormHelpers = require("../utils/bridgeFormHelpers.js");
7
8
  const useBridgeTokenSelection = ({
@@ -56,12 +57,33 @@ const useBridgeTokenSelection = ({
56
57
  ticker: token.symbol
57
58
  }))) ?? [];
58
59
  }, [firstToken == null ? void 0 : firstToken.symbol, toTokens]);
59
- const selectedChainOption = React.useMemo(
60
- () => (chains == null ? void 0 : chains.find(
61
- (option) => option.chainId.toString() === (activeChain == null ? void 0 : activeChain.id.toString())
62
- )) ?? (chains == null ? void 0 : chains[0]),
63
- [activeChain == null ? void 0 : activeChain.id, chains]
64
- );
60
+ const selectedChainOption = React.useMemo(() => {
61
+ const anchorToken = mvxChainId ? secondToken : firstToken;
62
+ const byAnchorToken = anchorToken && (chains == null ? void 0 : chains.find(
63
+ (option) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(option.chainId, anchorToken.chainId)
64
+ ));
65
+ if (byAnchorToken) {
66
+ return byAnchorToken;
67
+ }
68
+ const byActiveChain = chains == null ? void 0 : chains.find(
69
+ (option) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(option.chainId, activeChain == null ? void 0 : activeChain.id)
70
+ );
71
+ if (byActiveChain) {
72
+ return byActiveChain;
73
+ }
74
+ const byOtherToken = mvxChainId ? firstToken && (chains == null ? void 0 : chains.find(
75
+ (option) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(option.chainId, firstToken.chainId)
76
+ )) : secondToken && (chains == null ? void 0 : chains.find(
77
+ (option) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(option.chainId, secondToken.chainId)
78
+ ));
79
+ return byOtherToken ?? (chains == null ? void 0 : chains[0]);
80
+ }, [
81
+ activeChain == null ? void 0 : activeChain.id,
82
+ chains,
83
+ firstToken == null ? void 0 : firstToken.chainId,
84
+ mvxChainId,
85
+ secondToken == null ? void 0 : secondToken.chainId
86
+ ]);
65
87
  const getDefaultReceivingToken = React.useCallback(
66
88
  (values) => reactjs_components_BridgeForm_utils_bridgeFormHelpers.getDefaultReceivingToken(values, toTokens),
67
89
  [toTokens]
@@ -132,7 +154,7 @@ const useBridgeTokenSelection = ({
132
154
  secondTokenId: firstToken.address
133
155
  });
134
156
  const selectedOptionChain = sdkChains == null ? void 0 : sdkChains.find(
135
- (chain) => chain.id.toString() === secondToken.chainId.toString()
157
+ (chain) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(chain.id, secondToken.chainId)
136
158
  );
137
159
  if (selectedOptionChain && switchNetwork) {
138
160
  switchNetwork(selectedOptionChain);
@@ -154,7 +176,7 @@ const useBridgeTokenSelection = ({
154
176
  const firstOption = fromOptions.find(
155
177
  ({ identifier }) => (initialTokens == null ? void 0 : initialTokens.firstTokenId) === identifier
156
178
  ) ?? fromOptions.find(
157
- (option) => option.chainId.toString() === (activeChainId == null ? void 0 : activeChainId.toString())
179
+ (option) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(option.chainId, activeChainId)
158
180
  ) ?? fromOptions[0];
159
181
  let secondOption = toTokens == null ? void 0 : toTokens.find(
160
182
  (x) => x.symbol.toLowerCase() === (firstOption == null ? void 0 : firstOption.symbol.toLowerCase())
@@ -179,7 +201,7 @@ const useBridgeTokenSelection = ({
179
201
  setFirstToken(firstOption);
180
202
  updateUrlParams({ firstTokenId: firstOption.address });
181
203
  const selectedOptionChain = (sdkChains == null ? void 0 : sdkChains.find(
182
- (chain) => chain.id.toString() === firstOption.chainId.toString()
204
+ (chain) => reactjs_helpers_resolveBridgeApiChainId.sameBridgeApiChainId(chain.id, firstOption.chainId)
183
205
  )) ?? activeChain;
184
206
  if (selectedOptionChain && switchNetwork) {
185
207
  switchNetwork(selectedOptionChain);
@@ -1,4 +1,5 @@
1
1
  import { useRef, useState, useMemo, useCallback, useEffect } from "react";
2
+ import { sameBridgeApiChainId } from "../../../helpers/resolveBridgeApiChainId.mjs";
2
3
  import { getInitialTokens } from "../../../utils/getInitialTokens.mjs";
3
4
  import { getAvailableTokens, getDefaultReceivingToken, updateUrlParams } from "../utils/bridgeFormHelpers.mjs";
4
5
  const useBridgeTokenSelection = ({
@@ -53,12 +54,33 @@ const useBridgeTokenSelection = ({
53
54
  ticker: token.symbol
54
55
  }))) ?? [];
55
56
  }, [firstToken == null ? void 0 : firstToken.symbol, toTokens]);
56
- const selectedChainOption = useMemo(
57
- () => (chains == null ? void 0 : chains.find(
58
- (option) => option.chainId.toString() === (activeChain == null ? void 0 : activeChain.id.toString())
59
- )) ?? (chains == null ? void 0 : chains[0]),
60
- [activeChain == null ? void 0 : activeChain.id, chains]
61
- );
57
+ const selectedChainOption = useMemo(() => {
58
+ const anchorToken = mvxChainId ? secondToken : firstToken;
59
+ const byAnchorToken = anchorToken && (chains == null ? void 0 : chains.find(
60
+ (option) => sameBridgeApiChainId(option.chainId, anchorToken.chainId)
61
+ ));
62
+ if (byAnchorToken) {
63
+ return byAnchorToken;
64
+ }
65
+ const byActiveChain = chains == null ? void 0 : chains.find(
66
+ (option) => sameBridgeApiChainId(option.chainId, activeChain == null ? void 0 : activeChain.id)
67
+ );
68
+ if (byActiveChain) {
69
+ return byActiveChain;
70
+ }
71
+ const byOtherToken = mvxChainId ? firstToken && (chains == null ? void 0 : chains.find(
72
+ (option) => sameBridgeApiChainId(option.chainId, firstToken.chainId)
73
+ )) : secondToken && (chains == null ? void 0 : chains.find(
74
+ (option) => sameBridgeApiChainId(option.chainId, secondToken.chainId)
75
+ ));
76
+ return byOtherToken ?? (chains == null ? void 0 : chains[0]);
77
+ }, [
78
+ activeChain == null ? void 0 : activeChain.id,
79
+ chains,
80
+ firstToken == null ? void 0 : firstToken.chainId,
81
+ mvxChainId,
82
+ secondToken == null ? void 0 : secondToken.chainId
83
+ ]);
62
84
  const getDefaultReceivingToken$1 = useCallback(
63
85
  (values) => getDefaultReceivingToken(values, toTokens),
64
86
  [toTokens]
@@ -129,7 +151,7 @@ const useBridgeTokenSelection = ({
129
151
  secondTokenId: firstToken.address
130
152
  });
131
153
  const selectedOptionChain = sdkChains == null ? void 0 : sdkChains.find(
132
- (chain) => chain.id.toString() === secondToken.chainId.toString()
154
+ (chain) => sameBridgeApiChainId(chain.id, secondToken.chainId)
133
155
  );
134
156
  if (selectedOptionChain && switchNetwork) {
135
157
  switchNetwork(selectedOptionChain);
@@ -151,7 +173,7 @@ const useBridgeTokenSelection = ({
151
173
  const firstOption = fromOptions.find(
152
174
  ({ identifier }) => (initialTokens == null ? void 0 : initialTokens.firstTokenId) === identifier
153
175
  ) ?? fromOptions.find(
154
- (option) => option.chainId.toString() === (activeChainId == null ? void 0 : activeChainId.toString())
176
+ (option) => sameBridgeApiChainId(option.chainId, activeChainId)
155
177
  ) ?? fromOptions[0];
156
178
  let secondOption = toTokens == null ? void 0 : toTokens.find(
157
179
  (x) => x.symbol.toLowerCase() === (firstOption == null ? void 0 : firstOption.symbol.toLowerCase())
@@ -176,7 +198,7 @@ const useBridgeTokenSelection = ({
176
198
  setFirstToken(firstOption);
177
199
  updateUrlParams$1({ firstTokenId: firstOption.address });
178
200
  const selectedOptionChain = (sdkChains == null ? void 0 : sdkChains.find(
179
- (chain) => chain.id.toString() === firstOption.chainId.toString()
201
+ (chain) => sameBridgeApiChainId(chain.id, firstOption.chainId)
180
202
  )) ?? activeChain;
181
203
  if (selectedOptionChain && switchNetwork) {
182
204
  switchNetwork(selectedOptionChain);
@@ -1,11 +1,17 @@
1
1
  import { InitialTokensType } from '../../../utils/getInitialTokens';
2
+ import { ServerTransaction } from '../../../../types/transaction';
2
3
  import { TokenType } from '../../../../types/token';
4
+ import { ChainType } from '../../../../types/chainType';
3
5
 
4
6
  export declare const updateUrlParams: ({ firstTokenId, secondTokenId, callbackRoute, isTokensLoading, onNavigate }: InitialTokensType & {
5
7
  callbackRoute: string;
6
8
  isTokensLoading: boolean;
7
9
  onNavigate?: (url: string, options?: object) => void;
8
10
  }) => void;
11
+ /** Prefer server transaction shape so signing matches the API even if chain metadata is stale. */
12
+ export declare function resolveSigningChainType(transaction: ServerTransaction, fallbackChain?: {
13
+ chainType?: ChainType;
14
+ }): ChainType | undefined;
9
15
  /**
10
16
  * Gets available tokens based on the source token and forced destination
11
17
  */
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ const types_chainType = require("../../../../types/chainType.js");
4
5
  const reactjs_constants_index = require("../../../constants/index.js");
5
6
  const reactjs_utils_getCompletePathname = require("../../../utils/getCompletePathname.js");
6
7
  const updateUrlParams = ({
@@ -27,6 +28,22 @@ const updateUrlParams = ({
27
28
  }
28
29
  onNavigate == null ? void 0 : onNavigate(newUrl, { replace: true });
29
30
  };
31
+ function resolveSigningChainType(transaction, fallbackChain) {
32
+ var _a, _b;
33
+ if (((_a = transaction.suiParams) == null ? void 0 : _a.transactionBytes) && ((_b = transaction.suiParams) == null ? void 0 : _b.sender)) {
34
+ return types_chainType.ChainType.sui;
35
+ }
36
+ if (transaction.instructions && transaction.feePayer) {
37
+ return types_chainType.ChainType.sol;
38
+ }
39
+ if (transaction.bitcoinParams) {
40
+ return types_chainType.ChainType.btc;
41
+ }
42
+ if (transaction.to && transaction.data !== void 0) {
43
+ return types_chainType.ChainType.evm;
44
+ }
45
+ return fallbackChain == null ? void 0 : fallbackChain.chainType;
46
+ }
30
47
  const getAvailableTokens = (option, targetTokens, forcedDestinationTokenSymbol) => {
31
48
  if (forcedDestinationTokenSymbol) {
32
49
  const forcedToken = targetTokens == null ? void 0 : targetTokens.find(
@@ -56,4 +73,5 @@ const getDefaultReceivingToken = (values, fallbackTokens) => {
56
73
  };
57
74
  exports.getAvailableTokens = getAvailableTokens;
58
75
  exports.getDefaultReceivingToken = getDefaultReceivingToken;
76
+ exports.resolveSigningChainType = resolveSigningChainType;
59
77
  exports.updateUrlParams = updateUrlParams;