@aurora-is-near/intents-swap-widget 3.14.0-redesign.3 → 3.14.0-redesign.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.
Files changed (132) hide show
  1. package/dist/components/BlockingError.js +15 -9
  2. package/dist/components/BlockingError.js.map +1 -1
  3. package/dist/components/CloseButton.js +1 -1
  4. package/dist/components/CloseButton.js.map +1 -1
  5. package/dist/config-Behl5hcc.js +2836 -0
  6. package/dist/config-Behl5hcc.js.map +1 -0
  7. package/dist/config.d.ts +1 -0
  8. package/dist/config.js +4 -6
  9. package/dist/config.js.map +1 -1
  10. package/dist/errors.js +1 -1
  11. package/dist/ext/alchemy/index.js +1 -1
  12. package/dist/ext/index.js +1 -1
  13. package/dist/features/BalanceRpcLoader/TokenBalanceLoader.js +1 -1
  14. package/dist/features/BalanceRpcLoader/index.js +1 -1
  15. package/dist/features/BalanceRpcLoader/useTokenBalanceRpc.js +1 -1
  16. package/dist/features/ChainsDropdown/index.js +1 -1
  17. package/dist/features/DepositMethodSwitcher.js +26 -29
  18. package/dist/features/DepositMethodSwitcher.js.map +1 -1
  19. package/dist/features/ErrorBoundary.js +1 -1
  20. package/dist/features/ExternalDeposit.js +13 -14
  21. package/dist/features/ExternalDeposit.js.map +1 -1
  22. package/dist/features/SendAddress/index.js +1 -1
  23. package/dist/features/SendAddress/useNotification.js +1 -1
  24. package/dist/features/SubmitButton/index.js +1 -1
  25. package/dist/features/SuccessScreen/SummaryItem.js +2 -2
  26. package/dist/features/SuccessScreen/SummaryItem.js.map +1 -1
  27. package/dist/features/SuccessScreen/index.js +20 -20
  28. package/dist/features/SuccessScreen/index.js.map +1 -1
  29. package/dist/features/SwapDirectionSwitcher.js +1 -1
  30. package/dist/features/SwapQuote/SwapQuote.js +1 -1
  31. package/dist/features/SwapQuote/index.js +1 -1
  32. package/dist/features/TokenInput/TokenInput.js +1 -1
  33. package/dist/features/TokenInput/TokenInputEmpty.js +1 -1
  34. package/dist/features/TokenInput/TokenInputSource.js +1 -1
  35. package/dist/features/TokenInput/TokenInputTarget.js +1 -1
  36. package/dist/features/TokenInput/WalletBalance.js +1 -1
  37. package/dist/features/TokenInput/hooks/index.js +1 -1
  38. package/dist/features/TokenInput/hooks/useTokenInputBalance.js +1 -1
  39. package/dist/features/TokenInput/index.js +1 -1
  40. package/dist/features/TokensList/TokenItem.js +1 -1
  41. package/dist/features/TokensList/TokensList.js +1 -1
  42. package/dist/features/TokensList/index.js +1 -1
  43. package/dist/features/TokensModal.js +1 -1
  44. package/dist/features/WalletCompatibilityCheck/WalletCompatibilityModal.js +13 -191
  45. package/dist/features/WalletCompatibilityCheck/WalletCompatibilityModal.js.map +1 -1
  46. package/dist/features/WalletCompatibilityCheck/index.js +21 -26
  47. package/dist/features/WalletCompatibilityCheck/index.js.map +1 -1
  48. package/dist/features/index.js +1 -1
  49. package/dist/hooks/index.js +1 -1
  50. package/dist/hooks/useAllTokens.js +1 -1
  51. package/dist/hooks/useChains.js +1 -1
  52. package/dist/hooks/useCompatibilityCheck.js +1 -1
  53. package/dist/hooks/useDefaultToken.js +1 -1
  54. package/dist/hooks/useExternalDepositStatus/index.js +1 -1
  55. package/dist/hooks/useExternalDepositStatus/usePoaExternalDepositStatus.js +1 -1
  56. package/dist/hooks/useIntentsBalance.js +1 -1
  57. package/dist/hooks/useIsCompatibilityCheckRequired.d.ts +1 -1
  58. package/dist/hooks/useIsCompatibilityCheckRequired.js +2 -2
  59. package/dist/hooks/useIsCompatibilityCheckRequired.js.map +1 -1
  60. package/dist/hooks/useMakeDepositAddress.js +1 -1
  61. package/dist/hooks/useMakeIntentsTransfer.js +1 -1
  62. package/dist/hooks/useMakeNEARFtTransferCall.js +1 -1
  63. package/dist/hooks/useMakeQuote.js +1 -1
  64. package/dist/hooks/useMakeQuoteTransfer.js +1 -1
  65. package/dist/hooks/useMakeTransfer.js +1 -1
  66. package/dist/hooks/useMergedBalance.js +1 -1
  67. package/dist/hooks/useSwitchChain.js +1 -1
  68. package/dist/hooks/useTheme.js +1 -1
  69. package/dist/hooks/useToggleTheme.js +20 -17
  70. package/dist/hooks/useToggleTheme.js.map +1 -1
  71. package/dist/hooks/useTokenInputPair.js +1 -1
  72. package/dist/hooks/useTokens.js +1 -1
  73. package/dist/hooks/useTokensFiltered.js +1 -1
  74. package/dist/hooks/useTokensIntentsUnique.js +1 -1
  75. package/dist/index.js +1 -1
  76. package/dist/machine/effects/index.js +1 -1
  77. package/dist/machine/effects/useAlchemyBalanceEffect.js +1 -1
  78. package/dist/machine/effects/useBalancesUpdateEffect.js +1 -1
  79. package/dist/machine/effects/useMakeQuoteEffect.js +1 -1
  80. package/dist/machine/effects/useSelectedTokensEffect.js +1 -1
  81. package/dist/machine/effects/useSetTokenBalanceEffect.js +1 -1
  82. package/dist/machine/effects/useSetTokenIntentsTargetEffect.js +1 -1
  83. package/dist/machine/effects/useWalletConnEffect.js +1 -1
  84. package/dist/machine/events/index.js +1 -1
  85. package/dist/machine/events/tokenSelect.js +1 -1
  86. package/dist/machine/events/validateInputAndMoveTo.js +1 -1
  87. package/dist/machine/events/validateInputs.js +1 -1
  88. package/dist/machine/index.js +1 -1
  89. package/dist/machine/snap.js +1 -1
  90. package/dist/machine/subscriptions/checkers/isSendAddressAsConnected.js +1 -1
  91. package/dist/machine/subscriptions/index.js +1 -1
  92. package/dist/styles.css +1 -1
  93. package/dist/theme/ThemeProvider.js +7 -24
  94. package/dist/theme/ThemeProvider.js.map +1 -1
  95. package/dist/types/config.d.ts +1 -0
  96. package/dist/types/localisation.d.ts +1 -1
  97. package/dist/utils/intents/signers/near.js +1 -1
  98. package/dist/utils/intents/signers/privy.js +1 -1
  99. package/dist/utils/near/getNearNep141StorageBalance.js +1 -1
  100. package/dist/widgets/WidgetDeposit/WidgetDepositContent.js +11 -12
  101. package/dist/widgets/WidgetDeposit/WidgetDepositContent.js.map +1 -1
  102. package/dist/widgets/WidgetDeposit/WidgetDepositSkeleton.js +1 -1
  103. package/dist/widgets/WidgetSwap/WidgetSwapContent.js +27 -26
  104. package/dist/widgets/WidgetSwap/WidgetSwapContent.js.map +1 -1
  105. package/dist/widgets/WidgetSwap/WidgetSwapSkeleton.js +1 -1
  106. package/dist/widgets/WidgetWithdraw/WidgetWithdrawContent.js +5 -6
  107. package/dist/widgets/WidgetWithdraw/WidgetWithdrawContent.js.map +1 -1
  108. package/dist/widgets/WidgetWithdraw/WidgetWithdrawSkeleton.js +1 -1
  109. package/package.json +2 -1
  110. package/src/components/BlockingError.tsx +7 -4
  111. package/src/components/CloseButton.tsx +1 -1
  112. package/src/features/DepositMethodSwitcher.tsx +5 -17
  113. package/src/features/ExternalDeposit.tsx +6 -6
  114. package/src/features/SuccessScreen/SummaryItem.tsx +2 -2
  115. package/src/features/SuccessScreen/index.tsx +5 -3
  116. package/src/features/SwapQuote/SwapQuote.tsx +1 -1
  117. package/src/features/WalletCompatibilityCheck/WalletCompatibilityModal.tsx +3 -0
  118. package/src/features/WalletCompatibilityCheck/index.tsx +4 -8
  119. package/src/hooks/useIsCompatibilityCheckRequired.ts +1 -1
  120. package/src/hooks/useToggleTheme.ts +11 -4
  121. package/src/theme/ThemeProvider.tsx +33 -14
  122. package/src/types/config.ts +1 -0
  123. package/src/types/localisation.ts +1 -0
  124. package/src/widgets/WidgetDeposit/WidgetDepositContent.tsx +3 -3
  125. package/src/widgets/WidgetSwap/WidgetSwapContent.tsx +5 -3
  126. package/src/widgets/WidgetWithdraw/WidgetWithdrawContent.tsx +3 -3
  127. package/dist/config-1EcDCy24.js +0 -2628
  128. package/dist/config-1EcDCy24.js.map +0 -1
  129. package/dist/features/SuccessScreen/CloseButton.d.ts +0 -5
  130. package/dist/features/SuccessScreen/CloseButton.js +0 -15
  131. package/dist/features/SuccessScreen/CloseButton.js.map +0 -1
  132. package/src/features/SuccessScreen/CloseButton.tsx +0 -14
@@ -0,0 +1,2836 @@
1
+ import { p as st } from "./index-xuotMAFm.js";
2
+ import { jsx as o, jsxs as T, Fragment as Ft } from "react/jsx-runtime";
3
+ import Lt from "i18next";
4
+ import { deepClone as pe } from "valtio/utils";
5
+ import { snapshot as Ne, useSnapshot as oe, proxy as rt } from "valtio";
6
+ import { HelmetProvider as Bt, Helmet as qt } from "react-helmet-async";
7
+ import { memo as Ut, useEffect as C, useMemo as v, useRef as Y, useCallback as he, useState as re, useId as Pt, Fragment as Wt, createContext as at, useContext as Vt } from "react";
8
+ import { useQuery as _e, useInfiniteQuery as Mt, useQueryClient as Qt, QueryClient as $t, QueryClientProvider as Kt } from "@tanstack/react-query";
9
+ import { Trans as Ht, I18nextProvider as Gt } from "react-i18next";
10
+ import { useTypedTranslation as M, initLocalisation as jt } from "./localisation.js";
11
+ import { logger as b } from "./logger.js";
12
+ import { getTonTokenBalance as zt } from "./utils/ton/getTonTokenBalance.js";
13
+ import { getSolanaTokenBalance as Yt } from "./utils/solana/getSolanaTokenBalance.js";
14
+ import { useWalletAddressForToken as ot } from "./hooks/useWalletAddressForToken.js";
15
+ import "@headlessui/react";
16
+ import "framer-motion";
17
+ import "lucide-react";
18
+ import { cn as H } from "./utils/cn.js";
19
+ import { OneClickService as Zt, QuoteRequest as U, GetExecutionStatusResponse as ee } from "@defuse-protocol/one-click-sdk-typescript";
20
+ import { CHAINS_LIST as ye, DEFAULT_CHAIN_ICON as Xt, DEFAULT_CHAINS_ORDER as it, CHAIN_POA_MAP as ct, POA_EVM_CHAIN_ID as lt, CHAIN_BASE_TOKENS as Jt, EVM_CHAIN_IDS_MAP as Te, CHAIN_IDS_MAP as en, EVM_CHAINS as tn } from "./constants/chains.js";
21
+ import "use-debounce";
22
+ import { derive as nn } from "derive-valtio";
23
+ import { getIsNativeNearDeposit as sn } from "./machine/computed/getIsNativeNearDeposit.js";
24
+ import { getIsDirectTokenOnNearDeposit as rn } from "./machine/computed/getIsDirectTokenOnNearDeposit.js";
25
+ import "ethers";
26
+ import { moveTo as O, machine as Z } from "./machine/machine.js";
27
+ import an from "lodash.once";
28
+ import { guardStates as D } from "./machine/guards/index.js";
29
+ import { parse as on } from "./ext/alchemy/parse.js";
30
+ import { createLoader as cn } from "./ext/alchemy/load.js";
31
+ import { isAlchemySupportedChain as ln } from "./ext/alchemy/types.js";
32
+ import { fireEvent as p } from "./machine/events/utils/fireEvent.js";
33
+ import { NATIVE_NEAR_DUMB_ASSET_ID as $, TOKENS_DATA as be, WNEAR_ASSET_ID as ge } from "./constants/tokens.js";
34
+ import { isValidChain as dn } from "./utils/checkers/isValidChain.js";
35
+ import { useWalletBalance as Ee } from "./hooks/useWalletBalance.js";
36
+ import { getIntentsAccountId as te } from "./utils/intents/getIntentsAccountId.js";
37
+ import { getIntentsBalances as un } from "./utils/intents/getIntentsBalance.js";
38
+ import { notReachable as Ce } from "./utils/notReachable.js";
39
+ import { getTokenBalanceKey as G } from "./utils/intents/getTokenBalanceKey.js";
40
+ import { isDryQuote as Re } from "./machine/guards/checks/isDryQuote.js";
41
+ import { snakeCase as dt } from "change-case";
42
+ import mn, { CanceledError as ut, AxiosError as mt } from "axios";
43
+ import { oneClickApi as Ie, bridgeApi as ft } from "./network.js";
44
+ import { formatBigToHuman as z } from "./utils/formatters/formatBigToHuman.js";
45
+ import { getDryQuoteAddress as Pe } from "./utils/getDryQuoteAddress.js";
46
+ import { isEvmChain as Q } from "./utils/evm/isEvmChain.js";
47
+ import { checkNearAccountExists as fn } from "./utils/near/checkNearAccountExists.js";
48
+ import { isNotEmptyAmount as ne } from "./utils/checkers/isNotEmptyAmount.js";
49
+ import { isValidBigint as pt } from "./utils/checkers/isValidBigint.js";
50
+ import { isNearAddress as ht } from "./utils/near/isNearAddress.js";
51
+ import { isBalanceSufficient as ve } from "./machine/guards/checks/isBalanceSufficient.js";
52
+ import { isQuoteError as De, isTransferError as xe, isAsyncSendAddressValidationError as pn } from "./machine/errors.js";
53
+ import { isSolanaAddress as Tt } from "./utils/solana/isSolanaAddress.js";
54
+ import { isEvmAddress as gt } from "./utils/evm/isEvmAddress.js";
55
+ import { getMainTokenByChain as hn } from "./utils/tokens/getMainTokenByChain.js";
56
+ import { getDefaultIntentsToken as Tn } from "./utils/tokens/getDefaultIntentsToken.js";
57
+ import { getTokenWithHighBalance as gn } from "./utils/tokens/getTokenWithHighBalance.js";
58
+ import { isQuoteIdle as In } from "./machine/subscriptions/checkers/isQuoteIdle.js";
59
+ import { isInputChanged as wn } from "./machine/subscriptions/checkers/isInputChanged.js";
60
+ import { isErrorChanged as kn } from "./machine/subscriptions/checkers/isErrorChanged.js";
61
+ import { isOnlyErrorChanged as An } from "./machine/subscriptions/checkers/isOnlyErrorChanged.js";
62
+ import { isValidInitialState as Sn } from "./machine/subscriptions/checkers/isValidInitialState.js";
63
+ import { isWalletDisconnected as Nn } from "./machine/subscriptions/checkers/isWalletDisconnected.js";
64
+ import { isSendAddressForbidden as _n } from "./machine/subscriptions/checkers/isSendAddressForbidden.js";
65
+ import { isAmountChangedFromQuote as yn } from "./machine/subscriptions/checkers/isAmountChangedFromQuote.js";
66
+ import { reset as bn } from "./machine/events/reset.js";
67
+ import { tokenSelectRotate as we } from "./machine/events/tokenSelectRotate.js";
68
+ import { errorSet as En } from "./machine/events/errorSet.js";
69
+ import { quoteSet as Cn } from "./machine/events/quoteSet.js";
70
+ import { addressSet as Rn } from "./machine/events/addressSet.js";
71
+ import { tokenSetAmount as vn } from "./machine/events/tokenSetAmount.js";
72
+ import { quoteSetStatus as Dn } from "./machine/events/quoteSetStatus.js";
73
+ import { depositTypeSet as xn } from "./machine/events/depositTypeSet.js";
74
+ import { externalDepositTxSet as On } from "./machine/events/externalDepositTxSet.js";
75
+ import { setInputsValidating as Fn } from "./machine/events/setInputsValidating.js";
76
+ import { walletAddressSet as Ln } from "./machine/events/walletAddressSet.js";
77
+ import { tokenSetBalance as Bn } from "./machine/events/tokenSetBalance.js";
78
+ import { transferSetStatus as qn } from "./machine/events/transferSetStatus.js";
79
+ import { getUsdTradeDelta as Un } from "./machine/computed/getUsdTradeDelta.js";
80
+ import { getIsDirectNonNearWithdrawal as Pn } from "./machine/computed/getIsDirectNonNearWithdrawal.js";
81
+ import { getIsDirectTokenOnNearTransfer as Wn } from "./machine/computed/getIsDirectTokenOnNearTransfer.js";
82
+ import { getIsDirectNearTokenWithdrawal as Vn } from "./machine/computed/getIsDirectNearTokenWithdrawal.js";
83
+ import { getIsSameAssetDiffChainWithdrawal as Mn } from "./machine/computed/getIsSameAssetDiffChainWithdrawal.js";
84
+ import "viem";
85
+ import { Button as A } from "./components/Button.js";
86
+ import { TinyNumber as Oe } from "./components/TinyNumber.js";
87
+ import { ErrorMessage as K } from "./components/ErrorMessage.js";
88
+ import { FT_DEPOSIT_GAS as We, FT_TRANSFER_GAS as Ve } from "./utils/near/config.js";
89
+ import { a as Fe } from "./index-DEq3oXQF.js";
90
+ import { z as se } from "zod";
91
+ import { decodeQueryResult as Qn } from "./utils/near/decodeQueryResult.js";
92
+ import { nearRpcClient as $n } from "./utils/near/rpc.js";
93
+ import { getNearNep141MinStorageBalance as Kn } from "./utils/near/getNearNep141MinStorageBalance.js";
94
+ import { INTENTS_CONTRACT as ke } from "./constants/intents.js";
95
+ import { isEth as Hn } from "./utils/evm/isEth.js";
96
+ import { useMakeEvmTransfer as Gn } from "./hooks/useMakeEvmTransfer.js";
97
+ import { useMakeSolanaTransfer as jn } from "./hooks/useMakeSolanaTransfer.js";
98
+ import { isUserDeniedSigning as Ae } from "./utils/checkers/isUserDeniedSigning.js";
99
+ import { createIntentSignerNEP413 as zn, BridgeSDK as Yn, createNearWithdrawalRoute as Zn, createInternalTransferRoute as Xn } from "@defuse-protocol/bridge-sdk";
100
+ import { generateRandomBytes as Jn } from "./utils/near/getRandomBytes.js";
101
+ import { IntentSignerSolana as es } from "./utils/intents/signers/solana.js";
102
+ import { localStorageTyped as Me } from "./utils/localstorage.js";
103
+ import { queryContract as ts } from "./utils/near/queryContract.js";
104
+ import { utils as Qe } from "@defuse-protocol/internal-utils";
105
+ import { getTransactionLink as ns } from "./utils/formatters/getTransactionLink.js";
106
+ import { switchEthereumChain as ss } from "./utils/evm/switchEthereumChain.js";
107
+ import "copy-text-to-clipboard";
108
+ import { SwapQuoteSkeleton as It } from "./features/SwapQuote/SwapQuoteSkeleton.js";
109
+ import { Notes as de } from "./components/Notes.js";
110
+ import { Accordion as rs } from "./components/Accordion.js";
111
+ import { formatUsdAmount as $e } from "./utils/formatters/formatUsdAmount.js";
112
+ import { formatTinyNumber as as } from "./utils/formatters/formatTinyNumber.js";
113
+ import os from "clsx";
114
+ import { Skeleton as is } from "./components/Skeleton.js";
115
+ import { getBalancePortion as cs } from "./features/TokenInput/utils/getBalancePortion.js";
116
+ import { getUsdDisplayAmount as ls } from "./features/TokenInput/utils/getUsdDisplayAmount.js";
117
+ import { TokenInputHeading as wt } from "./features/TokenInput/TokenInputHeading.js";
118
+ import { noop as ds } from "./utils/noop.js";
119
+ import { Card as ie } from "./components/Card.js";
120
+ import { Badge as Ke } from "./components/Badge.js";
121
+ import { TokenIcon as kt } from "./components/TokenIcon.js";
122
+ import { InputAmount as us } from "./components/InputAmount.js";
123
+ import { TokenInputSkeleton as ms } from "./features/TokenInput/TokenInputSkeleton.js";
124
+ import { getUsdDisplayBalance as fs } from "./utils/formatters/getUsdDisplayBalance.js";
125
+ import { VList as ps } from "virtua";
126
+ import { TokensListPlaceholder as Se } from "./features/TokensList/TokensListPlaceholder.js";
127
+ import { Hr as hs } from "./components/Hr.js";
128
+ import { createTokenSorter as Ts } from "./utils/tokens/sort.js";
129
+ import { createFilterByIntents as He } from "./utils/tokens/filterByIntents.js";
130
+ import { createFilterBySearch as gs } from "./utils/tokens/filterBySearchString.js";
131
+ import { createFilterBySelectedChain as Is } from "./utils/tokens/filterBySelectedChain.js";
132
+ import "bs58";
133
+ import "viem/chains";
134
+ import { isBrowser as At } from "browser-or-node";
135
+ import "qrcode.react";
136
+ import { createColorPalette as ws } from "./theme/createColorPalette.js";
137
+ import { ArmingCountdownFill as ks, BeenhereFill as As, EncryptedFill as Ss, AccountBalanceWalletFill as Ns, CheckCircleFill as _s, GppBadFill as ys } from "@material-symbols-svg/react-rounded";
138
+ import { useTimer as bs } from "use-timer";
139
+ import { CloseButton as St } from "./components/CloseButton.js";
140
+ import { DEFAULT_RPCS as Es } from "./rpcs.js";
141
+ import { useAddClassToPortal as Cs } from "./hooks/useAddClassToPortal.js";
142
+ import { ErrorBoundary as Rs } from "react-error-boundary";
143
+ import { isEvmToken as vs } from "./utils/evm/isEvmToken.js";
144
+ import { isEvmBaseToken as Ds } from "./utils/evm/isEvmBaseToken.js";
145
+ import { getEvmMainTokenBalance as xs } from "./utils/evm/getEvmMainTokenBalance.js";
146
+ import { getNativeNearBalance as Os } from "./utils/near/getNativeNearBalance.js";
147
+ import { getNearTokenBalance as Fs } from "./utils/near/getNearTokenBalance.js";
148
+ import { getEvmTokenBalance as Ls } from "./utils/evm/getEvmTokenBalance.js";
149
+ function Bs({ rpcs: e, token: t, connectedWallets: r }) {
150
+ const { walletSupportedChains: s, tonCenterApiKey: n, alchemyApiKey: a } = y(), { walletAddress: l } = ot(r, t);
151
+ return _e({
152
+ retry: 2,
153
+ enabled: !!l && Object.keys(e).includes(t.blockchain),
154
+ queryKey: ["tokenBalance", t.assetId, r],
155
+ queryFn: async () => {
156
+ if (!l)
157
+ return null;
158
+ if (t.blockchain === "near" && s.includes(t.blockchain))
159
+ return !e.near || e.near.length === 0 ? null : t.assetId === $ ? Os(l, e.near) : Fs(t, l, e.near);
160
+ if (!s.includes("eth") && Q(t.blockchain))
161
+ return null;
162
+ if (Q(t.blockchain) && Ds(t)) {
163
+ const c = e[t.blockchain] ?? [];
164
+ return c.length > 0 ? xs(l, c[0]) : null;
165
+ }
166
+ if (vs(t) || Q(t.blockchain)) {
167
+ const c = e[t.blockchain] ?? [];
168
+ return c.length > 0 ? Ls(t, l, c[0]) : null;
169
+ }
170
+ return t.blockchain === "ton" ? zt(t, l, n) : t.blockchain === "sol" && s.includes(t.blockchain) ? Yt(t, l, a) : (b.warn(
171
+ `Failed to fetch token balance for ${t.symbol} on ${t.blockchain}`
172
+ ), null);
173
+ }
174
+ });
175
+ }
176
+ const qs = ({
177
+ rpcs: e,
178
+ token: t,
179
+ onBalancesLoaded: r
180
+ }) => (C(() => {
181
+ t.isIntent || !Object.keys(e).includes(t.blockchain) || r({ [t.assetId]: "0" });
182
+ }, [t.assetId]), null), Nt = Ut(
183
+ ({ rpcs: e, token: t, connectedWallets: r, onBalancesLoaded: s }) => {
184
+ const { data: n } = Bs({
185
+ rpcs: e,
186
+ token: t,
187
+ connectedWallets: r
188
+ });
189
+ return C(() => {
190
+ !t.isIntent && n != null && s({ [t.assetId]: n });
191
+ }, [t, n, s]), null;
192
+ },
193
+ (e, t) => e.token.assetId === t.token.assetId && e.connectedWallets === t.connectedWallets
194
+ );
195
+ Nt.displayName = "TokenBalanceLoader";
196
+ const Ge = Object.assign(Nt, {
197
+ Zero: qs
198
+ }), Us = (e) => {
199
+ const t = e.toLowerCase();
200
+ return be[t]?.icon ?? "";
201
+ }, je = (e) => ye[e].icon ?? Xt, Ps = (e) => `${e?.charAt(0).toUpperCase()}${e?.slice(1)}`, Ws = (e) => be[e]?.name ?? e, P = (e) => {
202
+ const {
203
+ showIntentTokens: t,
204
+ allowedTokensList: r,
205
+ allowedSourceTokensList: s,
206
+ allowedTargetTokensList: n,
207
+ filterTokens: a,
208
+ fetchSourceTokens: l,
209
+ fetchTargetTokens: c
210
+ } = y(), { data: d, ...u } = _e({
211
+ queryKey: ["tokens", e].filter(Boolean),
212
+ queryFn: async () => e === "source" && l ? l() : e === "target" && c ? c() : Zt.getTokens()
213
+ }), i = v(() => {
214
+ if (!d)
215
+ return [];
216
+ const m = d.map((f) => {
217
+ const w = f.blockchain.toLowerCase();
218
+ return !dn(w) || r && !r.includes(f.assetId) || e === "source" && s && !s.includes(f.assetId) || e === "target" && n && !n.includes(f.assetId) ? null : {
219
+ assetId: f.assetId,
220
+ symbol: f.symbol,
221
+ decimals: f.decimals,
222
+ price: f.price,
223
+ blockchain: w,
224
+ isIntent: !1,
225
+ icon: f.icon ?? Us(f.symbol),
226
+ name: Ws(f.symbol),
227
+ chainIcon: je(w),
228
+ chainName: ye[f.blockchain]?.label ?? Ps(f.blockchain),
229
+ contractAddress: f.contractAddress
230
+ };
231
+ }).filter((f) => !!f).filter(a ?? (() => !0)), h = m.filter(
232
+ (f) => f.symbol.toLowerCase() !== "wnear"
233
+ ), g = m.find((f) => f.symbol.toLowerCase() === "wnear");
234
+ return g && h.push({
235
+ name: "NEAR",
236
+ symbol: "NEAR",
237
+ chainName: "Near",
238
+ blockchain: "near",
239
+ assetId: $,
240
+ chainIcon: je("near"),
241
+ icon: be.near?.icon ?? "",
242
+ price: g?.price ?? 0,
243
+ contractAddress: g?.contractAddress,
244
+ isIntent: !1,
245
+ decimals: 24
246
+ }), t ? [
247
+ ...h,
248
+ // add intents tokens to the full list
249
+ ...m.map(
250
+ (f) => f.symbol.toLowerCase() === "wnear" ? { ...f, symbol: "NEAR", name: "NEAR", isIntent: !0 } : { ...f, isIntent: !0 }
251
+ )
252
+ ] : h;
253
+ }, [d, t, a]);
254
+ return {
255
+ ...u,
256
+ tokens: i
257
+ };
258
+ }, Vs = () => {
259
+ const { tokens: e } = P(), { tokens: t } = P("source"), { tokens: r } = P("target");
260
+ return { tokens: v(() => {
261
+ const n = {};
262
+ return [
263
+ ...e,
264
+ ...t || [],
265
+ ...r || []
266
+ ].forEach((a) => {
267
+ const l = `${a.assetId}-${a.isIntent}`;
268
+ n[l] = a;
269
+ }), Object.values(n);
270
+ }, [e, t, r]) };
271
+ }, ue = [
272
+ { eth: ["ETH", "USDT", "USDC", "AURORA"] },
273
+ { near: ["USDT", "USDC", "AURORA"] },
274
+ { arb: ["ARB", "ETH", "USDT", "USDC"] },
275
+ { btc: ["BTC"] }
276
+ ], Ms = (e) => [...e].sort((t, r) => {
277
+ const s = ue.findIndex(
278
+ (d) => Object.keys(d)[0] === t.blockchain
279
+ ), n = ue.findIndex(
280
+ (d) => Object.keys(d)[0] === r.blockchain
281
+ );
282
+ if (s !== n)
283
+ return s === -1 ? 1 : n === -1 ? -1 : s - n;
284
+ const a = ue[s]?.[t.blockchain] ?? [], l = a.indexOf(t.symbol), c = a.indexOf(r.symbol);
285
+ return l === -1 && c === -1 ? 0 : l === -1 ? 1 : c === -1 ? -1 : l - c;
286
+ }), Qs = ({ rpcs: e, connectedWallets: t }) => {
287
+ const { tokens: r } = Vs(), { walletSupportedChains: s } = y(), { setWalletBalance: n } = Ee(t);
288
+ return v(() => Ms(r), [r]).map((l) => s.includes(l.blockchain) ? /* @__PURE__ */ o(
289
+ Ge,
290
+ {
291
+ rpcs: e,
292
+ token: l,
293
+ connectedWallets: t,
294
+ onBalancesLoaded: (c) => n(t, c)
295
+ },
296
+ G(l)
297
+ ) : /* @__PURE__ */ o(
298
+ Ge.Zero,
299
+ {
300
+ rpcs: e,
301
+ token: l,
302
+ onBalancesLoaded: (c) => n(t, c)
303
+ },
304
+ G(l)
305
+ ));
306
+ };
307
+ function $s(e, t) {
308
+ const r = Array.from(
309
+ /* @__PURE__ */ new Set([...t ?? [], ...it])
310
+ ), s = new Map(r.map((n, a) => [n, a]));
311
+ return [...e].sort((n, a) => {
312
+ const l = s.has(n.id) ? s.get(n.id) : 1 / 0, c = s.has(a.id) ? s.get(a.id) : 1 / 0;
313
+ return l !== c ? l - c : n.id.localeCompare(a.id, void 0, { sensitivity: "base" });
314
+ });
315
+ }
316
+ const Ks = (e) => {
317
+ const {
318
+ chainsOrder: t,
319
+ allowedChainsList: r,
320
+ allowedSourceChainsList: s,
321
+ allowedTargetChainsList: n
322
+ } = y(), { tokens: a } = P();
323
+ return v(() => {
324
+ const l = Array.from(
325
+ new Set(a.map((c) => ye[c.blockchain]))
326
+ ).filter((c) => !(r && !r.includes(c.id) || e === "source" && s && !s.includes(c.id) || e === "target" && n && !n.includes(c.id)));
327
+ return $s(l, t);
328
+ }, [a, t, r]);
329
+ }, ze = 3, _t = ({
330
+ connectedWallets: e,
331
+ alchemyApiKey: t,
332
+ ...r
333
+ }) => {
334
+ const { ctx: s } = _(), { tokens: n } = P(), { walletSupportedChains: a } = y(), { setWalletBalance: l } = Ee(e), c = r.isEnabled && !!Object.values(e).length && a.length > 0, d = Mt({
335
+ initialPageParam: null,
336
+ enabled: !!c && !!t,
337
+ queryKey: ["walletTokensBalance", e],
338
+ queryFn: async ({ pageParam: i }) => cn({ alchemyApiKey: t })({
339
+ pageParam: i ? `${i}` : null,
340
+ connectedWallets: e,
341
+ walletSupportedChains: a
342
+ }),
343
+ getNextPageParam: (i, m) => {
344
+ if (i.pageKey && !(m.length >= ze))
345
+ return i.pageKey;
346
+ }
347
+ });
348
+ C(() => {
349
+ c && d.data && d.hasNextPage && d.data.pages.length < ze && !d.isFetchingNextPage && d.fetchNextPage();
350
+ }, [c, d]);
351
+ const u = v(() => {
352
+ if (!d.data?.pages)
353
+ return {};
354
+ const i = on(
355
+ n,
356
+ d.data.pages.flatMap((m) => m.data)
357
+ );
358
+ return n.forEach((m) => {
359
+ ln(m.blockchain) && !(m.assetId in i) && (i[m.assetId] = "0");
360
+ }), i;
361
+ }, [d.data, n]);
362
+ return C(() => {
363
+ D(s, ["initial_wallet"]) && (l(e, u), s.sourceToken && Object.keys(u).includes(s.sourceToken.assetId) && p("tokenSetBalance", u[s.sourceToken.assetId]));
364
+ }, [u]), {
365
+ status: d.status,
366
+ refetch: d.refetch,
367
+ balances: u
368
+ };
369
+ }, ce = () => {
370
+ const { intentsAccountType: e } = y(), {
371
+ ctx: { walletAddress: t }
372
+ } = _(), { tokens: r } = P(), s = r.filter((c) => c.isIntent).map((c) => c.assetId), n = te({
373
+ walletAddress: t,
374
+ addressType: e
375
+ }), a = _e({
376
+ enabled: !!t && !!n && r.length > 0,
377
+ queryKey: ["intentsBalances", n],
378
+ queryFn: async () => n ? await un(n, s) : {}
379
+ }), l = v(() => {
380
+ switch (a.status) {
381
+ case "error":
382
+ return b.error("Unable to load intents balances:", a.error), {};
383
+ case "success":
384
+ return Object.fromEntries(
385
+ Object.entries(a.data).map(([c, d]) => [
386
+ `intent-${c}`,
387
+ d
388
+ ])
389
+ );
390
+ case "pending":
391
+ return {};
392
+ default:
393
+ return Ce(a, { throwError: !1 }), {};
394
+ }
395
+ }, [a]) ?? {};
396
+ return {
397
+ ...a,
398
+ intentBalances: l
399
+ };
400
+ }, Hs = ({
401
+ isEnabled: e,
402
+ alchemyApiKey: t
403
+ }) => {
404
+ const { connectedWallets: r } = y(), { ctx: s } = _(), n = Qt(), { refetch: a } = ce(), { refetch: l } = _t({
405
+ isEnabled: e,
406
+ connectedWallets: r,
407
+ alchemyApiKey: t ?? ""
408
+ });
409
+ C(() => {
410
+ const c = D(s, ["transfer_success"]);
411
+ !e || !c || (async () => (await a(), t && (await new Promise((d) => {
412
+ setTimeout(d, 1e4);
413
+ }), await l()), await n.invalidateQueries({ queryKey: ["tokenBalance"] })))();
414
+ }, [s.state, e, t]);
415
+ }, le = () => {
416
+ const { connectedWallets: e } = y(), { intentBalances: t } = ce(), { walletBalance: r } = Ee(e);
417
+ return { mergedBalance: v(
418
+ () => ({ ...r, ...t }),
419
+ [r, t]
420
+ ) };
421
+ }, Gs = ({ isEnabled: e }) => {
422
+ const { ctx: t } = _(), { mergedBalance: r } = le();
423
+ C(() => {
424
+ if (!e)
425
+ return;
426
+ if (!t.sourceToken || !t.walletAddress) {
427
+ p("tokenSetBalance", void 0);
428
+ return;
429
+ }
430
+ const s = G(t.sourceToken);
431
+ p("tokenSetBalance", r[s]);
432
+ }, [r, t.sourceToken]);
433
+ }, Ye = {
434
+ // cbBTC (eth)
435
+ "nep141:eth-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near": "nep141:nbtc.bridge.near",
436
+ // cbBTC (base)
437
+ "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near": "nep141:nbtc.bridge.near",
438
+ // wBTC (near)
439
+ "nep141:2260fac5e5542a773aa44fbcfedf7c193bc2c599.factory.bridge.near": "nep141:nbtc.bridge.near",
440
+ // xBTC (sol)
441
+ "nep141:sol-91914f13d3b54f8126a2824d71632d4b078d7403.omft.near": "nep141:nbtc.bridge.near",
442
+ // wETH (gnosis)
443
+ "nep141:gnosis-0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1.omft.near": "nep141:eth.bridge.near",
444
+ // NEAR (bsc)
445
+ "nep245:v2_1.omni.hot.tg:56_SZzgw3HSudhZcTwPWUTi2RJB19t": "nep141:wrap.near",
446
+ // BTC (near)
447
+ "nep141:btc.omft.near": "nep141:nbtc.bridge.near"
448
+ }, js = ({
449
+ isEnabled: e
450
+ }) => {
451
+ const { ctx: t } = _(), { tokens: r } = P();
452
+ C(() => {
453
+ if (!e)
454
+ return;
455
+ if (!t.sourceToken) {
456
+ p("tokenSelect", { variant: "target", token: void 0 });
457
+ return;
458
+ }
459
+ const { sourceToken: s } = t;
460
+ if (t.sourceToken.assetId in Ye) {
461
+ const c = r.find(
462
+ (d) => d.isIntent && d.assetId === Ye[s.assetId]
463
+ );
464
+ p("tokenSelect", {
465
+ variant: "target",
466
+ token: c
467
+ });
468
+ return;
469
+ }
470
+ const n = r.find(
471
+ (c) => c.isIntent && c.symbol === s.symbol && c.blockchain === "near"
472
+ );
473
+ if (n) {
474
+ p("tokenSelect", { variant: "target", token: n });
475
+ return;
476
+ }
477
+ const a = r.find(
478
+ (c) => c.isIntent && c.assetId === s.assetId
479
+ ), l = r.find(
480
+ (c) => c.isIntent && c.symbol === "USDC" && c.blockchain === "near"
481
+ );
482
+ p("tokenSelect", {
483
+ variant: "target",
484
+ token: a ?? l
485
+ });
486
+ }, [r, t.sourceToken]);
487
+ }, zs = ({ isEnabled: e }) => {
488
+ const { connectedWallets: t } = y(), { ctx: r, state: s } = _(), { walletAddress: n } = ot(
489
+ t,
490
+ r.sourceToken
491
+ );
492
+ C(() => {
493
+ if (!e)
494
+ return;
495
+ p("walletAddressSet", n), D(r, ["initial_dry", "initial_wallet"]) && (s === "initial_wallet" && !n ? O("initial_dry") : s === "initial_dry" && n && O("initial_wallet"));
496
+ }, [e, n, r, s]);
497
+ }, Ys = (e) => (["depositAddress"].forEach((t) => {
498
+ if (!(t in e))
499
+ return b.error(`Missing ${t} in quote response`), !1;
500
+ }), !0), Zs = () => {
501
+ const { ctx: e } = _(), {
502
+ walletSupportedChains: t,
503
+ intentsAccountType: r,
504
+ appName: s,
505
+ appFees: n,
506
+ fetchQuote: a,
507
+ slippageTolerance: l
508
+ } = y(), c = Re(e), d = Y(null), u = Y(new AbortController()), i = v(() => async (h, g) => {
509
+ const { signal: f } = u.current;
510
+ return a ? a(h, {
511
+ ...g,
512
+ signal: f
513
+ }) : (await Ie.post(
514
+ "https://1click.chaindefuser.com/v0/quote",
515
+ h,
516
+ { signal: f }
517
+ )).data.quote;
518
+ }, [Ie]);
519
+ return {
520
+ make: async ({
521
+ message: h,
522
+ quoteType: g = "exact_in",
523
+ options: f = {}
524
+ } = {}) => {
525
+ if (!D(e, [
526
+ "input_valid_dry",
527
+ "input_valid_external",
528
+ "input_valid_internal",
529
+ "quote_success_internal",
530
+ "quote_success_external"
531
+ ])) {
532
+ const k = `Unable to run quote in current state ${e.state}`;
533
+ throw b.error(`[WIDGET] ${k}`), new q({
534
+ code: "QUOTE_INVALID_INITIAL",
535
+ meta: { isDry: c, message: k }
536
+ });
537
+ }
538
+ const S = te({
539
+ addressType: r,
540
+ walletAddress: c ? (
541
+ // address on the target chain should be a dry quote recipient
542
+ Pe(e.targetToken.blockchain)
543
+ ) : e.walletAddress ?? ""
544
+ }), E = S && (e.sourceToken.isIntent || !t.includes(e.sourceToken.blockchain)), B = () => c ? Pe(
545
+ e.sourceToken.blockchain,
546
+ e.sourceToken.isIntent
547
+ ) : E ? S : e.walletAddress ?? "";
548
+ if (!S) {
549
+ const k = "No corresponding intents account to run a quote";
550
+ throw b.error(`[WIDGET] ${k}`), new q({
551
+ code: "QUOTE_INVALID_INITIAL",
552
+ meta: { isDry: c, message: k }
553
+ });
554
+ }
555
+ d.current && (u.current.abort("Abort previous quote (auto)"), u.current = new AbortController());
556
+ let F;
557
+ const L = {
558
+ // Settings
559
+ dry: c,
560
+ slippageTolerance: l,
561
+ deadline: new Date(Date.now() + 3600 * 1e3).toISOString(),
562
+ // 1 hour
563
+ swapType: g === "exact_out" ? U.swapType.EXACT_OUTPUT : U.swapType.EXACT_INPUT,
564
+ // Target
565
+ destinationAsset: e.targetToken.assetId === $ ? ge : e.targetToken.assetId,
566
+ // Source
567
+ originAsset: e.sourceToken.assetId === $ ? ge : e.sourceToken.assetId,
568
+ amount: g === "exact_out" ? e.targetTokenAmount : e.sourceTokenAmount,
569
+ // Experimental
570
+ quoteWaitingTimeMs: 0
571
+ };
572
+ h && (L.customRecipientMsg = h), s && (L.referral = dt(s)), n && (L.appFees = [...n]);
573
+ try {
574
+ e.sourceToken.isIntent && e.targetToken.isIntent && (d.current = i(
575
+ {
576
+ ...L,
577
+ recipient: S,
578
+ recipientType: U.recipientType.INTENTS,
579
+ depositType: U.depositType.INTENTS,
580
+ // Refund
581
+ refundTo: S,
582
+ refundType: U.refundType.INTENTS
583
+ },
584
+ f
585
+ ), F = await d.current), d.current = i(
586
+ {
587
+ ...L,
588
+ recipient: !e.targetToken.isIntent && e.sendAddress ? e.sendAddress : S,
589
+ recipientType: e.targetToken.isIntent ? U.recipientType.INTENTS : U.recipientType.DESTINATION_CHAIN,
590
+ depositType: e.sourceToken.isIntent ? U.depositType.INTENTS : U.depositType.ORIGIN_CHAIN,
591
+ // Refund
592
+ refundTo: B(),
593
+ refundType: E ? U.refundType.INTENTS : U.refundType.ORIGIN_CHAIN
594
+ },
595
+ f
596
+ ), F = await d.current;
597
+ } catch (k) {
598
+ if (k instanceof ut)
599
+ return;
600
+ b.error("Quote error: ", k);
601
+ let x = k instanceof Error ? k.message : "";
602
+ if (k instanceof mt) {
603
+ if (x = k.response?.data.message || x, x.includes("Amount is too low")) {
604
+ const X = x.match(/\d+/), J = X ? X[0] : void 0;
605
+ throw new q({
606
+ code: "QUOTE_AMOUNT_IS_TOO_LOW",
607
+ meta: {
608
+ minAmount: (J && z(J, e.sourceToken.decimals)) ?? "0"
609
+ }
610
+ });
611
+ }
612
+ throw x.includes("recipient is not valid") ? new q({
613
+ code: "TOKEN_IS_NOT_SUPPORTED"
614
+ }) : x.includes("Failed to get a deposit address") ? new q({
615
+ code: "QUOTE_NO_ONE_TIME_ADDRESS"
616
+ }) : k;
617
+ }
618
+ throw new q({
619
+ code: "QUOTE_FAILED",
620
+ meta: {
621
+ message: x || "Failed to fetch quote. Please try again."
622
+ }
623
+ });
624
+ }
625
+ return c ? {
626
+ dry: !0,
627
+ ...F,
628
+ deadline: void 0,
629
+ depositAddress: void 0
630
+ } : (Ys(F), {
631
+ dry: !1,
632
+ ...F,
633
+ deadline: F.deadline,
634
+ depositAddress: F.depositAddress
635
+ });
636
+ },
637
+ cancel: () => {
638
+ u.current.abort("Abort quote manually"), u.current = new AbortController();
639
+ }
640
+ };
641
+ }, Xs = () => {
642
+ const { ctx: e } = _(), { intentsAccountType: t } = y(), { isNativeNearDeposit: r } = j(), s = te({
643
+ addressType: t,
644
+ walletAddress: e.walletAddress ?? ""
645
+ }), n = Y(null), a = Y(new AbortController()), l = v(() => async (d) => ft.post(
646
+ "",
647
+ {
648
+ id: 1,
649
+ jsonrpc: "2.0",
650
+ method: "deposit_address",
651
+ params: [
652
+ {
653
+ account_id: d.accountId,
654
+ chain: d.chain
655
+ }
656
+ ]
657
+ },
658
+ {
659
+ signal: a.current.signal
660
+ }
661
+ ), [Ie]);
662
+ return {
663
+ make: async () => {
664
+ if (!D(e, [
665
+ "input_valid_dry",
666
+ "input_valid_external",
667
+ "input_valid_internal",
668
+ "quote_success_internal",
669
+ "quote_success_external"
670
+ ])) {
671
+ const i = `Unable to run quote in current state ${e.state}`;
672
+ throw b.error(`[WIDGET] ${i}`), new q({
673
+ code: "QUOTE_INVALID_INITIAL",
674
+ meta: { isDry: !1, message: i }
675
+ });
676
+ }
677
+ if (r && !e.isDepositFromExternalWallet || !r && e.sourceToken.assetId !== e.targetToken.assetId)
678
+ throw new q({
679
+ code: "QUOTE_INVALID_INITIAL",
680
+ meta: {
681
+ isDry: !1,
682
+ message: "Asset IDs are not the same use 1Click Quote instead of POA"
683
+ }
684
+ });
685
+ if (e.sourceToken.isIntent)
686
+ throw new q({
687
+ code: "QUOTE_INVALID_INITIAL",
688
+ meta: {
689
+ isDry: !1,
690
+ message: "For withdrawals use withdrawal SDK instead of POA"
691
+ }
692
+ });
693
+ if (!e.isDepositFromExternalWallet && e.sourceToken.blockchain === "near")
694
+ throw new q({
695
+ code: "QUOTE_INVALID_INITIAL",
696
+ meta: {
697
+ isDry: !1,
698
+ message: "Use transfer call. POA for tokens on Near only used for external deposits"
699
+ }
700
+ });
701
+ if (!s) {
702
+ const i = "No corresponding intents account to run a quote";
703
+ throw b.error(`[WIDGET] ${i}`), new q({
704
+ code: "QUOTE_INVALID_INITIAL",
705
+ meta: { isDry: !1, message: i }
706
+ });
707
+ }
708
+ n.current && (a.current.abort("Abort previous quote (auto)"), a.current = new AbortController());
709
+ let u = ct[e.targetToken.blockchain];
710
+ if (!u)
711
+ if (Q(e.targetToken.blockchain))
712
+ u = lt;
713
+ else
714
+ throw new q({
715
+ code: "QUOTE_INVALID_INITIAL",
716
+ meta: { isDry: !1, message: "Chain is not supported by POA" }
717
+ });
718
+ try {
719
+ return n.current = l({
720
+ chain: u,
721
+ accountId: s
722
+ }), {
723
+ depositAddress: (await n.current).data.result.address,
724
+ amountIn: e.sourceTokenAmount,
725
+ amountOut: e.targetTokenAmount,
726
+ amountInUsd: `${parseFloat(
727
+ z(e.sourceTokenAmount, e.sourceToken.decimals)
728
+ ) * e.sourceToken.price}`,
729
+ amountOutUsd: `${parseFloat(
730
+ z(e.targetTokenAmount, e.targetToken.decimals)
731
+ ) * e.targetToken.price}`,
732
+ amountOutFormatted: z(
733
+ e.targetTokenAmount,
734
+ e.targetToken.decimals
735
+ ),
736
+ // dummy values to match quote type
737
+ deadline: new Date(Date.now() + 3600 * 1e3).toISOString(),
738
+ timeEstimate: 0,
739
+ dry: !1
740
+ };
741
+ } catch (i) {
742
+ if (i instanceof ut)
743
+ return;
744
+ if (b.error(i), i instanceof mt) {
745
+ const m = i.response?.data.message || i.message;
746
+ throw new q({
747
+ code: "QUOTE_FAILED",
748
+ meta: {
749
+ message: m ?? "Failed to fetch quote. Please try again."
750
+ }
751
+ });
752
+ }
753
+ }
754
+ },
755
+ cancel: () => {
756
+ a.current.abort("Abort quote manually"), a.current = new AbortController();
757
+ }
758
+ };
759
+ }, Ze = (e) => {
760
+ p("errorSet", e), p("quoteSet", void 0), p("quoteSetStatus", "idle"), p("transferSetStatus", { status: "idle" });
761
+ }, Xe = async (e) => {
762
+ if (!e.sendAddress)
763
+ return;
764
+ let t = !1;
765
+ try {
766
+ p("setInputsValidating", !0), t = await fn(e.sendAddress);
767
+ } catch {
768
+ Ze({
769
+ code: "SEND_ADDRESS_IS_NOT_VERIFIED",
770
+ meta: { address: e.sendAddress, chain: "near" }
771
+ }), p("setInputsValidating", !1), O("initial_wallet");
772
+ return;
773
+ }
774
+ if (p("setInputsValidating", !1), !t) {
775
+ Ze({
776
+ code: "SEND_ADDRESS_IS_NOT_FOUND",
777
+ meta: { address: e.sendAddress, chain: "near" }
778
+ }), O("initial_wallet");
779
+ return;
780
+ }
781
+ e.error ? pn(e.error) && (p("errorSet", null), O("input_valid_external")) : O("input_valid_external");
782
+ }, yt = (e) => {
783
+ const t = D(e, ["initial_dry"]), r = D(e, ["input_valid_dry"]);
784
+ if (!t && !r)
785
+ return;
786
+ let s;
787
+ return t && (e.sourceToken ? e.targetToken ? ne(e.sourceTokenAmount) ? e.walletAddress && !ve(e) && (s = { code: "SOURCE_BALANCE_INSUFFICIENT" }) : s = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" } : s = { code: "TARGET_TOKEN_IS_EMPTY" } : s = { code: "SOURCE_TOKEN_IS_EMPTY" }), !r && s ? p("errorSet", s) : e.error && !De(e.error) && !xe(e.error) && p("errorSet", null), r && s?.code === "SOURCE_BALANCE_INSUFFICIENT" && p("errorSet", s), r;
788
+ }, bt = (e) => {
789
+ const t = D(e, ["initial_wallet"]), r = D(e, ["input_valid_external"]);
790
+ if (!t && !r)
791
+ return;
792
+ const s = e.sourceTokenBalance;
793
+ let n;
794
+ return t && (e.sourceToken ? e.targetToken ? e.targetToken.isIntent ? n = { code: "SOURCE_TOKEN_IS_INTENT" } : ne(e.sourceTokenAmount) ? e.sendAddress ? e.targetToken.blockchain === "near" ? ht(e.sendAddress) ? Xe(e) : n = {
795
+ code: "SEND_ADDRESS_IS_INVALID",
796
+ meta: { address: e.sendAddress, chain: "near" }
797
+ } : e.isDepositFromExternalWallet || (!s || !pt(s) ? n = { code: "INVALID_SOURCE_BALANCE" } : ve(e) || (n = { code: "SOURCE_BALANCE_INSUFFICIENT" })) : n = { code: "SEND_ADDRESS_IS_EMPTY" } : n = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" } : n = { code: "TARGET_TOKEN_IS_EMPTY" } : n = { code: "SOURCE_TOKEN_IS_EMPTY" }), r && e.targetToken.blockchain === "near" && Xe(e), !r && n ? p("errorSet", n) : e.error && !De(e.error) && !xe(e.error) && p("errorSet", null), r;
798
+ }, Et = (e) => {
799
+ const t = D(e, ["initial_wallet"]), r = D(e, ["input_valid_internal"]);
800
+ if (!t && !r)
801
+ return;
802
+ const s = e.sourceTokenBalance;
803
+ let n;
804
+ return t && (e.sourceToken ? e.targetToken ? e.targetToken.isIntent ? ne(e.sourceTokenAmount) ? e.isDepositFromExternalWallet || (!s || !pt(s) ? n = { code: "INVALID_SOURCE_BALANCE" } : ve(e) || (n = { code: "SOURCE_BALANCE_INSUFFICIENT" })) : n = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" } : n = { code: "SOURCE_TOKEN_NOT_INTENT" } : n = { code: "TARGET_TOKEN_IS_EMPTY" } : n = { code: "SOURCE_TOKEN_IS_EMPTY" }), !r && n ? p("errorSet", n) : e.error && !De(e.error) && !xe(e.error) && p("errorSet", null), r;
805
+ }, Ct = (e) => {
806
+ const t = Re(e), r = !t && e.targetToken?.isIntent === !0, s = !t && e.targetToken?.isIntent === !1;
807
+ if (t) {
808
+ const n = yt(e);
809
+ return O(n ? "input_valid_dry" : "initial_dry");
810
+ }
811
+ s && bt(e) ? O("input_valid_external") : r && Et(e) ? O("input_valid_internal") : O("initial_wallet");
812
+ }, Js = ({
813
+ isEnabled: e,
814
+ message: t,
815
+ type: r = "exact_in",
816
+ refetchQuoteInterval: s
817
+ }) => {
818
+ const { ctx: n } = _(), {
819
+ isNativeNearDeposit: a,
820
+ isDirectNonNearWithdrawal: l,
821
+ isDirectTokenOnNearDeposit: c,
822
+ isDirectNearTokenWithdrawal: d,
823
+ isDirectTokenOnNearTransfer: u,
824
+ isSameAssetDiffChainWithdrawal: i
825
+ } = j(), m = Re(n), h = e && !n.areInputsValidating && (i || (c || a) && n.isDepositFromExternalWallet || !d && !l && !c && !u), { make: g, cancel: f } = Zs(), { make: w, cancel: S } = Xs(), E = Y(null), B = () => {
826
+ f(), S();
827
+ };
828
+ C(() => {
829
+ const L = D(n, ["input_valid_dry"]), k = D(n, ["input_valid_external"]), x = D(n, ["input_valid_internal"]);
830
+ (m && !L || !m && n.targetToken?.isIntent && !x || !m && !n.targetToken?.isIntent && !k || n.areInputsValidating) && B();
831
+ }, [B, m, n]);
832
+ const F = he(
833
+ async (L) => {
834
+ try {
835
+ let k;
836
+ if (n.sourceToken?.assetId === n.targetToken?.assetId || a && n.isDepositFromExternalWallet) {
837
+ if (m)
838
+ return;
839
+ p("quoteSetStatus", "pending"), k = await w();
840
+ } else
841
+ p("quoteSetStatus", "pending"), k = await g({ message: t, quoteType: r, options: L });
842
+ if (!k)
843
+ return;
844
+ if (p("quoteSetStatus", "success"), p("quoteSet", k), !m && n.error?.code !== "SOURCE_BALANCE_INSUFFICIENT" && p("errorSet", null), p("tokenSetAmount", {
845
+ variant: "target",
846
+ amount: k.amountOut
847
+ }), n.state === "input_valid_dry") {
848
+ O("quote_success_dry");
849
+ return;
850
+ }
851
+ n.targetToken?.isIntent ? O("quote_success_internal") : O("quote_success_external");
852
+ } catch (k) {
853
+ if (k instanceof q) {
854
+ if (k.data.code === "QUOTE_INVALID_INITIAL") {
855
+ p("quoteSetStatus", "idle"), p("quoteSet", void 0), p("errorSet", null);
856
+ return;
857
+ }
858
+ p("quoteSetStatus", "error"), p("quoteSet", void 0), p("errorSet", k.data), Ct(n);
859
+ return;
860
+ }
861
+ b.error("Unhandled error in useMakeQuoteEffect:", k), p("quoteSetStatus", "error"), p("quoteSet", void 0), p("errorSet", {
862
+ code: "QUOTE_FAILED",
863
+ meta: { message: "Unknown error" }
864
+ });
865
+ }
866
+ },
867
+ [n, m, w, g, t, r, h]
868
+ );
869
+ C(() => {
870
+ !h || !(m ? n.state === "input_valid_dry" : n.state === "input_valid_external" && !n.targetToken?.isIntent || n.state === "input_valid_internal" && n.targetToken?.isIntent) || n.quoteStatus !== "error" && (a && !n.isDepositFromExternalWallet || F({ isRefetch: !1 }));
871
+ }, [h, F, B, n.sourceToken, n.targetToken]), C(() => {
872
+ const L = () => {
873
+ E.current && (clearInterval(E.current), E.current = null);
874
+ };
875
+ return n.state !== "quote_success_internal" && n.state !== "quote_success_external" || !s || (E.current = setInterval(async () => {
876
+ await F({ isRefetch: !0 });
877
+ }, s)), L;
878
+ }, [h, F, B, n.state]);
879
+ }, me = {
880
+ sol: "sol",
881
+ evm: "eth",
882
+ near: "near"
883
+ }, er = ({
884
+ isEnabled: e,
885
+ skipIntents: t = !1,
886
+ target: r = "none"
887
+ }) => {
888
+ const { tokens: s } = P(), { ctx: n, state: a } = _(), { intentBalances: l } = ce(), { walletSupportedChains: c, chainsFilter: d, intentsAccountType: u } = y(), i = gn({
889
+ tokens: s,
890
+ walletSupportedChains: c,
891
+ balances: l,
892
+ across: "intents"
893
+ }), [m, h] = v(() => !n.walletAddress && !t ? [
894
+ { token: Tn({ tokens: s }), status: "loaded" },
895
+ { token: void 0, status: "loaded" }
896
+ ] : d.source.intents !== "none" && !t ? i ? [
897
+ { token: i, status: "loaded" },
898
+ { token: void 0, status: "loaded" }
899
+ ] : [
900
+ { token: void 0, status: "loading" },
901
+ { token: void 0, status: "loading" }
902
+ ] : [
903
+ { token: hn({
904
+ tokens: s,
905
+ walletSupportedChains: c
906
+ }), status: "loaded" },
907
+ { token: void 0, status: "loaded" }
908
+ ], [
909
+ s,
910
+ t,
911
+ d,
912
+ n.walletAddress,
913
+ i,
914
+ c,
915
+ a
916
+ ]);
917
+ C(() => {
918
+ if (!e)
919
+ return;
920
+ if (D(n, ["initial_dry", "initial_wallet"]) && (m.status === "loaded" && !n.sourceToken && p("tokenSelect", {
921
+ variant: "source",
922
+ token: m.token
923
+ }), h.status === "loaded" && m.status === "loaded" && !n.targetToken)) {
924
+ let w = h.token;
925
+ if (r === "same-asset")
926
+ if (m.token?.isIntent) {
927
+ if (!u)
928
+ throw new Error(
929
+ "Intents account type is required to select same-asset target token"
930
+ );
931
+ w = s.find(
932
+ (S) => !S.isIntent && S.symbol === n.sourceToken?.symbol && S.blockchain === me[u]
933
+ );
934
+ } else
935
+ w = s.find(
936
+ (S) => S.isIntent && S.symbol === n.sourceToken?.symbol
937
+ );
938
+ p("tokenSelect", {
939
+ variant: "target",
940
+ token: w
941
+ });
942
+ }
943
+ }, [n, m, h, e]);
944
+ const g = (f, w) => {
945
+ const S = s.find(
946
+ (E) => !E.isIntent && E.blockchain === me[f] && E.symbol.toLowerCase() === Jt[me[f]]?.toLowerCase()
947
+ ) ?? w;
948
+ p("tokenSelect", {
949
+ variant: "source",
950
+ token: S
951
+ });
952
+ };
953
+ return C(() => {
954
+ const f = D(n, ["initial_dry", "initial_wallet"]);
955
+ if (!e || !f)
956
+ return;
957
+ const w = s.find(
958
+ (E) => E.isIntent && E.symbol === "AURORA" && E.blockchain === "near"
959
+ ), S = setTimeout(() => {
960
+ m.token || (!t && i ? p("tokenSelect", {
961
+ variant: "source",
962
+ token: i
963
+ }) : c.length && u ? g(u, w) : n.walletAddress && Tt(n.walletAddress) ? g("sol", w) : n.walletAddress && gt(n.walletAddress) ? g("evm", w) : n.walletAddress && ht(n.walletAddress) ? g("near", w) : p("tokenSelect", {
964
+ variant: "source",
965
+ token: w
966
+ }));
967
+ }, 3e3);
968
+ return () => clearTimeout(S);
969
+ }, [s, m, t]), { source: n.sourceToken, target: n.targetToken };
970
+ }, tr = ({
971
+ isEnabled: e,
972
+ alchemyApiKey: t
973
+ }) => {
974
+ const { connectedWallets: r } = y();
975
+ _t({
976
+ isEnabled: e,
977
+ connectedWallets: r,
978
+ alchemyApiKey: t ?? ""
979
+ });
980
+ }, nr = (e, t) => {
981
+ const { config: r } = Ne(Ue);
982
+ return e.targetToken && !e.sendAddress && !!e.walletAddress && !e.targetToken.isIntent && !t.find((s) => s?.key === "sendAddress") && r.walletSupportedChains.includes(e.targetToken.blockchain);
983
+ }, sr = ({ debug: e }) => {
984
+ Z.onContextChange((t, r) => {
985
+ const s = r;
986
+ if (e && b.debug("[WIDGET] Context changed", s), e && t.error && kn(s) && b.debug(`[WIDGET] Error set to ${t.error.code}`), An(s) || yn(t, s, e))
987
+ return;
988
+ if (Nn(t, s)) {
989
+ p("reset", { clearWalletAddress: !0 }), O("initial_dry");
990
+ return;
991
+ }
992
+ const { isChanged: n, isDry: a } = wn(t, s);
993
+ if (n) {
994
+ if (Sn(t)) {
995
+ const l = a ? "initial_dry" : "initial_wallet";
996
+ O(l, {
997
+ onMoved: () => {
998
+ e && b.debug(
999
+ `[WIDGET] Inputs changed. State moved to ${l}`
1000
+ );
1001
+ }
1002
+ });
1003
+ }
1004
+ In(t) || (t.quote = void 0, t.quoteStatus = "idle", t.transferStatus = { status: "idle" }), _n(t) && (t.sendAddress = void 0), nr(t, s) && (t.sendAddress = t.walletAddress), Ct(t);
1005
+ }
1006
+ });
1007
+ }, rr = ({ debug: e }) => {
1008
+ Z.onTransition((t, r) => {
1009
+ e && b.debug(`===> [WIDGET] State moved from ${t} to ${r}`);
1010
+ });
1011
+ }, ar = (e, t) => {
1012
+ const { variant: r, token: s } = t, { config: n } = Ne(Ue);
1013
+ switch (r) {
1014
+ case "source":
1015
+ if (s && s.assetId === e.targetToken?.assetId && s.isIntent === e.targetToken.isIntent && n.enableAutoTokensSwitching) {
1016
+ if (!e.sourceToken)
1017
+ return;
1018
+ we(e);
1019
+ return;
1020
+ }
1021
+ if (s && !e.sourceToken && s.assetId === e.targetToken?.assetId && s.isIntent === e.targetToken.isIntent && n.enableAutoTokensSwitching)
1022
+ return;
1023
+ e.sourceToken = s;
1024
+ break;
1025
+ case "target":
1026
+ if (s && s.assetId === e.sourceToken?.assetId && s.isIntent === e.sourceToken.isIntent && n.enableAutoTokensSwitching) {
1027
+ if (!e.targetToken)
1028
+ return;
1029
+ we(e);
1030
+ return;
1031
+ }
1032
+ e.targetToken = s;
1033
+ break;
1034
+ default:
1035
+ Ce(r, { throwError: !1 });
1036
+ }
1037
+ }, R = (e, t) => Z.on(
1038
+ e,
1039
+ (r, s) => t(r, s, Z)
1040
+ ), or = () => {
1041
+ R("quoteSetStatus", Dn), R("walletAddressSet", Ln), R("transferSetStatus", qn), R("tokenSelectRotate", we), R("tokenSetBalance", Bn), R("tokenSetAmount", vn), R("depositTypeSet", xn), R("setInputsValidating", Fn), R("externalDepositTxSet", On), R("tokenSelect", ar), R("addressSet", Rn), R("errorSet", En), R("quoteSet", Cn), R("reset", bn), R("validateDryInputs", yt), R("validateExternalInputs", bt), R("validateInternalInputs", Et);
1042
+ }, ir = an(({ debug: e }) => {
1043
+ e && b.debug(
1044
+ "[WIDGET] Debug mode is enabled (package version: 3.14.0-redesign.7)"
1045
+ ), or(), rr({ debug: e }), sr({ debug: e });
1046
+ }), Bi = ({ listenTo: e, debug: t = !1 }) => {
1047
+ C(() => {
1048
+ ir({ debug: t });
1049
+ }, [t]);
1050
+ const r = e.find(
1051
+ (a) => Array.isArray(a) && a[0] === "setBalancesUsingAlchemyExt"
1052
+ ), s = e.find(
1053
+ (a) => Array.isArray(a) && a[0] === "setDefaultSelectedTokens"
1054
+ ), n = e.find(
1055
+ (a) => Array.isArray(a) && a[0] === "makeQuote"
1056
+ );
1057
+ tr({
1058
+ isEnabled: !!r,
1059
+ alchemyApiKey: r?.[1].alchemyApiKey
1060
+ }), er({
1061
+ isEnabled: !!s,
1062
+ skipIntents: s?.[1].skipIntents,
1063
+ target: s?.[1].target
1064
+ }), Js({
1065
+ isEnabled: !!n,
1066
+ message: n?.[1].message,
1067
+ type: n?.[1].type,
1068
+ refetchQuoteInterval: n?.[1].refetchQuoteInterval
1069
+ }), zs({
1070
+ isEnabled: e.includes("checkWalletConnection")
1071
+ }), Gs({
1072
+ isEnabled: e.includes("setSourceTokenBalance")
1073
+ }), js({
1074
+ isEnabled: e.includes("setSourceTokenIntentsTarget")
1075
+ }), Hs({
1076
+ isEnabled: e.includes("updateBalances"),
1077
+ alchemyApiKey: r?.[1].alchemyApiKey
1078
+ });
1079
+ }, cr = Z.getStore();
1080
+ class W extends Error {
1081
+ context;
1082
+ _is_widget_error = !0;
1083
+ constructor(t, r) {
1084
+ super(t), this.name = "WidgetError", this.cause = r?.cause, this.context = Ne(cr).context;
1085
+ }
1086
+ }
1087
+ class Rt extends W {
1088
+ data;
1089
+ constructor(t) {
1090
+ super(t.code), this.data = t, this.name = "MachineError";
1091
+ }
1092
+ }
1093
+ class q extends Rt {
1094
+ constructor(t) {
1095
+ super(t), this.name = "QuoteError";
1096
+ }
1097
+ }
1098
+ class I extends Rt {
1099
+ constructor(t) {
1100
+ super(t), this.name = "TransferError";
1101
+ }
1102
+ }
1103
+ const qi = (e) => typeof e == "object" && e !== null && "_is_widget_error" in e && !!e._is_widget_error, V = Z.getStore(), lr = nn({
1104
+ usdTradeDelta: (e) => Un(e(V.context)),
1105
+ isDirectNearTokenWithdrawal: (e) => Vn(e(V.context)),
1106
+ isDirectNonNearWithdrawal: (e) => Pn(e(V.context)),
1107
+ isDirectTokenOnNearDeposit: (e) => rn(e(V.context)),
1108
+ isNativeNearDeposit: (e) => sn(e(V.context)),
1109
+ isSameAssetDiffChainWithdrawal: (e) => Mn(e(V.context)),
1110
+ isDirectTokenOnNearTransfer: (e) => Wn(e(V.context))
1111
+ }), j = () => oe(lr), _ = () => {
1112
+ const e = oe(V);
1113
+ return {
1114
+ state: e.state,
1115
+ ctx: e.context
1116
+ };
1117
+ }, Ui = (e) => {
1118
+ const t = oe(V);
1119
+ if (!D(t.context, [e]))
1120
+ throw new W(
1121
+ `[WIDGET] Attempt to access snapshot for ${e} state while context does not match`
1122
+ );
1123
+ return t.context;
1124
+ }, dr = async ({
1125
+ contractId: e,
1126
+ accountId: t
1127
+ }) => {
1128
+ try {
1129
+ const r = { account_id: t }, s = Fe.from(JSON.stringify(r)).toString("base64"), n = await $n.query({
1130
+ request_type: "call_function",
1131
+ method_name: "storage_balance_of",
1132
+ account_id: e,
1133
+ args_base64: s,
1134
+ finality: "optimistic"
1135
+ }), a = Qn(
1136
+ n,
1137
+ se.union([se.null(), se.object({ total: se.string() })])
1138
+ );
1139
+ return BigInt(a?.total ?? "0");
1140
+ } catch (r) {
1141
+ throw new W("Error fetching balance", { cause: r });
1142
+ }
1143
+ };
1144
+ function ur(e) {
1145
+ const { ctx: t } = _(), { isNativeNearDeposit: r } = j(), s = t.sourceToken?.contractAddress, n = t.quote?.amountIn ?? t.sourceTokenAmount;
1146
+ return {
1147
+ make: async (l, c) => {
1148
+ if (!e)
1149
+ throw new I({
1150
+ code: "TRANSFER_INVALID_INITIAL",
1151
+ meta: { message: "No connected wallet to sign a transfer." }
1152
+ });
1153
+ if (!s && t.sourceToken?.assetId !== $)
1154
+ throw new I({
1155
+ code: "TRANSFER_INVALID_INITIAL",
1156
+ meta: { message: "No token selected to transfer." }
1157
+ });
1158
+ if (!l)
1159
+ throw new I({
1160
+ code: "TRANSFER_INVALID_INITIAL",
1161
+ meta: { message: "No recipient address to transfer." }
1162
+ });
1163
+ if (!n)
1164
+ throw new I({
1165
+ code: "TRANSFER_INVALID_INITIAL",
1166
+ meta: { message: "No amount to transfer." }
1167
+ });
1168
+ const d = e();
1169
+ if (t.sourceToken.assetId === $ && t.targetToken?.assetId !== ge) {
1170
+ const i = await d.signAndSendTransactions({
1171
+ transactions: [
1172
+ {
1173
+ signerId: t.walletAddress,
1174
+ receiverId: l,
1175
+ actions: [
1176
+ {
1177
+ type: "Transfer",
1178
+ params: {
1179
+ deposit: n
1180
+ // Amount in yoctoNEAR
1181
+ }
1182
+ }
1183
+ ]
1184
+ }
1185
+ ]
1186
+ });
1187
+ return i && i.length > 0 ? {
1188
+ hash: i[0]?.transaction?.hash ?? "",
1189
+ transactionLink: `https://nearblocks.io/txns/${i[0]?.transaction?.hash}`,
1190
+ intent: void 0
1191
+ } : {
1192
+ hash: "",
1193
+ transactionLink: "",
1194
+ intent: void 0
1195
+ };
1196
+ }
1197
+ const u = [];
1198
+ if (t.targetToken && r)
1199
+ try {
1200
+ u.push({
1201
+ type: "FunctionCall",
1202
+ params: {
1203
+ methodName: "near_deposit",
1204
+ gas: We,
1205
+ deposit: n,
1206
+ args: {}
1207
+ }
1208
+ }), u.push({
1209
+ type: "FunctionCall",
1210
+ params: {
1211
+ methodName: "ft_transfer_call",
1212
+ deposit: "1",
1213
+ // 1 yocto required by NEP-141
1214
+ gas: Ve,
1215
+ args: {
1216
+ amount: n,
1217
+ receiver_id: l,
1218
+ msg: c ?? ""
1219
+ }
1220
+ }
1221
+ });
1222
+ const i = await d.signAndSendTransactions({
1223
+ transactions: [
1224
+ {
1225
+ receiverId: "wrap.near",
1226
+ actions: u
1227
+ }
1228
+ ]
1229
+ });
1230
+ if (i?.[0]?.transaction?.hash)
1231
+ return {
1232
+ hash: i[0].transaction?.hash ?? "",
1233
+ transactionLink: `https://nearblocks.io/txns/${i[0].transaction?.hash}`,
1234
+ intent: void 0
1235
+ };
1236
+ throw new I({
1237
+ code: "NO_DEPOSIT_RESULT"
1238
+ });
1239
+ } catch (i) {
1240
+ throw b.error("[TRANSFER ERROR]", i), new I({
1241
+ code: "DIRECT_TRANSFER_ERROR"
1242
+ });
1243
+ }
1244
+ if (!s)
1245
+ throw new I({
1246
+ code: "TRANSFER_INVALID_INITIAL",
1247
+ meta: { message: "No token selected to transfer." }
1248
+ });
1249
+ try {
1250
+ const [i, m] = await Promise.all([
1251
+ Kn({
1252
+ contractId: s
1253
+ }),
1254
+ dr({
1255
+ contractId: s,
1256
+ accountId: l
1257
+ })
1258
+ ]), h = i - m;
1259
+ h > 0n && u.push({
1260
+ type: "FunctionCall",
1261
+ params: {
1262
+ methodName: "storage_deposit",
1263
+ args: { account_id: l },
1264
+ gas: We,
1265
+ deposit: h.toString()
1266
+ }
1267
+ }), u.push({
1268
+ type: "FunctionCall",
1269
+ params: {
1270
+ methodName: "ft_transfer_call",
1271
+ args: {
1272
+ receiver_id: l,
1273
+ amount: n,
1274
+ msg: c ?? ""
1275
+ },
1276
+ gas: Ve,
1277
+ deposit: "1"
1278
+ }
1279
+ });
1280
+ const g = await d.signAndSendTransactions({
1281
+ transactions: [
1282
+ {
1283
+ receiverId: s,
1284
+ actions: u
1285
+ }
1286
+ ]
1287
+ });
1288
+ if (g?.[0]?.transaction?.hash)
1289
+ return {
1290
+ hash: g[0].transaction?.hash ?? "",
1291
+ transactionLink: `https://nearblocks.io/txns/${g[0].transaction?.hash}`,
1292
+ intent: void 0
1293
+ };
1294
+ throw new I({
1295
+ code: "NO_DEPOSIT_RESULT"
1296
+ });
1297
+ } catch (i) {
1298
+ throw b.error("[TRANSFER ERROR]", i), new I({
1299
+ code: "DIRECT_TRANSFER_ERROR"
1300
+ });
1301
+ }
1302
+ }
1303
+ };
1304
+ }
1305
+ const mr = ({
1306
+ makeTransfer: e,
1307
+ providers: t
1308
+ }) => {
1309
+ const { ctx: r } = _(), { alchemyApiKey: s } = y(), { make: n } = Gn({
1310
+ provider: t?.evm
1311
+ }), { make: a } = jn({
1312
+ provider: t?.sol,
1313
+ alchemyApiKey: s
1314
+ }), l = (d) => {
1315
+ if (e)
1316
+ return e;
1317
+ if (gt(d))
1318
+ return n;
1319
+ if (Tt(d))
1320
+ return a;
1321
+ throw new I({
1322
+ code: "TRANSFER_INVALID_INITIAL",
1323
+ meta: { message: "No transfer function established." }
1324
+ });
1325
+ };
1326
+ return { make: async () => {
1327
+ if (!r.sourceToken) {
1328
+ const i = "No token selected to transfer.";
1329
+ throw new I({
1330
+ code: "TRANSFER_INVALID_INITIAL",
1331
+ meta: { message: i }
1332
+ });
1333
+ }
1334
+ if (!r.quote) {
1335
+ const i = "Quote is required for a transfer.";
1336
+ throw new I({
1337
+ code: "TRANSFER_INVALID_INITIAL",
1338
+ meta: { message: i }
1339
+ });
1340
+ }
1341
+ if (!r.quote.depositAddress) {
1342
+ const i = "Quote has no deposit address. Make sure not dry.";
1343
+ throw new I({
1344
+ code: "TRANSFER_INVALID_INITIAL",
1345
+ meta: { message: i }
1346
+ });
1347
+ }
1348
+ const d = {
1349
+ amount: r.quote.amountIn,
1350
+ decimals: r.sourceToken.decimals,
1351
+ address: r.quote.depositAddress,
1352
+ chain: r.sourceToken.blockchain,
1353
+ evmChainId: Q(r.sourceToken.blockchain) ? Te[r.sourceToken.blockchain] : null,
1354
+ isNativeEthTransfer: !!r.sourceToken && Hn(r.sourceToken),
1355
+ tokenAddress: r.sourceToken.assetId === $ ? $ : r.sourceToken.contractAddress,
1356
+ sourceAssetId: r.sourceToken.assetId,
1357
+ targetAssetId: r.targetToken.assetId
1358
+ }, u = l(d.address);
1359
+ try {
1360
+ const i = await u(d);
1361
+ if (!i) {
1362
+ if (e)
1363
+ return;
1364
+ throw b.error("[TRANSFER ERROR]", "No deposit result"), new I({
1365
+ code: "NO_DEPOSIT_RESULT"
1366
+ });
1367
+ }
1368
+ return {
1369
+ hash: i.hash,
1370
+ transactionLink: i.transactionLink,
1371
+ intent: void 0
1372
+ };
1373
+ } catch (i) {
1374
+ b.error("[TRANSFER ERROR]", i, { error: i });
1375
+ let m = "Failed to make a transfer. Please try again.";
1376
+ const h = i instanceof Error && Ae(i.message);
1377
+ if (h)
1378
+ return;
1379
+ throw mn.isAxiosError(i) ? (m = i.response?.data?.detail ?? i.message ?? "Failed to make deposit. Please try again.", new I({
1380
+ code: "QUOTE_ERROR",
1381
+ meta: { message: m }
1382
+ })) : m === "No quotes found" ? new I({
1383
+ code: "NO_QUOTE_FOUND"
1384
+ }) : i instanceof Error && !h ? new I({
1385
+ code: "QUOTE_ERROR",
1386
+ meta: { message: i.message }
1387
+ }) : new I({
1388
+ code: "QUOTE_ERROR",
1389
+ meta: { message: "Unknown quote transfer error" }
1390
+ });
1391
+ }
1392
+ } };
1393
+ };
1394
+ class fr {
1395
+ constructor(t, r) {
1396
+ this.account = t, this.provider = r;
1397
+ }
1398
+ async signIntent(t) {
1399
+ const r = JSON.stringify({
1400
+ verifying_contract: t.verifying_contract,
1401
+ deadline: t.deadline,
1402
+ nonce: t.nonce,
1403
+ intents: t.intents,
1404
+ signer_id: t.signer_id ?? Qe.authHandleToIntentsUserId({
1405
+ identifier: this.account.walletAddress,
1406
+ method: "evm"
1407
+ })
1408
+ }), s = typeof this.provider == "function" ? await this.provider() : this.provider, n = await s.request({
1409
+ method: "eth_requestAccounts"
1410
+ }), a = await s.request({
1411
+ method: "personal_sign",
1412
+ params: [r, n[0]]
1413
+ });
1414
+ if (a == null)
1415
+ throw new W("No signature is returned");
1416
+ return {
1417
+ payload: r,
1418
+ standard: "erc191",
1419
+ signature: Qe.transformERC191Signature(a)
1420
+ };
1421
+ }
1422
+ }
1423
+ const pr = ({
1424
+ walletAddress: e,
1425
+ getProvider: t
1426
+ }) => zn({
1427
+ accountId: e,
1428
+ signMessage: async (r) => {
1429
+ const s = t();
1430
+ if (!s.signMessage)
1431
+ throw new W("Near wallet has no signMessage method exposed");
1432
+ let n;
1433
+ try {
1434
+ n = await s.signMessage({
1435
+ ...r,
1436
+ nonce: Fe.from(r.nonce)
1437
+ });
1438
+ } catch (a) {
1439
+ throw new W("Near wallet failed to sign a message", {
1440
+ cause: a
1441
+ });
1442
+ }
1443
+ if (!n)
1444
+ throw new W("Near wallet failed to sign a message");
1445
+ return {
1446
+ publicKey: n.publicKey,
1447
+ signature: n.signature
1448
+ };
1449
+ }
1450
+ }), hr = (e, t) => {
1451
+ if (t) {
1452
+ if (e.sendAddress)
1453
+ return e.sendAddress;
1454
+ throw new I({
1455
+ code: "TRANSFER_INVALID_INITIAL",
1456
+ meta: { message: "Send to address is required for a direct transfer" }
1457
+ });
1458
+ }
1459
+ if (!e.quote || e.quote.dry)
1460
+ throw new I({
1461
+ code: "TRANSFER_INVALID_INITIAL",
1462
+ meta: { message: "Quote is required for intents non-direct transfer" }
1463
+ });
1464
+ return e.quote.depositAddress;
1465
+ }, Tr = async (e, t) => {
1466
+ let r = Me.getItem("nearWalletsPk")[t];
1467
+ if (!e.signMessage)
1468
+ throw new I({
1469
+ code: "DIRECT_TRANSFER_ERROR",
1470
+ meta: { message: "Your wallet doesn't support signing messages" }
1471
+ });
1472
+ if (!r)
1473
+ try {
1474
+ const a = await e.signMessage({
1475
+ message: "Authenticate",
1476
+ recipient: "intents.near",
1477
+ nonce: Fe.from(Jn(32))
1478
+ });
1479
+ if (!a)
1480
+ throw new I({
1481
+ code: "DIRECT_TRANSFER_ERROR",
1482
+ meta: { message: "Signing message failed" }
1483
+ });
1484
+ r = a.publicKey, Me.setItem("nearWalletsPk", {
1485
+ [t]: a.publicKey
1486
+ });
1487
+ } catch {
1488
+ throw new I({
1489
+ code: "DIRECT_TRANSFER_ERROR",
1490
+ meta: { message: "Your wallet doesn't support signing messages" }
1491
+ });
1492
+ }
1493
+ const s = te({
1494
+ walletAddress: t,
1495
+ addressType: "near"
1496
+ });
1497
+ if (!await ts({
1498
+ contractId: ke,
1499
+ methodName: "has_public_key",
1500
+ args: {
1501
+ account_id: s,
1502
+ public_key: r
1503
+ }
1504
+ }))
1505
+ try {
1506
+ await e.signAndSendTransactions({
1507
+ transactions: [
1508
+ {
1509
+ receiverId: ke,
1510
+ signerId: t,
1511
+ actions: [
1512
+ {
1513
+ type: "FunctionCall",
1514
+ params: {
1515
+ methodName: "add_public_key",
1516
+ args: { public_key: r },
1517
+ gas: "100000000000000",
1518
+ deposit: "1"
1519
+ }
1520
+ }
1521
+ ]
1522
+ }
1523
+ ]
1524
+ });
1525
+ } catch {
1526
+ throw new I({
1527
+ code: "DIRECT_TRANSFER_ERROR",
1528
+ meta: { message: "Unable to add public key to intents account" }
1529
+ });
1530
+ }
1531
+ }, gr = ({ providers: e }) => {
1532
+ const { ctx: t } = _(), { appName: r, intentsAccountType: s } = y(), {
1533
+ isNativeNearDeposit: n,
1534
+ isDirectNearTokenWithdrawal: a,
1535
+ isDirectNonNearWithdrawal: l
1536
+ } = j();
1537
+ return { make: async ({
1538
+ message: d,
1539
+ onPending: u
1540
+ }) => {
1541
+ if (!t.walletAddress)
1542
+ throw new I({
1543
+ code: "TRANSFER_INVALID_INITIAL",
1544
+ meta: { message: "No connected wallet to sign a transfer." }
1545
+ });
1546
+ if (!t.sourceToken || !t.targetToken)
1547
+ throw new I({
1548
+ code: "TRANSFER_INVALID_INITIAL",
1549
+ meta: { message: "No token selected to transfer." }
1550
+ });
1551
+ if (!t.sourceToken.isIntent)
1552
+ throw new I({
1553
+ code: "TRANSFER_INVALID_INITIAL",
1554
+ meta: {
1555
+ message: "For not intents source token use useMakeQuoteTransfer instead"
1556
+ }
1557
+ });
1558
+ let i;
1559
+ if (!s)
1560
+ throw new I({
1561
+ code: "TRANSFER_INVALID_INITIAL",
1562
+ meta: { message: "Intents account type is not defined" }
1563
+ });
1564
+ switch (s) {
1565
+ case "evm":
1566
+ if (!e?.evm)
1567
+ throw new I({
1568
+ code: "TRANSFER_INVALID_INITIAL",
1569
+ meta: { message: "No EVM provider configured" }
1570
+ });
1571
+ i = new fr(
1572
+ { walletAddress: t.walletAddress },
1573
+ e.evm
1574
+ );
1575
+ break;
1576
+ case "sol":
1577
+ if (!e?.sol)
1578
+ throw new I({
1579
+ code: "TRANSFER_INVALID_INITIAL",
1580
+ meta: { message: "No SOL provider configured" }
1581
+ });
1582
+ i = new es(
1583
+ { walletAddress: t.walletAddress },
1584
+ e.sol
1585
+ );
1586
+ break;
1587
+ case "near": {
1588
+ if (!e?.near)
1589
+ throw new I({
1590
+ code: "TRANSFER_INVALID_INITIAL",
1591
+ meta: { message: "No NEAR provider configured" }
1592
+ });
1593
+ await Tr(e.near(), t.walletAddress), i = pr({
1594
+ walletAddress: t.walletAddress,
1595
+ getProvider: e.near
1596
+ });
1597
+ break;
1598
+ }
1599
+ default:
1600
+ Ce(s);
1601
+ }
1602
+ const m = new Yn({ referral: dt(r) });
1603
+ m.setIntentSigner(i);
1604
+ let h;
1605
+ n ? h = void 0 : a ? h = Zn(d ?? void 0) : l ? h = void 0 : h = Xn();
1606
+ const g = m.createWithdrawal({
1607
+ withdrawalParams: {
1608
+ assetId: t.sourceToken.assetId,
1609
+ amount: BigInt(t.sourceTokenAmount),
1610
+ destinationAddress: hr(
1611
+ t,
1612
+ a || l
1613
+ ),
1614
+ destinationMemo: void 0,
1615
+ feeInclusive: !1,
1616
+ routeConfig: h
1617
+ }
1618
+ });
1619
+ try {
1620
+ await g.estimateFee(), u("WAITING_CONFIRMATION");
1621
+ const f = await g.signAndSendIntent();
1622
+ u("PROCESSING");
1623
+ const w = await g.waitForIntentSettlement();
1624
+ return await g.waitForWithdrawalCompletion(), {
1625
+ hash: w.hash,
1626
+ transactionLink: ns(en.near, w.hash),
1627
+ intent: f
1628
+ };
1629
+ } catch (f) {
1630
+ if (b.error("[TRANSFER ERROR]", f), f instanceof Error) {
1631
+ if (f.message.includes("Fee is not estimated"))
1632
+ throw new I({
1633
+ code: "FEES_NOT_ESTIMATED"
1634
+ });
1635
+ if (Ae(f.message) || Ae(`${f.cause}`))
1636
+ return;
1637
+ }
1638
+ throw new I({
1639
+ code: "DIRECT_TRANSFER_ERROR"
1640
+ });
1641
+ }
1642
+ } };
1643
+ }, Ir = ({
1644
+ message: e,
1645
+ providers: t,
1646
+ makeTransfer: r
1647
+ }) => {
1648
+ const { ctx: s } = _(), {
1649
+ isDirectTokenOnNearDeposit: n,
1650
+ isDirectTokenOnNearTransfer: a,
1651
+ isNativeNearDeposit: l
1652
+ } = j(), { make: c } = gr({ providers: t }), { make: d } = mr({
1653
+ makeTransfer: r,
1654
+ providers: t
1655
+ }), { make: u } = ur(
1656
+ t?.near
1657
+ );
1658
+ return { make: async () => {
1659
+ if (!s.targetToken)
1660
+ return;
1661
+ let m;
1662
+ try {
1663
+ if (p("transferSetStatus", {
1664
+ status: "pending",
1665
+ reason: "WAITING_CONFIRMATION"
1666
+ }), s.sourceToken?.isIntent)
1667
+ m = await c({
1668
+ message: e,
1669
+ onPending: (h) => {
1670
+ p("transferSetStatus", {
1671
+ status: "pending",
1672
+ reason: h
1673
+ });
1674
+ }
1675
+ });
1676
+ else if ((l || n) && !s.isDepositFromExternalWallet)
1677
+ m = await u(
1678
+ s.sendAddress ?? ke,
1679
+ e
1680
+ );
1681
+ else if (a) {
1682
+ if (!s.sendAddress)
1683
+ throw new I({
1684
+ code: "TRANSFER_INVALID_INITIAL",
1685
+ meta: { message: "No recipient address to transfer" }
1686
+ });
1687
+ m = await u(
1688
+ s.sendAddress,
1689
+ e
1690
+ );
1691
+ } else
1692
+ m = await d();
1693
+ } catch (h) {
1694
+ h instanceof I && (b.error(h.data), p("transferSetStatus", { status: "error" }), p("errorSet", h.data));
1695
+ }
1696
+ if (!m) {
1697
+ p("transferSetStatus", { status: "idle" });
1698
+ return;
1699
+ }
1700
+ return p("transferSetStatus", { status: "success" }), O("transfer_success"), m;
1701
+ } };
1702
+ }, wr = async (e) => {
1703
+ if (!e)
1704
+ return;
1705
+ const t = await e.request({
1706
+ method: "eth_chainId"
1707
+ });
1708
+ return parseInt(t, 16);
1709
+ }, kr = ({ providers: e }) => {
1710
+ const { ctx: t } = _(), [r, s] = re(!1), [n, a] = re(!1), l = he(async () => {
1711
+ const d = typeof e?.evm == "function" ? await e.evm() : e?.evm;
1712
+ if (!t.sourceToken || !d)
1713
+ return !1;
1714
+ const u = await wr(d);
1715
+ if (!Q(t.sourceToken.blockchain))
1716
+ return !1;
1717
+ const i = Te[t.sourceToken.blockchain];
1718
+ return !i || !u ? !1 : u !== i;
1719
+ }, [t.sourceToken, e]), c = he(async () => {
1720
+ const d = typeof e?.evm == "function" ? await e.evm() : e?.evm;
1721
+ if (!t.sourceToken || !d || !Q(t.sourceToken.blockchain))
1722
+ return !1;
1723
+ const u = Te[t.sourceToken.blockchain];
1724
+ if (!u)
1725
+ return !1;
1726
+ try {
1727
+ return s(!0), await ss(u, d), !0;
1728
+ } catch (i) {
1729
+ return b.error("Failed to switch chain:", i), !1;
1730
+ } finally {
1731
+ s(!1);
1732
+ }
1733
+ }, [t.sourceToken, e]);
1734
+ return C(() => {
1735
+ l().then(a);
1736
+ }, [l]), {
1737
+ isSwitchingChainRequired: n,
1738
+ switchChain: c,
1739
+ isSwitchingChain: r
1740
+ };
1741
+ }, N = {
1742
+ size: "lg",
1743
+ variant: "primary"
1744
+ }, Le = (e) => {
1745
+ const { t } = M();
1746
+ if (e.error?.code === "TOKEN_IS_NOT_SUPPORTED")
1747
+ return /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.invalidAddress", "Invalid address") });
1748
+ if (e.state === "initial_wallet" && e.error?.code === "SEND_ADDRESS_IS_EMPTY")
1749
+ return /* @__PURE__ */ o(A, { state: "disabled", ...N, children: t("submit.disabled.enterRecipientAddress", "Enter recipient address") });
1750
+ if (e.state === "initial_wallet" && e.error?.code === "SEND_ADDRESS_IS_NOT_FOUND")
1751
+ return /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.sendAddressNotFound", {
1752
+ defaultValue: "Address not found on {{chain}}",
1753
+ chain: e.error.meta.chain.toUpperCase()
1754
+ }) });
1755
+ if (e.state === "initial_wallet" && e.error?.code === "SEND_ADDRESS_IS_INVALID")
1756
+ return /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.sendAddressInvalid", {
1757
+ defaultValue: "Invalid {{chain}} address",
1758
+ chain: e.error.meta.chain.toUpperCase()
1759
+ }) });
1760
+ if (e.error?.code === "QUOTE_AMOUNT_IS_TOO_LOW")
1761
+ return /* @__PURE__ */ T("div", { className: "gap-sw-md flex flex-col", children: [
1762
+ /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.amountTooLow.label", "Amount is too low") }),
1763
+ /* @__PURE__ */ o(K, { children: /* @__PURE__ */ T(Ht, { i18nKey: "submit.error.amountTooLow.message", children: [
1764
+ "Amount you entered is very low. Please try increasing it",
1765
+ " ",
1766
+ /* @__PURE__ */ T("span", { className: "text-nowrap", children: [
1767
+ "above ",
1768
+ /* @__PURE__ */ o(Oe, { value: e.error.meta.minAmount ?? "0" }),
1769
+ " ",
1770
+ e.sourceToken?.symbol ?? "",
1771
+ "."
1772
+ ] })
1773
+ ] }) })
1774
+ ] });
1775
+ if (e.quoteStatus === "error")
1776
+ return /* @__PURE__ */ T("div", { className: "gap-sw-md flex flex-col", children: [
1777
+ /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.quoteFailed.label", "Quote failed") }),
1778
+ /* @__PURE__ */ o(K, { children: t(
1779
+ "submit.error.quoteFailed.message",
1780
+ "We couldn’t finalize your quote. Please try again or adjust your values."
1781
+ ) })
1782
+ ] });
1783
+ if (e.error?.code === "TRANSFER_INVALID_INITIAL")
1784
+ return /* @__PURE__ */ T("div", { className: "gap-sw-md flex flex-col", children: [
1785
+ /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.invalidTransferData.label", "Invalid transfer data") }),
1786
+ e.error.meta?.message ? /* @__PURE__ */ o(K, { children: e.error.meta.message }) : null
1787
+ ] });
1788
+ if (e.error?.code === "EXTERNAL_TRANSFER_FAILED")
1789
+ return /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.externalTransferFailed.label", "Transfer failed") });
1790
+ if (e.error?.code === "EXTERNAL_TRANSFER_INCOMPLETE")
1791
+ return /* @__PURE__ */ T("div", { className: "gap-sw-md flex flex-col", children: [
1792
+ /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.externalTransferFailed.label", "Transfer failed") }),
1793
+ /* @__PURE__ */ o(K, { children: t(
1794
+ "submit.error.externalTransferFailed.incompleteMessage",
1795
+ "Incomplete transfer. Deposited amount will be refunded."
1796
+ ) })
1797
+ ] });
1798
+ if (e.error?.code === "EXTERNAL_TRANSFER_REFUNDED")
1799
+ return /* @__PURE__ */ T("div", { className: "gap-sw-md flex flex-col", children: [
1800
+ /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.externalTransferFailed.label", "Transfer failed") }),
1801
+ /* @__PURE__ */ o(K, { children: t(
1802
+ "submit.error.externalTransferFailed.refundedMessage",
1803
+ "Deposited amount will be refunded."
1804
+ ) })
1805
+ ] });
1806
+ if (e.error?.code === "DIRECT_TRANSFER_ERROR")
1807
+ return /* @__PURE__ */ T("div", { className: "gap-sw-md flex flex-col", children: [
1808
+ /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.transferFailed.label", "Transfer failed") }),
1809
+ e.error.meta?.message ? /* @__PURE__ */ o(K, { children: e.error.meta.message }) : null
1810
+ ] });
1811
+ if (e.error?.code === "SOURCE_BALANCE_INSUFFICIENT")
1812
+ return /* @__PURE__ */ o(A, { state: "error", ...N, children: t("submit.error.insufficientBalance", "Insufficient balance") });
1813
+ }, Ar = ({ onClick: e }) => {
1814
+ const { t } = M();
1815
+ return /* @__PURE__ */ o(A, { state: "disabled", ...N, onClick: e, children: t("submit.error.connectWallet", "Connect wallet") });
1816
+ }, Sr = () => {
1817
+ const { ctx: e } = _();
1818
+ return Le(e) ?? null;
1819
+ }, Nr = (e) => {
1820
+ const { providers: t, makeTransfer: r, onSuccess: s } = e, { ctx: n } = _(), { t: a } = M(), {
1821
+ isNativeNearDeposit: l,
1822
+ isDirectNonNearWithdrawal: c,
1823
+ isDirectTokenOnNearDeposit: d,
1824
+ isDirectNearTokenWithdrawal: u
1825
+ } = j(), { make: i } = Ir({ providers: t, makeTransfer: r }), { isSwitchingChainRequired: m, switchChain: h, isSwitchingChain: g } = kr({ providers: t }), f = Le(n), w = async () => {
1826
+ if (m && !await h())
1827
+ return;
1828
+ const S = await i();
1829
+ S && s(S);
1830
+ };
1831
+ if (!n.targetToken)
1832
+ return /* @__PURE__ */ o(A, { ...N, state: "disabled", children: a("submit.disabled.selectTokenToReceive", "Select token to receive") });
1833
+ if (!ne(n.sourceTokenAmount))
1834
+ return /* @__PURE__ */ o(A, { ...N, state: "disabled", children: a("submit.disabled.enterAmount", "Enter amount") });
1835
+ if (n.areInputsValidating)
1836
+ return /* @__PURE__ */ o(A, { state: "loading", ...N, children: a("submit.pending.validating", "Validating...") });
1837
+ if (g)
1838
+ return /* @__PURE__ */ o(A, { state: "loading", ...N, children: a("submit.pending.switchingChain", "Switching network...") });
1839
+ if (!m && f)
1840
+ return f;
1841
+ if (n.transferStatus.status === "pending")
1842
+ switch (n.transferStatus.reason) {
1843
+ case "WAITING_CONFIRMATION":
1844
+ return /* @__PURE__ */ o(A, { state: "loading", ...N, children: a("submit.pending.transfer.confirmInWallet", "Confirm in wallet") });
1845
+ case "PROCESSING":
1846
+ default:
1847
+ return /* @__PURE__ */ o(A, { state: "loading", ...N, children: a("submit.pending.transfer.finalizing", "Finalizing transfer") });
1848
+ }
1849
+ return n.transferStatus.status === "error" ? /* @__PURE__ */ T("div", { className: "gap-sw-md flex flex-col", children: [
1850
+ /* @__PURE__ */ o(A, { ...N, children: e.label }),
1851
+ /* @__PURE__ */ o(K, { children: (() => {
1852
+ switch (n.error?.code) {
1853
+ case "FEES_NOT_ESTIMATED":
1854
+ return a(
1855
+ "submit.error.transfer.noFees",
1856
+ "Transfer fees could not be estimated."
1857
+ );
1858
+ default:
1859
+ return a(
1860
+ "submit.error.transfer.failed",
1861
+ "Transfer can not be completed."
1862
+ );
1863
+ }
1864
+ })() })
1865
+ ] }) : n.quoteStatus === "pending" ? /* @__PURE__ */ o(A, { state: "loading", ...N, children: n.quote ? a("submit.pending.quote.refreshing", "Refreshing quote") : a("submit.pending.quote.finalizing", "Finalizing quote") }) : n.error ? /* @__PURE__ */ o(A, { state: "disabled", ...N, children: e.label }) : !n.quote && !c && !d && !u && !l ? /* @__PURE__ */ o(A, { state: "disabled", ...N, children: e.label }) : /* @__PURE__ */ o(A, { ...N, onClick: w, children: e.label });
1866
+ }, _r = (e) => {
1867
+ const { t } = M(), { ctx: r } = _(), s = Le(r);
1868
+ return r.isDepositFromExternalWallet ? ne(r.sourceTokenAmount) ? r.externalDepositTxReceived ? /* @__PURE__ */ o(A, { state: "loading", ...N, children: t("submit.pending.externalDeposit.processing", "Processing") }) : /* @__PURE__ */ o(A, { state: "loading", ...N, children: t("submit.pending.externalDeposit.waiting", "Waiting for transaction") }) : /* @__PURE__ */ o(A, { ...N, state: "disabled", children: t("submit.disabled.enterAmount", "Enter amount") }) : s || /* @__PURE__ */ o(Nr, { ...e });
1869
+ }, yr = (e) => {
1870
+ const { ctx: t } = _(), r = y();
1871
+ return t.walletAddress ? /* @__PURE__ */ o(_r, { ...e }) : /* @__PURE__ */ o(Ar, { onClick: r.onWalletSignin });
1872
+ };
1873
+ yr.Error = Sr;
1874
+ const br = ({ className: e }) => {
1875
+ const { t } = M(), { slippageTolerance: r } = y(), { ctx: s } = _(), n = s.sourceToken && s.targetToken && s.sourceToken.price / s.targetToken.price;
1876
+ return s.sourceToken ? /* @__PURE__ */ o(
1877
+ rs,
1878
+ {
1879
+ expandedByDefault: !1,
1880
+ expandedHeightPx: s.walletAddress ? 80 : 50,
1881
+ isBadgeLoading: s.quoteStatus === "pending",
1882
+ badge: s.quote ? `~ ${s.quote.timeEstimate} sec` : void 0,
1883
+ className: e,
1884
+ title: s.sourceToken && s.targetToken ? /* @__PURE__ */ T("span", { style: { borderBottomWidth: "2px", borderStyle: "dotted" }, children: [
1885
+ `1 ${s.sourceToken.symbol} ≈ `,
1886
+ " ",
1887
+ as(n ?? 0),
1888
+ " ",
1889
+ `${s.targetToken.symbol}`,
1890
+ /* @__PURE__ */ o("span", { className: "text-sw-gray-50", children: ` (${$e(s.sourceToken.price)})` })
1891
+ ] }) : /* @__PURE__ */ T("span", { style: { borderBottomWidth: "2px", borderStyle: "dotted" }, children: [
1892
+ `1 ${s.sourceToken.symbol} ≈ `,
1893
+ " ",
1894
+ $e(s.sourceToken.price),
1895
+ " USD"
1896
+ ] }),
1897
+ children: /* @__PURE__ */ T(de, { children: [
1898
+ /* @__PURE__ */ o(
1899
+ de.Item,
1900
+ {
1901
+ label: t("quote.result.maxSlippage.label", "Max slippage"),
1902
+ value: `${(r / 100).toFixed(2)}%`
1903
+ }
1904
+ ),
1905
+ !!s.walletAddress && /* @__PURE__ */ o(
1906
+ de.Item,
1907
+ {
1908
+ isLoading: s.quoteStatus === "pending",
1909
+ label: t("quote.result.processingTime.label", "Processing time"),
1910
+ value: s.quote ? `${s.quote.timeEstimate} sec.` : "—"
1911
+ }
1912
+ )
1913
+ ] })
1914
+ }
1915
+ ) : /* @__PURE__ */ o(It, {});
1916
+ }, Pi = Object.assign(br, {
1917
+ Skeleton: It
1918
+ }), Er = ({
1919
+ token: e,
1920
+ balance: t,
1921
+ isNotSufficient: r = !1,
1922
+ onClick: s
1923
+ }) => {
1924
+ const n = y();
1925
+ return !e.isIntent && !n.walletSupportedChains.includes(e.blockchain) ? /* @__PURE__ */ o("span", {}) : t === void 0 ? /* @__PURE__ */ o(is, { width: 100 }) : /* @__PURE__ */ o(
1926
+ "span",
1927
+ {
1928
+ onClick: t ? s : void 0,
1929
+ style: t ? { borderBottomWidth: "2px", borderStyle: "dotted" } : void 0,
1930
+ className: os("text-sw-label-sm", {
1931
+ "text-sw-status-error": r,
1932
+ "text-sw-gray-100": !r,
1933
+ "cursor-pointer": !!t && !!s
1934
+ }),
1935
+ children: /* @__PURE__ */ o(
1936
+ Oe,
1937
+ {
1938
+ decimals: e.decimals,
1939
+ value: t === void 0 ? "0" : `${t}`
1940
+ }
1941
+ )
1942
+ }
1943
+ );
1944
+ }, Be = ({
1945
+ token: e,
1946
+ balance: t,
1947
+ value: r = "",
1948
+ quoteUsdDelta: s,
1949
+ quoteUsdValue: n,
1950
+ state: a = "default",
1951
+ showBalance: l = !0,
1952
+ showQuickBalanceActions: c = !0,
1953
+ heading: d,
1954
+ onMsg: u
1955
+ }) => {
1956
+ const i = Pt(), { ctx: m } = _(), { t: h } = M(), { hideTokenInputHeadings: g } = y(), f = ls(e, r, n), w = (S) => {
1957
+ u({
1958
+ type: "on_change_amount",
1959
+ amount: cs(t, e.decimals, S)
1960
+ });
1961
+ };
1962
+ return /* @__PURE__ */ T(ie, { className: "flex flex-col", "aria-label": d, children: [
1963
+ !g && /* @__PURE__ */ o(wt, { children: d }),
1964
+ /* @__PURE__ */ T(
1965
+ "div",
1966
+ {
1967
+ className: H(
1968
+ "flex items-center justify-between",
1969
+ !g && "mt-sw-2xl"
1970
+ ),
1971
+ children: [
1972
+ /* @__PURE__ */ o(
1973
+ us,
1974
+ {
1975
+ value: r,
1976
+ name: i,
1977
+ setValue: ds,
1978
+ placeholder: "0",
1979
+ state: a === "default" || a === "disabled" ? a : "error",
1980
+ onChange: (S) => {
1981
+ u({ type: "on_change_amount", amount: S.target.value });
1982
+ }
1983
+ }
1984
+ ),
1985
+ /* @__PURE__ */ T(
1986
+ "button",
1987
+ {
1988
+ type: "button",
1989
+ onClick: a === "disabled" ? void 0 : () => u({ type: "on_click_select_token" }),
1990
+ className: H(
1991
+ "gap-sw-md pl-sw-sm pr-sw-md flex h-[36px] min-w-[80px] shrink-0 items-center rounded-sw-md transition-colors bg-sw-gray-800 hover:bg-sw-gray-700 group",
1992
+ {
1993
+ "cursor-pointer": a !== "disabled",
1994
+ "animate-pulse cursor-default": a === "disabled"
1995
+ }
1996
+ ),
1997
+ children: [
1998
+ /* @__PURE__ */ o(
1999
+ kt,
2000
+ {
2001
+ chainShowIcon: !e.isIntent,
2002
+ className: "border-sw-gray-800 group-hover:border-sw-gray-700 transition-colors top-[14px]",
2003
+ ...e
2004
+ }
2005
+ ),
2006
+ /* @__PURE__ */ o("span", { className: "text-sw-label-md text-sw-gray-50", children: e.symbol })
2007
+ ]
2008
+ }
2009
+ )
2010
+ ]
2011
+ }
2012
+ ),
2013
+ /* @__PURE__ */ T("div", { className: "gap-sw-sm min-h-sw-2xl flex items-center justify-between mt-sw-lg", children: [
2014
+ /* @__PURE__ */ T("div", { className: "gap-sw-md flex items-center", children: [
2015
+ /* @__PURE__ */ o("span", { className: "text-sw-label-sm text-sw-gray-100", children: f }),
2016
+ s ? /* @__PURE__ */ o(
2017
+ "span",
2018
+ {
2019
+ className: H("text-sw-label-sm text-nowrap", {
2020
+ "text-sw-gray-400": s >= -2 && s <= 2,
2021
+ "text-sw-status-success": s > 2,
2022
+ "text-sw-status-error": s <= -5,
2023
+ "text-sw-status-warning": s < -2 && s > -5
2024
+ }),
2025
+ children: `${s > 0 ? "+" : ""}${s.toFixed(2)}%`
2026
+ }
2027
+ ) : null
2028
+ ] }),
2029
+ /* @__PURE__ */ T("div", { className: "gap-sw-sm flex items-center", children: [
2030
+ e && !!m.walletAddress && l && /* @__PURE__ */ o(
2031
+ Er,
2032
+ {
2033
+ token: e,
2034
+ balance: t,
2035
+ isNotSufficient: a === "error-balance",
2036
+ onClick: () => w(1)
2037
+ }
2038
+ ),
2039
+ !!t && l && c && /* @__PURE__ */ T(Ft, { children: [
2040
+ /* @__PURE__ */ o(
2041
+ Ke,
2042
+ {
2043
+ isClickable: a !== "disabled",
2044
+ onClick: () => w(2),
2045
+ children: h("tokens.input.half.label", "50%")
2046
+ }
2047
+ ),
2048
+ /* @__PURE__ */ o(
2049
+ Ke,
2050
+ {
2051
+ isClickable: a !== "disabled",
2052
+ onClick: () => w(1),
2053
+ children: h("tokens.input.max.label", "Max")
2054
+ }
2055
+ )
2056
+ ] }),
2057
+ !l && /* @__PURE__ */ o("div", { className: "rounded-full bg-sw-gray-700 py-sw-xs px-sw-sm flex items-center justify-center", children: /* @__PURE__ */ o("span", { className: "text-sw-gray-100 text-sw-label-sm", children: h("tokens.input.externalBalance.label", "External balance") }) })
2058
+ ] })
2059
+ ] })
2060
+ ] });
2061
+ }, qe = ({ onMsg: e, heading: t }) => {
2062
+ const { hideTokenInputHeadings: r } = y();
2063
+ return /* @__PURE__ */ T(
2064
+ ie,
2065
+ {
2066
+ isClickable: !0,
2067
+ className: "flex flex-col",
2068
+ onClick: () => e({ type: "on_click_select_token" }),
2069
+ children: [
2070
+ !r && /* @__PURE__ */ o(wt, { children: t }),
2071
+ /* @__PURE__ */ T(
2072
+ "div",
2073
+ {
2074
+ className: H(
2075
+ "flex items-center justify-between",
2076
+ !r && "mt-sw-2xl"
2077
+ ),
2078
+ children: [
2079
+ /* @__PURE__ */ o(
2080
+ "span",
2081
+ {
2082
+ className: "h-[36px] font-medium text-sw-gray-200",
2083
+ style: { fontSize: "32px" },
2084
+ children: "0"
2085
+ }
2086
+ ),
2087
+ /* @__PURE__ */ o(
2088
+ "button",
2089
+ {
2090
+ type: "button",
2091
+ onClick: () => e({ type: "on_click_select_token" }),
2092
+ className: "gap-sw-md px-sw-md flex h-[36px] min-w-[100px] shrink-0 cursor-pointer items-center rounded-sw-md bg-sw-gray-800",
2093
+ children: /* @__PURE__ */ o("span", { className: "text-sw-label-md text-sw-gray-50", children: "Select token" })
2094
+ }
2095
+ )
2096
+ ]
2097
+ }
2098
+ ),
2099
+ /* @__PURE__ */ o("div", { className: "h-sw-2xl w-full mt-sw-lg" })
2100
+ ]
2101
+ }
2102
+ );
2103
+ }, vt = (e) => {
2104
+ const { mergedBalance: t } = le(), [r, s] = re(
2105
+ e ? t[G(e)] : void 0
2106
+ );
2107
+ return C(() => {
2108
+ let n;
2109
+ if (e) {
2110
+ const a = t[G(e)];
2111
+ a ? n = setTimeout(() => {
2112
+ s(a);
2113
+ }, 0) : n = setTimeout(() => {
2114
+ s(
2115
+ e ? t[G(e)] ?? 0 : 0
2116
+ );
2117
+ }, 2e3);
2118
+ }
2119
+ return () => {
2120
+ n && clearTimeout(n);
2121
+ };
2122
+ }, [e, t]), r;
2123
+ }, Dt = (e, t) => {
2124
+ const { tokens: r } = P(e), s = Array.from(
2125
+ new Set(r.map((n) => n.assetId))
2126
+ );
2127
+ C(() => {
2128
+ const n = s.length === 1 ? r[0] : null;
2129
+ n && t({ type: "on_select_token", token: n });
2130
+ }, [r]);
2131
+ }, Cr = ({
2132
+ onMsg: e,
2133
+ isChanging: t = !0,
2134
+ showBalance: r = !0,
2135
+ heading: s
2136
+ }) => {
2137
+ const { ctx: n } = _(), a = vt(n.sourceToken);
2138
+ Dt("source", e);
2139
+ const l = v(() => {
2140
+ if (!t && n.quoteStatus === "pending")
2141
+ return "disabled";
2142
+ if (!n.error)
2143
+ return "default";
2144
+ if (n.error.code === "QUOTE_AMOUNT_IS_TOO_LOW")
2145
+ return "error";
2146
+ if (n.error.code === "SOURCE_BALANCE_INSUFFICIENT")
2147
+ return "error-balance";
2148
+ }, [t, n.error, n.quoteStatus]);
2149
+ return n.sourceToken ? /* @__PURE__ */ o(
2150
+ Be,
2151
+ {
2152
+ heading: s,
2153
+ token: n.sourceToken,
2154
+ state: l,
2155
+ balance: a,
2156
+ showBalance: r,
2157
+ showQuickBalanceActions: !0,
2158
+ value: z(n.sourceTokenAmount, n.sourceToken?.decimals),
2159
+ onMsg: e
2160
+ }
2161
+ ) : /* @__PURE__ */ o(qe, { heading: s, onMsg: e });
2162
+ }, Rr = ({
2163
+ isChanging: e = !1,
2164
+ onMsg: t,
2165
+ heading: r
2166
+ }) => {
2167
+ const { ctx: s } = _(), { usdTradeDelta: n } = j(), a = vt(s.targetToken);
2168
+ Dt("target", t);
2169
+ const l = v(() => !e && s.quoteStatus === "pending" ? "disabled" : "default", [e, s.quoteStatus]);
2170
+ return s.targetToken ? /* @__PURE__ */ o(
2171
+ Be,
2172
+ {
2173
+ heading: r,
2174
+ token: s.targetToken,
2175
+ balance: a,
2176
+ quoteUsdDelta: n?.percentage,
2177
+ quoteUsdValue: s.quote && parseFloat(s.quote.amountOutUsd),
2178
+ value: z(s.targetTokenAmount, s.targetToken?.decimals),
2179
+ state: l,
2180
+ showQuickBalanceActions: !1,
2181
+ showBalance: !0,
2182
+ onMsg: t
2183
+ }
2184
+ ) : /* @__PURE__ */ o(qe, { heading: r, onMsg: t });
2185
+ }, vr = ({ token: e, heading: t, ...r }) => e ? /* @__PURE__ */ o(Be, { ...r, token: e, heading: t }) : /* @__PURE__ */ o(qe, { onMsg: r.onMsg, heading: t }), Wi = Object.assign(vr, {
2186
+ Skeleton: ms,
2187
+ Source: Cr,
2188
+ Target: Rr
2189
+ }), Je = 58, xt = ({
2190
+ token: e,
2191
+ balance: t,
2192
+ showBalance: r = !0,
2193
+ isNotSelectable: s,
2194
+ className: n,
2195
+ onMsg: a
2196
+ }) => {
2197
+ const { ctx: l } = _(), { walletSupportedChains: c, appName: d } = y(), u = fs(t, e), i = c.includes(e.blockchain) || e.isIntent, m = t !== "0" && t !== 0 && t !== void 0;
2198
+ return /* @__PURE__ */ o("li", { className: "list-none group", children: /* @__PURE__ */ T(
2199
+ "div",
2200
+ {
2201
+ className: H(
2202
+ "gap-sw-lg p-sw-lg flex justify-between rounded-sw-md transition-colors",
2203
+ {
2204
+ "cursor-not-allowed": s,
2205
+ "cursor-pointer hover:bg-sw-gray-800": !s
2206
+ },
2207
+ n
2208
+ ),
2209
+ onClick: () => !s && a({ type: "on_select_token", token: e }),
2210
+ children: [
2211
+ /* @__PURE__ */ o(
2212
+ kt,
2213
+ {
2214
+ chainShowIcon: !e.isIntent,
2215
+ className: "border-sw-gray-900 group-hover:border-sw-gray-800 transition-colors",
2216
+ ...e
2217
+ }
2218
+ ),
2219
+ /* @__PURE__ */ T("div", { className: "gap-sw-xs mr-auto flex flex-col", children: [
2220
+ /* @__PURE__ */ o("span", { className: "text-sw-label-md text-sw-gray-50", children: e.name }),
2221
+ e.isIntent ? /* @__PURE__ */ T("div", { className: "flex items-center gap-sw-xs", children: [
2222
+ /* @__PURE__ */ o("span", { className: "text-sw-label-md text-sw-gray-300", children: e.symbol }),
2223
+ " ",
2224
+ /* @__PURE__ */ o("span", { className: "text-sw-label-sm text-sw-gray-300", children: `on ${d} ${e.chainName.toLowerCase() !== "near" && m ? `(${e.chainName})` : ""}` })
2225
+ ] }) : /* @__PURE__ */ T("div", { className: "flex items-center gap-sw-xs", children: [
2226
+ /* @__PURE__ */ o("span", { className: "text-sw-label-md text-sw-gray-300", children: e.symbol }),
2227
+ " ",
2228
+ /* @__PURE__ */ o("span", { className: "text-sw-label-sm text-sw-gray-300", children: `on ${e.chainName}` })
2229
+ ] })
2230
+ ] }),
2231
+ i && !!l.walletAddress && r && /* @__PURE__ */ T("div", { className: "gap-sw-xs flex flex-col items-end", children: [
2232
+ t === void 0 && !e.isIntent ? /* @__PURE__ */ o("span", { className: "h-[16px] w-[60px] animate-pulse rounded-full bg-sw-gray-700" }) : /* @__PURE__ */ o("span", { className: "h-[16px] text-sw-label-md text-sw-gray-50", children: m && /* @__PURE__ */ o(
2233
+ Oe,
2234
+ {
2235
+ decimals: e.decimals,
2236
+ value: t === void 0 ? "0" : `${t}`
2237
+ }
2238
+ ) }),
2239
+ m && /* @__PURE__ */ o("span", { className: "text-sw-label-sm text-sw-gray-300", children: u })
2240
+ ] })
2241
+ ]
2242
+ }
2243
+ ) });
2244
+ }, et = [
2245
+ "nep141:eth-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near",
2246
+ // cbBTC (eth)
2247
+ "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near",
2248
+ // cbBTC (base)
2249
+ "nep141:gnosis-0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1.omft.near",
2250
+ // wETH (gnosis)
2251
+ "nep141:2260fac5e5542a773aa44fbcfedf7c193bc2c599.factory.bridge.near",
2252
+ // wBTC (near)
2253
+ "nep245:v2_1.omni.hot.tg:56_SZzgw3HSudhZcTwPWUTi2RJB19t",
2254
+ // NEAR (bsc)
2255
+ "nep141:eth-0xe0f63a424a4439cbe457d80e4f4b51ad25b2c56c.omft.near"
2256
+ // SPX (eth)
2257
+ ], Dr = () => {
2258
+ const { tokens: e } = P();
2259
+ return {
2260
+ uniqueIntentsTokens: v(() => {
2261
+ const t = e.filter(
2262
+ (n) => n.isIntent && n.blockchain === "near" && !et.includes(n.assetId)
2263
+ ), r = t.map((n) => n.isIntent && n.symbol), s = e.filter((n) => n.isIntent && n.blockchain !== "near" && !r.includes(n.symbol) && !et.includes(n.assetId));
2264
+ return [...t, ...s];
2265
+ }, [e])
2266
+ };
2267
+ }, xr = ({
2268
+ variant: e,
2269
+ search: t,
2270
+ selectedChain: r,
2271
+ chainsFilter: s,
2272
+ walletSupportedChains: n
2273
+ }) => {
2274
+ Ks(e);
2275
+ const { tokens: a } = P(e), { mergedBalance: l } = le(), { intentBalances: c } = ce(), { uniqueIntentsTokens: d } = Dr(), u = Ts(
2276
+ l,
2277
+ n,
2278
+ t
2279
+ ), i = a.filter(gs({ search: t })).filter(
2280
+ Is({
2281
+ selectedChain: r,
2282
+ chainsFilter: s,
2283
+ walletSupportedChains: n,
2284
+ intentBalances: c,
2285
+ uniqueIntentTokenIds: d.map((m) => m.assetId)
2286
+ })
2287
+ );
2288
+ return {
2289
+ all: i.sort(u),
2290
+ intents: i.filter(He({ isIntent: !0 })).sort(u),
2291
+ wallet: i.filter(He({ isIntent: !1 })).sort(u)
2292
+ };
2293
+ }, Or = (e, t) => e.length === 0 && t ? "EMPTY_SEARCH" : e.length === 0 && !t ? "NO_TOKENS" : "HAS_TOKENS", Fr = ({
2294
+ variant: e,
2295
+ search: t,
2296
+ className: r,
2297
+ groupTokens: s,
2298
+ showBalances: n,
2299
+ chainsFilter: a,
2300
+ selectedChain: l,
2301
+ chainIsNotSupported: c,
2302
+ onMsg: d
2303
+ }) => {
2304
+ const { t: u } = M(), { ctx: i } = _(), { walletSupportedChains: m, appName: h } = y(), { mergedBalance: g } = le(), f = xr({
2305
+ variant: e,
2306
+ search: t,
2307
+ chainsFilter: a,
2308
+ selectedChain: l,
2309
+ walletSupportedChains: m
2310
+ }), w = i.walletAddress ? s : !1, S = Or(f.all, t), E = v(
2311
+ () => [{ label: null, tokens: f.all }],
2312
+ [f.all]
2313
+ ), B = v(
2314
+ () => [
2315
+ { label: `${h} account`, tokens: f.intents },
2316
+ {
2317
+ label: c ? null : "Connected wallet",
2318
+ tokens: f.wallet
2319
+ }
2320
+ ],
2321
+ [f.wallet, f.intents, c]
2322
+ ), F = v(() => (w ? B : E).reduce(
2323
+ (k, x) => k + x.tokens.length,
2324
+ 0
2325
+ ), [B, E, w]), L = "450px";
2326
+ switch (S) {
2327
+ case "EMPTY_SEARCH":
2328
+ return /* @__PURE__ */ o(
2329
+ Se,
2330
+ {
2331
+ hasAction: !0,
2332
+ actionType: "outlined",
2333
+ actionLabel: u("tokens.list.searchReset.label", "Clear search"),
2334
+ heading: u("tokens.list.searchEmpty.label", "No results"),
2335
+ subHeading: u(
2336
+ "tokens.list.searchEmpty.subLabel",
2337
+ "Try another search or check if a specific network is selected."
2338
+ ),
2339
+ className: "pt-sw-5xl pb-sw-5xl",
2340
+ onClick: () => d({ type: "on_reset_search" })
2341
+ }
2342
+ );
2343
+ case "HAS_TOKENS":
2344
+ return /* @__PURE__ */ o("div", { className: H("gap-sw-lg flex flex-col", r), children: /* @__PURE__ */ o(
2345
+ ps,
2346
+ {
2347
+ className: "hide-scrollbar",
2348
+ style: {
2349
+ maxHeight: L,
2350
+ minHeight: 200,
2351
+ height: F ? F * Je + (w ? B.length * 62 : 0) : Je * 2
2352
+ },
2353
+ children: (w ? B : E).map(
2354
+ ({ label: k, tokens: x }) => /* @__PURE__ */ T(Wt, { children: [
2355
+ x.length && k ? /* @__PURE__ */ T("header", { className: "pb-sw-lg flex flex-col", children: [
2356
+ /* @__PURE__ */ o(hs, {}),
2357
+ /* @__PURE__ */ o("span", { className: "text-sw-label-sm pt-sw-xl text-sw-gray-100", children: `${k} — ${x.length}` })
2358
+ ] }) : null,
2359
+ x.map((X) => {
2360
+ const J = G(X);
2361
+ return /* @__PURE__ */ o(
2362
+ xt,
2363
+ {
2364
+ token: X,
2365
+ showBalance: n,
2366
+ balance: g[J],
2367
+ isNotSelectable: c && !!i.walletAddress,
2368
+ onMsg: d
2369
+ },
2370
+ J
2371
+ );
2372
+ }),
2373
+ x.length ? /* @__PURE__ */ o("div", { className: "h-sw-2xl" }) : null
2374
+ ] }, k ?? "ungrouped-tokens")
2375
+ )
2376
+ }
2377
+ ) });
2378
+ case "NO_TOKENS":
2379
+ default:
2380
+ return /* @__PURE__ */ o(
2381
+ Se,
2382
+ {
2383
+ className: "pt-sw-5xl pb-sw-5xl",
2384
+ subHeading: u(
2385
+ "tokens.list.noBalanceOnApp.subLabel",
2386
+ "Deposit funds to get started"
2387
+ ),
2388
+ heading: u("tokens.list.noBalanceOnApp.label", {
2389
+ defaultValue: "You have no balances on {{appName}}",
2390
+ appName: h
2391
+ })
2392
+ }
2393
+ );
2394
+ }
2395
+ }, Vi = Object.assign(Fr, {
2396
+ Placeholder: Se,
2397
+ Item: xt
2398
+ }), Lr = (e, t) => {
2399
+ const r = t.assetId.substring(t.assetId.indexOf(":") + 1), s = (a) => {
2400
+ const l = (u) => u.replace(/(\.\d*?[1-9])0+$/, "$1").replace(/\.0+$/, ""), c = l(t.amount), d = l(
2401
+ a.amount.toLocaleString("en-US", {
2402
+ useGrouping: !1,
2403
+ maximumFractionDigits: 20
2404
+ })
2405
+ );
2406
+ return c.startsWith(d) || d.startsWith(c);
2407
+ }, n = (a) => new Date(a.created_at) >= new Date(t.initiatedAtDate);
2408
+ return (e.result.deposits || []).find(
2409
+ (a) => a.chain === t.chainId && a.account_id === t.intentsAccountId && a.address === t.depositAddress && a.near_token_id === r && n(a) && s(a)
2410
+ );
2411
+ }, Br = {
2412
+ CREDITED: ee.status.PROCESSING,
2413
+ PENDING: ee.status.PROCESSING,
2414
+ COMPLETED: ee.status.SUCCESS,
2415
+ FAILED: ee.status.FAILED
2416
+ }, Mi = ({ depositAddress: e }) => {
2417
+ const { ctx: t } = _(), { intentsAccountType: r } = y(), [s, n] = re(null), a = te({
2418
+ addressType: r,
2419
+ walletAddress: t.walletAddress
2420
+ });
2421
+ return { pollDepositStatus: async ({
2422
+ blockchain: c,
2423
+ amount: d,
2424
+ assetId: u
2425
+ }) => {
2426
+ if (!a)
2427
+ throw new W("Unknown intents account for POA deposit check");
2428
+ let i = ct[c];
2429
+ if (!i)
2430
+ if (Q(c))
2431
+ i = lt;
2432
+ else
2433
+ throw new W(
2434
+ `Unknown chain for POA deposit check ${c}`
2435
+ );
2436
+ const m = s ?? (/* @__PURE__ */ new Date()).toUTCString();
2437
+ s || n(m);
2438
+ const h = await ft.post("", {
2439
+ id: 1,
2440
+ jsonrpc: "2.0",
2441
+ method: "recent_deposits",
2442
+ params: [
2443
+ {
2444
+ account_id: a,
2445
+ chain: i
2446
+ }
2447
+ ]
2448
+ }), g = Lr(h.data, {
2449
+ intentsAccountId: a,
2450
+ initiatedAtDate: m,
2451
+ depositAddress: e,
2452
+ chainId: i,
2453
+ assetId: u,
2454
+ amount: d
2455
+ });
2456
+ return g ? {
2457
+ status: Br[g.status],
2458
+ swapDetails: {
2459
+ intentHashes: [""],
2460
+ destinationChainTxHashes: [{ hash: g.tx_hash ?? "" }]
2461
+ }
2462
+ } : {
2463
+ status: ee.status.PENDING_DEPOSIT,
2464
+ swapDetails: {
2465
+ destinationChainTxHashes: [{ hash: "" }],
2466
+ intentHashes: [""]
2467
+ }
2468
+ };
2469
+ } };
2470
+ }, qr = (e, t, r) => {
2471
+ if (At) {
2472
+ let s = document.body;
2473
+ r instanceof HTMLElement && (s = r), Object.entries(e).forEach(([n, a]) => {
2474
+ s.style.setProperty(`--c-sw-${t}-${n}`, a);
2475
+ });
2476
+ }
2477
+ }, tt = (e, t, r, s) => {
2478
+ const n = r ? ws(r, s ?? "dark") : null;
2479
+ n && qr(n, e, t);
2480
+ }, Ur = (e, t) => {
2481
+ const { primaryColor: r, surfaceColor: s, colorScheme: n } = t;
2482
+ tt("accent", e, r, n), tt("gray", e, s, n);
2483
+ }, Pr = at(void 0), Wr = ({ children: e, theme: t }) => {
2484
+ const { themeParentElementSelector: r } = y(), s = v(() => t, [t]);
2485
+ return C(() => {
2486
+ if (t && At) {
2487
+ const n = r ? document.querySelector(r) : null;
2488
+ Ur(n, t);
2489
+ }
2490
+ }, [t]), /* @__PURE__ */ o(Pr.Provider, { value: s, children: e });
2491
+ }, fe = ({
2492
+ text: e,
2493
+ icon: t
2494
+ }) => /* @__PURE__ */ T("li", { className: "flex items-center gap-sw-md", children: [
2495
+ t && /* @__PURE__ */ o(t, { size: 20, className: "text-sw-gray-300" }),
2496
+ /* @__PURE__ */ o("span", { className: "text-sw-label-md text-sw-gray-50", children: e })
2497
+ ] }), nt = ({
2498
+ label: e,
2499
+ icon: t,
2500
+ className: r
2501
+ }) => /* @__PURE__ */ T(
2502
+ "div",
2503
+ {
2504
+ className: H(
2505
+ "rounded-sw-lg flex align-center justify-center gap-sw-md w-full py-sw-2xl",
2506
+ r
2507
+ ),
2508
+ children: [
2509
+ t && /* @__PURE__ */ o(t, { size: 16 }),
2510
+ /* @__PURE__ */ o("span", { className: "text-sw-label-md", children: e })
2511
+ ]
2512
+ }
2513
+ ), Vr = ({ isSigned: e, isSigning: t, onMsg: r }) => {
2514
+ const { t: s } = M(), n = bs({
2515
+ endTime: 0,
2516
+ autostart: !1,
2517
+ timerType: "DECREMENTAL",
2518
+ initialTime: 7,
2519
+ onTimeOver: () => {
2520
+ r({ type: "on_close" });
2521
+ }
2522
+ });
2523
+ return C(() => {
2524
+ e ? n.start() : n.reset();
2525
+ }, [e]), /* @__PURE__ */ T(ie, { className: "relative w-full gap-sw-2xl flex flex-col", children: [
2526
+ /* @__PURE__ */ o(
2527
+ St,
2528
+ {
2529
+ onClick: () => r({ type: "on_close" }),
2530
+ className: "absolute top-sw-2xl right-sw-2xl"
2531
+ }
2532
+ ),
2533
+ /* @__PURE__ */ o(ks, { size: 48, className: "text-sw-status-warning" }),
2534
+ /* @__PURE__ */ T("header", { className: "flex flex-col gap-sw-lg", children: [
2535
+ /* @__PURE__ */ o("h1", { className: "text-sw-label-lg text-sw-gray-50", children: s(
2536
+ "walletCompatibility.modal.title.initial",
2537
+ "Verify your wallet to continue"
2538
+ ) }),
2539
+ /* @__PURE__ */ o("p", { className: "text-sw-body-md text-sw-gray-200", children: s(
2540
+ "walletCompatibility.modal.description.initial",
2541
+ "Please sign a message to verify your wallet. This confirms your wallet is compatible and lets us securely read your public key."
2542
+ ) })
2543
+ ] }),
2544
+ /* @__PURE__ */ T("ul", { className: "flex flex-col gap-sw-xl", children: [
2545
+ /* @__PURE__ */ o(
2546
+ fe,
2547
+ {
2548
+ text: s(
2549
+ "walletCompatibility.modal.feature.secureTransactions",
2550
+ "Read-only signature – no gas required."
2551
+ ),
2552
+ icon: As
2553
+ }
2554
+ ),
2555
+ /* @__PURE__ */ o(
2556
+ fe,
2557
+ {
2558
+ text: s(
2559
+ "walletCompatibility.modal.feature.fullAccess",
2560
+ "No access to your funds, no hidden permissions."
2561
+ ),
2562
+ icon: Ss
2563
+ }
2564
+ ),
2565
+ /* @__PURE__ */ o(
2566
+ fe,
2567
+ {
2568
+ text: s(
2569
+ "walletCompatibility.modal.feature.fundProtection",
2570
+ "Only checks whether your wallet is supported."
2571
+ ),
2572
+ icon: Ns
2573
+ }
2574
+ )
2575
+ ] }),
2576
+ e ? /* @__PURE__ */ T("div", { className: "flex flex-col gap-sw-xl mt-sw-lg w-full", children: [
2577
+ /* @__PURE__ */ o(
2578
+ nt,
2579
+ {
2580
+ label: s(
2581
+ "walletCompatibility.modal.button.verified",
2582
+ "Wallet verified"
2583
+ ),
2584
+ className: "bg-sw-status-success text-sw-gray-950",
2585
+ icon: _s
2586
+ }
2587
+ ),
2588
+ n.status === "RUNNING" && /* @__PURE__ */ o(
2589
+ nt,
2590
+ {
2591
+ className: "text-sw-gray-400",
2592
+ label: s("walletCompatibility.modal.button.closeTimer", {
2593
+ defaultValue: "Popup will close in {{count}} sec...",
2594
+ count: n.time
2595
+ })
2596
+ }
2597
+ )
2598
+ ] }) : /* @__PURE__ */ T("div", { className: "flex flex-col gap-sw-xl mt-sw-lg", children: [
2599
+ /* @__PURE__ */ o(
2600
+ A,
2601
+ {
2602
+ size: "lg",
2603
+ variant: "primary",
2604
+ onClick: () => r({ type: "on_check_compatibility" }),
2605
+ children: s("walletCompatibility.modal.button.verify", "Verify wallet")
2606
+ }
2607
+ ),
2608
+ /* @__PURE__ */ o(
2609
+ A,
2610
+ {
2611
+ size: "lg",
2612
+ variant: "outlined",
2613
+ state: t ? "loading" : "default",
2614
+ onClick: () => r({ type: "on_sign_out" }),
2615
+ children: t ? s(
2616
+ "walletCompatibility.modal.button.signing",
2617
+ "Sign with your wallet"
2618
+ ) : s("walletCompatibility.modal.button.signOut", "Sign out")
2619
+ }
2620
+ )
2621
+ ] })
2622
+ ] });
2623
+ }, Mr = ({ onMsg: e }) => {
2624
+ const { t } = M();
2625
+ return /* @__PURE__ */ T(ie, { className: "relative w-full gap-sw-2xl flex flex-col", children: [
2626
+ /* @__PURE__ */ o(
2627
+ St,
2628
+ {
2629
+ onClick: () => e({ type: "on_close" }),
2630
+ className: "absolute top-sw-2xl right-sw-2xl"
2631
+ }
2632
+ ),
2633
+ /* @__PURE__ */ o(ys, { size: 48, className: "text-sw-status-error" }),
2634
+ /* @__PURE__ */ T("header", { className: "flex flex-col gap-sw-lg", children: [
2635
+ /* @__PURE__ */ o("h1", { className: "text-sw-label-lg text-sw-gray-50", children: t(
2636
+ "walletCompatibility.modal.title.error",
2637
+ "Unable to verify wallet"
2638
+ ) }),
2639
+ /* @__PURE__ */ o("p", { className: "text-sw-body-md text-sw-gray-200", children: t(
2640
+ "walletCompatibility.modal.description.error",
2641
+ "We couldn’t complete the verification. It may have been interrupted or your wallet may not be compatible."
2642
+ ) }),
2643
+ /* @__PURE__ */ o("p", { className: "text-sw-body-md text-sw-gray-200", children: t(
2644
+ "walletCompatibility.modal.button.tryAgainDesc",
2645
+ "If the issue continues, please try another wallet."
2646
+ ) })
2647
+ ] }),
2648
+ /* @__PURE__ */ T("div", { className: "flex flex-col gap-sw-xl mt-sw-lg", children: [
2649
+ /* @__PURE__ */ o(
2650
+ A,
2651
+ {
2652
+ size: "lg",
2653
+ variant: "primary",
2654
+ onClick: () => e({ type: "on_try_again" }),
2655
+ children: t("walletCompatibility.modal.button.tryAgain", "Try again")
2656
+ }
2657
+ ),
2658
+ /* @__PURE__ */ o(
2659
+ A,
2660
+ {
2661
+ size: "lg",
2662
+ variant: "outlined",
2663
+ onClick: () => e({ type: "on_sign_out" }),
2664
+ children: t("walletCompatibility.modal.button.signOut", "Sign out")
2665
+ }
2666
+ )
2667
+ ] })
2668
+ ] });
2669
+ }, Qi = Object.assign(Vr, {
2670
+ Error: Mr
2671
+ }), Qr = (e) => null, $r = (e) => (t) => {
2672
+ if (t instanceof W)
2673
+ throw t;
2674
+ const r = new W(
2675
+ t instanceof Error ? t.message : "Unknown error",
2676
+ { cause: t }
2677
+ );
2678
+ throw r.context = e, r;
2679
+ }, Kr = ({ children: e }) => {
2680
+ const { ctx: t } = _();
2681
+ return /* @__PURE__ */ o(
2682
+ Rs,
2683
+ {
2684
+ FallbackComponent: Qr,
2685
+ onError: $r(t),
2686
+ children: e
2687
+ }
2688
+ );
2689
+ }, Hr = new $t({
2690
+ defaultOptions: {
2691
+ queries: {
2692
+ staleTime: 2e3 * 60,
2693
+ retry: st.env.NODE_ENV === "test" ? !1 : 3
2694
+ }
2695
+ }
2696
+ }), Gr = ["fms", "abg", "stjack", "noear", "testnebula"], ae = {
2697
+ appName: "Unknown",
2698
+ appIcon: "https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg",
2699
+ slippageTolerance: 100,
2700
+ // 1%
2701
+ intentsAccountType: "evm",
2702
+ walletSupportedChains: tn,
2703
+ connectedWallets: {},
2704
+ enableAutoTokensSwitching: !0,
2705
+ showIntentTokens: !0,
2706
+ chainsOrder: it,
2707
+ filterTokens: (e) => !Gr.includes(e.symbol.toLocaleLowerCase()),
2708
+ chainsFilter: {
2709
+ source: { external: "wallet-supported", intents: "none" },
2710
+ target: { external: "all", intents: "none" }
2711
+ }
2712
+ }, Ot = at({
2713
+ config: ae
2714
+ }), Ue = rt({
2715
+ config: ae
2716
+ }), y = () => {
2717
+ const e = Vt(Ot);
2718
+ return oe(e).config;
2719
+ }, jr = (e) => {
2720
+ Ue.config = pe(e);
2721
+ }, $i = ({
2722
+ children: e,
2723
+ config: t,
2724
+ balanceViaRpc: r = !0,
2725
+ // you don't usually want to disable it
2726
+ localisation: s,
2727
+ rpcs: n,
2728
+ theme: a
2729
+ }) => {
2730
+ const l = Y(
2731
+ rt({
2732
+ config: pe({
2733
+ ...ae,
2734
+ ...t
2735
+ })
2736
+ })
2737
+ );
2738
+ return C(() => {
2739
+ const c = pe({
2740
+ ...ae,
2741
+ ...t
2742
+ });
2743
+ Object.assign(l.current.config, c), jr(c);
2744
+ }, [t]), jt(s ?? {}), Cs("headlessui-portal-root", "sw"), /* @__PURE__ */ o(Kt, { client: Hr, children: /* @__PURE__ */ o(Gt, { i18n: Lt, children: /* @__PURE__ */ T(Ot.Provider, { value: l.current, children: [
2745
+ /* @__PURE__ */ T(Bt, { children: [
2746
+ /* @__PURE__ */ T(qt, { children: [
2747
+ /* @__PURE__ */ o("link", { rel: "preconnect", href: "https://rsms.me/" }),
2748
+ /* @__PURE__ */ o("link", { rel: "stylesheet", href: "https://rsms.me/inter/inter.css" })
2749
+ ] }),
2750
+ /* @__PURE__ */ o(Wr, { theme: a, children: st.env.NODE_ENV === "test" ? e : /* @__PURE__ */ o(Kr, { children: e }) })
2751
+ ] }),
2752
+ r && /* @__PURE__ */ o(
2753
+ Qs,
2754
+ {
2755
+ rpcs: n ?? Es,
2756
+ connectedWallets: t.connectedWallets ?? {}
2757
+ }
2758
+ )
2759
+ ] }) }) });
2760
+ };
2761
+ export {
2762
+ dr as $,
2763
+ Mi as A,
2764
+ Qs as B,
2765
+ Pr as C,
2766
+ Bs as D,
2767
+ Ge as E,
2768
+ Hs as F,
2769
+ Gs as G,
2770
+ js as H,
2771
+ zs as I,
2772
+ Xs as J,
2773
+ yt as K,
2774
+ bt as L,
2775
+ Rt as M,
2776
+ Et as N,
2777
+ Ct as O,
2778
+ Js as P,
2779
+ q as Q,
2780
+ er as R,
2781
+ yr as S,
2782
+ vr as T,
2783
+ tr as U,
2784
+ nr as V,
2785
+ $i as W,
2786
+ sr as X,
2787
+ rr as Y,
2788
+ ar as Z,
2789
+ or as _,
2790
+ Ui as a,
2791
+ ur as a0,
2792
+ fr as a1,
2793
+ pr as a2,
2794
+ br as a3,
2795
+ Er as a4,
2796
+ Be as a5,
2797
+ qe as a6,
2798
+ Dt as a7,
2799
+ Cr as a8,
2800
+ Rr as a9,
2801
+ Je as aa,
2802
+ xt as ab,
2803
+ Dr as ac,
2804
+ Fr as ad,
2805
+ Wr as ae,
2806
+ Vr as af,
2807
+ Mr as ag,
2808
+ Kr as ah,
2809
+ Ue as ai,
2810
+ _ as b,
2811
+ Bi as c,
2812
+ Ks as d,
2813
+ Vs as e,
2814
+ ce as f,
2815
+ gr as g,
2816
+ Zs as h,
2817
+ Ir as i,
2818
+ mr as j,
2819
+ le as k,
2820
+ kr as l,
2821
+ xr as m,
2822
+ P as n,
2823
+ Pi as o,
2824
+ Wi as p,
2825
+ Vi as q,
2826
+ ir as r,
2827
+ vt as s,
2828
+ _t as t,
2829
+ j as u,
2830
+ W as v,
2831
+ I as w,
2832
+ qi as x,
2833
+ y,
2834
+ Qi as z
2835
+ };
2836
+ //# sourceMappingURL=config-Behl5hcc.js.map