@aurora-is-near/intents-swap-widget 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/config-GUxZr_mK.js +934 -0
  2. package/dist/config-GUxZr_mK.js.map +1 -0
  3. package/dist/config.d.ts +3 -0
  4. package/dist/config.js +1 -1
  5. package/dist/errors.js +1 -1
  6. package/dist/ext/alchemy/index.js +1 -1
  7. package/dist/ext/index.js +1 -1
  8. package/dist/features/BalanceRpcLoader/index.js +1 -1
  9. package/dist/features/BalanceRpcLoader/useTokenBalanceRpc.js +1 -1
  10. package/dist/features/ChainsDropdown/index.js +1 -1
  11. package/dist/features/DepositMethodSwitcher.js +1 -1
  12. package/dist/features/ErrorBoundary.js +1 -1
  13. package/dist/features/ExternalDeposit.js +1 -1
  14. package/dist/features/SendAddress/index.js +1 -1
  15. package/dist/features/SendAddress/useNotification.js +1 -1
  16. package/dist/features/SubmitButton/index.js +1 -1
  17. package/dist/features/SuccessScreen/index.js +1 -1
  18. package/dist/features/SwapDirectionSwitcher.js +1 -1
  19. package/dist/features/SwapQuote/SwapQuote.js +1 -1
  20. package/dist/features/TokenInput/TokenInput.js +1 -1
  21. package/dist/features/TokenInput/TokenInputSource.js +1 -1
  22. package/dist/features/TokenInput/TokenInputTarget.js +1 -1
  23. package/dist/features/TokenInput/WalletBalance.js +1 -1
  24. package/dist/features/TokenInput/hooks/useTokenInputBalance.js +1 -1
  25. package/dist/features/TokensList/TokenItem.js +1 -1
  26. package/dist/features/TokensList/TokensList.js +1 -1
  27. package/dist/features/TokensModal.js +1 -1
  28. package/dist/features/WalletCompatibilityCheck/index.js +1 -1
  29. package/dist/hooks/index.js +1 -1
  30. package/dist/hooks/useChains.js +1 -1
  31. package/dist/hooks/useCompatibilityCheck.js +1 -1
  32. package/dist/hooks/useDefaultToken.js +1 -1
  33. package/dist/hooks/useExternalDepositStatus.js +1 -1
  34. package/dist/hooks/useIntentsBalance.js +1 -1
  35. package/dist/hooks/useMakeDepositAddress.js +1 -1
  36. package/dist/hooks/useMakeIntentsTransfer.js +1 -1
  37. package/dist/hooks/useMakeNEARFtTransferCall.js +1 -1
  38. package/dist/hooks/useMakeQuote.js +1 -1
  39. package/dist/hooks/useMakeQuoteTransfer.js +1 -1
  40. package/dist/hooks/useMakeTransfer.js +1 -1
  41. package/dist/hooks/useMergedBalance.js +1 -1
  42. package/dist/hooks/useTokenInputPair.js +1 -1
  43. package/dist/hooks/useTokens.d.ts +16 -17
  44. package/dist/hooks/useTokens.js +1 -1
  45. package/dist/hooks/useTokensFiltered.js +1 -1
  46. package/dist/hooks/useTokensIntentsUnique.js +1 -1
  47. package/dist/index.js +1 -1
  48. package/dist/machine/effects/index.js +1 -1
  49. package/dist/machine/effects/useAlchemyBalanceEffect.js +1 -1
  50. package/dist/machine/effects/useBalancesUpdateEffect.js +1 -1
  51. package/dist/machine/effects/useMakeQuoteEffect.js +1 -1
  52. package/dist/machine/effects/useSelectedTokensEffect.d.ts +10 -10
  53. package/dist/machine/effects/useSelectedTokensEffect.js +1 -1
  54. package/dist/machine/effects/useSetTokenBalanceEffect.js +1 -1
  55. package/dist/machine/effects/useSetTokenIntentsTargetEffect.js +1 -1
  56. package/dist/machine/effects/useWalletConnEffect.js +1 -1
  57. package/dist/machine/events/index.js +1 -1
  58. package/dist/machine/events/tokenSelect.js +1 -1
  59. package/dist/machine/events/validateInputAndMoveTo.js +1 -1
  60. package/dist/machine/index.js +1 -1
  61. package/dist/machine/snap.d.ts +90 -90
  62. package/dist/machine/snap.js +1 -1
  63. package/dist/machine/subscriptions/checkers/isSendAddressAsConnected.js +1 -1
  64. package/dist/machine/subscriptions/index.js +1 -1
  65. package/dist/types/config.d.ts +5 -1
  66. package/dist/types/token.d.ts +8 -6
  67. package/dist/utils/intents/signers/near.js +1 -1
  68. package/dist/utils/intents/signers/privy.js +1 -1
  69. package/dist/utils/near/getNearNep141StorageBalance.js +1 -1
  70. package/dist/widgets/WidgetDeposit/WidgetDepositContent.js +1 -1
  71. package/dist/widgets/WidgetSwap/WidgetSwapContent.js +1 -1
  72. package/dist/widgets/WidgetWithdraw/WidgetWithdrawContent.js +1 -1
  73. package/package.json +2 -1
  74. package/src/hooks/useMakeQuote.ts +26 -21
  75. package/src/hooks/useTokens.ts +28 -18
  76. package/src/types/config.ts +6 -2
  77. package/src/types/token.ts +9 -6
  78. package/dist/config-haLfG4Cu.js +0 -929
  79. package/dist/config-haLfG4Cu.js.map +0 -1
@@ -0,0 +1,934 @@
1
+ import { jsx as O } from "react/jsx-runtime";
2
+ import Ie from "i18next";
3
+ import { deepClone as F } from "valtio/utils";
4
+ import { useSnapshot as W, snapshot as K, proxy as se } from "valtio";
5
+ import { useMemo as C, useEffect as y, useRef as q, createContext as ge, useContext as ke } from "react";
6
+ import { useQuery as re, useInfiniteQuery as Ae, useQueryClient as he, QueryClient as ye, QueryClientProvider as we } from "@tanstack/react-query";
7
+ import { I18nextProvider as Se } from "react-i18next";
8
+ import { CHAINS_LIST as _e, DEFAULT_CHAIN_ICON as be, DRY_QUOTE_ADDRESSES as Y, CHAIN_POA_MAP as Ee, CHAIN_BASE_TOKENS as Ne, EVM_CHAINS as ve } from "./constants/chains.js";
9
+ import { ErrorBoundary as De } from "react-error-boundary";
10
+ import { derive as Ce } from "derive-valtio";
11
+ import { machine as L, moveTo as _ } from "./machine/machine.js";
12
+ import { guardStates as b } from "./machine/guards/index.js";
13
+ import { getUsdTradeDelta as Oe } from "./machine/computed/getUsdTradeDelta.js";
14
+ import { getIsDirectTransfer as qe } from "./machine/computed/getIsDirectTransfer.js";
15
+ import { getIsDirectNonNearWithdrawal as Le } from "./machine/computed/getIsDirectNonNearWithdrawal.js";
16
+ import { getIsNearToIntentsSameAssetTransfer as Be } from "./machine/computed/getIsNearToIntentsSameAssetTransfer.js";
17
+ import { getIsDirectNearDeposit as xe } from "./machine/computed/getIsDirectNearDeposit.js";
18
+ import "ethers";
19
+ import Ue from "lodash.once";
20
+ import { logger as E } from "./logger.js";
21
+ import { fireEvent as d } from "./machine/events/utils/fireEvent.js";
22
+ import { validateDryInputs as oe, validateExternalInputs as ae, validateInternalInputs as ie } from "./machine/events/validateInputs.js";
23
+ import { isQuoteIdle as Qe } from "./machine/subscriptions/checkers/isQuoteIdle.js";
24
+ import { isInputChanged as Pe } from "./machine/subscriptions/checkers/isInputChanged.js";
25
+ import { isErrorChanged as We } from "./machine/subscriptions/checkers/isErrorChanged.js";
26
+ import { isOnlyErrorChanged as Re } from "./machine/subscriptions/checkers/isOnlyErrorChanged.js";
27
+ import { isValidInitialState as Me } from "./machine/subscriptions/checkers/isValidInitialState.js";
28
+ import { isWalletDisconnected as Fe } from "./machine/subscriptions/checkers/isWalletDisconnected.js";
29
+ import { isSendAddressForbidden as Ve } from "./machine/subscriptions/checkers/isSendAddressForbidden.js";
30
+ import { useAddClassToPortal as Ge } from "./hooks/useAddClassToPortal.js";
31
+ import { initLocalisation as $e } from "./localisation.js";
32
+ import { isAmountChangedFromQuote as Ke } from "./machine/subscriptions/checkers/isAmountChangedFromQuote.js";
33
+ import { reset as He } from "./machine/events/reset.js";
34
+ import { tokenSelectRotate as V } from "./machine/events/tokenSelectRotate.js";
35
+ import { errorSet as je } from "./machine/events/errorSet.js";
36
+ import { quoteSet as ze } from "./machine/events/quoteSet.js";
37
+ import { addressSet as Xe } from "./machine/events/addressSet.js";
38
+ import { notReachable as ce } from "./utils/notReachable.js";
39
+ import { tokenSetAmount as Ze } from "./machine/events/tokenSetAmount.js";
40
+ import { quoteSetStatus as Je } from "./machine/events/quoteSetStatus.js";
41
+ import { depositTypeSet as Ye } from "./machine/events/depositTypeSet.js";
42
+ import { walletAddressSet as et } from "./machine/events/walletAddressSet.js";
43
+ import { tokenSetBalance as tt } from "./machine/events/tokenSetBalance.js";
44
+ import { transferSetStatus as nt } from "./machine/events/transferSetStatus.js";
45
+ import { OneClickService as st, QuoteRequest as S } from "@defuse-protocol/one-click-sdk-typescript";
46
+ import { TOKENS_DATA as H, NATIVE_NEAR_DUMB_ASSET_ID as U, WNEAR_ASSET_ID as G } from "./constants/tokens.js";
47
+ import { isValidChain as rt } from "./utils/checkers/isValidChain.js";
48
+ import { useWalletBalance as le } from "./hooks/useWalletBalance.js";
49
+ import { parse as ot } from "./ext/alchemy/parse.js";
50
+ import { createLoader as at } from "./ext/alchemy/load.js";
51
+ import { isAlchemySupportedChain as it } from "./ext/alchemy/types.js";
52
+ import { getIntentsAccountId as j } from "./utils/intents/getIntentsAccountId.js";
53
+ import { getIntentsBalances as ct } from "./utils/intents/getIntentsBalance.js";
54
+ import { getTokenBalanceKey as lt } from "./utils/intents/getTokenBalanceKey.js";
55
+ import { snakeCase as dt } from "change-case";
56
+ import { CanceledError as de, AxiosError as ue } from "axios";
57
+ import { oneClickApi as $, bridgeApi as ut } from "./network.js";
58
+ import { formatBigToHuman as x } from "./utils/formatters/formatBigToHuman.js";
59
+ import { getMainTokenByChain as ft } from "./utils/tokens/getMainTokenByChain.js";
60
+ import { getDefaultIntentsToken as mt } from "./utils/tokens/getDefaultIntentsToken.js";
61
+ import { getTokenWithHighBalance as pt } from "./utils/tokens/getTokenWithHighBalance.js";
62
+ const D = L.getStore(), Tt = Ce({
63
+ usdTradeDelta: (e) => Oe(e(D.context)),
64
+ isDirectTransfer: (e) => qe(e(D.context)),
65
+ isNearToIntentsSameAssetTransfer: (e) => Be(e(D.context)),
66
+ isDirectNearDeposit: (e) => xe(e(D.context)),
67
+ isDirectNonNearWithdrawal: (e) => Le(e(D.context))
68
+ }), It = () => W(Tt), N = () => {
69
+ const e = W(D);
70
+ return {
71
+ state: e.state,
72
+ ctx: e.context
73
+ };
74
+ }, Zn = (e) => {
75
+ const t = W(D);
76
+ if (!b(t.context, [e]))
77
+ throw new Q(
78
+ `[WIDGET] Attempt to access snapshot for ${e} state while context does not match`
79
+ );
80
+ return t.context;
81
+ }, fe = (e) => {
82
+ const t = !e.walletAddress, s = !t && e.targetToken?.isIntent === !0, n = !t && e.targetToken?.isIntent === !1;
83
+ if (t) {
84
+ const r = oe(e);
85
+ return _(r ? "input_valid_dry" : "initial_dry");
86
+ }
87
+ n && ae(e) ? _("input_valid_external") : s && ie(e) ? _("input_valid_internal") : _("initial_wallet");
88
+ }, gt = (e, t) => {
89
+ const { config: s } = K(X);
90
+ return e.targetToken && !e.sendAddress && !!e.walletAddress && !e.targetToken.isIntent && !t.find((n) => n?.key === "sendAddress") && s.walletSupportedChains.includes(e.targetToken.blockchain);
91
+ }, kt = ({ debug: e }) => {
92
+ L.onContextChange((t, s) => {
93
+ const n = s;
94
+ if (e && E.debug("[WIDGET] Context changed", n), e && t.error && We(n) && E.debug(`[WIDGET] Error set to ${t.error.code}`), Re(n) || Ke(t, n, e))
95
+ return;
96
+ if (Fe(t, n)) {
97
+ d("reset", null), _("initial_dry");
98
+ return;
99
+ }
100
+ const { isChanged: r, isDry: o } = Pe(t, n);
101
+ if (r) {
102
+ if (Me(t)) {
103
+ const u = o ? "initial_dry" : "initial_wallet";
104
+ _(u, {
105
+ onMoved: () => {
106
+ e && E.debug(
107
+ `[WIDGET] Inputs changed. State moved to ${u}`
108
+ );
109
+ }
110
+ });
111
+ }
112
+ Qe(t) || (t.quote = void 0, t.quoteStatus = "idle", t.transferStatus = { status: "idle" }), Ve(t) && (t.sendAddress = void 0), gt(t, n) && (t.sendAddress = t.walletAddress), fe(t);
113
+ }
114
+ });
115
+ }, At = ({ debug: e }) => {
116
+ L.onTransition((t, s) => {
117
+ e && E.debug(`===> [WIDGET] State moved from ${t} to ${s}`);
118
+ });
119
+ }, ht = (e, t) => {
120
+ const { variant: s, token: n } = t, { config: r } = K(X);
121
+ switch (s) {
122
+ case "source":
123
+ if (n && n.assetId === e.targetToken?.assetId && n.isIntent === e.targetToken.isIntent && r.enableAutoTokensSwitching) {
124
+ if (!e.sourceToken)
125
+ return;
126
+ V(e);
127
+ return;
128
+ }
129
+ if (n && !e.sourceToken && n.assetId === e.targetToken?.assetId && n.isIntent === e.targetToken.isIntent && r.enableAutoTokensSwitching)
130
+ return;
131
+ e.sourceToken = n;
132
+ break;
133
+ case "target":
134
+ if (n && n.assetId === e.sourceToken?.assetId && n.isIntent === e.sourceToken.isIntent && r.enableAutoTokensSwitching) {
135
+ if (!e.targetToken)
136
+ return;
137
+ V(e);
138
+ return;
139
+ }
140
+ e.targetToken = n;
141
+ break;
142
+ default:
143
+ ce(s, { throwError: !1 });
144
+ }
145
+ }, k = (e, t) => {
146
+ L.on(e, (s, n) => t(s, n));
147
+ }, yt = () => {
148
+ k("quoteSetStatus", Je), k("walletAddressSet", et), k("transferSetStatus", nt), k("tokenSelectRotate", V), k("tokenSetBalance", tt), k("tokenSetAmount", Ze), k("depositTypeSet", Ye), k("tokenSelect", ht), k("addressSet", Xe), k("errorSet", je), k("quoteSet", ze), k("reset", He), k("validateDryInputs", oe), k("validateExternalInputs", ae), k("validateInternalInputs", ie);
149
+ }, wt = (e) => {
150
+ const t = e.toLowerCase();
151
+ return H[t]?.icon ?? "";
152
+ }, ee = (e) => _e[e].icon ?? be, St = (e) => `${e?.charAt(0).toUpperCase()}${e?.slice(1)}`, _t = (e) => H[e]?.name ?? e, R = (e) => {
153
+ const {
154
+ showIntentTokens: t,
155
+ allowedTokensList: s,
156
+ allowedSourceTokensList: n,
157
+ allowedTargetTokensList: r,
158
+ filterTokens: o,
159
+ fetchSourceTokens: u,
160
+ fetchTargetTokens: a
161
+ } = v(), i = re({
162
+ queryKey: ["tokens", e],
163
+ queryFn: async () => e === "source" && u ? u() : e === "target" && a ? a() : st.getTokens()
164
+ }), I = C(() => {
165
+ if (!i.data)
166
+ return [];
167
+ const c = i.data.map((l) => {
168
+ const h = l.blockchain.toLowerCase();
169
+ return !rt(h) || s && !s.includes(l.assetId) || e === "source" && n && !n.includes(l.assetId) || e === "target" && r && !r.includes(l.assetId) ? null : {
170
+ assetId: l.assetId,
171
+ symbol: l.symbol,
172
+ decimals: l.decimals,
173
+ price: l.price,
174
+ blockchain: h,
175
+ isIntent: !1,
176
+ icon: wt(l.symbol),
177
+ name: _t(l.symbol),
178
+ chainIcon: ee(h),
179
+ chainName: St(l.blockchain),
180
+ contractAddress: l.contractAddress
181
+ };
182
+ }).filter((l) => !!l).filter(o ?? (() => !0)), m = c.filter(
183
+ (l) => l.symbol.toLowerCase() !== "wnear"
184
+ ), p = c.find((l) => l.symbol.toLowerCase() === "wnear");
185
+ return p && m.push({
186
+ name: "NEAR",
187
+ symbol: "NEAR",
188
+ chainName: "Near",
189
+ blockchain: "near",
190
+ assetId: U,
191
+ chainIcon: ee("near"),
192
+ icon: H.near?.icon ?? "",
193
+ price: p?.price ?? 0,
194
+ contractAddress: p?.contractAddress,
195
+ isIntent: !1,
196
+ decimals: 24
197
+ }), t ? [
198
+ ...m,
199
+ // add intents tokens to the full list
200
+ ...c.map(
201
+ (l) => l.symbol.toLowerCase() === "wnear" ? { ...l, symbol: "NEAR", name: "NEAR", isIntent: !0 } : { ...l, isIntent: !0 }
202
+ )
203
+ ] : m;
204
+ }, [i.data, t, o]);
205
+ return {
206
+ ...i,
207
+ tokens: I
208
+ };
209
+ }, te = 3, me = ({
210
+ walletAddress: e,
211
+ alchemyApiKey: t,
212
+ ...s
213
+ }) => {
214
+ const { ctx: n } = N(), { tokens: r } = R(), { walletSupportedChains: o } = v(), { setWalletBalance: u } = le(n.walletAddress), a = s.isEnabled && !!e && o.length > 0, i = Ae({
215
+ initialPageParam: null,
216
+ enabled: a && !!e && !!t,
217
+ queryKey: ["walletTokensBalance", e],
218
+ queryFn: async ({ pageParam: c }) => at({ alchemyApiKey: t })({
219
+ pageParam: c ? `${c}` : null,
220
+ walletAddress: e,
221
+ walletSupportedChains: o
222
+ }),
223
+ getNextPageParam: (c, m) => {
224
+ if (c.pageKey && !(m.length >= te))
225
+ return c.pageKey;
226
+ }
227
+ });
228
+ y(() => {
229
+ a && i.data && i.hasNextPage && i.data.pages.length < te && !i.isFetchingNextPage && i.fetchNextPage();
230
+ }, [a, i]);
231
+ const I = C(() => {
232
+ if (!i.data?.pages)
233
+ return {};
234
+ const c = ot(
235
+ r,
236
+ i.data.pages.flatMap((m) => m.data)
237
+ );
238
+ return r.forEach((m) => {
239
+ it(m.blockchain) && !(m.assetId in c) && (c[m.assetId] = "0");
240
+ }), c;
241
+ }, [i.data, r]);
242
+ return y(() => {
243
+ b(n, ["initial_wallet"]) && (u(n.walletAddress, I), n.sourceToken && Object.keys(I).includes(n.sourceToken.assetId) && d("tokenSetBalance", I[n.sourceToken.assetId]));
244
+ }, [I]), {
245
+ status: i.status,
246
+ refetch: i.refetch,
247
+ balances: I
248
+ };
249
+ }, z = () => {
250
+ const { walletAddress: e, intentsAccountType: t } = v(), { tokens: s } = R(), n = s.filter((a) => a.isIntent).map((a) => a.assetId), r = j({
251
+ walletAddress: e ?? "",
252
+ addressType: t
253
+ }), o = re({
254
+ enabled: !!e && !!r && s.length > 0,
255
+ queryKey: ["intentsBalances", r],
256
+ queryFn: async () => r ? await ct(r, n) : {}
257
+ }), u = C(() => {
258
+ switch (o.status) {
259
+ case "error":
260
+ return E.error("Unable to load intents balances:", o.error), {};
261
+ case "success":
262
+ return Object.fromEntries(
263
+ Object.entries(o.data).map(([a, i]) => [
264
+ `intent-${a}`,
265
+ i
266
+ ])
267
+ );
268
+ case "pending":
269
+ return {};
270
+ default:
271
+ return ce(o, { throwError: !1 }), {};
272
+ }
273
+ }, [o]) ?? {};
274
+ return {
275
+ ...o,
276
+ intentBalances: u
277
+ };
278
+ }, bt = ({
279
+ isEnabled: e,
280
+ alchemyApiKey: t
281
+ }) => {
282
+ const { ctx: s } = N(), n = he(), { refetch: r } = z(), { refetch: o } = me({
283
+ isEnabled: e,
284
+ walletAddress: s.walletAddress,
285
+ alchemyApiKey: t ?? ""
286
+ });
287
+ y(() => {
288
+ const u = b(s, ["transfer_success"]);
289
+ !e || !u || (async () => (await r(), t && (await new Promise((a) => {
290
+ setTimeout(a, 1e4);
291
+ }), await o()), await n.invalidateQueries({ queryKey: ["tokenBalance"] })))();
292
+ }, [s.state, e, t]);
293
+ }, Et = () => {
294
+ const { walletAddress: e } = v(), { intentBalances: t } = z(), { walletBalance: s } = le(e);
295
+ return { mergedBalance: C(
296
+ () => ({ ...s, ...t }),
297
+ [s, t]
298
+ ) };
299
+ }, Nt = ({ isEnabled: e }) => {
300
+ const { ctx: t } = N(), { mergedBalance: s } = Et();
301
+ y(() => {
302
+ if (!e)
303
+ return;
304
+ if (!t.sourceToken || !t.walletAddress) {
305
+ d("tokenSetBalance", void 0);
306
+ return;
307
+ }
308
+ const n = lt(t.sourceToken);
309
+ d("tokenSetBalance", s[n]);
310
+ }, [s, t.sourceToken]);
311
+ }, ne = {
312
+ // cbBTC (eth)
313
+ "nep141:eth-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near": "nep141:nbtc.bridge.near",
314
+ // cbBTC (base)
315
+ "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near": "nep141:nbtc.bridge.near",
316
+ // wBTC (near)
317
+ "nep141:2260fac5e5542a773aa44fbcfedf7c193bc2c599.factory.bridge.near": "nep141:nbtc.bridge.near",
318
+ // xBTC (sol)
319
+ "nep141:sol-91914f13d3b54f8126a2824d71632d4b078d7403.omft.near": "nep141:nbtc.bridge.near",
320
+ // wETH (gnosis)
321
+ "nep141:gnosis-0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1.omft.near": "nep141:eth.bridge.near",
322
+ // NEAR (bsc)
323
+ "nep245:v2_1.omni.hot.tg:56_SZzgw3HSudhZcTwPWUTi2RJB19t": "nep141:wrap.near",
324
+ // BTC (near)
325
+ "nep141:btc.omft.near": "nep141:nbtc.bridge.near"
326
+ }, vt = ({
327
+ isEnabled: e
328
+ }) => {
329
+ const { ctx: t } = N(), { tokens: s } = R();
330
+ y(() => {
331
+ if (!e)
332
+ return;
333
+ if (!t.sourceToken) {
334
+ d("tokenSelect", { variant: "target", token: void 0 });
335
+ return;
336
+ }
337
+ const { sourceToken: n } = t;
338
+ if (t.sourceToken.assetId in ne) {
339
+ const a = s.find(
340
+ (i) => i.isIntent && i.assetId === ne[n.assetId]
341
+ );
342
+ d("tokenSelect", {
343
+ variant: "target",
344
+ token: a
345
+ });
346
+ return;
347
+ }
348
+ const r = s.find(
349
+ (a) => a.isIntent && a.symbol === n.symbol && a.blockchain === "near"
350
+ );
351
+ if (r) {
352
+ d("tokenSelect", { variant: "target", token: r });
353
+ return;
354
+ }
355
+ const o = s.find(
356
+ (a) => a.isIntent && a.assetId === n.assetId
357
+ ), u = s.find(
358
+ (a) => a.isIntent && a.symbol === "USDC" && a.blockchain === "near"
359
+ );
360
+ d("tokenSelect", {
361
+ variant: "target",
362
+ token: o ?? u
363
+ });
364
+ }, [s, t.sourceToken]);
365
+ }, Dt = ({ isEnabled: e }) => {
366
+ const { walletAddress: t } = v(), { ctx: s, state: n } = N();
367
+ y(() => {
368
+ if (!e)
369
+ return;
370
+ d("walletAddressSet", t ?? void 0), b(s, ["initial_dry", "initial_wallet"]) && (n === "initial_wallet" && !t ? _("initial_dry") : n === "initial_dry" && t && _("initial_wallet"));
371
+ }, [e, t, s, n]);
372
+ }, Ct = () => {
373
+ const { ctx: e } = N(), { intentsAccountType: t, oneClickApiQuoteProxyUrl: s, appName: n, fetchQuote: r } = v(), o = !e.walletAddress, u = j({
374
+ addressType: t,
375
+ walletAddress: o ? Y[t] : e.walletAddress ?? ""
376
+ }), a = q(null), i = q(new AbortController()), I = C(() => async (p) => r ? r(p) : (await $.post(
377
+ s,
378
+ p,
379
+ {
380
+ signal: i.current.signal
381
+ }
382
+ )).data.quote, [s, $]), c = o ? Y[t] : e.walletAddress ?? "";
383
+ return {
384
+ make: async ({ message: p, quoteType: l = "exact_in" } = {}) => {
385
+ if (!b(e, [
386
+ "input_valid_dry",
387
+ "input_valid_external",
388
+ "input_valid_internal"
389
+ ])) {
390
+ const g = `Unable to run quote in current state ${e.state}`;
391
+ throw E.error(`[WIDGET] ${g}`), new A({
392
+ code: "QUOTE_INVALID_INITIAL",
393
+ meta: { isDry: o, message: g }
394
+ });
395
+ }
396
+ if (!u) {
397
+ const g = "No corresponding intents account to run a quote";
398
+ throw E.error(`[WIDGET] ${g}`), new A({
399
+ code: "QUOTE_INVALID_INITIAL",
400
+ meta: { isDry: o, message: g }
401
+ });
402
+ }
403
+ a.current && (i.current.abort("Abort previous quote (auto)"), i.current = new AbortController());
404
+ let T;
405
+ const f = {
406
+ // Settings
407
+ dry: o,
408
+ slippageTolerance: 100,
409
+ // 1%
410
+ deadline: new Date(Date.now() + 3600 * 1e3).toISOString(),
411
+ // 1 hour
412
+ swapType: l === "exact_out" ? S.swapType.EXACT_OUTPUT : S.swapType.EXACT_INPUT,
413
+ // Target
414
+ destinationAsset: e.targetToken.assetId === U ? G : e.targetToken.assetId,
415
+ // Source
416
+ originAsset: e.sourceToken.assetId === U ? G : e.sourceToken.assetId,
417
+ amount: l === "exact_out" ? e.targetTokenAmount : e.sourceTokenAmount
418
+ };
419
+ p && (f.customRecipientMsg = p), n && (f.referral = dt(n));
420
+ try {
421
+ e.sourceToken.isIntent && e.targetToken.isIntent && (a.current = I({
422
+ ...f,
423
+ recipient: u,
424
+ recipientType: S.recipientType.INTENTS,
425
+ depositType: S.depositType.INTENTS,
426
+ // Refund
427
+ refundTo: u,
428
+ refundType: S.refundType.INTENTS
429
+ }), T = await a.current), a.current = I({
430
+ ...f,
431
+ recipient: !e.targetToken.isIntent && e.sendAddress ? e.sendAddress : u,
432
+ recipientType: e.targetToken.isIntent ? S.recipientType.INTENTS : S.recipientType.DESTINATION_CHAIN,
433
+ depositType: e.sourceToken.isIntent ? S.depositType.INTENTS : S.depositType.ORIGIN_CHAIN,
434
+ // Refund
435
+ refundTo: e.sourceToken.isIntent ? u : c,
436
+ refundType: e.sourceToken.isIntent ? S.refundType.INTENTS : S.refundType.ORIGIN_CHAIN
437
+ }), T = await a.current;
438
+ } catch (g) {
439
+ if (g instanceof de)
440
+ return;
441
+ if (g instanceof ue) {
442
+ const B = g.response?.data.message || g.message;
443
+ if (B.includes("Amount is too low")) {
444
+ const Z = B.match(/\d+/), J = Z ? Z[0] : void 0;
445
+ throw new A({
446
+ code: "QUOTE_AMOUNT_IS_TOO_LOW",
447
+ meta: {
448
+ minAmount: (J && x(J, e.sourceToken.decimals)) ?? "0"
449
+ }
450
+ });
451
+ }
452
+ throw B.includes("recipient is not valid") ? new A({
453
+ code: "TOKEN_IS_NOT_SUPPORTED"
454
+ }) : B.includes("Failed to get a deposit address") ? new A({
455
+ code: "QUOTE_NO_ONE_TIME_ADDRESS"
456
+ }) : g;
457
+ }
458
+ throw new A({
459
+ code: "QUOTE_FAILED",
460
+ meta: {
461
+ // @ts-expect-error In case error has a message
462
+ message: errorMessage ?? "Failed to fetch quote. Please try again."
463
+ }
464
+ });
465
+ }
466
+ let w;
467
+ if (o)
468
+ w = {
469
+ dry: !0,
470
+ ...T,
471
+ deadline: void 0,
472
+ depositAddress: void 0
473
+ };
474
+ else if (T.deadline && T.depositAddress)
475
+ w = {
476
+ dry: !1,
477
+ ...T,
478
+ deadline: T.deadline,
479
+ depositAddress: T.depositAddress
480
+ };
481
+ else
482
+ throw new A({
483
+ code: "QUOTE_INVALID",
484
+ meta: { isDry: o }
485
+ });
486
+ return w;
487
+ },
488
+ cancel: () => {
489
+ i.current.abort("Abort quote manually"), i.current = new AbortController();
490
+ }
491
+ };
492
+ }, Ot = () => {
493
+ const { ctx: e } = N(), { intentsAccountType: t, oneClickApiQuoteProxyUrl: s } = v(), n = j({
494
+ addressType: t,
495
+ walletAddress: e.walletAddress ?? ""
496
+ }), r = q(null), o = q(new AbortController()), u = C(() => async (i) => ut.post(
497
+ "",
498
+ {
499
+ id: 1,
500
+ jsonrpc: "2.0",
501
+ method: "deposit_address",
502
+ params: [
503
+ {
504
+ account_id: i.accountId,
505
+ chain: i.chain
506
+ }
507
+ ]
508
+ },
509
+ {
510
+ signal: o.current.signal
511
+ }
512
+ ), [s, $]);
513
+ return {
514
+ make: async () => {
515
+ if (!b(e, [
516
+ "input_valid_dry",
517
+ "input_valid_external",
518
+ "input_valid_internal"
519
+ ])) {
520
+ const c = `Unable to run quote in current state ${e.state}`;
521
+ throw E.error(`[WIDGET] ${c}`), new A({
522
+ code: "QUOTE_INVALID_INITIAL",
523
+ meta: { isDry: !1, message: c }
524
+ });
525
+ }
526
+ if (e.sourceToken.assetId !== e.targetToken.assetId)
527
+ throw new A({
528
+ code: "QUOTE_INVALID_INITIAL",
529
+ meta: {
530
+ isDry: !1,
531
+ message: "Asset IDs are not the same use 1Click Quote instead of POA"
532
+ }
533
+ });
534
+ if (e.sourceToken.isIntent)
535
+ throw new A({
536
+ code: "QUOTE_INVALID_INITIAL",
537
+ meta: {
538
+ isDry: !1,
539
+ message: "For withdrawals use withdrawal SDK instead of POA"
540
+ }
541
+ });
542
+ if (!n) {
543
+ const c = "No corresponding intents account to run a quote";
544
+ throw E.error(`[WIDGET] ${c}`), new A({
545
+ code: "QUOTE_INVALID_INITIAL",
546
+ meta: { isDry: !1, message: c }
547
+ });
548
+ }
549
+ r.current && (o.current.abort("Abort previous quote (auto)"), o.current = new AbortController());
550
+ const I = Ee[e.targetToken.blockchain];
551
+ if (!I)
552
+ throw new A({
553
+ code: "QUOTE_INVALID_INITIAL",
554
+ meta: { isDry: !1, message: "Chain is not supported by POA" }
555
+ });
556
+ try {
557
+ return r.current = u({
558
+ chain: I,
559
+ accountId: n
560
+ }), {
561
+ depositAddress: (await r.current).data.result.address,
562
+ amountIn: e.sourceTokenAmount,
563
+ amountOut: e.targetTokenAmount,
564
+ amountInUsd: `${parseFloat(
565
+ x(e.sourceTokenAmount, e.sourceToken.decimals)
566
+ ) * e.sourceToken.price}`,
567
+ amountOutUsd: `${parseFloat(
568
+ x(e.targetTokenAmount, e.targetToken.decimals)
569
+ ) * e.targetToken.price}`,
570
+ amountOutFormatted: x(
571
+ e.targetTokenAmount,
572
+ e.targetToken.decimals
573
+ ),
574
+ // dummy values to match quote type
575
+ deadline: new Date(Date.now() + 3600 * 1e3).toISOString(),
576
+ timeEstimate: 0,
577
+ dry: !1
578
+ };
579
+ } catch (c) {
580
+ if (c instanceof de)
581
+ return;
582
+ if (E.error(c), c instanceof ue) {
583
+ const m = c.response?.data.message || c.message;
584
+ throw new A({
585
+ code: "QUOTE_FAILED",
586
+ meta: {
587
+ message: m ?? "Failed to fetch quote. Please try again."
588
+ }
589
+ });
590
+ }
591
+ }
592
+ },
593
+ cancel: () => {
594
+ o.current.abort("Abort quote manually"), o.current = new AbortController();
595
+ }
596
+ };
597
+ }, qt = ({
598
+ isEnabled: e,
599
+ message: t,
600
+ type: s = "exact_in"
601
+ }) => {
602
+ const { ctx: n } = N(), {
603
+ isDirectTransfer: r,
604
+ isDirectNonNearWithdrawal: o,
605
+ isNearToIntentsSameAssetTransfer: u,
606
+ isDirectNearDeposit: a
607
+ } = It(), i = !n.walletAddress, I = e && !r && !o && !u && !a, { make: c, cancel: m } = Ct(), { make: p, cancel: l } = Ot(), h = () => {
608
+ m(), l();
609
+ };
610
+ y(() => {
611
+ const T = b(n, ["input_valid_dry"]), f = b(n, ["input_valid_external"]), w = b(n, ["input_valid_internal"]);
612
+ (i && !T || !i && n.targetToken?.isIntent && !w || !i && !n.targetToken?.isIntent && !f) && h();
613
+ }, [h, i, n]), y(() => {
614
+ if (!I || n.sourceToken?.assetId === U && n.targetToken?.assetId === G)
615
+ return;
616
+ const T = i ? n.state === "input_valid_dry" : n.state === "input_valid_external" && !n.targetToken?.isIntent || n.state === "input_valid_internal" && n.targetToken?.isIntent;
617
+ (async () => {
618
+ try {
619
+ if (T && n.quoteStatus === "idle") {
620
+ d("quoteSetStatus", "pending");
621
+ let f;
622
+ if (n.sourceToken?.assetId === n.targetToken?.assetId ? f = await p() : f = await c({ message: t, quoteType: s }), !f)
623
+ return;
624
+ if (d("quoteSetStatus", "success"), d("quoteSet", f), d("errorSet", null), d("tokenSetAmount", {
625
+ variant: "target",
626
+ amount: f.amountOut
627
+ }), n.state === "input_valid_dry") {
628
+ _("quote_success_dry");
629
+ return;
630
+ }
631
+ n.targetToken?.isIntent ? _("quote_success_internal") : _("quote_success_external");
632
+ }
633
+ } catch (f) {
634
+ if (f instanceof A) {
635
+ if (f.data.code === "QUOTE_INVALID_INITIAL") {
636
+ d("quoteSetStatus", "idle"), d("quoteSet", void 0), d("errorSet", null);
637
+ return;
638
+ }
639
+ d("quoteSetStatus", "error"), d("quoteSet", void 0), d("errorSet", f.data), fe(n);
640
+ return;
641
+ }
642
+ d("quoteSetStatus", "error"), d("quoteSet", void 0), d("errorSet", {
643
+ code: "QUOTE_FAILED",
644
+ meta: { message: "Unknown error" }
645
+ });
646
+ }
647
+ })();
648
+ }, [n, I, i, c]);
649
+ }, M = {
650
+ sol: "sol",
651
+ evm: "eth",
652
+ near: "near"
653
+ }, Lt = ({
654
+ isEnabled: e,
655
+ skipIntents: t = !1,
656
+ target: s = "none"
657
+ }) => {
658
+ const { tokens: n } = R(), { ctx: r, state: o } = N(), { intentBalances: u } = z(), {
659
+ walletSupportedChains: a,
660
+ chainsFilter: i,
661
+ walletAddress: I,
662
+ intentsAccountType: c
663
+ } = v(), m = pt({
664
+ tokens: n,
665
+ walletSupportedChains: a,
666
+ balances: u,
667
+ across: "intents"
668
+ }), [p, l] = C(() => !I && !t ? [
669
+ { token: mt({ tokens: n }), status: "loaded" },
670
+ { token: void 0, status: "loaded" }
671
+ ] : i.source.intents !== "none" && !t ? m ? [
672
+ { token: m, status: "loaded" },
673
+ { token: void 0, status: "loaded" }
674
+ ] : [
675
+ { token: void 0, status: "loading" },
676
+ { token: void 0, status: "loading" }
677
+ ] : [
678
+ { token: ft({
679
+ tokens: n,
680
+ walletSupportedChains: a
681
+ }), status: "loaded" },
682
+ { token: void 0, status: "loaded" }
683
+ ], [
684
+ n,
685
+ t,
686
+ i,
687
+ I,
688
+ m,
689
+ a,
690
+ o
691
+ ]);
692
+ return y(() => {
693
+ if (!e)
694
+ return;
695
+ if (b(r, ["initial_dry", "initial_wallet"]) && (p.status === "loaded" && !r.sourceToken && d("tokenSelect", {
696
+ variant: "source",
697
+ token: p.token
698
+ }), l.status === "loaded" && p.status === "loaded" && !r.targetToken)) {
699
+ let T = l.token;
700
+ s === "same-asset" && (p.token?.isIntent ? T = n.find(
701
+ (f) => !f.isIntent && f.symbol === r.sourceToken?.symbol && f.blockchain === M[c]
702
+ ) : T = n.find(
703
+ (f) => f.isIntent && f.symbol === r.sourceToken?.symbol
704
+ )), d("tokenSelect", {
705
+ variant: "target",
706
+ token: T
707
+ });
708
+ }
709
+ }, [r, p, l, e]), y(() => {
710
+ const h = b(r, ["initial_dry", "initial_wallet"]);
711
+ if (!e || !h)
712
+ return;
713
+ const T = n.find(
714
+ (w) => w.isIntent && w.symbol === "AURORA" && w.blockchain === "near"
715
+ ), f = setTimeout(() => {
716
+ if (!p.token)
717
+ if (!t && m)
718
+ d("tokenSelect", {
719
+ variant: "source",
720
+ token: m
721
+ });
722
+ else if (a.length) {
723
+ const w = n.find(
724
+ (g) => !g.isIntent && g.blockchain === M[c] && g.symbol.toLowerCase() === Ne[M[c]]?.toLowerCase()
725
+ ) ?? T;
726
+ d("tokenSelect", {
727
+ variant: "source",
728
+ token: w
729
+ });
730
+ } else
731
+ d("tokenSelect", {
732
+ variant: "source",
733
+ token: T
734
+ });
735
+ }, 3e3);
736
+ return () => clearTimeout(f);
737
+ }, [n, p, t]), { source: r.sourceToken, target: r.targetToken };
738
+ }, Bt = ({
739
+ isEnabled: e,
740
+ alchemyApiKey: t
741
+ }) => {
742
+ const { ctx: s } = N();
743
+ me({
744
+ isEnabled: e,
745
+ walletAddress: s.walletAddress,
746
+ alchemyApiKey: t ?? ""
747
+ });
748
+ }, xt = Ue(({ debug: e }) => {
749
+ e && E.debug("[WIDGET] Debug mode is enabled"), yt(), At({ debug: e }), kt({ debug: e });
750
+ }), Jn = ({ listenTo: e, debug: t = !1 }) => {
751
+ y(() => {
752
+ xt({ debug: t });
753
+ }, [t]);
754
+ const s = e.find(
755
+ (o) => Array.isArray(o) && o[0] === "setBalancesUsingAlchemyExt"
756
+ ), n = e.find(
757
+ (o) => Array.isArray(o) && o[0] === "setDefaultSelectedTokens"
758
+ ), r = e.find(
759
+ (o) => Array.isArray(o) && o[0] === "makeQuote"
760
+ );
761
+ Bt({
762
+ isEnabled: !!s,
763
+ alchemyApiKey: s?.[1].alchemyApiKey
764
+ }), Lt({
765
+ isEnabled: !!n,
766
+ skipIntents: n?.[1].skipIntents,
767
+ target: n?.[1].target
768
+ }), qt({
769
+ isEnabled: !!r,
770
+ message: r?.[1].message,
771
+ type: r?.[1].type
772
+ }), Dt({
773
+ isEnabled: e.includes("checkWalletConnection")
774
+ }), Nt({
775
+ isEnabled: e.includes("setSourceTokenBalance")
776
+ }), vt({
777
+ isEnabled: e.includes("setSourceTokenIntentsTarget")
778
+ }), bt({
779
+ isEnabled: e.includes("updateBalances"),
780
+ alchemyApiKey: s?.[1].alchemyApiKey
781
+ });
782
+ }, Ut = L.getStore();
783
+ class Q extends Error {
784
+ context;
785
+ _is_widget_error = !0;
786
+ constructor(t, s) {
787
+ super(t), this.name = "WidgetError", this.cause = s?.cause, this.context = K(Ut).context;
788
+ }
789
+ }
790
+ class pe extends Q {
791
+ data;
792
+ constructor(t) {
793
+ super(t.code), this.data = t, this.name = "MachineError";
794
+ }
795
+ }
796
+ class A extends pe {
797
+ constructor(t) {
798
+ super(t), this.name = "QuoteError";
799
+ }
800
+ }
801
+ class Yn extends pe {
802
+ constructor(t) {
803
+ super(t), this.name = "TransferError";
804
+ }
805
+ }
806
+ const es = (e) => typeof e == "object" && e !== null && "_is_widget_error" in e && !!e._is_widget_error, Qt = (e) => null, Pt = (e) => (t) => {
807
+ if (t instanceof Q)
808
+ throw t;
809
+ const s = new Q(
810
+ t instanceof Error ? t.message : "Unknown error",
811
+ { cause: t }
812
+ );
813
+ throw s.context = e, s;
814
+ }, Wt = ({ children: e }) => {
815
+ const { ctx: t } = N();
816
+ return /* @__PURE__ */ O(
817
+ De,
818
+ {
819
+ FallbackComponent: Qt,
820
+ onError: Pt(t),
821
+ children: e
822
+ }
823
+ );
824
+ }, Rt = new ye({
825
+ defaultOptions: {
826
+ queries: {
827
+ staleTime: 2e3 * 60
828
+ }
829
+ }
830
+ }), Mt = ["fms", "abg", "stjack", "noear", "testnebula"], P = {
831
+ appName: "Unknown",
832
+ appIcon: "https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg",
833
+ defaultMaxSlippage: 0.01,
834
+ intentsAccountType: "evm",
835
+ walletSupportedChains: ve,
836
+ walletAddress: void 0,
837
+ oneClickApiQuoteProxyUrl: "https://1click.chaindefuser.com/v0/quote",
838
+ enableAutoTokensSwitching: !0,
839
+ showIntentTokens: !0,
840
+ chainsOrder: [
841
+ "eth",
842
+ "btc",
843
+ "near",
844
+ "sol",
845
+ "bsc",
846
+ "base",
847
+ "arb",
848
+ "cardano",
849
+ "sui",
850
+ "ton",
851
+ "pol",
852
+ "op",
853
+ "zec",
854
+ "tron",
855
+ "xrp",
856
+ "avax",
857
+ "bera",
858
+ "xrp",
859
+ "gnosis",
860
+ "doge"
861
+ ],
862
+ filterTokens: (e) => !Mt.includes(e.symbol.toLocaleLowerCase()),
863
+ allowedTokensList: void 0,
864
+ allowedChainsList: void 0,
865
+ chainsFilter: {
866
+ source: { external: "wallet-supported", intents: "with-balance" },
867
+ target: { external: "all", intents: "all" }
868
+ }
869
+ }, Te = ge({
870
+ config: P
871
+ }), X = se({
872
+ config: P
873
+ }), v = () => {
874
+ const e = ke(Te);
875
+ return W(e).config;
876
+ }, Ft = (e) => {
877
+ X.config = F(e);
878
+ }, ts = ({
879
+ children: e,
880
+ config: t,
881
+ localisation: s
882
+ }) => {
883
+ const n = q(
884
+ se({
885
+ config: F({
886
+ ...P,
887
+ ...t
888
+ })
889
+ })
890
+ );
891
+ return y(() => {
892
+ const r = F({
893
+ ...P,
894
+ ...t
895
+ });
896
+ Object.assign(n.current.config, r), Ft(r);
897
+ }, [t]), $e(s ?? {}), Ge("headlessui-portal-root", "sw"), /* @__PURE__ */ O(we, { client: Rt, children: /* @__PURE__ */ O(Se, { i18n: Ie, children: /* @__PURE__ */ O(Te.Provider, { value: n.current, children: /* @__PURE__ */ O(Wt, { children: e }) }) }) });
898
+ };
899
+ export {
900
+ Bt as A,
901
+ X as B,
902
+ Wt as E,
903
+ pe as M,
904
+ A as Q,
905
+ Yn as T,
906
+ ts as W,
907
+ Zn as a,
908
+ N as b,
909
+ Jn as c,
910
+ z as d,
911
+ Ct as e,
912
+ Et as f,
913
+ R as g,
914
+ me as h,
915
+ Q as i,
916
+ es as j,
917
+ v as k,
918
+ gt as l,
919
+ kt as m,
920
+ At as n,
921
+ yt as o,
922
+ bt as p,
923
+ Nt as q,
924
+ xt as r,
925
+ vt as s,
926
+ ht as t,
927
+ It as u,
928
+ fe as v,
929
+ Dt as w,
930
+ Ot as x,
931
+ qt as y,
932
+ Lt as z
933
+ };
934
+ //# sourceMappingURL=config-GUxZr_mK.js.map