@jup-ag/plugin 1.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,4074 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __pow = Math.pow;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ var __objRest = (source, exclude) => {
27
+ var target = {};
28
+ for (var prop in source)
29
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
+ target[prop] = source[prop];
31
+ if (source != null && __getOwnPropSymbols)
32
+ for (var prop of __getOwnPropSymbols(source)) {
33
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
+ target[prop] = source[prop];
35
+ }
36
+ return target;
37
+ };
38
+ var __commonJS = (cb, mod) => function __require() {
39
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
40
+ };
41
+ var __export = (target, all) => {
42
+ for (var name in all)
43
+ __defProp(target, name, { get: all[name], enumerable: true });
44
+ };
45
+ var __copyProps = (to, from, except, desc) => {
46
+ if (from && typeof from === "object" || typeof from === "function") {
47
+ for (let key of __getOwnPropNames(from))
48
+ if (!__hasOwnProp.call(to, key) && key !== except)
49
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
50
+ }
51
+ return to;
52
+ };
53
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
54
+ // If the importer is in node compatibility mode or this is not an ESM
55
+ // file that has been converted to a CommonJS file using a Babel-
56
+ // compatible transform (i.e. "__esModule" has not been set), then set
57
+ // "default" to the CommonJS "module.exports" for node compatibility.
58
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
59
+ mod
60
+ ));
61
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
62
+ var __async = (__this, __arguments, generator) => {
63
+ return new Promise((resolve, reject) => {
64
+ var fulfilled = (value) => {
65
+ try {
66
+ step(generator.next(value));
67
+ } catch (e) {
68
+ reject(e);
69
+ }
70
+ };
71
+ var rejected = (value) => {
72
+ try {
73
+ step(generator.throw(value));
74
+ } catch (e) {
75
+ reject(e);
76
+ }
77
+ };
78
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
79
+ step((generator = generator.apply(__this, __arguments)).next());
80
+ });
81
+ };
82
+
83
+ // package.json
84
+ var require_package = __commonJS({
85
+ "package.json"(exports2, module2) {
86
+ module2.exports = {
87
+ name: "@jup-ag/plugin",
88
+ version: "1.0.0",
89
+ private: false,
90
+ license: "MIT",
91
+ scripts: {
92
+ dev: "next dev",
93
+ build: "next build",
94
+ tsup: "tsup && npx tailwindcss --yes -i ./src/styles/globals.css -o ./dist/global.css",
95
+ start: "next start",
96
+ lint: "next lint",
97
+ "format:fix": "prettier --write src",
98
+ "build-widget": "NODE_ENV=production MODE=widget webpack",
99
+ analyse: "NODE_ENV=production MODE=widget ANALYSE=true webpack"
100
+ },
101
+ files: [
102
+ "dist"
103
+ ],
104
+ exports: {
105
+ ".": "./dist/index.js",
106
+ "./tailwind": "./dist/tailwind.config.js",
107
+ "./css": "./dist/global.css"
108
+ },
109
+ typesVersions: {
110
+ "*": {
111
+ index: [
112
+ "dist/index.d.ts"
113
+ ]
114
+ }
115
+ },
116
+ peerDependencies: {
117
+ "@solana/spl-token": "^0.1.8",
118
+ "@solana/web3.js": "^1.87.6",
119
+ react: "^18",
120
+ "react-dom": "^18"
121
+ },
122
+ dependencies: {
123
+ "@jup-ag/wallet-adapter": "0.2.3",
124
+ "@popperjs/core": "^2.11.8",
125
+ "@solana/wallet-adapter-wallets": "0.19.33",
126
+ "@tanstack/react-query": "^4.36.1",
127
+ "bn.js": "5.2.1",
128
+ clsx: "^2.1.1",
129
+ "decimal.js": "10.4.3",
130
+ jotai: "^2.8.3",
131
+ jsbi: "4.3.0",
132
+ "lodash.debounce": "^4.0.8",
133
+ next: "13.4.19",
134
+ "next-seo": "5.15.0",
135
+ "react-colorful": "^5.6.1",
136
+ "react-hook-form": "7.42.1",
137
+ "react-number-format": "5.1.3",
138
+ "react-popper": "^2.3.0",
139
+ "react-syntax-highlighter": "^15.5.0",
140
+ "react-use": "^17.5.0",
141
+ "react-virtualized-auto-sizer": "1.0.7",
142
+ "react-window": "1.8.8",
143
+ superstruct: "1.0.3",
144
+ "tailwind-merge": "^2.5.2",
145
+ "tailwindcss-animate": "^1.0.7"
146
+ },
147
+ devDependencies: {
148
+ "@svgr/webpack": "^6.5.1",
149
+ "@types/bn.js": "^5.1.5",
150
+ "@types/bs58": "^4.0.4",
151
+ "@types/lodash.debounce": "^4.0.9",
152
+ "@types/node": "18.11.5",
153
+ "@types/react": "18.0.23",
154
+ "@types/react-dom": "18.0.7",
155
+ "@types/react-syntax-highlighter": "^15.5.13",
156
+ "@types/react-virtualized-auto-sizer": "~1.0.4",
157
+ "@types/react-window": "~1.8.8",
158
+ autoprefixer: "10.4.13",
159
+ "css-loader": "^6.11.0",
160
+ "css-minimizer-webpack-plugin": "^4.2.2",
161
+ cssnano: "^5.1.15",
162
+ "esbuild-plugins-node-modules-polyfill": "^1.6.6",
163
+ eslint: "8.26.0",
164
+ "eslint-config-next": "13.0.0",
165
+ "eslint-config-prettier": "^8.10.0",
166
+ "mini-css-extract-plugin": "^2.9.0",
167
+ "next-transpile-modules": "10.0.0",
168
+ "node-polyfill-webpack-plugin": "^2.0.1",
169
+ postcss: "^8.4.38",
170
+ "postcss-loader": "^7.3.4",
171
+ "postcss-preset-env": "^7.8.3",
172
+ prettier: "^3.3.2",
173
+ "react-twitter-embed": "^4.0.4",
174
+ sass: "^1.77.6",
175
+ "sass-loader": "^13.3.3",
176
+ "style-loader": "^3.3.4",
177
+ stylus: "^0.59.0",
178
+ "svg-inline-loader": "^0.8.2",
179
+ tailwindcss: "3.3.3",
180
+ "ts-loader": "^9.5.1",
181
+ tsup: "8.2.4",
182
+ typescript: "5.2.2",
183
+ webpack: "^5.92.1",
184
+ "webpack-bundle-analyzer": "^4.10.2",
185
+ "webpack-cli": "^4.10.0"
186
+ },
187
+ pnpm: {
188
+ overrides: {
189
+ "@solana/web3.js": "1.87.6",
190
+ "@solana/buffer-layout": "4.0.0"
191
+ }
192
+ }
193
+ };
194
+ }
195
+ });
196
+
197
+ // src/npmlibary.tsx
198
+ var npmlibary_exports = {};
199
+ __export(npmlibary_exports, {
200
+ appProps: () => appProps,
201
+ close: () => close,
202
+ init: () => init2,
203
+ resume: () => resume,
204
+ syncProps: () => syncProps
205
+ });
206
+ module.exports = __toCommonJS(npmlibary_exports);
207
+
208
+ // src/library.tsx
209
+ var import_client = require("react-dom/client");
210
+ var import_jotai2 = require("jotai");
211
+ var import_react2 = require("react");
212
+
213
+ // src/icons/JupiterLogo.tsx
214
+ var import_jsx_runtime = require("react/jsx-runtime");
215
+ var JupiterLogo = ({ width = 24, height = 24 }) => {
216
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: "https://jup.ag/svg/jupiter-logo.svg", width, height, alt: "Jupiter aggregator" });
217
+ };
218
+ var JupiterLogo_default = JupiterLogo;
219
+
220
+ // src/icons/ChevronDownIcon.tsx
221
+ var import_jsx_runtime2 = require("react/jsx-runtime");
222
+ var ChevronDownIcon = ({ width = 10, height = 6 }) => {
223
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
224
+ "svg",
225
+ {
226
+ width,
227
+ height,
228
+ viewBox: "0 0 10 6",
229
+ fill: "inherit",
230
+ xmlns: "http://www.w3.org/2000/svg",
231
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
232
+ "path",
233
+ {
234
+ fillRule: "evenodd",
235
+ clipRule: "evenodd",
236
+ d: "M0.292893 0.292893C0.683416 -0.097631 1.31658 -0.097631 1.7071 0.292893L4.99999 3.58579L8.29288 0.292893C8.6834 -0.0976311 9.31657 -0.0976311 9.70709 0.292893C10.0976 0.683417 10.0976 1.31658 9.70709 1.70711L5.7071 5.70711C5.31657 6.09763 4.68341 6.09763 4.29289 5.70711L0.292893 1.70711C-0.0976309 1.31658 -0.0976309 0.683417 0.292893 0.292893Z",
237
+ fill: "currentColor"
238
+ }
239
+ )
240
+ }
241
+ );
242
+ };
243
+ var ChevronDownIcon_default = ChevronDownIcon;
244
+
245
+ // src/stores/jotai-plugin-in-view.tsx
246
+ var import_jotai = require("jotai");
247
+ var pluginInViewAtom = (0, import_jotai.atom)(false);
248
+ var getPluginInView = () => {
249
+ var _a2;
250
+ const store2 = (_a2 = window.Jupiter) == null ? void 0 : _a2.store;
251
+ if (!store2) {
252
+ console.warn("Jupiter store is not available.");
253
+ return false;
254
+ }
255
+ return store2.get(pluginInViewAtom);
256
+ };
257
+ var setPluginInView = (value) => {
258
+ var _a2;
259
+ const store2 = (_a2 = window.Jupiter) == null ? void 0 : _a2.store;
260
+ if (!store2) {
261
+ console.warn("Jupiter store is not available.");
262
+ return;
263
+ }
264
+ store2.set(pluginInViewAtom, value);
265
+ };
266
+
267
+ // src/misc/cn.ts
268
+ var import_clsx = require("clsx");
269
+ var import_tailwind_merge = require("tailwind-merge");
270
+ function cn(...inputs) {
271
+ return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
272
+ }
273
+
274
+ // src/components/ShadowDomContainer.tsx
275
+ var import_react = require("react");
276
+ var import_react_dom = require("react-dom");
277
+ var import_jsx_runtime3 = require("react/jsx-runtime");
278
+ var ShadowDomContainer = ({ children, stylesheetUrls }) => {
279
+ const hostRef = (0, import_react.useRef)(null);
280
+ const [shadowRoot, setShadowRoot] = (0, import_react.useState)(null);
281
+ const [stylesLoaded, setStylesLoaded] = (0, import_react.useState)(false);
282
+ (0, import_react.useEffect)(() => {
283
+ if (hostRef.current && !shadowRoot) {
284
+ const newShadowRoot = hostRef.current.attachShadow({ mode: "open" });
285
+ const loadStyles = () => __async(void 0, null, function* () {
286
+ try {
287
+ const stylePromises = stylesheetUrls.map(
288
+ (url) => fetch(url).then((res) => {
289
+ if (!res.ok) {
290
+ throw new Error(`Failed to fetch stylesheet: ${url}`);
291
+ }
292
+ return res.text();
293
+ })
294
+ );
295
+ const allCssText = yield Promise.all(stylePromises);
296
+ allCssText.forEach((cssText) => {
297
+ const styleEl = document.createElement("style");
298
+ styleEl.textContent = cssText;
299
+ newShadowRoot.appendChild(styleEl);
300
+ });
301
+ setStylesLoaded(true);
302
+ } catch (error) {
303
+ console.error("Error fetching and applying styles:", error);
304
+ }
305
+ });
306
+ loadStyles();
307
+ const portalContainer = document.createElement("div");
308
+ portalContainer.id = "portal-container";
309
+ portalContainer.style.width = "100%";
310
+ portalContainer.style.height = "100%";
311
+ newShadowRoot.appendChild(portalContainer);
312
+ setShadowRoot(newShadowRoot);
313
+ }
314
+ }, [hostRef, shadowRoot, stylesheetUrls]);
315
+ const portalTarget = shadowRoot == null ? void 0 : shadowRoot.getElementById("portal-container");
316
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: hostRef, children: portalTarget && stylesLoaded ? (0, import_react_dom.createPortal)(children, portalTarget) : null });
317
+ };
318
+
319
+ // src/library.tsx
320
+ var import_jsx_runtime4 = require("react/jsx-runtime");
321
+ var containerId = "jupiter-plugin-instance";
322
+ var packageJson = require_package();
323
+ var bundleName = `plugin-${packageJson.version}`;
324
+ var scriptDomain = (() => {
325
+ var _a2;
326
+ if (typeof window === "undefined" || typeof document === "undefined") return "";
327
+ const url = (_a2 = document.currentScript) == null ? void 0 : _a2.src;
328
+ if (url) {
329
+ return new URL(url).origin;
330
+ }
331
+ return "";
332
+ })() || "https://plugin.jup.ag";
333
+ function loadRemote(id, href, type2) {
334
+ return __async(this, null, function* () {
335
+ return new Promise((res, rej) => {
336
+ const existing = document.getElementById(id);
337
+ if (existing) {
338
+ res({});
339
+ } else {
340
+ let el = type2 === "text/javascript" ? document.createElement("script") : document.createElement("link");
341
+ el.id = id;
342
+ el.onload = res;
343
+ el.onerror = rej;
344
+ if (el instanceof HTMLScriptElement) {
345
+ el.type = "text/javascript";
346
+ el.src = href;
347
+ } else if (el instanceof HTMLLinkElement) {
348
+ el.rel = "stylesheet";
349
+ el.href = href;
350
+ }
351
+ document.head.append(el);
352
+ }
353
+ });
354
+ });
355
+ }
356
+ function loadJupiter() {
357
+ return __async(this, null, function* () {
358
+ if (process.env.NODE_ENV === "development") {
359
+ return;
360
+ }
361
+ try {
362
+ yield loadRemote("jupiter-load-script-app", `${scriptDomain}/${bundleName}-app.js`, "text/javascript");
363
+ } catch (error) {
364
+ console.error(`Error loading Jupiter Plugin: ${error}`);
365
+ throw new Error(`Error loading Jupiter Plugin: ${error}`);
366
+ }
367
+ });
368
+ }
369
+ var defaultStyles = {
370
+ zIndex: 50
371
+ };
372
+ var RenderLoadableJupiter = (props) => {
373
+ const [loaded, setLoaded] = (0, import_react2.useState)(false);
374
+ (0, import_react2.useEffect)(() => {
375
+ loadJupiter();
376
+ let intervalId;
377
+ if (!loaded) {
378
+ intervalId = setInterval(() => {
379
+ var _a2;
380
+ const instance2 = (_a2 = window.JupiterRenderer) == null ? void 0 : _a2.RenderJupiter;
381
+ if (instance2) {
382
+ setLoaded(true);
383
+ }
384
+ }, 50);
385
+ }
386
+ return () => {
387
+ clearInterval(intervalId);
388
+ };
389
+ }, [loaded]);
390
+ const RenderJupiter2 = (0, import_react2.useMemo)(() => {
391
+ if (loaded) {
392
+ return window.JupiterRenderer.RenderJupiter;
393
+ }
394
+ return EmptyJSX;
395
+ }, [loaded]);
396
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RenderJupiter2, __spreadValues({}, props));
397
+ };
398
+ var EmptyJSX = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, {});
399
+ var RenderShell = (props) => {
400
+ const displayMode = props.displayMode;
401
+ const containerStyles = props.containerStyles;
402
+ const containerClassName = props.containerClassName;
403
+ (0, import_react2.useEffect)(() => setPluginInView(true), []);
404
+ const displayClassName = (0, import_react2.useMemo)(() => {
405
+ if (!displayMode || displayMode === "modal") {
406
+ return "fixed top-0 w-full h-full flex items-center justify-center bg-black/50 z-10";
407
+ } else if (displayMode === "integrated" || displayMode === "widget") {
408
+ return "flex items-center justify-center w-full h-full z-10";
409
+ }
410
+ }, [displayMode]);
411
+ const contentClassName = (0, import_react2.useMemo)(() => {
412
+ if (!displayMode || displayMode === "modal" || displayMode === "integrated") {
413
+ return `flex flex-col h-[550px] w-full max-w-[360px] overflow-auto text-black relative bg-black rounded-lg webkit-scrollbar ${containerClassName || ""}`;
414
+ } else if (displayMode === "widget") {
415
+ return "flex flex-col h-[550px] w-full overflow-auto text-black relative webkit-scrollbar";
416
+ }
417
+ }, [containerClassName, displayMode]);
418
+ const onClose = () => {
419
+ if (window.Jupiter) {
420
+ setPluginInView(false);
421
+ window.Jupiter.close();
422
+ }
423
+ };
424
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: displayClassName, children: [
425
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: __spreadValues(__spreadValues({}, defaultStyles), containerStyles), className: contentClassName, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RenderLoadableJupiter, __spreadValues({}, props)) }),
426
+ !displayMode || displayMode === "modal" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: onClose, className: "absolute w-screen h-screen top-0 left-0 backdrop-blur-sm" }) : null
427
+ ] });
428
+ };
429
+ var RenderWidgetShell = (props) => {
430
+ var _a2, _b, _c, _d, _e;
431
+ const [isOpen, setIsOpen] = (0, import_react2.useState)(false);
432
+ const classes = (0, import_react2.useMemo)(() => {
433
+ var _a3, _b2, _c2, _d2, _e2, _f, _g, _h, _i, _j, _k, _l;
434
+ const size = ((_a3 = props.widgetStyle) == null ? void 0 : _a3.size) || "default";
435
+ const offsetX = (_d2 = (_c2 = (_b2 = props.widgetStyle) == null ? void 0 : _b2.offset) == null ? void 0 : _c2.x) != null ? _d2 : 0;
436
+ const offsetY = (_g = (_f = (_e2 = props.widgetStyle) == null ? void 0 : _e2.offset) == null ? void 0 : _f.y) != null ? _g : 0;
437
+ let result = void 0;
438
+ if (!((_h = props.widgetStyle) == null ? void 0 : _h.position) || ((_i = props.widgetStyle) == null ? void 0 : _i.position) === "bottom-right") {
439
+ result = {
440
+ containerClassName: "bottom-6 right-6",
441
+ contentClassName: size === "default" ? "bottom-[60px] -right-3" : "bottom-[44px] -right-4",
442
+ style: { transform: `translate(-${offsetX}px, -${offsetY}px)` }
443
+ };
444
+ }
445
+ if (((_j = props.widgetStyle) == null ? void 0 : _j.position) === "bottom-left") {
446
+ result = {
447
+ containerClassName: "bottom-6 left-6",
448
+ contentClassName: size === "default" ? "bottom-[60px] -left-3" : "bottom-[44px] -left-4",
449
+ style: { transform: `translate(${offsetX}px, -${offsetY}px)` }
450
+ };
451
+ }
452
+ if (((_k = props.widgetStyle) == null ? void 0 : _k.position) === "top-left") {
453
+ result = {
454
+ containerClassName: "top-6 left-6",
455
+ contentClassName: size === "default" ? "top-[60px] -left-3" : "top-[44px] -left-4",
456
+ style: { transform: `translate(${offsetX}px, ${offsetY}px)` }
457
+ };
458
+ }
459
+ if (((_l = props.widgetStyle) == null ? void 0 : _l.position) === "top-right") {
460
+ result = {
461
+ containerClassName: "top-6 right-6",
462
+ contentClassName: size === "default" ? "top-[60px] -right-3" : "top-[44px] -right-4",
463
+ style: { transform: `translate(-${offsetX}px, ${offsetY}px)` }
464
+ };
465
+ }
466
+ return __spreadProps(__spreadValues({}, result), {
467
+ widgetContainerClassName: size === "default" ? "h-14 w-14" : "h-10 w-10",
468
+ widgetLogoSize: size === "default" ? 42 : 32
469
+ });
470
+ }, [(_a2 = props.widgetStyle) == null ? void 0 : _a2.position, (_b = props.widgetStyle) == null ? void 0 : _b.size, (_c = props.widgetStyle) == null ? void 0 : _c.offset]);
471
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `fixed ${classes.containerClassName}`, style: classes.style, children: [
472
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
473
+ "div",
474
+ {
475
+ className: `${classes.widgetContainerClassName} rounded-full bg-black flex items-center justify-center cursor-pointer`,
476
+ onClick: () => {
477
+ if (isOpen) {
478
+ setIsOpen(false);
479
+ setPluginInView(false);
480
+ } else {
481
+ setIsOpen(true);
482
+ setPluginInView(true);
483
+ }
484
+ },
485
+ children: isOpen ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
486
+ "div",
487
+ {
488
+ className: cn("text-white fill-current pt-1", {
489
+ "rotate-180": ((_d = props.widgetStyle) == null ? void 0 : _d.position) === "top-left" || ((_e = props.widgetStyle) == null ? void 0 : _e.position) === "top-right"
490
+ }),
491
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChevronDownIcon_default, { width: classes.widgetLogoSize * 0.4, height: classes.widgetLogoSize * 0.4 })
492
+ }
493
+ ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(JupiterLogo_default, { width: classes.widgetLogoSize, height: classes.widgetLogoSize })
494
+ }
495
+ ),
496
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
497
+ "div",
498
+ {
499
+ id: "target-container",
500
+ className: `absolute overflow-hidden ${classes.contentClassName} flex flex-col w-[90vw] h-[600px] max-w-[384px] max-h-[75vh] rounded-2xl bg-black transition-opacity duration-300 shadow-2xl ${!isOpen ? "!h-0 !w-0 opacity-0" : "opacity-100"}`,
501
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RenderLoadableJupiter, __spreadValues({}, props))
502
+ }
503
+ )
504
+ ] });
505
+ };
506
+ var store = (0, import_jotai2.createStore)();
507
+ var appProps = (0, import_jotai2.atom)(void 0);
508
+ function init(passedProps) {
509
+ return __async(this, null, function* () {
510
+ var _b;
511
+ if (typeof window === "undefined" || typeof document === "undefined") return null;
512
+ const props = __spreadValues({}, passedProps);
513
+ const _a2 = props, {
514
+ enableWalletPassthrough,
515
+ passthroughWalletContextState,
516
+ onRequestConnectWallet,
517
+ onSwapError,
518
+ onSuccess,
519
+ onFormUpdate,
520
+ onScreenUpdate,
521
+ integratedTargetId
522
+ } = _a2, restProps = __objRest(_a2, [
523
+ "enableWalletPassthrough",
524
+ "passthroughWalletContextState",
525
+ "onRequestConnectWallet",
526
+ "onSwapError",
527
+ "onSuccess",
528
+ "onFormUpdate",
529
+ "onScreenUpdate",
530
+ "integratedTargetId"
531
+ ]);
532
+ const targetDiv = document.createElement("div");
533
+ const instanceExist = document.getElementById(containerId);
534
+ window.Jupiter.store = store;
535
+ store.set(appProps, __spreadProps(__spreadValues({}, props), { scriptDomain }));
536
+ setPluginInView(false);
537
+ if (instanceExist) {
538
+ window.Jupiter._instance = null;
539
+ instanceExist.remove();
540
+ (_b = window.Jupiter.root) == null ? void 0 : _b.unmount();
541
+ }
542
+ targetDiv.id = containerId;
543
+ targetDiv.classList.add("w-full");
544
+ targetDiv.classList.add("h-full");
545
+ if (restProps.displayMode === "integrated") {
546
+ const target = document.getElementById(integratedTargetId);
547
+ if (!target) {
548
+ throw new Error(`Jupiter Plugin: document.getElementById cannot find ${integratedTargetId}`);
549
+ }
550
+ target == null ? void 0 : target.appendChild(targetDiv);
551
+ } else {
552
+ document.body.appendChild(targetDiv);
553
+ }
554
+ if (enableWalletPassthrough) {
555
+ window.Jupiter.enableWalletPassthrough = true;
556
+ window.Jupiter.onRequestConnectWallet = onRequestConnectWallet;
557
+ } else {
558
+ window.Jupiter.enableWalletPassthrough = false;
559
+ }
560
+ let element;
561
+ if (restProps.displayMode === "widget") {
562
+ element = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RenderWidgetShell, __spreadValues({}, props));
563
+ } else {
564
+ element = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RenderShell, __spreadValues({}, props));
565
+ }
566
+ const stylesheetUrls = [
567
+ `${scriptDomain}/${bundleName}-Tailwind.css`,
568
+ `${scriptDomain}/scoped-preflight-v4.css`,
569
+ `${scriptDomain}/${bundleName}-Jupiter.css`,
570
+ "https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&family=Poppins&display=swap"
571
+ ];
572
+ const root = (0, import_client.createRoot)(targetDiv);
573
+ root.render(/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ShadowDomContainer, { stylesheetUrls, children: element }));
574
+ window.Jupiter.root = root;
575
+ window.Jupiter._instance = element;
576
+ window.Jupiter.onSwapError = onSwapError;
577
+ window.Jupiter.onSuccess = onSuccess;
578
+ window.Jupiter.onFormUpdate = onFormUpdate;
579
+ window.Jupiter.onScreenUpdate = onScreenUpdate;
580
+ });
581
+ }
582
+ var _a;
583
+ var attributes = typeof document !== "undefined" ? (_a = document.currentScript) == null ? void 0 : _a.attributes : void 0;
584
+ if (typeof window !== "undefined" && typeof document !== "undefined" && attributes) {
585
+ document.onreadystatechange = function() {
586
+ const loadComplete = document.readyState === "complete";
587
+ const shouldPreload = Boolean(attributes.getNamedItem("data-preload"));
588
+ if (loadComplete && shouldPreload) {
589
+ setTimeout(() => {
590
+ loadJupiter().catch((error) => {
591
+ console.error(`Error pre-loading Jupiter Plugin: ${error}`);
592
+ throw new Error(`Error pre-loading Jupiter Plugin: ${error}`);
593
+ });
594
+ }, 2e3);
595
+ }
596
+ };
597
+ }
598
+ var resume = () => {
599
+ const instanceExist = document.getElementById(containerId);
600
+ if (instanceExist) {
601
+ instanceExist.style.display = "block";
602
+ return;
603
+ }
604
+ };
605
+ var close = () => {
606
+ const targetDiv = document.getElementById(containerId);
607
+ if (targetDiv) {
608
+ targetDiv.style.display = "none";
609
+ }
610
+ };
611
+ var syncProps = (props) => {
612
+ const currentProps = store.get(appProps);
613
+ const newProps = __spreadProps(__spreadValues({}, currentProps), {
614
+ passthroughWalletContextState: props.passthroughWalletContextState || (currentProps == null ? void 0 : currentProps.passthroughWalletContextState)
615
+ });
616
+ store.set(appProps, newProps);
617
+ };
618
+
619
+ // src/index.tsx
620
+ var import_jotai4 = require("jotai");
621
+
622
+ // src/contexts/ScreenProvider.tsx
623
+ var import_react3 = require("react");
624
+ var import_jsx_runtime5 = require("react/jsx-runtime");
625
+ var ScreenStateContext = (0, import_react3.createContext)({ screen: "Initial", setScreen() {
626
+ } });
627
+ function useScreenState() {
628
+ return (0, import_react3.useContext)(ScreenStateContext);
629
+ }
630
+ var ScreenProvider = ({ children }) => {
631
+ const [screen2, setScreen] = (0, import_react3.useState)("Initial");
632
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ScreenStateContext.Provider, { value: { screen: screen2, setScreen }, children });
633
+ };
634
+
635
+ // src/contexts/SwapContext.tsx
636
+ var import_decimal2 = __toESM(require("decimal.js"));
637
+ var import_jsbi2 = __toESM(require("jsbi"));
638
+ var import_react7 = require("react");
639
+
640
+ // src/constants/index.ts
641
+ var import_web3 = require("@solana/web3.js");
642
+
643
+ // src/types/constants.ts
644
+ var SwapMode = {
645
+ ExactInOrOut: "ExactInOrOut",
646
+ ExactIn: "ExactIn",
647
+ ExactOut: "ExactOut"
648
+ };
649
+
650
+ // src/constants/index.ts
651
+ var USDC_MINT = new import_web3.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
652
+ var USDT_MINT = new import_web3.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB");
653
+ var JLP_MINT = new import_web3.PublicKey("27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4");
654
+ var WRAPPED_SOL_MINT = new import_web3.PublicKey("So11111111111111111111111111111111111111112");
655
+ var INITIAL_FORM_CONFIG = Object.freeze({
656
+ simulateWalletPassthrough: false,
657
+ defaultExplorer: "Solana Explorer",
658
+ formProps: {
659
+ fixedAmount: false,
660
+ initialAmount: "",
661
+ initialInputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
662
+ initialOutputMint: WRAPPED_SOL_MINT.toString(),
663
+ swapMode: SwapMode.ExactIn
664
+ },
665
+ colors: {
666
+ primary: "199, 242, 132",
667
+ background: "0, 0, 0",
668
+ primaryText: "232, 249, 255",
669
+ warning: "251, 191, 36",
670
+ interactive: "33, 42, 54",
671
+ module: "16, 23, 31"
672
+ }
673
+ });
674
+
675
+ // src/misc/utils.ts
676
+ var import_web32 = require("@solana/web3.js");
677
+ var import_decimal = __toESM(require("decimal.js"));
678
+ var import_react4 = require("react");
679
+
680
+ // src/misc/tokenTags.ts
681
+ var checkIsStrictOrVerified = (tokenInfo) => {
682
+ var _a2, _b, _c;
683
+ return Boolean(
684
+ ((_a2 = tokenInfo.tags) == null ? void 0 : _a2.includes("verified")) || ((_b = tokenInfo.tags) == null ? void 0 : _b.includes("strict")) || ((_c = tokenInfo.tags) == null ? void 0 : _c.includes("community"))
685
+ );
686
+ };
687
+ var checkIsUnknownToken = (tokenInfo) => {
688
+ return checkIsStrictOrVerified(tokenInfo) === false;
689
+ };
690
+ var checkIsToken2022 = (tokenInfo) => {
691
+ var _a2;
692
+ return (_a2 = tokenInfo.tags) == null ? void 0 : _a2.includes("token-2022");
693
+ };
694
+
695
+ // src/misc/utils.ts
696
+ var userLocale = typeof window !== "undefined" ? navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.language : "en-US";
697
+ var numberFormatter = new Intl.NumberFormat(userLocale, {
698
+ style: "decimal",
699
+ minimumFractionDigits: 0,
700
+ maximumFractionDigits: 9
701
+ });
702
+ var getDecimalCount = (value) => {
703
+ const parts = value.split(".");
704
+ return parts.length > 1 ? parts[1].length : 0;
705
+ };
706
+ var formatNumber = {
707
+ format: (val, precision) => {
708
+ if (!val) {
709
+ return "";
710
+ }
711
+ const defaultDecimals = getDecimalCount(val.toString());
712
+ const numberFormatter2 = new Intl.NumberFormat(userLocale, {
713
+ maximumFractionDigits: precision != null ? precision : defaultDecimals
714
+ });
715
+ return numberFormatter2.format(val.toString());
716
+ }
717
+ };
718
+ function shortenAddress(address, chars = 4) {
719
+ return `${address.slice(0, chars)}...${address.slice(-chars)}`;
720
+ }
721
+ function readableValue(lamportsAmount, decimals) {
722
+ return new import_decimal.default(lamportsAmount.toString()).div(__pow(10, decimals)).toDP(decimals, import_decimal.default.ROUND_DOWN).toFixed();
723
+ }
724
+ function fromLamports(lamportsAmount, decimals) {
725
+ return new import_decimal.default(lamportsAmount.toString()).div(__pow(10, decimals)).toDP(decimals, import_decimal.default.ROUND_DOWN).toNumber();
726
+ }
727
+ var detectedSeparator = formatNumber.format("1.1").substring(1, 2);
728
+ function useDebounce(value, delay) {
729
+ const [debouncedValue, setDebouncedValue] = (0, import_react4.useState)(value);
730
+ (0, import_react4.useEffect)(
731
+ () => {
732
+ const handler = setTimeout(() => {
733
+ setDebouncedValue(value);
734
+ }, delay);
735
+ return () => {
736
+ clearTimeout(handler);
737
+ };
738
+ },
739
+ [value, delay]
740
+ // Only re-call effect if value or delay changes
741
+ );
742
+ return debouncedValue;
743
+ }
744
+ function useOutsideClick(ref, handler) {
745
+ (0, import_react4.useEffect)(() => {
746
+ const listener = (event) => {
747
+ if (!ref.current || ref.current.contains(event.target)) {
748
+ return;
749
+ }
750
+ handler(event);
751
+ };
752
+ document.addEventListener("mouseup", listener);
753
+ return () => {
754
+ document.removeEventListener("mouseup", listener);
755
+ };
756
+ }, [ref, handler]);
757
+ }
758
+ var hasNumericValue = (amount) => {
759
+ if (amount && !Number.isNaN(Number(amount))) {
760
+ return true;
761
+ }
762
+ return false;
763
+ };
764
+ var sortByUserBalance = (searchResults, balances) => {
765
+ const userBalanceMap = /* @__PURE__ */ new Map();
766
+ const userUsdValueMap = /* @__PURE__ */ new Map();
767
+ Object.entries(balances).filter(([_, item]) => item.uiAmount > 0).forEach(([mint, item]) => {
768
+ const tokenInfo = searchResults.find((token) => token.id === mint);
769
+ if (!tokenInfo) return;
770
+ const amount = item.uiAmount;
771
+ userBalanceMap.set(mint, amount);
772
+ const tokenPrice = tokenInfo.usdPrice || 0;
773
+ if (tokenPrice) {
774
+ const usdValue = new import_decimal.default(amount).mul(tokenPrice);
775
+ if (usdValue.greaterThan(0)) {
776
+ userUsdValueMap.set(mint, usdValue);
777
+ }
778
+ }
779
+ });
780
+ const deduplicatedResults = (() => {
781
+ const map = /* @__PURE__ */ new Map();
782
+ searchResults.forEach((item) => {
783
+ if (!map.has(item.id)) {
784
+ map.set(item.id, item);
785
+ }
786
+ });
787
+ return Array.from(map.values());
788
+ })();
789
+ return deduplicatedResults.sort((t1, t2) => {
790
+ var _a2, _b, _c, _d;
791
+ const t1UsdValue = userUsdValueMap.get(t1.id);
792
+ const t2UsdValue = userUsdValueMap.get(t2.id);
793
+ if (t1UsdValue && t2UsdValue) {
794
+ const usdComparison = t2UsdValue.cmp(t1UsdValue);
795
+ if (usdComparison !== 0) return usdComparison;
796
+ } else if (t1UsdValue && !t2UsdValue) {
797
+ return -1;
798
+ } else if (!t1UsdValue && t2UsdValue) {
799
+ return 1;
800
+ }
801
+ const t1Balance = userBalanceMap.get(t1.id);
802
+ const t2Balance = userBalanceMap.get(t2.id);
803
+ if (t1Balance && t2Balance) {
804
+ const balanceComparison = new import_decimal.default(t2Balance).cmp(t1Balance);
805
+ if (balanceComparison !== 0) return balanceComparison;
806
+ } else if (t1Balance && !t2Balance) {
807
+ return -1;
808
+ } else if (!t1Balance && t2Balance) {
809
+ return 1;
810
+ }
811
+ const t1HasBalance = userBalanceMap.has(t1.id);
812
+ const t2HasBalance = userBalanceMap.has(t2.id);
813
+ if (t1HasBalance && !t2HasBalance) return -1;
814
+ if (!t1HasBalance && t2HasBalance) return 1;
815
+ let t1Score = 0;
816
+ let t2Score = 0;
817
+ const t1Volume = (((_a2 = t1.stats24h) == null ? void 0 : _a2.buyVolume) || 0) + (((_b = t1.stats24h) == null ? void 0 : _b.sellVolume) || 0);
818
+ const t2Volume = (((_c = t2.stats24h) == null ? void 0 : _c.buyVolume) || 0) + (((_d = t2.stats24h) == null ? void 0 : _d.sellVolume) || 0);
819
+ if (t1Volume > t2Volume) t1Score += 1;
820
+ if (t2Volume > t1Volume) t2Score += 1;
821
+ if (checkIsUnknownToken(t1)) t1Score -= 2;
822
+ if (checkIsUnknownToken(t2)) t2Score -= 2;
823
+ return t2Score - t1Score;
824
+ });
825
+ };
826
+
827
+ // src/contexts/WalletPassthroughProvider.tsx
828
+ var import_wallet_adapter = require("@jup-ag/wallet-adapter");
829
+ var import_jotai3 = require("jotai");
830
+ var import_react5 = require("react");
831
+ var import_jsx_runtime6 = require("react/jsx-runtime");
832
+ var initialPassThrough = {
833
+ publicKey: null,
834
+ wallets: [],
835
+ wallet: null,
836
+ connect: () => __async(void 0, null, function* () {
837
+ }),
838
+ select: () => {
839
+ },
840
+ connecting: false,
841
+ connected: false,
842
+ disconnect: () => __async(void 0, null, function* () {
843
+ }),
844
+ autoConnect: false,
845
+ disconnecting: false,
846
+ sendTransaction: (transaction, connection, options) => __async(void 0, null, function* () {
847
+ return "";
848
+ }),
849
+ signTransaction: void 0,
850
+ signAllTransactions: void 0,
851
+ signMessage: void 0,
852
+ signIn: void 0
853
+ };
854
+ var WalletPassthroughContext = (0, import_react5.createContext)(initialPassThrough);
855
+ function useWalletPassThrough() {
856
+ return (0, import_react5.useContext)(WalletPassthroughContext);
857
+ }
858
+ var FromWalletAdapter = ({ children }) => {
859
+ const walletContextState = (0, import_wallet_adapter.useWallet)();
860
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(WalletPassthroughContext.Provider, { value: walletContextState, children });
861
+ };
862
+ var WalletPassthroughProvider = ({ children }) => {
863
+ var _a2;
864
+ const [atom3] = (0, import_jotai3.useAtom)(appProps);
865
+ const wallet = (_a2 = atom3 == null ? void 0 : atom3.passthroughWalletContextState) == null ? void 0 : _a2.wallet;
866
+ const walletPassthrough = (0, import_react5.useMemo)(() => {
867
+ return __spreadProps(__spreadValues(__spreadValues({}, initialPassThrough), atom3 == null ? void 0 : atom3.passthroughWalletContextState), {
868
+ disconnect: () => __async(void 0, null, function* () {
869
+ var _a3, _b;
870
+ try {
871
+ if ((_a3 = wallet == null ? void 0 : wallet.adapter) == null ? void 0 : _a3.disconnect) {
872
+ return (_b = wallet == null ? void 0 : wallet.adapter) == null ? void 0 : _b.disconnect();
873
+ }
874
+ } catch (error) {
875
+ console.log(error);
876
+ }
877
+ })
878
+ });
879
+ }, [atom3 == null ? void 0 : atom3.passthroughWalletContextState, wallet == null ? void 0 : wallet.adapter]);
880
+ if (!window.Jupiter.enableWalletPassthrough) {
881
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FromWalletAdapter, { children });
882
+ }
883
+ if (walletPassthrough) {
884
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(WalletPassthroughContext.Provider, { value: walletPassthrough, children });
885
+ }
886
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children });
887
+ };
888
+ var WalletPassthroughProvider_default = WalletPassthroughProvider;
889
+
890
+ // src/queries/useQuoteQuery.ts
891
+ var import_react_query = require("@tanstack/react-query");
892
+
893
+ // src/data/UltraSwapService.ts
894
+ var UltraSwapService = class {
895
+ constructor() {
896
+ this.BASE_URL = "https://ultra-api.jup.ag";
897
+ this.ROUTE = {
898
+ SWAP: `${this.BASE_URL}/execute`,
899
+ ORDER: `${this.BASE_URL}/order`,
900
+ ROUTERS: `${this.BASE_URL}/order/routers`,
901
+ BALANCES: `${this.BASE_URL}/balances`,
902
+ SHIELD: `${this.BASE_URL}/shield`
903
+ };
904
+ }
905
+ getQuote(params, signal) {
906
+ return __async(this, null, function* () {
907
+ const queryParams = new URLSearchParams(
908
+ Object.entries(params).filter(([_, value]) => value !== void 0).reduce(
909
+ (acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
910
+ [key]: value.toString()
911
+ }),
912
+ {}
913
+ )
914
+ );
915
+ const response = yield fetch(`${this.ROUTE.ORDER}?${queryParams.toString()}`, { signal });
916
+ if (!response.ok) {
917
+ throw response;
918
+ }
919
+ const result = yield response.json();
920
+ return result;
921
+ });
922
+ }
923
+ submitSwap(signedTransaction, requestId) {
924
+ return __async(this, null, function* () {
925
+ const response = yield fetch(this.ROUTE.SWAP, {
926
+ method: "POST",
927
+ headers: { "Content-Type": "application/json" },
928
+ body: JSON.stringify({ signedTransaction, requestId })
929
+ });
930
+ if (!response.ok) {
931
+ throw response;
932
+ }
933
+ const result = yield response.json();
934
+ return result;
935
+ });
936
+ }
937
+ getRouters() {
938
+ return __async(this, null, function* () {
939
+ const response = yield fetch(this.ROUTE.ROUTERS);
940
+ if (!response.ok) {
941
+ throw response;
942
+ }
943
+ const result = yield response.json();
944
+ return result;
945
+ });
946
+ }
947
+ getBalance(address, signal) {
948
+ return __async(this, null, function* () {
949
+ const response = yield fetch(`${this.ROUTE.BALANCES}/${address}`, { signal });
950
+ if (!response.ok) {
951
+ throw response;
952
+ }
953
+ const result = yield response.json();
954
+ return result;
955
+ });
956
+ }
957
+ getShield(mintAddress) {
958
+ return __async(this, null, function* () {
959
+ const response = yield fetch(`${this.ROUTE.SHIELD}?mints=${mintAddress.join(",")}`);
960
+ if (!response.ok) {
961
+ throw response;
962
+ }
963
+ const result = yield response.json();
964
+ return result;
965
+ });
966
+ }
967
+ };
968
+ var ultraSwapService = new UltraSwapService();
969
+
970
+ // src/entity/FormattedUltraQuoteResponse.ts
971
+ var import_web33 = require("@solana/web3.js");
972
+ var import_jsbi = __toESM(require("jsbi"));
973
+ var import_superstruct = require("superstruct");
974
+ var PublicKeyFromString = (0, import_superstruct.coerce)((0, import_superstruct.instance)(import_web33.PublicKey), (0, import_superstruct.string)(), (value) => new import_web33.PublicKey(value));
975
+ var AmountFromString = (0, import_superstruct.coerce)((0, import_superstruct.instance)(import_jsbi.default), (0, import_superstruct.string)(), (value) => import_jsbi.default.BigInt(value));
976
+ var NumberFromString = (0, import_superstruct.coerce)((0, import_superstruct.string)(), (0, import_superstruct.number)(), (value) => Number(value));
977
+ var SwapInfo = (0, import_superstruct.type)({
978
+ ammKey: PublicKeyFromString,
979
+ label: (0, import_superstruct.string)(),
980
+ inputMint: (0, import_superstruct.string)(),
981
+ outputMint: (0, import_superstruct.string)(),
982
+ inAmount: AmountFromString,
983
+ outAmount: AmountFromString,
984
+ feeAmount: AmountFromString,
985
+ feeMint: PublicKeyFromString
986
+ });
987
+ var RoutePlanStep = (0, import_superstruct.type)({
988
+ swapInfo: SwapInfo,
989
+ percent: (0, import_superstruct.number)()
990
+ });
991
+ var RoutePlanWithMetadata = (0, import_superstruct.array)(RoutePlanStep);
992
+ var FormattedUltraQuoteResponse = (0, import_superstruct.type)({
993
+ inputMint: PublicKeyFromString,
994
+ inAmount: AmountFromString,
995
+ outputMint: PublicKeyFromString,
996
+ outAmount: AmountFromString,
997
+ otherAmountThreshold: AmountFromString,
998
+ priceImpactPct: NumberFromString,
999
+ routePlan: RoutePlanWithMetadata,
1000
+ slippageBps: (0, import_superstruct.number)(),
1001
+ contextSlot: (0, import_superstruct.defaulted)((0, import_superstruct.number)(), 0),
1002
+ computedAutoSlippage: (0, import_superstruct.optional)((0, import_superstruct.number)()),
1003
+ transaction: (0, import_superstruct.nullable)((0, import_superstruct.string)()),
1004
+ swapType: (0, import_superstruct.string)(),
1005
+ gasless: (0, import_superstruct.boolean)(),
1006
+ requestId: (0, import_superstruct.string)(),
1007
+ prioritizationFeeLamports: (0, import_superstruct.optional)((0, import_superstruct.number)()),
1008
+ feeBps: (0, import_superstruct.number)(),
1009
+ router: (0, import_superstruct.string)()
1010
+ });
1011
+
1012
+ // src/queries/useQuoteQuery.ts
1013
+ var import_superstruct2 = require("superstruct");
1014
+ var useQuoteQuery = (params, shouldRefetch = true) => {
1015
+ const { amount } = params;
1016
+ return (0, import_react_query.useQuery)({
1017
+ queryKey: ["quote", params],
1018
+ queryFn: (_0) => __async(void 0, [_0], function* ({ signal }) {
1019
+ if (Number(amount) === 0) {
1020
+ return null;
1021
+ }
1022
+ try {
1023
+ const response = yield ultraSwapService.getQuote(params, signal);
1024
+ const quoteResponse = (0, import_superstruct2.create)(response, FormattedUltraQuoteResponse, "conver FormattedUltraQuoteResponse Error");
1025
+ return {
1026
+ quoteResponse,
1027
+ original: response
1028
+ };
1029
+ } catch (e) {
1030
+ if (e instanceof Response) {
1031
+ const errorObj = yield e.json();
1032
+ throw errorObj.error;
1033
+ }
1034
+ throw e;
1035
+ }
1036
+ }),
1037
+ refetchInterval: shouldRefetch ? 5e3 : false,
1038
+ retry: 0,
1039
+ enabled: Number(amount) > 0,
1040
+ keepPreviousData: Number(amount) > 0,
1041
+ onError: (error) => {
1042
+ console.error("useQuoteQuery", error);
1043
+ }
1044
+ });
1045
+ };
1046
+
1047
+ // src/queries/useUltraSwapMutation.ts
1048
+ var import_wallet_adapter2 = require("@jup-ag/wallet-adapter");
1049
+ var import_react_query2 = require("@tanstack/react-query");
1050
+ var import_buffer = require("buffer");
1051
+ var import_web34 = require("@solana/web3.js");
1052
+
1053
+ // src/entity/TransactionError.ts
1054
+ var TransactionError = class extends Error {
1055
+ constructor(message, txid, code, programIds, serializedTx) {
1056
+ super(message);
1057
+ this.name = "TransactionError";
1058
+ this.txid = txid;
1059
+ this.code = code;
1060
+ this.programIds = programIds;
1061
+ this.serializedTx = serializedTx;
1062
+ }
1063
+ };
1064
+
1065
+ // src/queries/useUltraSwapMutation.ts
1066
+ var UltraSwapError = class extends Error {
1067
+ constructor(message, type2, txid) {
1068
+ super(message);
1069
+ this.type = type2;
1070
+ this.txid = txid;
1071
+ }
1072
+ };
1073
+ function useUltraSwapMutation() {
1074
+ const { wallet, signTransaction } = useWalletPassThrough();
1075
+ return (0, import_react_query2.useMutation)({
1076
+ mutationFn: (_0) => __async(this, [_0], function* ({
1077
+ setTxStatus,
1078
+ setLastSwapResult,
1079
+ fromTokenInfo,
1080
+ toTokenInfo,
1081
+ quoteResponseMeta
1082
+ }) {
1083
+ const publicKey = wallet == null ? void 0 : wallet.adapter.publicKey;
1084
+ if (!signTransaction || !publicKey) {
1085
+ throw new UltraSwapError(
1086
+ "Wallet not connected, or missing wallet functions",
1087
+ "WALLET_SIGNING_FAILED" /* WALLET_SIGNING_FAILED */
1088
+ );
1089
+ }
1090
+ setTxStatus({
1091
+ txid: "",
1092
+ status: "pending-approval"
1093
+ });
1094
+ const selectedQuote = quoteResponseMeta.original;
1095
+ const { transaction, requestId } = selectedQuote;
1096
+ if (!transaction) throw new Error("Missing transaction");
1097
+ const based64tx = import_buffer.Buffer.from(transaction, "base64");
1098
+ const versionedTransaction = import_web34.VersionedTransaction.deserialize(new Uint8Array(based64tx));
1099
+ const signedTransaction = yield signTransaction(versionedTransaction);
1100
+ const serializedTransaction = import_buffer.Buffer.from(signedTransaction.serialize()).toString("base64");
1101
+ setTxStatus({
1102
+ txid: "",
1103
+ status: "sending"
1104
+ });
1105
+ const response = yield ultraSwapService.submitSwap(serializedTransaction, requestId);
1106
+ const { signature, status } = response;
1107
+ if (status === "Failed") {
1108
+ throw new UltraSwapError(response.error, "FAILED" /* FAILED */, signature);
1109
+ }
1110
+ const { inputAmountResult, outputAmountResult } = response;
1111
+ setTxStatus({
1112
+ txid: signature,
1113
+ status: "success"
1114
+ });
1115
+ setLastSwapResult({
1116
+ swapResult: {
1117
+ txid: signature,
1118
+ inputAddress: new import_web34.PublicKey(fromTokenInfo.id),
1119
+ outputAddress: new import_web34.PublicKey(toTokenInfo.id),
1120
+ inputAmount: Number(inputAmountResult),
1121
+ outputAmount: Number(outputAmountResult)
1122
+ },
1123
+ quoteReponse: quoteResponseMeta
1124
+ });
1125
+ return signature;
1126
+ }),
1127
+ onError: (error, variables) => __async(this, null, function* () {
1128
+ const { setTxStatus, setLastSwapResult, quoteResponseMeta } = variables;
1129
+ if (error instanceof import_wallet_adapter2.WalletSignTransactionError) {
1130
+ const message = error.message || error.error || "Transaction cancelled";
1131
+ setLastSwapResult({
1132
+ swapResult: {
1133
+ error: new TransactionError(message)
1134
+ },
1135
+ quoteReponse: quoteResponseMeta
1136
+ });
1137
+ return;
1138
+ }
1139
+ if (error instanceof Error) {
1140
+ setLastSwapResult({
1141
+ swapResult: {
1142
+ error: new TransactionError(error.message)
1143
+ },
1144
+ quoteReponse: quoteResponseMeta
1145
+ });
1146
+ return;
1147
+ }
1148
+ if ("json" in error) {
1149
+ const json = yield error.json();
1150
+ setLastSwapResult({
1151
+ swapResult: {
1152
+ error: new TransactionError(json.error || "Unknown error")
1153
+ },
1154
+ quoteReponse: quoteResponseMeta
1155
+ });
1156
+ setTxStatus({
1157
+ txid: json.txid || "",
1158
+ status: "fail"
1159
+ });
1160
+ }
1161
+ })
1162
+ });
1163
+ }
1164
+
1165
+ // src/hooks/useBalances.ts
1166
+ var import_react_query3 = require("@tanstack/react-query");
1167
+ var import_react6 = require("react");
1168
+ var ULTRA_NATIVESOL_ID = "SOL";
1169
+ var WSOL_ID = WRAPPED_SOL_MINT.toString();
1170
+ var WRAPPED_SOL_ID = "wSOL";
1171
+ function combineSolAmounts(data) {
1172
+ const balances = structuredClone(data);
1173
+ if (balances[WSOL_ID]) {
1174
+ balances[WRAPPED_SOL_ID] = __spreadValues({}, balances[WSOL_ID]);
1175
+ }
1176
+ if (balances[ULTRA_NATIVESOL_ID]) {
1177
+ balances[WSOL_ID] = __spreadValues({}, balances[ULTRA_NATIVESOL_ID]);
1178
+ }
1179
+ return balances;
1180
+ }
1181
+ var useBalances = () => {
1182
+ const { publicKey } = useWalletPassThrough();
1183
+ const address = (0, import_react6.useMemo)(() => {
1184
+ if (!publicKey) return "";
1185
+ return publicKey.toString();
1186
+ }, [publicKey]);
1187
+ return (0, import_react_query3.useQuery)({
1188
+ queryKey: ["ultra", "balances", address],
1189
+ queryFn: (_0) => __async(void 0, [_0], function* ({ signal }) {
1190
+ return yield ultraSwapService.getBalance(address, signal);
1191
+ }),
1192
+ enabled: !!address && getPluginInView(),
1193
+ cacheTime: 2e4,
1194
+ staleTime: 2e4,
1195
+ refetchOnWindowFocus: false,
1196
+ refetchIntervalInBackground: false,
1197
+ refetchOnMount: false,
1198
+ select: (data) => combineSolAmounts(data)
1199
+ });
1200
+ };
1201
+
1202
+ // src/hooks/useAsset.ts
1203
+ var import_react_query4 = require("@tanstack/react-query");
1204
+
1205
+ // src/contexts/SearchService.ts
1206
+ var BASE_URL = "https://datapi.jup.ag";
1207
+ var SearchService = class {
1208
+ constructor() {
1209
+ this.ROUTE = {
1210
+ SEARCH: `${BASE_URL}/v1/assets`
1211
+ };
1212
+ }
1213
+ search(query) {
1214
+ return __async(this, null, function* () {
1215
+ const response = yield fetch(`${this.ROUTE.SEARCH}/search?query=${query}`, {
1216
+ credentials: "include"
1217
+ });
1218
+ const data = yield response.json();
1219
+ return data;
1220
+ });
1221
+ }
1222
+ };
1223
+ var searchService = new SearchService();
1224
+
1225
+ // src/hooks/useAsset.ts
1226
+ var ASSET_QUERY_KEY = ["search", "assets"];
1227
+ var useAsset = (mint) => {
1228
+ return (0, import_react_query4.useQuery)({
1229
+ queryKey: [...ASSET_QUERY_KEY, mint],
1230
+ queryFn: () => searchService.search(mint),
1231
+ enabled: !!mint,
1232
+ staleTime: Infinity,
1233
+ select: (data) => data[0]
1234
+ });
1235
+ };
1236
+
1237
+ // src/contexts/SwapContext.tsx
1238
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1239
+ var SwapContext = (0, import_react7.createContext)(null);
1240
+ function useSwapContext() {
1241
+ const context = (0, import_react7.useContext)(SwapContext);
1242
+ if (!context) throw new Error("Missing SwapContextProvider");
1243
+ return context;
1244
+ }
1245
+ var INITIAL_FORM = {
1246
+ fromMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
1247
+ toMint: WRAPPED_SOL_MINT.toString(),
1248
+ fromValue: "",
1249
+ toValue: ""
1250
+ };
1251
+ var DEFAULT_FORM_PROPS = {
1252
+ swapMode: "ExactIn"
1253
+ };
1254
+ var SwapContextProvider = (props) => {
1255
+ var _a2, _b;
1256
+ const { displayMode, scriptDomain: scriptDomain2, formProps: originalFormProps, children, enableWalletPassthrough } = props;
1257
+ const { screen: screen2 } = useScreenState();
1258
+ const { wallet } = useWalletPassThrough();
1259
+ const { refetch: refetchBalances } = useBalances();
1260
+ const isToPairFocused = (0, import_react7.useRef)(false);
1261
+ const walletPublicKey = (0, import_react7.useMemo)(() => {
1262
+ var _a3;
1263
+ return (_a3 = wallet == null ? void 0 : wallet.adapter.publicKey) == null ? void 0 : _a3.toString();
1264
+ }, [wallet == null ? void 0 : wallet.adapter.publicKey]);
1265
+ const formProps = (0, import_react7.useMemo)(() => __spreadValues(__spreadValues({}, DEFAULT_FORM_PROPS), originalFormProps), [originalFormProps]);
1266
+ const [form, setForm] = (0, import_react7.useState)({
1267
+ fromMint: (_a2 = formProps == null ? void 0 : formProps.initialInputMint) != null ? _a2 : "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
1268
+ toMint: (_b = formProps == null ? void 0 : formProps.initialOutputMint) != null ? _b : WRAPPED_SOL_MINT.toString(),
1269
+ fromValue: "",
1270
+ toValue: ""
1271
+ });
1272
+ const { data: fromTokenInfo } = useAsset(form.fromMint);
1273
+ const { data: toTokenInfo } = useAsset(form.toMint);
1274
+ (0, import_react7.useEffect)(() => {
1275
+ if (formProps.fixedMint) {
1276
+ if (formProps.fixedMint !== formProps.initialInputMint && formProps.fixedMint !== formProps.initialOutputMint) {
1277
+ console.error("fixedMint is not the same as the initial input or output mint");
1278
+ }
1279
+ }
1280
+ }, [formProps.fixedMint, formProps.initialInputMint, formProps.initialOutputMint]);
1281
+ const [errors, setErrors] = (0, import_react7.useState)({});
1282
+ const setupInitialAmount = (0, import_react7.useCallback)(() => {
1283
+ if (!(formProps == null ? void 0 : formProps.initialAmount) || !fromTokenInfo || !toTokenInfo) return;
1284
+ const toUiAmount = () => {
1285
+ if (!formProps.initialAmount) {
1286
+ return;
1287
+ }
1288
+ if (!fromTokenInfo) return;
1289
+ const value = new import_decimal2.default(formProps.initialAmount).div(Math.pow(10, fromTokenInfo.decimals)).toFixed();
1290
+ return value;
1291
+ };
1292
+ setTimeout(() => {
1293
+ setForm((prev) => {
1294
+ var _a3;
1295
+ return __spreadProps(__spreadValues({}, prev), { fromValue: (_a3 = toUiAmount()) != null ? _a3 : "" });
1296
+ });
1297
+ }, 0);
1298
+ }, [formProps.initialAmount, fromTokenInfo, toTokenInfo]);
1299
+ (0, import_react7.useEffect)(() => {
1300
+ setupInitialAmount();
1301
+ }, [formProps.initialAmount, setupInitialAmount]);
1302
+ const debouncedForm = useDebounce(form, 250);
1303
+ const amount = (0, import_react7.useMemo)(() => {
1304
+ if (!fromTokenInfo || !toTokenInfo) {
1305
+ return import_jsbi2.default.BigInt(0);
1306
+ }
1307
+ if (isToPairFocused.current === true) {
1308
+ if (!debouncedForm.toValue || !hasNumericValue(debouncedForm.toValue)) {
1309
+ return import_jsbi2.default.BigInt(0);
1310
+ }
1311
+ return import_jsbi2.default.BigInt(new import_decimal2.default(debouncedForm.toValue).mul(Math.pow(10, toTokenInfo.decimals)).floor().toFixed());
1312
+ } else {
1313
+ if (!debouncedForm.fromValue || !hasNumericValue(debouncedForm.fromValue)) {
1314
+ return import_jsbi2.default.BigInt(0);
1315
+ }
1316
+ return import_jsbi2.default.BigInt(
1317
+ new import_decimal2.default(debouncedForm.fromValue).mul(Math.pow(10, fromTokenInfo.decimals)).floor().toFixed()
1318
+ );
1319
+ }
1320
+ }, [debouncedForm.fromValue, debouncedForm.toValue, fromTokenInfo, toTokenInfo]);
1321
+ const [txStatus, setTxStatus] = (0, import_react7.useState)(void 0);
1322
+ const {
1323
+ data: ogQuoteResponseMeta,
1324
+ isFetching: loading,
1325
+ error: quoteError,
1326
+ refetch: refresh,
1327
+ errorUpdatedAt,
1328
+ dataUpdatedAt,
1329
+ isSuccess,
1330
+ isError
1331
+ } = useQuoteQuery(
1332
+ {
1333
+ inputMint: debouncedForm.fromMint,
1334
+ outputMint: debouncedForm.toMint,
1335
+ amount: amount.toString(),
1336
+ taker: walletPublicKey,
1337
+ swapMode: isToPairFocused.current ? "ExactOut" : "ExactIn",
1338
+ referralAccount: formProps.referralAccount,
1339
+ referralFee: formProps.referralFee
1340
+ },
1341
+ // Stop refetching when transaction is in progress
1342
+ !txStatus
1343
+ );
1344
+ (0, import_react7.useEffect)(() => {
1345
+ if (quoteError) {
1346
+ if (typeof quoteError === "string") {
1347
+ setErrors({
1348
+ fromValue: { title: quoteError, message: "" }
1349
+ });
1350
+ return;
1351
+ }
1352
+ setErrors({
1353
+ fromValue: { title: "Error fetching route. Try changing your input", message: "" }
1354
+ });
1355
+ return;
1356
+ }
1357
+ setErrors({});
1358
+ }, [quoteError]);
1359
+ const lastRefreshTimestamp = (0, import_react7.useMemo)(() => {
1360
+ if (loading) {
1361
+ return (/* @__PURE__ */ new Date()).getTime();
1362
+ }
1363
+ if (isError) {
1364
+ return new Date(errorUpdatedAt).getTime();
1365
+ }
1366
+ if (isSuccess) {
1367
+ return new Date(dataUpdatedAt).getTime();
1368
+ }
1369
+ return void 0;
1370
+ }, [loading, errorUpdatedAt, dataUpdatedAt, isError, isSuccess]);
1371
+ const [quoteResponseMeta, setQuoteResponseMeta] = (0, import_react7.useState)(null);
1372
+ (0, import_react7.useEffect)(() => {
1373
+ if (!ogQuoteResponseMeta) {
1374
+ setQuoteResponseMeta(null);
1375
+ return;
1376
+ }
1377
+ setQuoteResponseMeta(ogQuoteResponseMeta);
1378
+ }, [ogQuoteResponseMeta]);
1379
+ (0, import_react7.useEffect)(() => {
1380
+ if (!form.fromValue && !form.toValue && !quoteResponseMeta) {
1381
+ setForm((prev) => __spreadProps(__spreadValues({}, prev), { fromValue: "", toValue: "" }));
1382
+ return;
1383
+ }
1384
+ setForm((prev) => {
1385
+ const newValue = __spreadValues({}, prev);
1386
+ if (!fromTokenInfo || !toTokenInfo) return prev;
1387
+ const { outAmount, inAmount } = (quoteResponseMeta == null ? void 0 : quoteResponseMeta.quoteResponse) || {};
1388
+ if (!isToPairFocused.current) {
1389
+ newValue.toValue = outAmount ? new import_decimal2.default(outAmount.toString()).div(__pow(10, toTokenInfo.decimals)).toFixed() : "";
1390
+ } else {
1391
+ newValue.fromValue = inAmount ? new import_decimal2.default(inAmount.toString()).div(__pow(10, fromTokenInfo.decimals)).toFixed() : "";
1392
+ }
1393
+ return newValue;
1394
+ });
1395
+ }, [form.fromValue, form.toValue, fromTokenInfo, quoteResponseMeta, toTokenInfo]);
1396
+ const [lastSwapResult, setLastSwapResult] = (0, import_react7.useState)(null);
1397
+ const { mutateAsync: ultraSwapMutation } = useUltraSwapMutation();
1398
+ const onSubmit = (0, import_react7.useCallback)(() => __async(void 0, null, function* () {
1399
+ if (!walletPublicKey || !(wallet == null ? void 0 : wallet.adapter) || !quoteResponseMeta) {
1400
+ return null;
1401
+ }
1402
+ setTxStatus({
1403
+ txid: "",
1404
+ status: "loading"
1405
+ });
1406
+ try {
1407
+ if (!fromTokenInfo) throw new Error("Missing fromTokenInfo");
1408
+ if (!toTokenInfo) throw new Error("Missing toTokenInfo");
1409
+ yield ultraSwapMutation({
1410
+ quoteResponseMeta,
1411
+ fromTokenInfo,
1412
+ toTokenInfo,
1413
+ setTxStatus,
1414
+ setLastSwapResult
1415
+ });
1416
+ } catch (error) {
1417
+ console.log("Swap error", error);
1418
+ }
1419
+ }), [walletPublicKey, wallet == null ? void 0 : wallet.adapter, quoteResponseMeta, ultraSwapMutation, fromTokenInfo, toTokenInfo]);
1420
+ const reset = (0, import_react7.useCallback)(
1421
+ ({ resetValues } = { resetValues: false }) => {
1422
+ if (resetValues) {
1423
+ setForm(INITIAL_FORM);
1424
+ setupInitialAmount();
1425
+ } else {
1426
+ setForm((prev) => __spreadProps(__spreadValues({}, prev), { toValue: "" }));
1427
+ }
1428
+ setQuoteResponseMeta(null);
1429
+ setErrors({});
1430
+ setLastSwapResult(null);
1431
+ setTxStatus(void 0);
1432
+ refetchBalances();
1433
+ },
1434
+ [refetchBalances, setupInitialAmount]
1435
+ );
1436
+ (0, import_react7.useEffect)(() => {
1437
+ if (typeof window.Jupiter.onFormUpdate === "function") {
1438
+ window.Jupiter.onFormUpdate(form);
1439
+ }
1440
+ }, [form]);
1441
+ (0, import_react7.useEffect)(() => {
1442
+ if (typeof window.Jupiter.onScreenUpdate === "function") {
1443
+ window.Jupiter.onScreenUpdate(screen2);
1444
+ }
1445
+ }, [screen2]);
1446
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1447
+ SwapContext.Provider,
1448
+ {
1449
+ value: {
1450
+ form,
1451
+ setForm,
1452
+ errors,
1453
+ setErrors,
1454
+ fromTokenInfo,
1455
+ toTokenInfo,
1456
+ quoteResponseMeta,
1457
+ setQuoteResponseMeta,
1458
+ onSubmit,
1459
+ lastSwapResult,
1460
+ reset,
1461
+ refresh,
1462
+ loading,
1463
+ quoteError,
1464
+ lastRefreshTimestamp,
1465
+ isToPairFocused,
1466
+ displayMode,
1467
+ formProps,
1468
+ scriptDomain: scriptDomain2,
1469
+ swapping: {
1470
+ txStatus
1471
+ },
1472
+ enableWalletPassthrough
1473
+ },
1474
+ children
1475
+ }
1476
+ );
1477
+ };
1478
+
1479
+ // src/components/Header.tsx
1480
+ var import_react11 = require("react");
1481
+
1482
+ // src/icons/RefreshSVG.tsx
1483
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1484
+ var RefreshSVG = ({ width = "12", height = "12" }) => {
1485
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { width, height, viewBox: "0 0 12 12", fill: "inherit", xmlns: "http://www.w3.org/2000/svg", children: [
1486
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("g", { clipPath: "url(#clip0_841_4053)", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1487
+ "path",
1488
+ {
1489
+ d: "M11.6466 4.23513V0.706082L10.4111 1.94156C9.3173 0.741165 7.72912 0 6 0C2.6827 0 0 2.6827 0 6C0 9.3173 2.68203 12 6 12C7.69405 12 9.21142 11.2939 10.3059 10.165L9.31797 9.14128C8.50601 10.0234 7.30561 10.5879 6 10.5879C3.45892 10.5879 1.41216 8.5411 1.41216 6.00002C1.41216 3.45894 3.45892 1.41218 6 1.41218C7.34135 1.41218 8.57615 2.01238 9.42317 2.92954L8.11757 4.23515L11.6466 4.23513Z",
1490
+ fill: "inherit"
1491
+ }
1492
+ ) }),
1493
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("clipPath", { id: "clip0_841_4053", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("rect", { width, height, fill: "white" }) }) })
1494
+ ] });
1495
+ };
1496
+ var RefreshSVG_default = RefreshSVG;
1497
+
1498
+ // src/components/WalletComponents/components/WalletModalButton.tsx
1499
+ var import_react8 = require("react");
1500
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1501
+ var WalletModalButton = () => {
1502
+ const { connecting } = useWalletPassThrough();
1503
+ const { setScreen } = useScreenState();
1504
+ const handleClick = (0, import_react8.useCallback)((event) => {
1505
+ if (window.Jupiter.enableWalletPassthrough && window.Jupiter.onRequestConnectWallet) {
1506
+ window.Jupiter.onRequestConnectWallet();
1507
+ } else {
1508
+ setScreen("Wallet");
1509
+ }
1510
+ }, [setScreen]);
1511
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1512
+ "button",
1513
+ {
1514
+ type: "button",
1515
+ className: "py-2 px-3 h-7 flex items-center rounded-2xl text-xs bg-interactive text-primary-text",
1516
+ onClick: handleClick,
1517
+ children: connecting ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Connecting..." }) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Connect Wallet" }) })
1518
+ }
1519
+ );
1520
+ };
1521
+
1522
+ // src/components/WalletComponents/WalletButton.tsx
1523
+ var import_react9 = require("react");
1524
+
1525
+ // src/components/CurrentUserBadge.tsx
1526
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1527
+ var CurrentUserBadge = () => {
1528
+ var _a2;
1529
+ const { publicKey, wallet } = useWalletPassThrough();
1530
+ if (!wallet || !publicKey) {
1531
+ return null;
1532
+ }
1533
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex items-center bg-interactive py-2 px-3 rounded-2xl h-7", children: [
1534
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1535
+ "div",
1536
+ {
1537
+ className: "w-4 h-4 rounded-full bg-interactive dark:bg-white-10 flex justify-center items-center",
1538
+ style: { position: "relative" },
1539
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("img", { alt: "Wallet logo", width: 16, height: 16, src: (_a2 = wallet == null ? void 0 : wallet.adapter) == null ? void 0 : _a2.icon })
1540
+ }
1541
+ ),
1542
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "ml-2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "text-xs text-primary-text", children: shortenAddress(`${publicKey}`, 2) }) })
1543
+ ] });
1544
+ };
1545
+
1546
+ // src/components/WalletComponents/WalletButton.tsx
1547
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1548
+ var WalletButton = () => {
1549
+ const { publicKey, connected, connecting, disconnect } = useWalletPassThrough();
1550
+ const [active, setActive] = (0, import_react9.useState)(false);
1551
+ const ref = (0, import_react9.useRef)(null);
1552
+ const { screen: screen2, setScreen } = useScreenState();
1553
+ const base58 = (0, import_react9.useMemo)(() => publicKey == null ? void 0 : publicKey.toBase58(), [publicKey]);
1554
+ const onClickDisconnect = () => {
1555
+ setActive(false);
1556
+ disconnect();
1557
+ };
1558
+ const closePopup = () => {
1559
+ setActive(false);
1560
+ };
1561
+ useOutsideClick(ref, closePopup);
1562
+ if (!connected && !connecting || !base58) {
1563
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { onClick: () => setScreen("Wallet"), className: "text-primary-text", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(WalletModalButton, {}) });
1564
+ }
1565
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "cursor-pointer relative", children: [
1566
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { onClick: () => setActive(!active), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CurrentUserBadge, {}) }),
1567
+ screen2 === "Initial" ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1568
+ "ul",
1569
+ {
1570
+ "aria-label": "dropdown-list",
1571
+ className: active ? "absolute block top-10 right-0 text-sm bg-black rounded-lg p-2 text-primary-text dark:bg-white dark:text-black" : "hidden",
1572
+ ref,
1573
+ role: "menu",
1574
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("li", { onClick: onClickDisconnect, role: "menuitem", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { children: "Disconnect" }) })
1575
+ }
1576
+ ) : null
1577
+ ] });
1578
+ };
1579
+
1580
+ // src/contexts/BrandingProvider.tsx
1581
+ var import_react10 = require("react");
1582
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1583
+ var BrandingContext = (0, import_react10.createContext)({});
1584
+ var BrandingProvider = (props) => {
1585
+ const { branding, children } = props;
1586
+ const logoUri = (0, import_react10.useMemo)(() => (branding == null ? void 0 : branding.logoUri) ? branding.logoUri : "https://jup.ag/svg/jupiter-logo.svg", [branding == null ? void 0 : branding.logoUri]);
1587
+ const name = (0, import_react10.useMemo)(() => (branding == null ? void 0 : branding.name) ? branding.name : "Jupiter", [branding == null ? void 0 : branding.name]);
1588
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(BrandingContext.Provider, { value: { logoUri, name }, children });
1589
+ };
1590
+ function useBranding() {
1591
+ const context = (0, import_react10.useContext)(BrandingContext);
1592
+ return context;
1593
+ }
1594
+
1595
+ // src/components/Header.tsx
1596
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1597
+ var Header = () => {
1598
+ const { refresh, enableWalletPassthrough } = useSwapContext();
1599
+ const { refetch: refetchBalances } = useBalances();
1600
+ const { logoUri, name } = useBranding();
1601
+ const onRefresh = (0, import_react11.useCallback)(() => {
1602
+ refetchBalances();
1603
+ refresh();
1604
+ }, [refetchBalances, refresh]);
1605
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "mt-2 h-7 pl-3 pr-2", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "w-full flex items-center justify-between ", children: [
1606
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex items-center space-x-2", children: [
1607
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("img", { src: logoUri, alt: "Plugin Branding", className: "w-6 h-6" }),
1608
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "font-bold text-sm text-primary-text", children: name })
1609
+ ] }),
1610
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex space-x-1 items-center", children: [
1611
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1612
+ "button",
1613
+ {
1614
+ type: "button",
1615
+ className: "p-2 h-7 w-7 flex items-center justify-center rounded-full bg-interactive text-primary-text fill-current",
1616
+ onClick: onRefresh,
1617
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(RefreshSVG_default, {})
1618
+ }
1619
+ ),
1620
+ !enableWalletPassthrough && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(WalletButton, {})
1621
+ ] })
1622
+ ] }) });
1623
+ };
1624
+ var Header_default = Header;
1625
+
1626
+ // src/components/screens/InitialScreen.tsx
1627
+ var import_react24 = require("react");
1628
+
1629
+ // src/components/Form.tsx
1630
+ var import_react19 = require("react");
1631
+ var import_react_number_format = require("react-number-format");
1632
+
1633
+ // src/misc/constants.ts
1634
+ var import_web35 = require("@solana/web3.js");
1635
+ var MINIMUM_SOL_BALANCE = 0.01;
1636
+ var ROUTE_CACHE_DURATION = 2e4;
1637
+ var MAX_INPUT_LIMIT = 1e14;
1638
+ var WRAPPED_SOL_MINT2 = new import_web35.PublicKey("So11111111111111111111111111111111111111112");
1639
+
1640
+ // src/components/Coinbalance.tsx
1641
+ var React6 = __toESM(require("react"));
1642
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1643
+ var CoinBalance = (props) => {
1644
+ const { data: balances } = useBalances();
1645
+ const { connected } = useWalletPassThrough();
1646
+ const formattedBalance = React6.useMemo(() => {
1647
+ if (!balances) {
1648
+ return "0";
1649
+ }
1650
+ const accBalanceObj = balances[props.mintAddress];
1651
+ if (!accBalanceObj) return "0";
1652
+ const balance = accBalanceObj.uiAmount.toString();
1653
+ return balance;
1654
+ }, [balances, props.mintAddress]);
1655
+ if (props.hideZeroBalance && (formattedBalance === "0" || !formattedBalance)) return null;
1656
+ if (!connected) return null;
1657
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { translate: "no", children: formattedBalance });
1658
+ };
1659
+ var Coinbalance_default = CoinBalance;
1660
+
1661
+ // src/components/JupButton.tsx
1662
+ var import_react12 = __toESM(require("react"));
1663
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1664
+ var JupButton = import_react12.default.forwardRef(
1665
+ ({ onClick, disabled, children, className = "", size = "md" }, ref) => {
1666
+ const contentClass = (() => {
1667
+ if (size === "sm") {
1668
+ return "px-4 py-2.5 text-xs";
1669
+ }
1670
+ if (size === "md") {
1671
+ return "px-4 py-3 text-sm font-semibold";
1672
+ }
1673
+ if (size === "lg") {
1674
+ return "p-5 text-md font-semibold";
1675
+ }
1676
+ })();
1677
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1678
+ "button",
1679
+ {
1680
+ type: "button",
1681
+ ref,
1682
+ className: cn("rounded-xl", {
1683
+ relative: true,
1684
+ "opacity-50 cursor-not-allowed": disabled,
1685
+ [className]: true
1686
+ }),
1687
+ disabled,
1688
+ onClick,
1689
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: `${contentClass} h-full w-full leading-none`, children })
1690
+ }
1691
+ );
1692
+ }
1693
+ );
1694
+ JupButton.displayName = "JupButton";
1695
+ var JupButton_default = JupButton;
1696
+
1697
+ // src/components/TokenIcon.tsx
1698
+ var React8 = __toESM(require("react"));
1699
+
1700
+ // src/icons/WarningIcon.tsx
1701
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1702
+ var WarningIcon = (props) => {
1703
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("svg", __spreadProps(__spreadValues({ width: "12", height: "12", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, props), { children: [
1704
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("rect", { x: "8", y: "6", width: "4", height: "10", fill: "white" }),
1705
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1706
+ "path",
1707
+ {
1708
+ fillRule: "evenodd",
1709
+ clipRule: "evenodd",
1710
+ d: "M17.8634 15.6962C17.5539 15.1565 11.3038 4.37041 10.7692 3.44957C10.4179 2.8452 9.58075 2.85511 9.22912 3.44957C8.83702 4.11227 2.55515 14.9396 2.11839 15.7235C1.7984 16.2978 2.15189 17.0509 2.88009 17.0509H17.0974C17.7586 17.0509 18.2502 16.3695 17.8635 15.696L17.8634 15.6962ZM10.0005 15.6277C9.50937 15.6277 9.11108 15.2297 9.11108 14.7383C9.11108 14.247 9.50937 13.8489 10.0005 13.8489C10.4918 13.8489 10.8899 14.247 10.8899 14.7383C10.8899 15.2297 10.4918 15.6277 10.0005 15.6277ZM10.5341 12.7817C10.5341 13.1374 10.3562 13.3154 10.0005 13.3154C9.64474 13.3154 9.46681 13.1375 9.46681 12.7817L8.93314 7.62324C8.93314 7.08957 9.28887 6.5559 10.0005 6.5559C10.7119 6.5559 11.0678 7.08957 11.0678 7.62324L10.5341 12.7817Z",
1711
+ fill: "currentColor"
1712
+ }
1713
+ )
1714
+ ] }));
1715
+ };
1716
+ var WarningIcon_default = WarningIcon;
1717
+
1718
+ // src/components/TokenIcon.tsx
1719
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1720
+ function genImageTransformURL(url) {
1721
+ const qs = new URLSearchParams({
1722
+ w: "48",
1723
+ h: "48",
1724
+ url: (() => {
1725
+ if (url.endsWith("/")) return url.slice(0, -1);
1726
+ return url;
1727
+ })()
1728
+ });
1729
+ return `https://wsrv.nl/?${qs.toString()}`;
1730
+ }
1731
+ var UnknownTokenImage = ({ width, height, imageUrl }) => {
1732
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
1733
+ "svg",
1734
+ {
1735
+ width,
1736
+ height,
1737
+ viewBox: "0 0 24 24",
1738
+ fill: "none",
1739
+ xmlns: "http://www.w3.org/2000/svg",
1740
+ "data-url": imageUrl,
1741
+ "data-transformed-url": genImageTransformURL((imageUrl == null ? void 0 : imageUrl.toString()) || ""),
1742
+ children: [
1743
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1744
+ "path",
1745
+ {
1746
+ d: "M12 0C18.6271 0 24 5.37288 24 12C24 18.6271 18.6269 24 12 24C5.37312 24 0 18.6286 0 12C0 5.37144 5.37216 0 12 0Z",
1747
+ fill: "#23C1AA"
1748
+ }
1749
+ ),
1750
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1751
+ "path",
1752
+ {
1753
+ d: "M10.79 14.55H12.89V14.355C12.89 13.925 13.01 13.55 13.25 13.23C13.49 12.91 13.765 12.605 14.075 12.315C14.315 12.085 14.545 11.85 14.765 11.61C14.985 11.36 15.165 11.09 15.305 10.8C15.455 10.5 15.53 10.16 15.53 9.78C15.53 9.25 15.395 8.75 15.125 8.28C14.855 7.8 14.45 7.41 13.91 7.11C13.38 6.8 12.725 6.645 11.945 6.645C11.305 6.645 10.725 6.765 10.205 7.005C9.69504 7.245 9.27504 7.575 8.94504 7.995C8.62504 8.415 8.42004 8.905 8.33004 9.465L10.415 9.99C10.475 9.61 10.64 9.31 10.91 9.09C11.19 8.86 11.515 8.745 11.885 8.745C12.315 8.745 12.64 8.85 12.86 9.06C13.09 9.26 13.205 9.52 13.205 9.84C13.205 10.15 13.09 10.425 12.86 10.665C12.63 10.895 12.37 11.155 12.08 11.445C11.77 11.765 11.475 12.14 11.195 12.57C10.925 13 10.79 13.545 10.79 14.205V14.55ZM10.73 18H12.98V15.75H10.73V18Z",
1754
+ fill: "white"
1755
+ }
1756
+ )
1757
+ ]
1758
+ }
1759
+ );
1760
+ };
1761
+ var TokenIcon = ({
1762
+ info,
1763
+ width = 32,
1764
+ height = 32,
1765
+ enableUnknownTokenWarning = true
1766
+ }) => {
1767
+ const [transformerHasError, setTransformerHasError] = React8.useState(false);
1768
+ const [hasError, setHasError] = React8.useState(false);
1769
+ React8.useEffect(() => {
1770
+ setHasError(false);
1771
+ }, [info]);
1772
+ const imageUrl = React8.useMemo(() => {
1773
+ var _a2;
1774
+ try {
1775
+ if (!(info == null ? void 0 : info.icon)) return void 0;
1776
+ if (typeof window !== "undefined" && ((_a2 = info == null ? void 0 : info.icon) == null ? void 0 : _a2.startsWith("/")))
1777
+ return new URL(window.location.origin + info.icon);
1778
+ return (info == null ? void 0 : info.icon) ? new URL(info.icon) : void 0;
1779
+ } catch (error) {
1780
+ return void 0;
1781
+ }
1782
+ }, [info == null ? void 0 : info.icon]);
1783
+ const isUnknown = React8.useMemo(() => {
1784
+ if (!enableUnknownTokenWarning) return false;
1785
+ if (info) {
1786
+ return checkIsUnknownToken(info);
1787
+ }
1788
+ }, [enableUnknownTokenWarning, info]);
1789
+ const ImageComp = React8.useMemo(() => {
1790
+ if (!imageUrl || !info || hasError && transformerHasError) {
1791
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(UnknownTokenImage, { width, height, imageUrl: (imageUrl == null ? void 0 : imageUrl.toString()) || "" });
1792
+ }
1793
+ if (transformerHasError) {
1794
+ return (
1795
+ // eslint-disable-next-line
1796
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1797
+ "img",
1798
+ {
1799
+ src: info.icon,
1800
+ alt: info.symbol,
1801
+ width,
1802
+ height,
1803
+ style: { maxWidth: width, maxHeight: height },
1804
+ className: `object-cover rounded-full`,
1805
+ onError: () => {
1806
+ setHasError(true);
1807
+ }
1808
+ }
1809
+ )
1810
+ );
1811
+ }
1812
+ return (
1813
+ // eslint-disable-next-line
1814
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1815
+ "img",
1816
+ {
1817
+ src: genImageTransformURL(info.icon || ""),
1818
+ alt: info.symbol,
1819
+ width,
1820
+ height,
1821
+ style: { maxWidth: width, maxHeight: height },
1822
+ className: `object-cover rounded-full`,
1823
+ onError: () => {
1824
+ setTransformerHasError(true);
1825
+ }
1826
+ }
1827
+ )
1828
+ );
1829
+ }, [hasError, height, imageUrl, info, transformerHasError, width]);
1830
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "relative", children: [
1831
+ ImageComp,
1832
+ isUnknown && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1833
+ WarningIcon_default,
1834
+ {
1835
+ width: Math.max(width * 0.6, 16),
1836
+ height: Math.max(height * 0.6, 16),
1837
+ className: "absolute -p-1 text-warning -bottom-[2px] -right-[5px]"
1838
+ }
1839
+ )
1840
+ ] });
1841
+ };
1842
+ var TokenIcon_default = TokenIcon;
1843
+
1844
+ // src/icons/WalletIcon.tsx
1845
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1846
+ var WalletIcon = ({ width = 20, height = 20 }) => {
1847
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("svg", { width, height, viewBox: "0 0 11 11", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1848
+ "path",
1849
+ {
1850
+ d: "M2.0625 11H10.3125V2.75H8.59375V0H2.0625C0.923158 0 0 0.923158 0 2.0625V8.9375C0 10.0768 0.923158 11 2.0625 11ZM8.9375 4.125V9.625H2.0625C1.6825 9.625 1.375 9.3175 1.375 8.9375V4.00486C1.59589 4.08408 1.82818 4.12437 2.0625 4.12504L8.9375 4.125ZM2.0625 1.375H7.21875V2.75H2.0625C1.6825 2.75 1.375 2.4425 1.375 2.0625C1.375 1.6825 1.6825 1.375 2.0625 1.375Z",
1851
+ fill: "white",
1852
+ fillOpacity: "0.25"
1853
+ }
1854
+ ) });
1855
+ };
1856
+ var WalletIcon_default = WalletIcon;
1857
+
1858
+ // src/components/CoinBalanceUSD.tsx
1859
+ var import_decimal3 = __toESM(require("decimal.js"));
1860
+ var import_react13 = require("react");
1861
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1862
+ var CoinBalanceUSD = (props) => {
1863
+ const { tokenInfo, amount, maxDecimals, prefix = "" } = props;
1864
+ const tokenPrice = tokenInfo.usdPrice || 0;
1865
+ const amountInUSD = (0, import_react13.useMemo)(() => {
1866
+ if (!amount || !hasNumericValue(amount)) return new import_decimal3.default(0);
1867
+ return new import_decimal3.default(amount).mul(tokenPrice);
1868
+ }, [amount, tokenPrice]);
1869
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
1870
+ prefix,
1871
+ "$",
1872
+ formatNumber.format(amountInUSD, maxDecimals || 2)
1873
+ ] });
1874
+ };
1875
+
1876
+ // src/components/PriceInfo/index.tsx
1877
+ var import_decimal6 = __toESM(require("decimal.js"));
1878
+ var import_jsbi3 = __toESM(require("jsbi"));
1879
+ var import_react14 = require("react");
1880
+
1881
+ // src/components/ExchangeRate.tsx
1882
+ var import_decimal5 = __toESM(require("decimal.js"));
1883
+ var React9 = __toESM(require("react"));
1884
+
1885
+ // src/components/PrecisionTickSize/index.tsx
1886
+ var import_decimal4 = __toESM(require("decimal.js"));
1887
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1888
+ function generateSubscriptNumbers(x) {
1889
+ const subscriptNumbers = ["\u2080", "\u2081", "\u2082", "\u2083", "\u2084", "\u2085", "\u2086", "\u2087", "\u2088", "\u2089"];
1890
+ const xString = x.toString();
1891
+ let result = "";
1892
+ for (let i = 0; i < xString.length; i++) {
1893
+ const digit = parseInt(xString.charAt(i), 10);
1894
+ const subscriptNumber = subscriptNumbers[digit];
1895
+ result += subscriptNumber;
1896
+ }
1897
+ return result;
1898
+ }
1899
+ var usePrecisionTick = (value) => {
1900
+ const firstSD = import_decimal4.default.abs(import_decimal4.default.ceil(new import_decimal4.default(-1).mul(import_decimal4.default.log10(value)))).toNumber();
1901
+ const [prefix, suffix] = [
1902
+ new import_decimal4.default(value).toFixed().slice(0, firstSD + 2),
1903
+ // +2 to account for 0.
1904
+ new import_decimal4.default(value).toFixed().slice(firstSD + 1)
1905
+ // +1 to account for 0. - and slice index
1906
+ ];
1907
+ return [firstSD, prefix, suffix];
1908
+ };
1909
+ var PrecisionTickSize = ({ value, maxSuffix }) => {
1910
+ const [firstSD, _, suffix] = usePrecisionTick(value);
1911
+ if (firstSD <= 5) {
1912
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { children: value.toFixed(6) });
1913
+ }
1914
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("span", { className: "flex items-center h-4", children: [
1915
+ "0.0",
1916
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "mb-3 text-xl mx-0.5", children: generateSubscriptNumbers(firstSD - 1) }),
1917
+ suffix.slice(0, maxSuffix)
1918
+ ] });
1919
+ };
1920
+ var PrecisionTickSize_default = PrecisionTickSize;
1921
+
1922
+ // src/components/ExchangeRate.tsx
1923
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1924
+ var calculateRate = ({ inAmount, inputDecimal, outAmount, outputDecimal }, reverse) => {
1925
+ const input = fromLamports(inAmount, inputDecimal);
1926
+ const output = fromLamports(outAmount, outputDecimal);
1927
+ const rate = !reverse ? new import_decimal5.default(input).div(output) : new import_decimal5.default(output).div(input);
1928
+ if (Number.isNaN(rate.toNumber())) {
1929
+ return new import_decimal5.default(0);
1930
+ }
1931
+ return rate;
1932
+ };
1933
+ var ApproxSVG = ({ width = 16, height = 16 }) => {
1934
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("svg", { width, height, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1935
+ "path",
1936
+ {
1937
+ d: "M10.8573 8.18429L13.6323 5.95933L10.8573 3.73438V5.31937H3.32735V6.59937H10.8573V8.18429ZM5.14223 7.81429L2.36719 10.0393L5.14223 12.2642V10.6792H12.6722V9.39922H5.14223V7.81429Z",
1938
+ fill: "currentColor"
1939
+ }
1940
+ ) });
1941
+ };
1942
+ var ExchangeRate = ({
1943
+ className,
1944
+ textClassName,
1945
+ loading = false,
1946
+ fromTokenInfo,
1947
+ rateParams,
1948
+ toTokenInfo,
1949
+ reversible = true
1950
+ }) => {
1951
+ const [reverse, setReverse] = React9.useState(reversible != null ? reversible : true);
1952
+ const rate = React9.useMemo(() => calculateRate(rateParams, reverse), [reverse, rateParams]);
1953
+ const onReverse = React9.useCallback((event) => {
1954
+ event.stopPropagation();
1955
+ setReverse((prevState) => !prevState);
1956
+ }, []);
1957
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
1958
+ "div",
1959
+ {
1960
+ className: cn(className, "flex cursor-pointer text-primary-text text-xs align-center"),
1961
+ onClick: onReverse,
1962
+ children: [
1963
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: cn(textClassName, "max-w-full flex whitespace-nowrap"), children: reverse ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1964
+ "1 ",
1965
+ fromTokenInfo.symbol,
1966
+ " \u2248",
1967
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex ml-0.5", children: rate.gt(1e-5) ? `${formatNumber.format(rate, 6)} ${toTokenInfo.symbol}` : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1968
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PrecisionTickSize_default, { value: rate.toNumber(), maxSuffix: 6 }),
1969
+ " ",
1970
+ toTokenInfo.symbol
1971
+ ] }) })
1972
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1973
+ "1 ",
1974
+ toTokenInfo.symbol,
1975
+ " \u2248",
1976
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex ml-0.5", children: rate.gt(1e-5) ? `${formatNumber.format(rate, 6)} ${fromTokenInfo.symbol}` : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1977
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PrecisionTickSize_default, { value: rate.toNumber(), maxSuffix: 6 }),
1978
+ " ",
1979
+ fromTokenInfo.symbol
1980
+ ] }) })
1981
+ ] }) }),
1982
+ reversible ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "ml-2", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ApproxSVG, {}) }) : null
1983
+ ]
1984
+ }
1985
+ );
1986
+ };
1987
+ var ExchangeRate_default = ExchangeRate;
1988
+
1989
+ // src/icons/UltraIcon.tsx
1990
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1991
+ var UltraIcon = (props) => {
1992
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("svg", __spreadProps(__spreadValues({ viewBox: "0 0 10 10", fill: "none", xmlns: "http://www.w3.org/2000/svg", height: "1em", width: "1em" }, props), { children: [
1993
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("g", { clipPath: "url(#clip0_1785_33901)", children: [
1994
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1995
+ "path",
1996
+ {
1997
+ d: "M7.20001 7.86127C7.45429 7.86127 7.69815 7.96228 7.87795 8.14208C8.05775 8.32188 8.15876 8.56574 8.15876 8.82002C8.15876 8.56574 8.25977 8.32188 8.43957 8.14208C8.61937 7.96228 8.86324 7.86127 9.11751 7.86127C8.86324 7.86127 8.61937 7.76026 8.43957 7.58046C8.25977 7.40066 8.15876 7.15679 8.15876 6.90252C8.15876 7.15679 8.05775 7.40066 7.87795 7.58046C7.69815 7.76026 7.45429 7.86127 7.20001 7.86127ZM7.20001 2.10877C7.45429 2.10877 7.69815 2.20978 7.87795 2.38958C8.05775 2.56938 8.15876 2.81324 8.15876 3.06752C8.15876 2.81324 8.25977 2.56938 8.43957 2.38958C8.61937 2.20978 8.86324 2.10877 9.11751 2.10877C8.86324 2.10877 8.61937 2.00776 8.43957 1.82796C8.25977 1.64816 8.15876 1.40429 8.15876 1.15002C8.15876 1.40429 8.05775 1.64816 7.87795 1.82796C7.69815 2.00776 7.45429 2.10877 7.20001 2.10877Z",
1998
+ stroke: "currentColor",
1999
+ strokeWidth: "0.95875",
2000
+ strokeLinecap: "round",
2001
+ strokeLinejoin: "round"
2002
+ }
2003
+ ),
2004
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2005
+ "path",
2006
+ {
2007
+ d: "M4.09971 1.42435C4.08095 1.37314 4.04691 1.32892 4.00219 1.29768C3.95748 1.26644 3.90425 1.24969 3.84971 1.24969C3.79517 1.24969 3.74194 1.26644 3.69723 1.29768C3.65251 1.32892 3.61847 1.37314 3.59971 1.42435L3.34534 2.11935C3.1457 2.6643 2.82969 3.15919 2.41931 3.56957C2.00893 3.97996 1.51403 4.29596 0.969084 4.4956L0.274086 4.74998C0.222871 4.76874 0.178655 4.80279 0.147417 4.8475C0.116179 4.89221 0.0994263 4.94543 0.0994263 4.99998C0.0994263 5.05452 0.116179 5.10775 0.147417 5.15246C0.178655 5.19717 0.222871 5.23122 0.274086 5.24998L0.969084 5.50435C1.51403 5.70399 2.00893 6.02001 2.41931 6.43039C2.82969 6.84077 3.1457 7.33566 3.34534 7.88061L3.59971 8.5756C3.61847 8.62681 3.65251 8.67103 3.69723 8.70227C3.74194 8.7335 3.79517 8.75026 3.84971 8.75026C3.90425 8.75026 3.95748 8.7335 4.00219 8.70227C4.04691 8.67103 4.08095 8.62681 4.09971 8.5756L4.35409 7.88061C4.55372 7.33566 4.86973 6.84077 5.28011 6.43039C5.69049 6.02001 6.18538 5.70399 6.73033 5.50435L7.42533 5.24998C7.47654 5.23122 7.52076 5.19717 7.552 5.15246C7.58323 5.10775 7.59999 5.05452 7.59999 4.99998C7.59999 4.94543 7.58323 4.89221 7.552 4.8475C7.52076 4.80279 7.47654 4.76874 7.42533 4.74998L6.73033 4.4956C6.18538 4.29596 5.8125 3.97995 5.40212 3.56957C4.99174 3.15919 4.55372 2.6643 4.35409 2.11935L4.09971 1.42435Z",
2008
+ fill: "currentColor"
2009
+ }
2010
+ )
2011
+ ] }),
2012
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("clipPath", { id: "clip0_1785_33901", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("rect", { width: "10", height: "10", fill: "white" }) }) })
2013
+ ] }));
2014
+ };
2015
+
2016
+ // src/components/PriceInfo/TransactionFee.tsx
2017
+ var import_jsx_runtime23 = require("react/jsx-runtime");
2018
+ var TransactionFee = ({ gasFee, gasless }) => {
2019
+ if (!gasFee) return null;
2020
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex items-center justify-between text-xs", children: [
2021
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "flex w-[50%] text-primary-text/50", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { children: "Network Fee" }) }),
2022
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex items-center gap-1", children: [
2023
+ gasless && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
2024
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(UltraIcon, { color: "#FDB022", width: 12, height: 12 }),
2025
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "text-xs text-primary-text", children: "Gasless" })
2026
+ ] }),
2027
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2028
+ "div",
2029
+ {
2030
+ className: cn("text-primary-text", {
2031
+ "line-through": gasless
2032
+ }),
2033
+ children: [
2034
+ gasFee,
2035
+ " SOL"
2036
+ ]
2037
+ }
2038
+ )
2039
+ ] })
2040
+ ] });
2041
+ };
2042
+ var TransactionFee_default = TransactionFee;
2043
+
2044
+ // src/queries/useUltraRouter.ts
2045
+ var import_react_query5 = require("@tanstack/react-query");
2046
+ var useUltraRouters = (options) => {
2047
+ return (0, import_react_query5.useQuery)(__spreadValues({
2048
+ queryKey: ["routers"],
2049
+ queryFn: () => ultraSwapService.getRouters(),
2050
+ cacheTime: Infinity,
2051
+ staleTime: Infinity
2052
+ }, options));
2053
+ };
2054
+
2055
+ // src/components/PriceInfo/index.tsx
2056
+ var import_jsx_runtime24 = require("react/jsx-runtime");
2057
+ var Index = ({
2058
+ quoteResponse,
2059
+ fromTokenInfo,
2060
+ toTokenInfo,
2061
+ loading,
2062
+ containerClassName
2063
+ }) => {
2064
+ const rateParams = {
2065
+ inAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.inAmount) || import_jsbi3.default.BigInt(0),
2066
+ // If there's no selectedRoute, we will use first route value to temporarily calculate
2067
+ inputDecimal: fromTokenInfo.decimals,
2068
+ outAmount: (quoteResponse == null ? void 0 : quoteResponse.quoteResponse.outAmount) || import_jsbi3.default.BigInt(0),
2069
+ // If there's no selectedRoute, we will use first route value to temporarily calculate
2070
+ outputDecimal: toTokenInfo.decimals
2071
+ };
2072
+ const { data: routerInfo } = useUltraRouters({
2073
+ select: (data) => {
2074
+ if (!quoteResponse) {
2075
+ return null;
2076
+ }
2077
+ return data.find((router2) => router2.id === quoteResponse.quoteResponse.router);
2078
+ }
2079
+ });
2080
+ const priceImpact = formatNumber.format(
2081
+ new import_decimal6.default((quoteResponse == null ? void 0 : quoteResponse.quoteResponse.priceImpactPct) || 0).mul(100).toDP(2)
2082
+ );
2083
+ const priceImpactText = Number(priceImpact) < 0.01 ? void 0 : `-${priceImpact}%`;
2084
+ const fee = (0, import_react14.useMemo)(() => {
2085
+ if (!quoteResponse) {
2086
+ return 0;
2087
+ }
2088
+ return quoteResponse.quoteResponse.feeBps / 100;
2089
+ }, [quoteResponse]);
2090
+ const router = (0, import_react14.useMemo)(() => {
2091
+ if (!quoteResponse) {
2092
+ return;
2093
+ }
2094
+ return quoteResponse.quoteResponse.router;
2095
+ }, [quoteResponse]);
2096
+ const gasFee = (0, import_react14.useMemo)(() => {
2097
+ if (quoteResponse) {
2098
+ const { prioritizationFeeLamports } = quoteResponse.quoteResponse;
2099
+ if (prioritizationFeeLamports) {
2100
+ return prioritizationFeeLamports / 1e9;
2101
+ }
2102
+ }
2103
+ return 0;
2104
+ }, [quoteResponse]);
2105
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: cn("mt-4 space-y-4 border border-white/5 rounded-xl", containerClassName), children: [
2106
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center justify-between text-xs", children: [
2107
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-primary-text/50", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: "Rate" }) }),
2108
+ import_jsbi3.default.greaterThan(rateParams.inAmount, import_jsbi3.default.BigInt(0)) && import_jsbi3.default.greaterThan(rateParams.outAmount, import_jsbi3.default.BigInt(0)) ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2109
+ ExchangeRate_default,
2110
+ {
2111
+ loading,
2112
+ rateParams,
2113
+ fromTokenInfo,
2114
+ toTokenInfo,
2115
+ reversible: true
2116
+ }
2117
+ ) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { className: "text-primary-text/50", children: "-" })
2118
+ ] }),
2119
+ priceImpactText && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center justify-between text-xs text-primary-text/50", children: [
2120
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: "Price Impact" }) }),
2121
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-primary-text", children: priceImpactText })
2122
+ ] }),
2123
+ router && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center justify-between text-xs", children: [
2124
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-primary-text/50", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: "Router" }) }),
2125
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "flex items-center gap-1", children: routerInfo && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2126
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("img", { src: routerInfo.icon, alt: quoteResponse.quoteResponse.router, width: 10, height: 10 }),
2127
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-primary-text", children: routerInfo.name })
2128
+ ] }) })
2129
+ ] }),
2130
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center justify-between text-xs", children: [
2131
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "text-primary-text/50", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: "Fee" }) }),
2132
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "text-primary-text", children: [
2133
+ fee,
2134
+ "%"
2135
+ ] })
2136
+ ] }),
2137
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(TransactionFee_default, { gasFee, gasless: quoteResponse == null ? void 0 : quoteResponse.quoteResponse.gasless })
2138
+ ] });
2139
+ };
2140
+ var PriceInfo_default = Index;
2141
+
2142
+ // src/components/SwitchPairButton.tsx
2143
+ var import_jsx_runtime25 = require("react/jsx-runtime");
2144
+ var IconSwitchPairDark = () => /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("svg", { width: 20, height: 20, viewBox: "0 0 21 22", fill: "white", fillOpacity: 0.5, xmlns: "http://www.w3.org/2000/svg", children: [
2145
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2146
+ "path",
2147
+ {
2148
+ d: "M6.51043 7.47998V14.99H7.77043V7.47998L9.66043 9.36998L10.5505 8.47994L7.5859 5.51453C7.3398 5.26925 6.94114 5.26925 6.69504 5.51453L3.73047 8.47994L4.62051 9.36998L6.51043 7.47998Z",
2149
+ fill: "white"
2150
+ }
2151
+ ),
2152
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2153
+ "path",
2154
+ {
2155
+ d: "M14.4902 14.52V7.01001H13.2302V14.52L11.3402 12.63L10.4502 13.5201L13.4148 16.4855C13.6609 16.7308 14.0595 16.7308 14.3056 16.4855L17.2702 13.5201L16.3802 12.63L14.4902 14.52Z",
2156
+ fill: "white"
2157
+ }
2158
+ )
2159
+ ] });
2160
+ var SwitchPairButton = ({
2161
+ className,
2162
+ onClick,
2163
+ disabled
2164
+ }) => {
2165
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "flex justify-center bg-background rounded-full", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2166
+ "div",
2167
+ {
2168
+ onClick,
2169
+ className: cn(
2170
+ "border-[3px] border-background fill-current text-black bg-interactive hover:bg-interactive/80 dark:text-primary-text-35 dark:hover:border-primary dark:border dark:border-white-35 h-8 w-8 rounded-full flex items-center justify-center cursor-pointer",
2171
+ className,
2172
+ {
2173
+ "opacity-50 cursor-not-allowed": disabled
2174
+ }
2175
+ ),
2176
+ children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconSwitchPairDark, {})
2177
+ }
2178
+ ) });
2179
+ };
2180
+ var SwitchPairButton_default = SwitchPairButton;
2181
+
2182
+ // src/components/useTimeDiff/useTimeDiff.tsx
2183
+ var import_react15 = __toESM(require("react"));
2184
+ var useTimeDiff = () => {
2185
+ const { lastRefreshTimestamp } = useSwapContext();
2186
+ const [hasExpired, setHasExpired] = import_react15.default.useState(false);
2187
+ const [timeDiff, setTimeDiff] = (0, import_react15.useState)(0);
2188
+ (0, import_react15.useEffect)(() => {
2189
+ const intervalId = setInterval(() => {
2190
+ if (!lastRefreshTimestamp) {
2191
+ return;
2192
+ }
2193
+ const value = Date.now() > lastRefreshTimestamp + ROUTE_CACHE_DURATION;
2194
+ const elapsedSeconds = (Date.now() - (lastRefreshTimestamp + ROUTE_CACHE_DURATION)) / 1e3;
2195
+ setTimeDiff(elapsedSeconds / (ROUTE_CACHE_DURATION / 1e3) * 100);
2196
+ setHasExpired(value);
2197
+ }, 1e3);
2198
+ return () => clearInterval(intervalId);
2199
+ }, [lastRefreshTimestamp]);
2200
+ return [hasExpired, timeDiff];
2201
+ };
2202
+ var useTimeDiff_default = useTimeDiff;
2203
+
2204
+ // src/components/Form.tsx
2205
+ var import_decimal7 = __toESM(require("decimal.js"));
2206
+
2207
+ // src/components/JupShield.tsx
2208
+ var import_react_query6 = require("@tanstack/react-query");
2209
+
2210
+ // src/hooks/useMobile.ts
2211
+ var import_react16 = require("react");
2212
+ var import_react_use = require("react-use");
2213
+ var useMobile = () => {
2214
+ const [isDesktop, setIsDesktop] = (0, import_react16.useState)(false);
2215
+ (0, import_react_use.useIsomorphicLayoutEffect)(() => {
2216
+ function updateSize() {
2217
+ const desktopQuery = window.matchMedia("(min-width: 1024px)");
2218
+ setIsDesktop(desktopQuery.matches);
2219
+ }
2220
+ updateSize();
2221
+ window.addEventListener("resize", updateSize);
2222
+ return () => window.removeEventListener("resize", updateSize);
2223
+ }, []);
2224
+ return !isDesktop;
2225
+ };
2226
+
2227
+ // src/components/Popover/Popover.tsx
2228
+ var import_react17 = require("react");
2229
+ var import_react_popper = require("react-popper");
2230
+ var import_lodash = __toESM(require("lodash.debounce"));
2231
+ var import_jsx_runtime26 = require("react/jsx-runtime");
2232
+ var Popover = ({
2233
+ placement = "auto",
2234
+ trigger = "click",
2235
+ persistOnClick = true,
2236
+ strategy = "fixed",
2237
+ arrow = false,
2238
+ buttonContent,
2239
+ popoverContent,
2240
+ contentClassName,
2241
+ buttonContentClassName,
2242
+ isOpen,
2243
+ onClose,
2244
+ matchWidth,
2245
+ offset,
2246
+ drawShades = false
2247
+ }) => {
2248
+ const isLocalMode = (0, import_react17.useMemo)(
2249
+ () => typeof isOpen === "undefined",
2250
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2251
+ []
2252
+ );
2253
+ const isMobile = useMobile();
2254
+ const [localOpen, setLocalOpen] = (0, import_react17.useState)(isLocalMode ? false : true);
2255
+ const [referenceElement, setReferenceElement] = (0, import_react17.useState)(null);
2256
+ const [popperElement, setPopperElement] = (0, import_react17.useState)(null);
2257
+ const shouldShowArrow = (0, import_react17.useMemo)(() => Boolean(popoverContent) && arrow, [popoverContent, arrow]);
2258
+ const modifiers = offset ? [
2259
+ {
2260
+ name: "offset",
2261
+ options: {
2262
+ offset
2263
+ }
2264
+ }
2265
+ ] : void 0;
2266
+ const { styles, attributes: attributes2 } = (0, import_react_popper.usePopper)(referenceElement, popperElement, {
2267
+ strategy,
2268
+ placement,
2269
+ modifiers
2270
+ });
2271
+ const handleClose = (0, import_react17.useCallback)(
2272
+ (0, import_lodash.default)(
2273
+ () => {
2274
+ if (isLocalMode) {
2275
+ setLocalOpen(false);
2276
+ } else if (onClose) {
2277
+ onClose();
2278
+ }
2279
+ },
2280
+ // persistOnClick makes sure Tooltip stays open when user click on it
2281
+ // to make sure that if user hover to content, we don't close it
2282
+ trigger === "hover" && persistOnClick ? 50 : 0
2283
+ ),
2284
+ [setLocalOpen, isLocalMode, onClose, trigger, persistOnClick]
2285
+ );
2286
+ const handleOpen = (0, import_react17.useCallback)(() => {
2287
+ handleClose.cancel();
2288
+ setLocalOpen(true);
2289
+ }, [setLocalOpen, handleClose]);
2290
+ useOutsideClick({ current: popperElement }, handleClose);
2291
+ const onClick = () => {
2292
+ if (isLocalMode) {
2293
+ if (persistOnClick && trigger === "hover" || trigger === "click") {
2294
+ handleOpen();
2295
+ }
2296
+ } else if (isOpen && onClose) {
2297
+ onClose();
2298
+ }
2299
+ };
2300
+ const shouldRenderContent = isLocalMode ? localOpen : isOpen;
2301
+ const hoverProps = trigger === "hover" ? isMobile ? {
2302
+ onTouchStart: handleOpen,
2303
+ onTouchEnd: handleClose
2304
+ } : {
2305
+ onMouseEnter: handleOpen,
2306
+ onMouseLeave: handleClose
2307
+ } : {};
2308
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
2309
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
2310
+ "div",
2311
+ __spreadProps(__spreadValues({
2312
+ ref: setReferenceElement,
2313
+ onClick,
2314
+ className: cn(buttonContentClassName, {
2315
+ "z-50": shouldRenderContent
2316
+ })
2317
+ }, hoverProps), {
2318
+ children: buttonContent
2319
+ })
2320
+ ),
2321
+ shouldRenderContent && /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
2322
+ "div",
2323
+ __spreadProps(__spreadValues(__spreadValues({
2324
+ id: "tooltip",
2325
+ ref: setPopperElement,
2326
+ style: __spreadProps(__spreadValues({}, styles.popper), { maxWidth: matchWidth ? referenceElement == null ? void 0 : referenceElement.clientWidth : "auto" })
2327
+ }, attributes2.popper), hoverProps), {
2328
+ className: cn(
2329
+ "rounded-lg w-auto bg-none shadow-xl dark:bg-white/5 backdrop-blur-xl transition-opacity opacity-0",
2330
+ contentClassName,
2331
+ {
2332
+ "z-50 opacity-100": shouldRenderContent
2333
+ }
2334
+ ),
2335
+ children: [
2336
+ popoverContent,
2337
+ shouldShowArrow ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
2338
+ "div",
2339
+ {
2340
+ id: "arrow",
2341
+ className: "before:absolute absolute before:w-2 w-2 before:h-2 h-2 before:bg-inherit bg-inherit before:visible before:rotate-45 invisible",
2342
+ "data-popper-arrow": true
2343
+ }
2344
+ ) : null
2345
+ ]
2346
+ })
2347
+ ),
2348
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
2349
+ "div",
2350
+ {
2351
+ className: cn("fixed top-0 left-0 w-full h-full transition-all opacity-0 pointer-events-none z-[-1]", {
2352
+ "!backdrop-blur-xxs !bg-black/20 opacity-100 pointer-events-auto z-40": drawShades && shouldRenderContent
2353
+ }),
2354
+ onClick: handleClose
2355
+ }
2356
+ )
2357
+ ] });
2358
+ };
2359
+ var Popover_default = Popover;
2360
+
2361
+ // src/components/Tooltip/PopoverTooltip.tsx
2362
+ var import_jsx_runtime27 = require("react/jsx-runtime");
2363
+ var PopoverTooltip = ({
2364
+ content,
2365
+ disabled = false,
2366
+ variant = "dark",
2367
+ children,
2368
+ offset,
2369
+ placement,
2370
+ persistOnClick,
2371
+ buttonContentClassName,
2372
+ contentClassName,
2373
+ drawShades,
2374
+ strategy
2375
+ }) => {
2376
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
2377
+ Popover_default,
2378
+ {
2379
+ placement: placement || "top",
2380
+ buttonContent: children,
2381
+ buttonContentClassName,
2382
+ offset: offset || [0, 2.5],
2383
+ contentClassName,
2384
+ drawShades,
2385
+ popoverContent: content && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
2386
+ "div",
2387
+ {
2388
+ className: cn("p-2 rounded-lg max-w-[360px] w-full text-xs", {
2389
+ "bg-white text-black": variant === "light",
2390
+ "bg-black text-primary-text": variant === "dark",
2391
+ "group-hover:visible group-hover:z-50": !disabled
2392
+ }),
2393
+ children: content
2394
+ }
2395
+ ),
2396
+ id: "TooltipPopover",
2397
+ trigger: persistOnClick ? "click" : "hover",
2398
+ persistOnClick,
2399
+ strategy
2400
+ }
2401
+ );
2402
+ };
2403
+ var PopoverTooltip_default = PopoverTooltip;
2404
+
2405
+ // src/components/JupShield.tsx
2406
+ var import_react18 = require("react");
2407
+
2408
+ // src/components/Plural/index.tsx
2409
+ var import_jsx_runtime28 = require("react/jsx-runtime");
2410
+ var Plural = ({ value, one, other }) => {
2411
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children: value === 1 ? one.replace("#", value.toString()) : other.replace("#", value.toString()) });
2412
+ };
2413
+ var Plural_default = Plural;
2414
+
2415
+ // src/icons/InfoIcon.tsx
2416
+ var import_jsx_runtime29 = require("react/jsx-runtime");
2417
+ var InfoIcon = (props) => {
2418
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("svg", __spreadProps(__spreadValues({ xmlns: "http://www.w3.org/2000/svg", height: "1em", width: "1em", viewBox: "0 0 256 256" }, props), { children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2419
+ "path",
2420
+ {
2421
+ fill: "currentColor",
2422
+ d: "M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m0 192a88 88 0 1 1 88-88a88.1 88.1 0 0 1-88 88m-8-80V80a8 8 0 0 1 16 0v56a8 8 0 0 1-16 0m20 36a12 12 0 1 1-12-12a12 12 0 0 1 12 12"
2423
+ }
2424
+ ) }));
2425
+ };
2426
+ var InfoIcon_default = InfoIcon;
2427
+
2428
+ // src/components/JupShield.tsx
2429
+ var import_jsx_runtime30 = require("react/jsx-runtime");
2430
+ var parseShieldWarningtoSentenceCase = (warning) => {
2431
+ const str = warning.type.replace(/_/g, " ");
2432
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
2433
+ };
2434
+ var JupShieldIcon = (props) => {
2435
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("svg", __spreadProps(__spreadValues({ xmlns: "http://www.w3.org/2000/svg", height: "1em", width: "1em", viewBox: "0 0 24 24" }, props), { children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("g", { fill: "none", children: [
2436
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2437
+ "path",
2438
+ {
2439
+ stroke: "currentColor",
2440
+ strokeWidth: "1.5",
2441
+ d: "M3 10.417c0-3.198 0-4.797.378-5.335c.377-.537 1.88-1.052 4.887-2.081l.573-.196C10.405 2.268 11.188 2 12 2s1.595.268 3.162.805l.573.196c3.007 1.029 4.51 1.544 4.887 2.081C21 5.62 21 7.22 21 10.417v1.574c0 5.638-4.239 8.375-6.899 9.536C13.38 21.842 13.02 22 12 22s-1.38-.158-2.101-.473C7.239 20.365 3 17.63 3 11.991z"
2442
+ }
2443
+ ),
2444
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("path", { stroke: "currentColor", strokeLinecap: "round", strokeWidth: "1.5", d: "M12 8v4" }),
2445
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("circle", { cx: "12", cy: "15", r: "1", fill: "currentColor" })
2446
+ ] }) }));
2447
+ };
2448
+ var Warnings = ({
2449
+ warning,
2450
+ children,
2451
+ isHighRisk
2452
+ }) => {
2453
+ const warningTitle = (0, import_react18.useCallback)((warning2) => {
2454
+ return parseShieldWarningtoSentenceCase(warning2);
2455
+ }, []);
2456
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "flex gap-1", children: [
2457
+ children,
2458
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "flex flex-1 flex-col", children: [
2459
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: cn("text-neutral-300", isHighRisk && "text-warning"), children: warningTitle(warning) }),
2460
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: cn("text-neutral-500", isHighRisk && "text-amber-200"), children: warning.message })
2461
+ ] })
2462
+ ] }, warning.type);
2463
+ };
2464
+ var JupShield = ({ tokenAddress }) => {
2465
+ const isMobile = useMobile();
2466
+ const { data, isFetching } = (0, import_react_query6.useQuery)({
2467
+ queryKey: ["shield", tokenAddress],
2468
+ queryFn: () => ultraSwapService.getShield([tokenAddress]),
2469
+ cacheTime: 5 * 6e4,
2470
+ staleTime: 5 * 6e4,
2471
+ keepPreviousData: true,
2472
+ select: (data2) => {
2473
+ const warnings = data2.warnings[tokenAddress];
2474
+ return {
2475
+ isNotVerified: warnings.find((warning) => warning.type === "NOT_VERIFIED"),
2476
+ totalWarnings: warnings.length,
2477
+ highRiskWarnings: warnings.filter(
2478
+ (warning) => warning.severity === "critical" /* CRITICAL */ || warning.severity === "warning" /* WARNING */
2479
+ ),
2480
+ otherWarnings: warnings.filter((warning) => warning.severity === "info" /* INFO */)
2481
+ };
2482
+ }
2483
+ });
2484
+ if (!data || data.totalWarnings === 0) return null;
2485
+ const { isNotVerified, totalWarnings, highRiskWarnings, otherWarnings } = data;
2486
+ if (!isNotVerified) return null;
2487
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2488
+ PopoverTooltip_default,
2489
+ {
2490
+ persistOnClick: isMobile,
2491
+ placement: "bottom",
2492
+ drawShades: true,
2493
+ buttonContentClassName: "!cursor-help",
2494
+ offset: [120, 5],
2495
+ content: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "flex flex-col gap-y-2 p-0 w-[260px]", children: [
2496
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "text-sm font-semibold text-warning", children: [
2497
+ totalWarnings,
2498
+ " JupShield ",
2499
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Plural_default, { one: "Warning", other: "Warnings", value: totalWarnings })
2500
+ ] }),
2501
+ highRiskWarnings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "flex flex-col gap-y-2 rounded-md bg-warning/[8%] p-2", children: highRiskWarnings.map((warning) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Warnings, { warning, isHighRisk: true, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(InfoIcon_default, { width: 15, height: 15, className: "text-warning" }) }, warning.type)) }),
2502
+ otherWarnings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: cn("flex flex-col gap-y-2", highRiskWarnings.length > 0 && "p-2"), children: otherWarnings.map((warning) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Warnings, { warning, isHighRisk: false, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(InfoIcon_default, { width: 15, height: 15 }) }, warning.type)) })
2503
+ ] }),
2504
+ children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: cn("mt-1 flex items-center gap-x-1", isFetching && "blur-sm"), children: [
2505
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(JupShieldIcon, { width: 15, height: 15, className: "text-warning" }),
2506
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
2507
+ "span",
2508
+ {
2509
+ className: cn(
2510
+ "!text-xxs font-semibold text-warning underline decoration-warning decoration-dashed underline-offset-4"
2511
+ ),
2512
+ children: [
2513
+ totalWarnings,
2514
+ " Warnings"
2515
+ ]
2516
+ }
2517
+ )
2518
+ ] })
2519
+ }
2520
+ );
2521
+ };
2522
+ var JupShield_default = JupShield;
2523
+
2524
+ // src/components/Form.tsx
2525
+ var import_jsx_runtime31 = require("react/jsx-runtime");
2526
+ var FormInputContainer = ({ tokenInfo, onBalanceClick, title, pairSelectDisabled, onClickSelectPair, children, value }) => {
2527
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(
2528
+ "div",
2529
+ {
2530
+ className: cn(
2531
+ "border border-transparent bg-module rounded-xl transition-all",
2532
+ "py-3 px-4 flex flex-col dark:text-primary-text gap-y-2",
2533
+ "group focus-within:border-primary/50 focus-within:shadow-swap-input-dark rounded-xl"
2534
+ ),
2535
+ children: [
2536
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex justify-between items-center text-xs text-primary-text", children: [
2537
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { children: title }),
2538
+ tokenInfo && /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(
2539
+ "div",
2540
+ {
2541
+ className: cn("flex space-x-1 text-xs items-center text-primary-text/50 fill-current ", {
2542
+ "cursor-pointer": onBalanceClick
2543
+ }),
2544
+ onClick: (e) => {
2545
+ onBalanceClick == null ? void 0 : onBalanceClick(e);
2546
+ },
2547
+ children: [
2548
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(WalletIcon_default, { width: 10, height: 10 }),
2549
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Coinbalance_default, { mintAddress: tokenInfo.id, hideZeroBalance: false }),
2550
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { children: tokenInfo.symbol })
2551
+ ]
2552
+ }
2553
+ )
2554
+ ] }),
2555
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex", children: [
2556
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { children: [
2557
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(
2558
+ "button",
2559
+ {
2560
+ type: "button",
2561
+ className: cn("py-2 px-3 rounded-lg flex items-center bg-interactive text-primary-text", {
2562
+ "hover:bg-interactive/80": !pairSelectDisabled
2563
+ }),
2564
+ disabled: pairSelectDisabled,
2565
+ onClick: onClickSelectPair,
2566
+ children: [
2567
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "h-5 w-5", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(TokenIcon_default, { info: tokenInfo, width: 20, height: 20 }) }),
2568
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "ml-4 mr-2 font-semibold", translate: "no", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "truncate", children: tokenInfo == null ? void 0 : tokenInfo.symbol }) }),
2569
+ pairSelectDisabled ? null : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { className: "text-primary-text/25 fill-current", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ChevronDownIcon_default, {}) })
2570
+ ]
2571
+ }
2572
+ ),
2573
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "flex justify-between items-center h-[20px]", children: (tokenInfo == null ? void 0 : tokenInfo.id) && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(JupShield_default, { tokenAddress: tokenInfo.id }) })
2574
+ ] }),
2575
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex flex-col items-end justify-between w-full", children: [
2576
+ children,
2577
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { className: "text-xs text-primary-text/50", children: tokenInfo && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(CoinBalanceUSD, { tokenInfo, amount: value }) })
2578
+ ] })
2579
+ ] })
2580
+ ]
2581
+ }
2582
+ );
2583
+ };
2584
+ var Form = ({ onSubmit, isDisabled, setSelectPairSelector }) => {
2585
+ const { publicKey } = useWalletPassThrough();
2586
+ const { data: balances } = useBalances();
2587
+ const {
2588
+ form,
2589
+ setForm,
2590
+ fromTokenInfo,
2591
+ toTokenInfo,
2592
+ quoteResponseMeta,
2593
+ formProps: { fixedAmount, swapMode, fixedMint },
2594
+ loading,
2595
+ refresh,
2596
+ quoteError,
2597
+ errors,
2598
+ isToPairFocused,
2599
+ onSubmit: onSubmitUltra
2600
+ } = useSwapContext();
2601
+ const [hasExpired, timeDiff] = useTimeDiff_default();
2602
+ const { setScreen } = useScreenState();
2603
+ (0, import_react19.useEffect)(() => {
2604
+ if (hasExpired) {
2605
+ refresh();
2606
+ }
2607
+ }, [hasExpired]);
2608
+ const shouldDisabledFromSelector = (0, import_react19.useMemo)(() => {
2609
+ if ((fromTokenInfo == null ? void 0 : fromTokenInfo.id) === fixedMint) {
2610
+ return true;
2611
+ }
2612
+ return false;
2613
+ }, [fixedMint, fromTokenInfo == null ? void 0 : fromTokenInfo.id]);
2614
+ const shouldDisabledToSelector = (0, import_react19.useMemo)(() => {
2615
+ if ((toTokenInfo == null ? void 0 : toTokenInfo.id) === fixedMint) {
2616
+ return true;
2617
+ }
2618
+ return false;
2619
+ }, [fixedMint, toTokenInfo == null ? void 0 : toTokenInfo.id]);
2620
+ const walletPublicKey = (0, import_react19.useMemo)(() => publicKey == null ? void 0 : publicKey.toString(), [publicKey]);
2621
+ const onChangeFromValue = ({ value }) => {
2622
+ if (value === "") {
2623
+ setForm((form2) => __spreadProps(__spreadValues({}, form2), { fromValue: "", toValue: "" }));
2624
+ return;
2625
+ }
2626
+ const isInvalid = Number.isNaN(value);
2627
+ if (isInvalid) return;
2628
+ setForm((form2) => __spreadProps(__spreadValues({}, form2), { fromValue: value }));
2629
+ };
2630
+ const onChangeToValue = ({ value }) => {
2631
+ if (value === "") {
2632
+ setForm((form2) => __spreadProps(__spreadValues({}, form2), { fromValue: "", toValue: "" }));
2633
+ return;
2634
+ }
2635
+ const isInvalid = Number.isNaN(value);
2636
+ if (isInvalid) return;
2637
+ setForm((form2) => __spreadProps(__spreadValues({}, form2), { toValue: value }));
2638
+ };
2639
+ const balance = (0, import_react19.useMemo)(() => {
2640
+ if (!(fromTokenInfo == null ? void 0 : fromTokenInfo.id)) return null;
2641
+ if (!balances) return null;
2642
+ const accBalanceObj = balances[fromTokenInfo.id];
2643
+ if (!accBalanceObj) return null;
2644
+ return accBalanceObj.uiAmount.toString();
2645
+ }, [balances, fromTokenInfo == null ? void 0 : fromTokenInfo.id]);
2646
+ const onClickMax = (0, import_react19.useCallback)(
2647
+ (e) => {
2648
+ e.preventDefault();
2649
+ if (!balance) return;
2650
+ if ((fromTokenInfo == null ? void 0 : fromTokenInfo.id) === WRAPPED_SOL_MINT.toBase58()) {
2651
+ setForm((prev) => __spreadProps(__spreadValues({}, prev), {
2652
+ fromValue: new import_decimal7.default(balance).gt(MINIMUM_SOL_BALANCE) ? new import_decimal7.default(balance).minus(MINIMUM_SOL_BALANCE).toFixed(9) : "0"
2653
+ }));
2654
+ } else {
2655
+ setForm((prev) => __spreadProps(__spreadValues({}, prev), {
2656
+ fromValue: balance
2657
+ }));
2658
+ }
2659
+ },
2660
+ [balance, fromTokenInfo == null ? void 0 : fromTokenInfo.id, setForm]
2661
+ );
2662
+ const onClickSwitchPair = () => {
2663
+ setForm((prev) => __spreadProps(__spreadValues({}, prev), {
2664
+ fromValue: "",
2665
+ toValue: "",
2666
+ fromMint: prev.toMint,
2667
+ toMint: prev.fromMint
2668
+ }));
2669
+ };
2670
+ const { inputAmountDisabled, outputAmountDisabled } = (0, import_react19.useMemo)(() => {
2671
+ const result = { inputAmountDisabled: true, outputAmountDisabled: true };
2672
+ if (!fixedAmount) {
2673
+ if (swapMode === SwapMode.ExactIn) {
2674
+ result.inputAmountDisabled = false;
2675
+ } else if (swapMode === SwapMode.ExactOut) {
2676
+ result.outputAmountDisabled = false;
2677
+ } else {
2678
+ result.inputAmountDisabled = false;
2679
+ result.outputAmountDisabled = false;
2680
+ }
2681
+ }
2682
+ return result;
2683
+ }, [fixedAmount, swapMode]);
2684
+ const onClickSelectFromMint = (0, import_react19.useCallback)(() => {
2685
+ if (shouldDisabledFromSelector) return;
2686
+ setSelectPairSelector("fromMint");
2687
+ }, [shouldDisabledFromSelector, setSelectPairSelector]);
2688
+ const onClickSelectToMint = (0, import_react19.useCallback)(() => {
2689
+ if (shouldDisabledToSelector) return;
2690
+ setSelectPairSelector("toMint");
2691
+ }, [shouldDisabledToSelector, setSelectPairSelector]);
2692
+ const thousandSeparator = (0, import_react19.useMemo)(() => detectedSeparator === "," ? "." : ",", []);
2693
+ const withValueLimit = (0, import_react19.useCallback)(
2694
+ ({ floatValue }) => !floatValue || floatValue <= MAX_INPUT_LIMIT,
2695
+ []
2696
+ );
2697
+ const handleClick = (0, import_react19.useCallback)(
2698
+ (event) => {
2699
+ if (window.Jupiter.enableWalletPassthrough && window.Jupiter.onRequestConnectWallet) {
2700
+ window.Jupiter.onRequestConnectWallet();
2701
+ } else {
2702
+ setScreen("Wallet");
2703
+ }
2704
+ },
2705
+ [setScreen]
2706
+ );
2707
+ const shouldButtonDisabled = (0, import_react19.useMemo)(() => {
2708
+ if (isDisabled || loading || !!errors.fromValue) {
2709
+ return true;
2710
+ }
2711
+ return false;
2712
+ }, [isDisabled, loading, errors.fromValue]);
2713
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "h-full flex flex-col items-center justify-center", children: [
2714
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "w-full mt-2 rounded-xl flex flex-col px-2", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex-col", children: [
2715
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2716
+ FormInputContainer,
2717
+ {
2718
+ tokenInfo: fromTokenInfo,
2719
+ onBalanceClick: (e) => {
2720
+ isToPairFocused.current = false;
2721
+ onClickMax(e);
2722
+ },
2723
+ title: "Selling",
2724
+ pairSelectDisabled: shouldDisabledFromSelector,
2725
+ onClickSelectPair: onClickSelectFromMint,
2726
+ value: form.fromValue,
2727
+ children: (fromTokenInfo == null ? void 0 : fromTokenInfo.decimals) && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2728
+ import_react_number_format.NumericFormat,
2729
+ {
2730
+ disabled: fixedAmount || swapMode === SwapMode.ExactOut,
2731
+ value: typeof form.fromValue === "undefined" ? "" : form.fromValue,
2732
+ decimalScale: fromTokenInfo.decimals,
2733
+ thousandSeparator,
2734
+ allowNegative: false,
2735
+ valueIsNumericString: true,
2736
+ inputMode: "decimal",
2737
+ onValueChange: onChangeFromValue,
2738
+ placeholder: "0.00",
2739
+ className: cn(
2740
+ "w-full h-[40px] bg-transparent text-primary-text text-right font-semibold text-xl placeholder:text-primary-text/50",
2741
+ {
2742
+ "cursor-not-allowed": inputAmountDisabled || swapMode === SwapMode.ExactOut
2743
+ }
2744
+ ),
2745
+ onKeyDown: () => {
2746
+ isToPairFocused.current = false;
2747
+ },
2748
+ decimalSeparator: detectedSeparator,
2749
+ isAllowed: withValueLimit
2750
+ }
2751
+ )
2752
+ }
2753
+ ),
2754
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "relative z-10 -my-3 flex justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(SwitchPairButton_default, { onClick: onClickSwitchPair, className: cn("transition-all") }) }),
2755
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2756
+ FormInputContainer,
2757
+ {
2758
+ tokenInfo: toTokenInfo,
2759
+ title: "Buying",
2760
+ pairSelectDisabled: shouldDisabledToSelector,
2761
+ onClickSelectPair: onClickSelectToMint,
2762
+ value: form.toValue,
2763
+ children: (toTokenInfo == null ? void 0 : toTokenInfo.decimals) && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2764
+ import_react_number_format.NumericFormat,
2765
+ {
2766
+ inputMode: "decimal",
2767
+ disabled: outputAmountDisabled || swapMode === SwapMode.ExactIn,
2768
+ value: typeof form.toValue === "undefined" ? "" : form.toValue,
2769
+ decimalScale: toTokenInfo.decimals,
2770
+ thousandSeparator,
2771
+ allowNegative: false,
2772
+ valueIsNumericString: true,
2773
+ onValueChange: onChangeToValue,
2774
+ className: cn(
2775
+ "h-[40px] w-full bg-transparent text-primary-text text-right font-semibold text-lg placeholder:text-primary-text/50",
2776
+ {
2777
+ "cursor-not-allowed": outputAmountDisabled || swapMode === SwapMode.ExactIn
2778
+ }
2779
+ ),
2780
+ placeholder: swapMode === SwapMode.ExactOut ? "Enter desired amount" : "0.00",
2781
+ decimalSeparator: detectedSeparator,
2782
+ isAllowed: withValueLimit,
2783
+ onKeyDown: (e) => {
2784
+ if (e.metaKey || e.ctrlKey || e.key === "Meta" || e.key === "Control" || e.key === "Alt" || e.key === "Shift") {
2785
+ return;
2786
+ }
2787
+ isToPairFocused.current = true;
2788
+ }
2789
+ }
2790
+ )
2791
+ }
2792
+ )
2793
+ ] }) }),
2794
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "w-full px-2", children: [
2795
+ !walletPublicKey ? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(JupButton_default, { size: "lg", className: "w-full mt-4 bg-primary !text-uiv2-text/75", onClick: handleClick, children: "Connect Wallet" }) : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2796
+ JupButton_default,
2797
+ {
2798
+ size: "lg",
2799
+ className: cn("w-full mt-4 disabled:opacity-50 !text-uiv2-text/75 !bg-primary "),
2800
+ onClick: () => {
2801
+ onSubmit();
2802
+ onSubmitUltra();
2803
+ },
2804
+ disabled: shouldButtonDisabled,
2805
+ children: loading ? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { children: "Loading" }) : errors.fromValue ? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { children: errors.fromValue.title }) : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { children: "Swap" })
2806
+ }
2807
+ ),
2808
+ quoteResponseMeta && fromTokenInfo && toTokenInfo ? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2809
+ PriceInfo_default,
2810
+ {
2811
+ quoteResponse: quoteResponseMeta,
2812
+ fromTokenInfo,
2813
+ toTokenInfo,
2814
+ loading
2815
+ }
2816
+ ) : null
2817
+ ] })
2818
+ ] });
2819
+ };
2820
+ var Form_default = Form;
2821
+
2822
+ // src/components/FormPairSelector.tsx
2823
+ var import_react23 = require("react");
2824
+ var import_react_virtualized_auto_sizer = __toESM(require("react-virtualized-auto-sizer"));
2825
+ var import_react_window = require("react-window");
2826
+
2827
+ // src/icons/LeftArrowIcon.tsx
2828
+ var import_jsx_runtime32 = require("react/jsx-runtime");
2829
+ var LeftArrowIcon = ({ width = "12", height = "12" }) => {
2830
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("svg", { width, height, viewBox: "0 0 53 52", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2831
+ "path",
2832
+ {
2833
+ d: "M17.3336 23.8334H43.7062V28.1667H17.3336L28.9555 39.7887L25.8919 42.8524L9.03955 26L25.8919 9.14771L28.9555 12.2114L17.3336 23.8334Z",
2834
+ fill: "currentColor"
2835
+ }
2836
+ ) });
2837
+ };
2838
+ var LeftArrowIcon_default = LeftArrowIcon;
2839
+
2840
+ // src/icons/SearchIcon.tsx
2841
+ var import_jsx_runtime33 = require("react/jsx-runtime");
2842
+ var SearchIcon = () => {
2843
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "flex items-center text-primary-text fill-current", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 18 18", fill: "inherit", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2844
+ "path",
2845
+ {
2846
+ d: "M7.30327 14.6058C8.75327 14.6074 10.1705 14.1746 11.3729 13.3637L15.5971 17.5871C16.1463 18.1371 17.0377 18.1371 17.5877 17.5871C18.1377 17.0371 18.1377 16.1457 17.5877 15.5964L13.3643 11.3722C14.5823 9.55661 14.9229 7.28943 14.2909 5.19563C13.6596 3.10183 12.1229 1.40183 10.1033 0.56283C8.08365 -0.276231 5.79385 -0.16607 3.86505 0.86283C1.93537 1.89251 0.569053 3.73243 0.140853 5.87683C-0.286487 8.02143 0.269759 10.2448 1.65725 11.9354C3.04397 13.6261 5.11665 14.6064 7.30325 14.6058H7.30327ZM7.30327 1.68943C8.79233 1.68865 10.2197 2.28005 11.2729 3.33319C12.3252 4.38631 12.9166 5.81359 12.9166 7.30279C12.9166 8.79199 12.3252 10.2192 11.2729 11.2724C10.2198 12.3247 8.79247 12.9162 7.30327 12.9162C5.81407 12.9162 4.38687 12.3247 3.33367 11.2724C2.28133 10.2193 1.68913 8.79199 1.68991 7.30279C1.69148 5.81451 2.28287 4.38719 3.33523 3.33479C4.38759 2.28239 5.81483 1.69103 7.30323 1.68947L7.30327 1.68943Z",
2847
+ fill: "inherit",
2848
+ fillOpacity: "0.25"
2849
+ }
2850
+ ) }) });
2851
+ };
2852
+ var SearchIcon_default = SearchIcon;
2853
+
2854
+ // src/components/FormPairSelector.tsx
2855
+ var import_lodash2 = __toESM(require("lodash.debounce"));
2856
+
2857
+ // src/components/FormPairRow.tsx
2858
+ var import_react21 = __toESM(require("react"));
2859
+ var import_decimal8 = __toESM(require("decimal.js"));
2860
+
2861
+ // src/contexts/preferredExplorer/index.tsx
2862
+ var import_react20 = require("react");
2863
+ var import_jsx_runtime34 = require("react/jsx-runtime");
2864
+ var AVAILABLE_EXPLORER = [
2865
+ {
2866
+ name: "Solana Explorer",
2867
+ url: "https://explorer.solana.com/",
2868
+ get: (txid, cluster = "mainnet-beta") => {
2869
+ if (cluster !== "mainnet-beta") return `https://explorer.solana.com/tx/${txid}?cluster=${cluster}`;
2870
+ return `https://explorer.solana.com/tx/${txid}`;
2871
+ },
2872
+ getToken: (mint, cluster = "mainnet-beta") => {
2873
+ if (cluster !== "mainnet-beta") return `https://explorer.solana.com/address/${mint}?cluster=${cluster}`;
2874
+ return `https://explorer.solana.com/address/${mint}`;
2875
+ }
2876
+ },
2877
+ {
2878
+ name: "Solscan",
2879
+ url: "https://solscan.io/",
2880
+ get: (txid, cluster = "mainnet-beta") => {
2881
+ if (cluster !== "mainnet-beta") return `https://solscan.io/tx/${txid}?cluster=${cluster}`;
2882
+ return `https://solscan.io/tx/${txid}`;
2883
+ },
2884
+ getToken: (mint, cluster = "mainnet-beta") => {
2885
+ if (cluster !== "mainnet-beta") return `https://solscan.io/token/${mint}?cluster=${cluster}`;
2886
+ return `https://solscan.io/token/${mint}`;
2887
+ }
2888
+ },
2889
+ {
2890
+ name: "Solana Beach",
2891
+ url: "https://solanabeach.io/",
2892
+ get: (txid, cluster = "mainnet-beta") => {
2893
+ if (cluster !== "mainnet-beta") return `https://solanabeach.io/transaction/${txid}?cluster=${cluster}`;
2894
+ return `https://solanabeach.io/transaction/${txid}`;
2895
+ },
2896
+ getToken: (mint, cluster = "mainnet-beta") => {
2897
+ if (cluster !== "mainnet-beta") return `https://solanabeach.io/address/${mint}?cluster=${cluster}`;
2898
+ return `https://solanabeach.io/address/${mint}`;
2899
+ }
2900
+ },
2901
+ {
2902
+ name: "SolanaFM",
2903
+ url: "https://solana.fm/",
2904
+ get: (txid, cluster = "mainnet-beta") => {
2905
+ if (cluster === "devnet") return `https://solana.fm/tx/${txid}?cluster=devnet-solana`;
2906
+ if (cluster === "testnet") return `https://solana.fm/tx/${txid}?cluster=testnet-qn1`;
2907
+ return `https://solana.fm/tx/${txid}`;
2908
+ },
2909
+ getToken: (mint, cluster = "mainnet-beta") => {
2910
+ if (cluster === "devnet") return `https://solana.fm/address/${mint}?cluster=devnet-solana`;
2911
+ if (cluster === "testnet") return `https://solana.fm/address/${mint}?cluster=testnet-qn1`;
2912
+ return `https://solana.fm/address/${mint}`;
2913
+ }
2914
+ }
2915
+ ];
2916
+ var PreferredExplorerContext = (0, import_react20.createContext)({
2917
+ explorer: AVAILABLE_EXPLORER[0].name,
2918
+ getExplorer: (txid, cluster) => "",
2919
+ getTokenExplorer: (mint, cluster) => "",
2920
+ setExplorer: (explorer) => {
2921
+ }
2922
+ });
2923
+ var PreferredExplorerProvider = ({
2924
+ defaultExplorer,
2925
+ children
2926
+ }) => {
2927
+ const [explorer, setExplorer] = (0, import_react20.useState)(defaultExplorer != null ? defaultExplorer : AVAILABLE_EXPLORER[0].name);
2928
+ const explorerObject = (0, import_react20.useMemo)(() => {
2929
+ return AVAILABLE_EXPLORER.find((e) => e.name === explorer) || AVAILABLE_EXPLORER[0];
2930
+ }, [explorer]);
2931
+ const getExplorer = (0, import_react20.useCallback)(
2932
+ (txid, cluster) => explorerObject.get(txid, cluster),
2933
+ [explorerObject]
2934
+ );
2935
+ const getTokenExplorer = (0, import_react20.useCallback)(
2936
+ (mint, cluster) => explorerObject.getToken(mint, cluster),
2937
+ [explorerObject]
2938
+ );
2939
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2940
+ PreferredExplorerContext.Provider,
2941
+ {
2942
+ value: { explorer, getExplorer, getTokenExplorer, setExplorer: (explorer2) => setExplorer(explorer2) },
2943
+ children
2944
+ }
2945
+ );
2946
+ };
2947
+ function usePreferredExplorer() {
2948
+ const context = (0, import_react20.useContext)(PreferredExplorerContext);
2949
+ return context;
2950
+ }
2951
+
2952
+ // src/icons/ExternalIcon.tsx
2953
+ var import_jsx_runtime35 = require("react/jsx-runtime");
2954
+ var ExternalIcon = () => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("svg", { width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
2955
+ "path",
2956
+ {
2957
+ d: "M4 2V3H1.5V8.5H7V6H8V9C8 9.13261 7.94732 9.25979 7.85355 9.35355C7.75979 9.44732 7.63261 9.5 7.5 9.5H1C0.867392 9.5 0.740215 9.44732 0.646447 9.35355C0.552678 9.25979 0.5 9.13261 0.5 9V2.5C0.5 2.36739 0.552678 2.24021 0.646447 2.14645C0.740215 2.05268 0.867392 2 1 2H4ZM9.5 0.5V4.5H8.5V2.2065L4.6035 6.1035L3.8965 5.3965L7.7925 1.5H5.5V0.5H9.5Z",
2958
+ fill: "currentColor"
2959
+ }
2960
+ ) });
2961
+ var ExternalIcon_default = ExternalIcon;
2962
+
2963
+ // src/components/TokenLink.tsx
2964
+ var import_jsx_runtime36 = require("react/jsx-runtime");
2965
+ var TokenLink = ({ tokenInfo, className }) => {
2966
+ const { getTokenExplorer } = usePreferredExplorer();
2967
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
2968
+ "a",
2969
+ {
2970
+ target: "_blank",
2971
+ rel: "noreferrer",
2972
+ className: cn(
2973
+ "flex items-center bg-black/25 text-primary-text/75 px-2 py-0.5 space-x-1 rounded cursor-pointer",
2974
+ className
2975
+ ),
2976
+ href: getTokenExplorer(tokenInfo.id),
2977
+ onClick: (e) => e.stopPropagation(),
2978
+ children: [
2979
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "text-xxs", children: shortenAddress(tokenInfo.id) }),
2980
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ExternalIcon_default, {})
2981
+ ]
2982
+ }
2983
+ );
2984
+ };
2985
+ TokenLink.displayName = "TokenLink";
2986
+ var TokenLink_default = TokenLink;
2987
+
2988
+ // src/components/CheckedBadge.tsx
2989
+ var import_jsx_runtime37 = require("react/jsx-runtime");
2990
+ var CheckedBadge = ({ width = 24, height = 24 }) => {
2991
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
2992
+ "svg",
2993
+ {
2994
+ width,
2995
+ height,
2996
+ viewBox: "0 0 24 24",
2997
+ fill: "none",
2998
+ xmlns: "http://www.w3.org/2000/svg",
2999
+ children: [
3000
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3001
+ "path",
3002
+ {
3003
+ d: "M13.8179 4.54512L13.6275 4.27845C12.8298 3.16176 11.1702 3.16176 10.3725 4.27845L10.1821 4.54512C9.76092 5.13471 9.05384 5.45043 8.33373 5.37041L7.48471 5.27608C6.21088 5.13454 5.13454 6.21088 5.27608 7.48471L5.37041 8.33373C5.45043 9.05384 5.13471 9.76092 4.54512 10.1821L4.27845 10.3725C3.16176 11.1702 3.16176 12.8298 4.27845 13.6275L4.54512 13.8179C5.13471 14.2391 5.45043 14.9462 5.37041 15.6663L5.27608 16.5153C5.13454 17.7891 6.21088 18.8655 7.48471 18.7239L8.33373 18.6296C9.05384 18.5496 9.76092 18.8653 10.1821 19.4549L10.3725 19.7215C11.1702 20.8382 12.8298 20.8382 13.6275 19.7215L13.8179 19.4549C14.2391 18.8653 14.9462 18.5496 15.6663 18.6296L16.5153 18.7239C17.7891 18.8655 18.8655 17.7891 18.7239 16.5153L18.6296 15.6663C18.5496 14.9462 18.8653 14.2391 19.4549 13.8179L19.7215 13.6275C20.8382 12.8298 20.8382 11.1702 19.7215 10.3725L19.4549 10.1821C18.8653 9.76092 18.5496 9.05384 18.6296 8.33373L18.7239 7.48471C18.8655 6.21088 17.7891 5.13454 16.5153 5.27608L15.6663 5.37041C14.9462 5.45043 14.2391 5.13471 13.8179 4.54512Z",
3004
+ stroke: "currentColor",
3005
+ strokeWidth: "2",
3006
+ strokeLinecap: "round",
3007
+ strokeLinejoin: "round"
3008
+ }
3009
+ ),
3010
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3011
+ "path",
3012
+ {
3013
+ d: "M9 12L10.8189 13.8189V13.8189C10.9189 13.9189 11.0811 13.9189 11.1811 13.8189V13.8189L15 10",
3014
+ stroke: "currentColor",
3015
+ strokeWidth: "2",
3016
+ strokeLinecap: "round",
3017
+ strokeLinejoin: "round"
3018
+ }
3019
+ )
3020
+ ]
3021
+ }
3022
+ );
3023
+ };
3024
+ var CheckedBadge_default = CheckedBadge;
3025
+
3026
+ // src/queries/useLstApy.ts
3027
+ var import_react_query7 = require("@tanstack/react-query");
3028
+ function useLstApyFetcher() {
3029
+ return (0, import_react_query7.useQuery)(
3030
+ ["lst-apy"],
3031
+ () => __async(this, null, function* () {
3032
+ const lstApy = yield fetch(`https://worker.jup.ag/lst-apys`);
3033
+ const apyResult = yield lstApy.json();
3034
+ return apyResult;
3035
+ }),
3036
+ {
3037
+ retry: 3,
3038
+ keepPreviousData: true,
3039
+ staleTime: 3e5
3040
+ // 5m
3041
+ }
3042
+ );
3043
+ }
3044
+
3045
+ // src/components/FormPairRow.tsx
3046
+ var import_react_query8 = require("@tanstack/react-query");
3047
+ var import_jsx_runtime38 = require("react/jsx-runtime");
3048
+ var PAIR_ROW_HEIGHT = 72;
3049
+ var LSTTag = ({ mintAddress }) => {
3050
+ const { data: lstApy } = useLstApyFetcher();
3051
+ const apy = (0, import_react21.useMemo)(() => {
3052
+ if (!lstApy) return;
3053
+ const value = lstApy.apys[mintAddress];
3054
+ if (value && hasNumericValue(value)) {
3055
+ return new import_decimal8.default(value).mul(100).toDP(2).toString();
3056
+ }
3057
+ return;
3058
+ }, [lstApy, mintAddress]);
3059
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("p", { className: "rounded-md text-xxs leading-none transition-all py-0.5 px-1 text-primary/50 border border-primary/50 font-semibold", children: [
3060
+ "LST ",
3061
+ apy ? `${apy}%` : ""
3062
+ ] });
3063
+ };
3064
+ var MultiTags = ({ item }) => {
3065
+ const { data: balances } = useBalances();
3066
+ const isLoading = (0, import_react21.useRef)(false);
3067
+ const isLoaded = (0, import_react21.useRef)(false);
3068
+ const [renderedTag, setRenderedTag] = import_react21.default.useState({
3069
+ isVerified: false,
3070
+ isLST: false,
3071
+ // isUnknown: false,
3072
+ isToken2022: false,
3073
+ isFrozen: false
3074
+ });
3075
+ (0, import_react21.useEffect)(() => {
3076
+ if (isLoaded.current || isLoading.current) return;
3077
+ isLoading.current = true;
3078
+ setTimeout(() => {
3079
+ var _a2, _b;
3080
+ const result = {
3081
+ isVerified: checkIsStrictOrVerified(item),
3082
+ isLST: Boolean((_a2 = item.tags) == null ? void 0 : _a2.includes("lst")),
3083
+ // isUnknown: checkIsUnknownToken(item),
3084
+ isToken2022: Boolean(checkIsToken2022(item)),
3085
+ isFrozen: ((_b = balances == null ? void 0 : balances[item.id]) == null ? void 0 : _b.isFrozen) || false
3086
+ };
3087
+ setRenderedTag(result);
3088
+ isLoading.current = false;
3089
+ isLoaded.current = true;
3090
+ }, 0);
3091
+ }, []);
3092
+ const remainingTags = [];
3093
+ if (!renderedTag) return null;
3094
+ const { isToken2022, isFrozen, isLST } = renderedTag;
3095
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex justify-end gap-x-1", children: [
3096
+ isFrozen && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { className: "border rounded-md text-xxs leading-none transition-all py-0.5 px-1 border-warning/50 text-warning/50", children: "Frozen" }),
3097
+ isToken2022 && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { className: "rounded-md text-xxs leading-none transition-all py-0.5 px-1 bg-black/10 font-semibold text-primary-text/20", children: "Token2022" }),
3098
+ remainingTags == null ? void 0 : remainingTags.map((tag, idx) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3099
+ "div",
3100
+ {
3101
+ className: "rounded-md text-xxs leading-none transition-all py-0.5 px-1 bg-black/10 font-semibold text-primary-text/20",
3102
+ children: tag
3103
+ },
3104
+ idx
3105
+ )),
3106
+ isLST && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(LSTTag, { mintAddress: item.id })
3107
+ ] });
3108
+ };
3109
+ var FormPairRow = (props) => {
3110
+ var _a2;
3111
+ const {
3112
+ item,
3113
+ style,
3114
+ onSubmit,
3115
+ suppressCloseModal,
3116
+ showExplorer = true,
3117
+ enableUnknownTokenWarning = true
3118
+ } = props;
3119
+ const queryClient = (0, import_react_query8.useQueryClient)();
3120
+ const onClick = import_react21.default.useCallback(() => {
3121
+ queryClient.setQueryData([...ASSET_QUERY_KEY, item.id], [item]);
3122
+ onSubmit(item);
3123
+ if (suppressCloseModal) return;
3124
+ }, [onSubmit, item, suppressCloseModal, queryClient]);
3125
+ const { data: balances } = useBalances();
3126
+ const balance = (_a2 = balances == null ? void 0 : balances[item.id]) == null ? void 0 : _a2.uiAmount;
3127
+ const usdValue = balance ? new import_decimal8.default(balance).mul(item.usdPrice || 0) : void 0;
3128
+ const usdValueDisplay = usdValue && usdValue.gte(0.01) ? `$${formatNumber.format(usdValue, 2)}` : "";
3129
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3130
+ "li",
3131
+ {
3132
+ className: `rounded cursor-pointer px-5 my-1 list-none flex w-full items-center bg-interactive hover:bg-interactive/80`,
3133
+ style: __spreadValues({ maxHeight: PAIR_ROW_HEIGHT - 4, height: PAIR_ROW_HEIGHT - 4 }, style),
3134
+ onClick,
3135
+ translate: "no",
3136
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex h-full w-full items-center space-x-4", children: [
3137
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: "flex-shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: "bg-gray-200 rounded-full", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(TokenIcon_default, { info: item, width: 36, height: 36, enableUnknownTokenWarning }) }) }),
3138
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex flex-col gap-y-px", children: [
3139
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex items-center", children: [
3140
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { className: "text-sm font-medium text-primary-text truncate", children: item.symbol }),
3141
+ checkIsStrictOrVerified(item) && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { className: "rounded-md text-xxs leading-none transition-all py-0.5 px-1 text-primary", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CheckedBadge_default, { width: 18, height: 18 }) })
3142
+ ] }),
3143
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { className: "text-xs text-primary-text/50 dark:text-primary-text-35 truncate", children: item.id === WRAPPED_SOL_MINT.toBase58() ? "Solana" : item.name }),
3144
+ showExplorer ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: "-ml-1 z-10 w-fit", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(TokenLink_default, { tokenInfo: item }) }) : null
3145
+ ] }) }),
3146
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "text-xs text-primary-text/50 text-right h-full flex flex-col justify-evenly", children: [
3147
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Coinbalance_default, { mintAddress: item.id, hideZeroBalance: true }),
3148
+ usdValueDisplay ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { children: usdValueDisplay }) : null,
3149
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(MultiTags, __spreadValues({}, props))
3150
+ ] })
3151
+ ] })
3152
+ }
3153
+ );
3154
+ };
3155
+ var FormPairRow_default = FormPairRow;
3156
+
3157
+ // src/hooks/useSearch.ts
3158
+ var import_react22 = require("react");
3159
+ var import_react_query9 = require("@tanstack/react-query");
3160
+ var CHUNK_SIZE = 100;
3161
+ var useSearch = (mintAddresses, options = {}) => {
3162
+ var _a2, _b;
3163
+ const mintAddressesString = (0, import_react22.useMemo)(() => mintAddresses.join(","), [mintAddresses]);
3164
+ return (0, import_react_query9.useQuery)({
3165
+ queryKey: ["search", mintAddressesString],
3166
+ queryFn: () => __async(void 0, null, function* () {
3167
+ if (mintAddresses.length === 0) {
3168
+ return searchService.search("");
3169
+ }
3170
+ const chunks = [];
3171
+ for (let i = 0; i < mintAddresses.length; i += CHUNK_SIZE) {
3172
+ chunks.push(mintAddresses.slice(i, i + CHUNK_SIZE));
3173
+ }
3174
+ const chunkPromises = chunks.map(
3175
+ (chunk) => searchService.search(chunk.join(","))
3176
+ );
3177
+ const results = yield Promise.allSettled(chunkPromises);
3178
+ return results.flatMap((result) => result.status === "fulfilled" ? result.value : []);
3179
+ }),
3180
+ enabled: (_a2 = options.enabled) != null ? _a2 : true,
3181
+ staleTime: (_b = options.staleTime) != null ? _b : Infinity
3182
+ });
3183
+ };
3184
+
3185
+ // src/components/FormPairSelector.tsx
3186
+ var import_jsx_runtime39 = require("react/jsx-runtime");
3187
+ var PAIR_ROW_HEIGHT2 = 72;
3188
+ var SEARCH_BOX_HEIGHT = 56;
3189
+ var rowRenderer = (0, import_react23.memo)((props) => {
3190
+ const { data, index, style } = props;
3191
+ const item = data.searchResult[index];
3192
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(FormPairRow_default, { item, style, onSubmit: data.onSubmit }, item.address);
3193
+ }, import_react_window.areEqual);
3194
+ var FormPairSelector = ({ onSubmit, onClose }) => {
3195
+ const [search, setSearch] = (0, import_react23.useState)("");
3196
+ const { data: balances = {} } = useBalances();
3197
+ const { data: blueChipTokens = [] } = useSearch([]);
3198
+ const { data: searchTokens = [], isLoading } = useSearch([search], { staleTime: 5 * 60 * 1e3 });
3199
+ const { data: userBalanceTokens = [] } = useSearch([Object.keys(balances).join(",")]);
3200
+ const searchResult = (0, import_react23.useMemo)(() => {
3201
+ if (!search) {
3202
+ return sortByUserBalance([...userBalanceTokens, ...blueChipTokens], balances);
3203
+ } else {
3204
+ return sortByUserBalance(searchTokens, balances);
3205
+ }
3206
+ }, [blueChipTokens, balances, searchTokens, search, userBalanceTokens]);
3207
+ const triggerSearch = (0, import_react23.useCallback)(
3208
+ (0, import_lodash2.default)((value) => __async(void 0, null, function* () {
3209
+ setSearch(value);
3210
+ }), 200),
3211
+ [blueChipTokens]
3212
+ );
3213
+ const onChange = (0, import_react23.useCallback)(
3214
+ (e) => {
3215
+ setSearch("");
3216
+ triggerSearch(e.target.value);
3217
+ },
3218
+ [triggerSearch]
3219
+ );
3220
+ const listRef = (0, import_react23.createRef)();
3221
+ const inputRef = (0, import_react23.createRef)();
3222
+ (0, import_react23.useEffect)(() => {
3223
+ var _a2;
3224
+ return (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
3225
+ }, [inputRef]);
3226
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex flex-col h-full w-full py-4 px-2 bg-black", children: [
3227
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex w-full justify-between", children: [
3228
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "text-primary-text fill-current w-6 h-6 cursor-pointer", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(LeftArrowIcon_default, { width: 24, height: 24 }) }),
3229
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "text-primary-text", children: "Select Token" }),
3230
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: " w-6 h-6" })
3231
+ ] }),
3232
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
3233
+ "div",
3234
+ {
3235
+ className: "flex px-5 mt-4 w-[98%] rounded-xl bg-module",
3236
+ style: { height: SEARCH_BOX_HEIGHT, maxHeight: SEARCH_BOX_HEIGHT },
3237
+ children: [
3238
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SearchIcon_default, {}),
3239
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3240
+ "input",
3241
+ {
3242
+ autoComplete: "off",
3243
+ className: "w-full rounded-xl ml-4 truncate bg-transparent text-primary-text placeholder:text-primary-text/50",
3244
+ placeholder: `Search`,
3245
+ onChange: (e) => onChange(e),
3246
+ ref: inputRef
3247
+ }
3248
+ )
3249
+ ]
3250
+ }
3251
+ ),
3252
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "mt-2", style: { flexGrow: 1 }, children: [
3253
+ searchResult && searchResult.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_virtualized_auto_sizer.default, { children: ({ height, width }) => {
3254
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3255
+ import_react_window.FixedSizeList,
3256
+ {
3257
+ ref: listRef,
3258
+ height,
3259
+ itemCount: searchResult.length,
3260
+ itemSize: PAIR_ROW_HEIGHT2,
3261
+ width: width - 2,
3262
+ itemData: {
3263
+ searchResult,
3264
+ onSubmit
3265
+ },
3266
+ className: cn("overflow-y-scroll mr-1 min-h-[12rem] px-5 webkit-scrollbar"),
3267
+ children: rowRenderer
3268
+ }
3269
+ );
3270
+ } }),
3271
+ isLoading ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "mt-4 mb-4 text-center text-primary-text/50", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { children: "Loading..." }) }) : searchResult && searchResult.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "mt-4 mb-4 text-center text-primary-text/50", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { children: "No tokens found" }) }) : /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_jsx_runtime39.Fragment, {})
3272
+ ] })
3273
+ ] });
3274
+ };
3275
+ var FormPairSelector_default = FormPairSelector;
3276
+
3277
+ // src/components/screens/InitialScreen.tsx
3278
+ var import_decimal9 = __toESM(require("decimal.js"));
3279
+ var import_jsx_runtime40 = require("react/jsx-runtime");
3280
+ var InitialScreen = () => {
3281
+ const { data: balances } = useBalances();
3282
+ const {
3283
+ form,
3284
+ setForm,
3285
+ setErrors,
3286
+ quoteResponseMeta,
3287
+ loading
3288
+ } = useSwapContext();
3289
+ const { setScreen } = useScreenState();
3290
+ const balance = (0, import_react24.useMemo)(() => {
3291
+ var _a2;
3292
+ if (!balances) return 0;
3293
+ return ((_a2 = balances[form.fromMint]) == null ? void 0 : _a2.uiAmount) || 0;
3294
+ }, [balances, form.fromMint]);
3295
+ const [isDisabled, setIsDisabled] = (0, import_react24.useState)(false);
3296
+ const { data: asset } = useAsset(form.fromMint);
3297
+ (0, import_react24.useEffect)(() => {
3298
+ if (!form.fromValue || !form.fromMint || !form.toMint || !form.toValue || !quoteResponseMeta || loading) {
3299
+ setErrors({});
3300
+ setIsDisabled(true);
3301
+ return;
3302
+ }
3303
+ if (new import_decimal9.default(form.fromValue).gt(balance)) {
3304
+ setErrors({
3305
+ fromValue: { title: `Insufficient ${asset == null ? void 0 : asset.symbol}`, message: "" }
3306
+ });
3307
+ setIsDisabled(true);
3308
+ return;
3309
+ }
3310
+ setErrors({});
3311
+ setIsDisabled(false);
3312
+ }, [form, asset, balance, quoteResponseMeta, loading, setErrors]);
3313
+ const [selectPairSelector, setSelectPairSelector] = (0, import_react24.useState)(null);
3314
+ const onSelectMint = (0, import_react24.useCallback)(
3315
+ (tokenInfo) => __async(void 0, null, function* () {
3316
+ if (selectPairSelector === "fromMint") {
3317
+ setForm((prev) => __spreadValues(__spreadProps(__spreadValues({}, prev), {
3318
+ fromMint: tokenInfo.id,
3319
+ fromValue: ""
3320
+ }), prev.toMint === tokenInfo.id ? { toMint: prev.fromMint } : void 0));
3321
+ } else {
3322
+ setForm((prev) => __spreadValues(__spreadProps(__spreadValues({}, prev), {
3323
+ toMint: tokenInfo.id,
3324
+ toValue: ""
3325
+ }), prev.fromMint === tokenInfo.id ? { fromMint: prev.toMint } : void 0));
3326
+ }
3327
+ setSelectPairSelector(null);
3328
+ }),
3329
+ [selectPairSelector, setForm]
3330
+ );
3331
+ const onSubmitToConfirmation = (0, import_react24.useCallback)(() => {
3332
+ setScreen("Swapping");
3333
+ }, [setScreen]);
3334
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
3335
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3336
+ "form",
3337
+ {
3338
+ onSubmit: onSubmitToConfirmation,
3339
+ className: cn({
3340
+ hidden: Boolean(selectPairSelector)
3341
+ }),
3342
+ children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3343
+ Form_default,
3344
+ {
3345
+ onSubmit: onSubmitToConfirmation,
3346
+ isDisabled,
3347
+ setSelectPairSelector
3348
+ }
3349
+ )
3350
+ }
3351
+ ),
3352
+ selectPairSelector !== null ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "absolute top-0 left-0 h-full w-full bg-black rounded-lg overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3353
+ FormPairSelector_default,
3354
+ {
3355
+ onSubmit: onSelectMint,
3356
+ onClose: () => setSelectPairSelector(null)
3357
+ }
3358
+ ) }) : null
3359
+ ] });
3360
+ };
3361
+ var InitialScreen_default = InitialScreen;
3362
+
3363
+ // src/components/screens/ReviewOrderScreen.tsx
3364
+ var import_react25 = require("react");
3365
+ var import_jsx_runtime41 = require("react/jsx-runtime");
3366
+ var ConfirmationScreen = () => {
3367
+ const {
3368
+ fromTokenInfo,
3369
+ toTokenInfo,
3370
+ onSubmit: onSubmitJupiter,
3371
+ quoteResponseMeta,
3372
+ loading,
3373
+ refresh
3374
+ } = useSwapContext();
3375
+ const [hasExpired] = useTimeDiff_default();
3376
+ const { setScreen } = useScreenState();
3377
+ const onGoBack = () => {
3378
+ refresh();
3379
+ setScreen("Initial");
3380
+ };
3381
+ const onSubmit = (0, import_react25.useCallback)(() => __async(void 0, null, function* () {
3382
+ setScreen("Swapping");
3383
+ onSubmitJupiter();
3384
+ }), [onSubmitJupiter, setScreen]);
3385
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex flex-col h-full w-full py-4 px-2", children: [
3386
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex w-full justify-between", children: [
3387
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "text-primary-text fill-current w-6 h-6 cursor-pointer", onClick: onGoBack, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(LeftArrowIcon_default, { width: 24, height: 24 }) }),
3388
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "text-primary-text", children: "Review Order" }),
3389
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: " w-6 h-6" })
3390
+ ] }),
3391
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { children: quoteResponseMeta && fromTokenInfo && toTokenInfo ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3392
+ PriceInfo_default,
3393
+ {
3394
+ quoteResponse: quoteResponseMeta,
3395
+ fromTokenInfo,
3396
+ toTokenInfo,
3397
+ loading,
3398
+ containerClassName: "bg-modiu; border-none"
3399
+ }
3400
+ ) : null }),
3401
+ hasExpired ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(JupButton_default, { size: "lg", className: "w-full mt-4 disabled:opacity-50 !p-0", onClick: onGoBack, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "text-sm", children: "Refresh" }) }) : /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3402
+ JupButton_default,
3403
+ {
3404
+ size: "lg",
3405
+ className: cn(
3406
+ "w-full mt-4 disabled:opacity-50 !text-uiv2-text/75 leading-none !max-h-14 bg-gradient-to-r from-[#00BEF0] to-[#C7F284]"
3407
+ ),
3408
+ onClick: onSubmit,
3409
+ children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { children: "Confirm" })
3410
+ }
3411
+ )
3412
+ ] });
3413
+ };
3414
+ var ReviewOrderScreen_default = ConfirmationScreen;
3415
+
3416
+ // src/components/screens/SwappingScreen.tsx
3417
+ var import_react26 = require("react");
3418
+
3419
+ // src/components/Spinner/index.tsx
3420
+ var import_jsx_runtime42 = require("react/jsx-runtime");
3421
+ var Spinner = ({
3422
+ className,
3423
+ baseColor = "currentColor",
3424
+ spinnerColor = "currentColor",
3425
+ width = 16,
3426
+ height = 16
3427
+ }) => /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { className: `rounded-full flex items-center justify-center ${className}`, style: { width, height }, children: /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
3428
+ "svg",
3429
+ {
3430
+ className: "animate-spin h-5 w-5 text-black dark:text-primary-text",
3431
+ xmlns: "http://www.w3.org/2000/svg",
3432
+ fill: "none",
3433
+ viewBox: "0 0 24 24",
3434
+ children: [
3435
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: baseColor, strokeWidth: "4" }),
3436
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
3437
+ "path",
3438
+ {
3439
+ className: "opacity-75",
3440
+ fill: spinnerColor,
3441
+ d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
3442
+ }
3443
+ )
3444
+ ]
3445
+ }
3446
+ ) });
3447
+ var Spinner_default = Spinner;
3448
+
3449
+ // src/icons/SuccessIcon.tsx
3450
+ var import_jsx_runtime43 = require("react/jsx-runtime");
3451
+ var SuccessIcon = (props) => {
3452
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("svg", __spreadProps(__spreadValues({ xmlns: "http://www.w3.org/2000/svg", width: "256", height: "256", viewBox: "0 0 256 256" }, props), { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
3453
+ "path",
3454
+ {
3455
+ fill: "currentColor",
3456
+ d: "M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m45.66 85.66l-56 56a8 8 0 0 1-11.32 0l-24-24a8 8 0 0 1 11.32-11.32L112 148.69l50.34-50.35a8 8 0 0 1 11.32 11.32"
3457
+ }
3458
+ ) }));
3459
+ };
3460
+ var SuccessIcon_default = SuccessIcon;
3461
+
3462
+ // src/components/screens/SwappingScreen.tsx
3463
+ var import_jsx_runtime44 = require("react/jsx-runtime");
3464
+ var ErrorIcon = () => {
3465
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
3466
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("g", { clipPath: "url(#clip0_7547_116874)", children: [
3467
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("circle", { cx: "20", cy: "20", r: "20", fill: "#F04A44" }),
3468
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
3469
+ "path",
3470
+ {
3471
+ d: "M19.8444 25.4321C18.6773 25.4332 17.7205 24.5092 17.6793 23.3431L17.1718 9.04107C17.1507 8.45326 17.3706 7.88344 17.7786 7.46056C18.1867 7.03768 18.7492 6.7998 19.337 6.7998H20.3519C20.9397 6.7998 21.5021 7.03768 21.9102 7.46056C22.3183 7.88344 22.5382 8.45329 22.5171 9.04107L22.0096 23.3431C21.9684 24.5092 21.0116 25.4332 19.8444 25.4321Z",
3472
+ fill: "white"
3473
+ }
3474
+ ),
3475
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
3476
+ "path",
3477
+ {
3478
+ d: "M22.8893 30.4989C22.8893 32.1809 21.5266 33.5436 19.8446 33.5436C18.1626 33.5436 16.7998 32.1809 16.7998 30.4989C16.7998 28.8169 18.1626 27.4541 19.8446 27.4541C21.5266 27.4541 22.8893 28.8169 22.8893 30.4989Z",
3479
+ fill: "white"
3480
+ }
3481
+ )
3482
+ ] }),
3483
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("clipPath", { id: "clip0_7547_116874", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("rect", { width: "40", height: "40", fill: "white" }) }) })
3484
+ ] });
3485
+ };
3486
+ var SwappingScreen = () => {
3487
+ const {
3488
+ displayMode,
3489
+ lastSwapResult,
3490
+ reset,
3491
+ swapping: { txStatus },
3492
+ fromTokenInfo,
3493
+ toTokenInfo,
3494
+ refresh
3495
+ } = useSwapContext();
3496
+ const { screen: screen2, setScreen } = useScreenState();
3497
+ const [errorMessage, setErrorMessage] = (0, import_react26.useState)("");
3498
+ const onSwapMore = () => {
3499
+ reset();
3500
+ setErrorMessage("");
3501
+ setScreen("Initial");
3502
+ refresh();
3503
+ };
3504
+ const onGoBack = () => {
3505
+ reset({ resetValues: false });
3506
+ setErrorMessage("");
3507
+ setScreen("Initial");
3508
+ refresh();
3509
+ };
3510
+ (0, import_react26.useEffect)(() => {
3511
+ var _a2, _b, _c, _d;
3512
+ if (screen2 !== "Swapping") return;
3513
+ if ((lastSwapResult == null ? void 0 : lastSwapResult.swapResult) && "error" in (lastSwapResult == null ? void 0 : lastSwapResult.swapResult)) {
3514
+ setErrorMessage(((_b = (_a2 = lastSwapResult == null ? void 0 : lastSwapResult.swapResult) == null ? void 0 : _a2.error) == null ? void 0 : _b.message) || "");
3515
+ if (window.Jupiter.onSwapError) {
3516
+ window.Jupiter.onSwapError({
3517
+ error: (_c = lastSwapResult == null ? void 0 : lastSwapResult.swapResult) == null ? void 0 : _c.error,
3518
+ quoteResponseMeta: lastSwapResult == null ? void 0 : lastSwapResult.quoteReponse
3519
+ });
3520
+ }
3521
+ return;
3522
+ } else if ((lastSwapResult == null ? void 0 : lastSwapResult.swapResult) && "txid" in (lastSwapResult == null ? void 0 : lastSwapResult.swapResult)) {
3523
+ if (window.Jupiter.onSuccess) {
3524
+ window.Jupiter.onSuccess({
3525
+ txid: (_d = lastSwapResult == null ? void 0 : lastSwapResult.swapResult) == null ? void 0 : _d.txid,
3526
+ swapResult: lastSwapResult == null ? void 0 : lastSwapResult.swapResult,
3527
+ quoteResponseMeta: lastSwapResult == null ? void 0 : lastSwapResult.quoteReponse
3528
+ });
3529
+ }
3530
+ return;
3531
+ }
3532
+ }, [lastSwapResult, screen2]);
3533
+ const onClose = () => {
3534
+ if (!displayMode || displayMode === "modal") {
3535
+ window.Jupiter.close();
3536
+ }
3537
+ reset();
3538
+ setScreen("Initial");
3539
+ };
3540
+ const { explorer, getExplorer } = usePreferredExplorer();
3541
+ const isLoading = (txStatus == null ? void 0 : txStatus.status) === "loading" || (txStatus == null ? void 0 : txStatus.status) === "pending-approval" || (txStatus == null ? void 0 : txStatus.status) === "sending";
3542
+ const Content2 = () => {
3543
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(import_jsx_runtime44.Fragment, { children: [
3544
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "flex w-full justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "text-primary-text", children: "Swapping" }) }),
3545
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "flex w-full justify-center items-center mt-9", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "h-16 w-16 animate-hue duration-100", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(JupiterLogo_default, { width: 64, height: 64 }) }) }),
3546
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "flex flex-col w-full justify-center items-center px-5 mt-7", children: isLoading && /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "flex items-center w-full rounded-xl p-4 bg-module mb-2", children: [
3547
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Spinner_default, { spinnerColor: "white" }),
3548
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "ml-4 flex w-full justify-between", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("span", { className: "text-primary-text text-sm", children: [
3549
+ txStatus.status === "loading" && "Preparing transactions",
3550
+ txStatus.status === "pending-approval" && "Pending Approval",
3551
+ txStatus.status === "sending" && "Swapping"
3552
+ ] }) })
3553
+ ] }) })
3554
+ ] });
3555
+ };
3556
+ const SuccessContent = () => {
3557
+ const { inputAmount, outputAmount, explorerLink } = (0, import_react26.useMemo)(() => {
3558
+ return {
3559
+ inputAmount: (lastSwapResult == null ? void 0 : lastSwapResult.swapResult) && "inputAmount" in (lastSwapResult == null ? void 0 : lastSwapResult.swapResult) ? lastSwapResult == null ? void 0 : lastSwapResult.swapResult.inputAmount : 0,
3560
+ outputAmount: (lastSwapResult == null ? void 0 : lastSwapResult.swapResult) && "outputAmount" in (lastSwapResult == null ? void 0 : lastSwapResult.swapResult) ? lastSwapResult == null ? void 0 : lastSwapResult.swapResult.outputAmount : 0,
3561
+ explorerLink: (lastSwapResult == null ? void 0 : lastSwapResult.swapResult) && "txid" in (lastSwapResult == null ? void 0 : lastSwapResult.swapResult) ? getExplorer(lastSwapResult == null ? void 0 : lastSwapResult.swapResult.txid) : ""
3562
+ };
3563
+ }, []);
3564
+ if (!fromTokenInfo || !toTokenInfo || !(lastSwapResult == null ? void 0 : lastSwapResult.quoteReponse)) {
3565
+ return null;
3566
+ }
3567
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(import_jsx_runtime44.Fragment, { children: [
3568
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "flex justify-center mt-8", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: " flex justify-center relative items-center", children: [
3569
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "bg-success bg-opacity-[15%] animate-pulse h-[60px] w-[60px] rounded-full" }),
3570
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "rounded-full absolute justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(SuccessIcon_default, { className: "text-success", height: 56, width: 56 }) })
3571
+ ] }) }),
3572
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "flex flex-col justify-center items-center gap-y-2", children: [
3573
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "mt-2 flex flex-col items-center justify-center text-center px-4", children: [
3574
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("p", { className: "text-xs font-semibold text-primary-text", children: [
3575
+ "Swapped ",
3576
+ readableValue(inputAmount, fromTokenInfo.decimals),
3577
+ " ",
3578
+ fromTokenInfo.symbol,
3579
+ " to"
3580
+ ] }),
3581
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("p", { className: "text-2xl font-semibold text-primary-text", children: [
3582
+ readableValue(outputAmount, toTokenInfo.decimals),
3583
+ " ",
3584
+ toTokenInfo.symbol
3585
+ ] })
3586
+ ] }),
3587
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: " bg-module rounded-xl overflow-y-auto w-full webkit-scrollbar py-3 max-h-[260px] px-3", children: [
3588
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
3589
+ PriceInfo_default,
3590
+ {
3591
+ quoteResponse: lastSwapResult == null ? void 0 : lastSwapResult.quoteReponse,
3592
+ fromTokenInfo,
3593
+ toTokenInfo,
3594
+ loading: false,
3595
+ containerClassName: " border-none mt-0"
3596
+ }
3597
+ ),
3598
+ explorerLink && /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "flex items-center justify-between text-xs text-primary-text/50 mt-4", children: [
3599
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { children: "Transaction" }) }),
3600
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(
3601
+ "a",
3602
+ {
3603
+ href: explorerLink,
3604
+ target: "_blank",
3605
+ rel: "noopener noreferrer",
3606
+ className: "cursor-pointer text-primary-text ml-2 text-xs hover:underline",
3607
+ children: [
3608
+ "View on ",
3609
+ explorer
3610
+ ]
3611
+ }
3612
+ )
3613
+ ] })
3614
+ ] })
3615
+ ] }),
3616
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "pb-4 flex space-x-2", children: [
3617
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
3618
+ JupButton_default,
3619
+ {
3620
+ size: "lg",
3621
+ className: "w-full mt-4 disabled:opacity-50 !text-uiv2-text/75 leading-none !max-h-14 bg-primary",
3622
+ onClick: onSwapMore,
3623
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { className: "text-sm", children: "Swap More" }) })
3624
+ }
3625
+ ),
3626
+ displayMode !== "integrated" ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
3627
+ JupButton_default,
3628
+ {
3629
+ size: "lg",
3630
+ className: "w-full mt-4 disabled:opacity-50 leading-none !max-h-14 text-primary-text bg-interactive",
3631
+ onClick: onClose,
3632
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { className: "text-sm", children: "Close" })
3633
+ }
3634
+ ) : null
3635
+ ] })
3636
+ ] });
3637
+ };
3638
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "flex flex-col h-full w-full px-2", children: [
3639
+ errorMessage || (txStatus == null ? void 0 : txStatus.status) === "fail" ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "flex flex-col items-center justify-center text-center mt-12", children: [
3640
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(ErrorIcon, {}),
3641
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "text-primary-text mt-2", children: "Swap Failed" }),
3642
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "text-primary-text/50 text-xs mt-2", children: "We were unable to complete the swap, please try again." }),
3643
+ errorMessage ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "text-primary-text/50 text-xs mt-2 break-all", children: errorMessage }) : "",
3644
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
3645
+ JupButton_default,
3646
+ {
3647
+ size: "lg",
3648
+ className: "w-full mt-6 disabled:opacity-50 !text-uiv2-text/75 leading-none !max-h-14 bg-primary",
3649
+ onClick: onGoBack,
3650
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { children: "Retry" })
3651
+ }
3652
+ )
3653
+ ] }) }) : null,
3654
+ !errorMessage && (txStatus == null ? void 0 : txStatus.status) === "timeout" ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { className: "flex justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "flex flex-col items-center justify-center text-center mt-12", children: [
3655
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(ErrorIcon, {}),
3656
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "text-primary-text mt-2", children: "Transaction timed-out" }),
3657
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "text-primary-text/50 text-xs mt-2", children: "We were unable to complete the swap, please try again." }),
3658
+ errorMessage ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "text-primary-text/50 text-xs mt-2", children: errorMessage }) : "",
3659
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
3660
+ JupButton_default,
3661
+ {
3662
+ size: "lg",
3663
+ className: "w-full mt-6 disabled:opacity-50 !text-uiv2-text/75 leading-none !max-h-14 bg-primary",
3664
+ onClick: onGoBack,
3665
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { children: "Retry" })
3666
+ }
3667
+ )
3668
+ ] }) }) : null,
3669
+ !errorMessage && isLoading ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Content2, {}) : null,
3670
+ !errorMessage && (txStatus == null ? void 0 : txStatus.status) === "success" ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(SuccessContent, {}) : null
3671
+ ] });
3672
+ };
3673
+ var SwappingScreen_default = SwappingScreen;
3674
+
3675
+ // src/components/screens/WalletScreen.tsx
3676
+ var import_wallet_adapter3 = require("@jup-ag/wallet-adapter");
3677
+ var import_react27 = require("react");
3678
+
3679
+ // src/icons/CloseIcon.tsx
3680
+ var import_jsx_runtime45 = require("react/jsx-runtime");
3681
+ var CloseIcon = ({ width = 20, height = 20 }) => {
3682
+ return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("svg", { width, height, viewBox: "0 0 20 21", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3683
+ "path",
3684
+ {
3685
+ d: "M2.0336 16.2126L8.2336 10.0126L2.0336 3.81263C1.7961 3.57903 1.66172 3.25951 1.66016 2.92669C1.65938 2.59309 1.79141 2.27357 2.02734 2.03763C2.26328 1.80247 2.5828 1.67045 2.9164 1.67201C3.25 1.67357 3.56874 1.80795 3.80234 2.04623L9.99994 8.24623L16.1999 2.04623C16.4335 1.80795 16.7523 1.67357 17.0859 1.67201C17.4187 1.67045 17.739 1.80248 17.9749 2.03763C18.2109 2.27357 18.3429 2.59309 18.3413 2.92669C18.3406 3.25951 18.2062 3.57903 17.9687 3.81263L11.7663 10.0126L17.9663 16.2126C18.2038 16.4462 18.3382 16.7658 18.3397 17.0986C18.3405 17.4322 18.2085 17.7517 17.9725 17.9876C17.7366 18.2228 17.4171 18.3548 17.0835 18.3533C16.7499 18.3517 16.4311 18.2173 16.1975 17.979L9.99994 11.779L3.79994 17.979C3.31088 18.4611 2.52494 18.4579 2.039 17.9736C1.55384 17.4884 1.54994 16.7025 2.03119 16.2126L2.0336 16.2126Z",
3686
+ fill: "currentColor"
3687
+ }
3688
+ ) });
3689
+ };
3690
+ var CloseIcon_default = CloseIcon;
3691
+
3692
+ // src/components/screens/WalletScreen.tsx
3693
+ var import_jsx_runtime46 = require("react/jsx-runtime");
3694
+ var WalletScreen = () => {
3695
+ const { setScreen } = useScreenState();
3696
+ const { handleConnectClick } = (0, import_wallet_adapter3.useUnifiedWalletContext)();
3697
+ const { wallets } = useWalletPassThrough();
3698
+ const handleConnect = (event, wallet) => __async(void 0, null, function* () {
3699
+ try {
3700
+ yield handleConnectClick(event, wallet.adapter);
3701
+ } catch (error) {
3702
+ console.error("Failed to connect wallet:", error);
3703
+ } finally {
3704
+ setScreen("Initial");
3705
+ }
3706
+ });
3707
+ const numberOfWallets = (0, import_react27.useMemo)(() => {
3708
+ return wallets == null ? void 0 : wallets.length;
3709
+ }, [wallets]);
3710
+ const hasWallet = (0, import_react27.useMemo)(() => {
3711
+ return numberOfWallets > 0;
3712
+ }, [numberOfWallets]);
3713
+ return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { className: "text-primary-text p-2", children: [
3714
+ /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { className: "flex justify-between items-center mb-2 h-[28px] ", children: [
3715
+ /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("h1", { className: "text-sm font-bold", children: [
3716
+ "Available Wallets (",
3717
+ numberOfWallets,
3718
+ ")"
3719
+ ] }),
3720
+ /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
3721
+ "button",
3722
+ {
3723
+ onClick: () => setScreen("Initial"),
3724
+ className: "text-primary-text hover:text-primary-text/50 transition-colors bg-interactive rounded-full p-1",
3725
+ children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(CloseIcon_default, { width: 15, height: 15 })
3726
+ }
3727
+ )
3728
+ ] }),
3729
+ !hasWallet && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("div", { className: "text-sm font-medium text-primary-text flex items-center justify-center h-full py-4", children: "No wallet found" }),
3730
+ /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("div", { className: "grid grid-cols-2 gap-2", children: wallets == null ? void 0 : wallets.map((wallet) => /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
3731
+ "button",
3732
+ {
3733
+ onClick: (e) => handleConnect(e, wallet),
3734
+ className: `w-full text-left bg-interactive p-4 rounded-lg transition-colors ${"hover:bg-interactive/80 cursor-pointer"}`,
3735
+ children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { className: "flex items-center gap-3", children: [
3736
+ wallet.adapter.icon && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("img", { src: wallet.adapter.icon, alt: `${wallet.adapter.name} icon`, className: "w-8 h-8" }),
3737
+ /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("h2", { className: "text-sm font-medium", children: wallet.adapter.name }) })
3738
+ ] }) })
3739
+ },
3740
+ wallet.adapter.name
3741
+ )) })
3742
+ ] });
3743
+ };
3744
+ var WalletScreen_default = WalletScreen;
3745
+
3746
+ // src/icons/JupiterLogoV2.tsx
3747
+ var import_jsx_runtime47 = require("react/jsx-runtime");
3748
+ var JupiterLogoV2 = (props) => {
3749
+ return /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)("svg", __spreadProps(__spreadValues({ xmlns: "http://www.w3.org/2000/svg", width: "128", height: "128", viewBox: "0 0 33 32", fill: "none" }, props), { children: [
3750
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("g", { clipPath: "url(#clip0_11565_169621)", children: /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)("g", { filter: "url(#filter0_d_11565_169621)", children: [
3751
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
3752
+ "path",
3753
+ {
3754
+ d: "M3.09074 25.1666C4.44267 27.0471 6.17683 28.6205 8.1795 29.7838C10.1822 30.947 12.4081 31.6738 14.7114 31.9165C13.5264 30.1333 11.8039 28.4928 9.65354 27.2438C7.50318 25.9948 5.22592 25.3125 3.09074 25.1666Z",
3755
+ fill: "url(#paint0_linear_11565_169621)"
3756
+ }
3757
+ ),
3758
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
3759
+ "path",
3760
+ {
3761
+ d: "M12.543 22.2705C8.40015 19.8636 3.91612 19.2502 0.707663 20.3338C1.0174 21.3575 1.42589 22.3487 1.92738 23.2934C4.71498 23.2288 7.75856 23.9859 10.5906 25.6308C13.4227 27.2757 15.5888 29.5459 16.9143 32C17.9839 31.9672 19.0479 31.8309 20.0913 31.5932C19.4426 28.2698 16.6849 24.6779 12.543 22.2705Z",
3762
+ fill: "url(#paint1_linear_11565_169621)"
3763
+ }
3764
+ ),
3765
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
3766
+ "path",
3767
+ {
3768
+ d: "M32.2852 12.5009C31.7585 10.3584 30.8054 8.34403 29.4829 6.57804C28.1604 4.81205 26.4956 3.33067 24.5879 2.22235C22.6802 1.11403 20.5687 0.401504 18.3796 0.127309C16.1904 -0.146885 13.9684 0.0228794 11.8463 0.626465C15.3915 1.06033 19.3267 2.39122 23.1859 4.63324C27.0452 6.87525 30.1533 9.63411 32.2852 12.5009Z",
3769
+ fill: "url(#paint2_linear_11565_169621)"
3770
+ }
3771
+ ),
3772
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
3773
+ "path",
3774
+ {
3775
+ d: "M27.1271 20.3583C25.3124 17.3446 22.2038 14.4588 18.3743 12.2342C14.5449 10.0095 10.4991 8.7388 6.98531 8.65474C3.894 8.58152 1.57389 9.48017 0.621548 11.1197C0.616125 11.1294 0.608532 11.1386 0.602566 11.1484C0.516877 11.4559 0.44312 11.7639 0.37587 12.0731C1.70568 11.5481 3.24645 11.2558 4.95969 11.2232C8.76959 11.1517 13.0334 12.3703 16.9681 14.6562C20.9027 16.9422 24.0759 20.0438 25.9003 23.3878C26.7182 24.8944 27.2285 26.3777 27.4308 27.7948C27.6662 27.5844 27.8972 27.3669 28.1212 27.1408C28.1272 27.1305 28.131 27.1196 28.1369 27.1088C29.0893 25.4677 28.721 23.0076 27.1271 20.3583Z",
3776
+ fill: "url(#paint3_linear_11565_169621)"
3777
+ }
3778
+ ),
3779
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
3780
+ "path",
3781
+ {
3782
+ d: "M15.4609 17.2485C9.59662 13.8416 3.11626 13.3079 0 15.6855C0.00612096 16.4297 0.0630166 17.1726 0.170292 17.9091C1.08699 17.6312 2.03177 17.4562 2.98718 17.3874C6.46952 17.1254 10.3087 18.0957 13.7927 20.1207C17.2766 22.1458 20.023 25.0018 21.5209 28.1543C21.935 29.018 22.2508 29.9254 22.4624 30.8595C23.1555 30.5878 23.8294 30.2694 24.4794 29.9066C25.0011 26.0213 21.3268 20.656 15.4609 17.2485Z",
3783
+ fill: "url(#paint4_linear_11565_169621)"
3784
+ }
3785
+ ),
3786
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
3787
+ "path",
3788
+ {
3789
+ d: "M30.1434 15.3141C28.3082 12.3036 25.1724 9.40969 21.3158 7.17039C17.4593 4.93109 13.3977 3.64033 9.87257 3.53674C7.1853 3.45919 5.10382 4.11053 4.02457 5.34109C8.50588 4.58182 14.4168 5.85794 20.146 9.18625C25.8753 12.5146 29.9135 17.0181 31.4722 21.2868C32.0064 19.7406 31.5416 17.6098 30.1434 15.3141Z",
3790
+ fill: "url(#paint5_linear_11565_169621)"
3791
+ }
3792
+ )
3793
+ ] }) }),
3794
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)("defs", { children: [
3795
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
3796
+ "filter",
3797
+ {
3798
+ id: "filter0_d_11565_169621",
3799
+ x: "-22.7449",
3800
+ y: "-20.4704",
3801
+ width: "77.7749",
3802
+ height: "77.4898",
3803
+ filterUnits: "userSpaceOnUse",
3804
+ colorInterpolationFilters: "sRGB",
3805
+ children: [
3806
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("feFlood", { floodOpacity: "0", result: "BackgroundImageFix" }),
3807
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
3808
+ "feColorMatrix",
3809
+ {
3810
+ in: "SourceAlpha",
3811
+ type: "matrix",
3812
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",
3813
+ result: "hardAlpha"
3814
+ }
3815
+ ),
3816
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("feOffset", { dy: "2.27449" }),
3817
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("feGaussianBlur", { stdDeviation: "11.3724" }),
3818
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("feComposite", { in2: "hardAlpha", operator: "out" }),
3819
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("feColorMatrix", { type: "matrix", values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" }),
3820
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("feBlend", { mode: "normal", in2: "BackgroundImageFix", result: "effect1_dropShadow_11565_169621" }),
3821
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("feBlend", { mode: "normal", in: "SourceGraphic", in2: "effect1_dropShadow_11565_169621", result: "shape" })
3822
+ ]
3823
+ }
3824
+ ),
3825
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
3826
+ "linearGradient",
3827
+ {
3828
+ id: "paint0_linear_11565_169621",
3829
+ x1: "21.5",
3830
+ y1: "6.5",
3831
+ x2: "6.66667",
3832
+ y2: "32",
3833
+ gradientUnits: "userSpaceOnUse",
3834
+ children: [
3835
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "0.0001", stopColor: "currentColor" }),
3836
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "1", stopColor: "currentColor" })
3837
+ ]
3838
+ }
3839
+ ),
3840
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
3841
+ "linearGradient",
3842
+ {
3843
+ id: "paint1_linear_11565_169621",
3844
+ x1: "21.5",
3845
+ y1: "6.5",
3846
+ x2: "6.66667",
3847
+ y2: "32",
3848
+ gradientUnits: "userSpaceOnUse",
3849
+ children: [
3850
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "0.0001", stopColor: "currentColor" }),
3851
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "1", stopColor: "currentColor" })
3852
+ ]
3853
+ }
3854
+ ),
3855
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
3856
+ "linearGradient",
3857
+ {
3858
+ id: "paint2_linear_11565_169621",
3859
+ x1: "21.5",
3860
+ y1: "6.5",
3861
+ x2: "6.66667",
3862
+ y2: "32",
3863
+ gradientUnits: "userSpaceOnUse",
3864
+ children: [
3865
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "0.0001", stopColor: "currentColor" }),
3866
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "1", stopColor: "currentColor" })
3867
+ ]
3868
+ }
3869
+ ),
3870
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
3871
+ "linearGradient",
3872
+ {
3873
+ id: "paint3_linear_11565_169621",
3874
+ x1: "21.5",
3875
+ y1: "6.5",
3876
+ x2: "6.66667",
3877
+ y2: "32",
3878
+ gradientUnits: "userSpaceOnUse",
3879
+ children: [
3880
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "0.0001", stopColor: "currentColor" }),
3881
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "1", stopColor: "currentColor" })
3882
+ ]
3883
+ }
3884
+ ),
3885
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
3886
+ "linearGradient",
3887
+ {
3888
+ id: "paint4_linear_11565_169621",
3889
+ x1: "21.5",
3890
+ y1: "6.5",
3891
+ x2: "6.66667",
3892
+ y2: "32",
3893
+ gradientUnits: "userSpaceOnUse",
3894
+ children: [
3895
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "0.0001", stopColor: "currentColor" }),
3896
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "1", stopColor: "currentColor" })
3897
+ ]
3898
+ }
3899
+ ),
3900
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
3901
+ "linearGradient",
3902
+ {
3903
+ id: "paint5_linear_11565_169621",
3904
+ x1: "21.5",
3905
+ y1: "6.5",
3906
+ x2: "6.66667",
3907
+ y2: "32",
3908
+ gradientUnits: "userSpaceOnUse",
3909
+ children: [
3910
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "0.0001", stopColor: "currentColor" }),
3911
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("stop", { offset: "1", stopColor: "currentColor" })
3912
+ ]
3913
+ }
3914
+ ),
3915
+ /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("clipPath", { id: "clip0_11565_169621", children: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("rect", { width: "32.2852", height: "32", fill: "white" }) })
3916
+ ] })
3917
+ ] }));
3918
+ };
3919
+ var JupiterLogoV2_default = JupiterLogoV2;
3920
+
3921
+ // src/components/Jupiter.tsx
3922
+ var import_jsx_runtime48 = require("react/jsx-runtime");
3923
+ var Content = () => {
3924
+ const { screen: screen2 } = useScreenState();
3925
+ return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("div", { id: "jupiter-plugin", className: " h-full bg-background relative flex flex-col justify-between", children: [
3926
+ /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("div", { children: [
3927
+ screen2 === "Initial" ? /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(import_jsx_runtime48.Fragment, { children: [
3928
+ /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(Header_default, {}),
3929
+ /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(InitialScreen_default, {})
3930
+ ] }) : null,
3931
+ screen2 === "Confirmation" ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(ReviewOrderScreen_default, {}) : null,
3932
+ screen2 === "Swapping" ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(SwappingScreen_default, {}) : null,
3933
+ screen2 === "Wallet" ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(WalletScreen_default, {}) : null
3934
+ ] }),
3935
+ /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("span", { className: "text-primary-text/50 text-xs p-2 flex-row flex gap-1 justify-center", children: [
3936
+ "Powered by",
3937
+ /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("a", { href: "https://jup.ag", target: "_blank", rel: "noreferrer noopener", className: "flex items-center gap-1 ", children: [
3938
+ /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(JupiterLogoV2_default, { className: "text-primary-text/50", width: 15, height: 15 }),
3939
+ "Jupiter"
3940
+ ] })
3941
+ ] })
3942
+ ] });
3943
+ };
3944
+ var JupiterApp = (props) => {
3945
+ return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(SwapContextProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(BrandingProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(Content, {}) })) }));
3946
+ };
3947
+ var Jupiter_default = JupiterApp;
3948
+
3949
+ // src/contexts/ContextProvider.tsx
3950
+ var import_wallet_adapter4 = require("@jup-ag/wallet-adapter");
3951
+ var import_react28 = __toESM(require("react"));
3952
+ var import_react29 = require("react");
3953
+ var import_jsx_runtime49 = require("react/jsx-runtime");
3954
+ var noop = () => {
3955
+ };
3956
+ var WalletContextProvider = ({
3957
+ autoConnect,
3958
+ children
3959
+ }) => {
3960
+ const enableWalletPassthrough = (() => {
3961
+ if (typeof window === "undefined") return void 0;
3962
+ return window.Jupiter.enableWalletPassthrough;
3963
+ })();
3964
+ const wallets = (0, import_react29.useMemo)(() => {
3965
+ if (enableWalletPassthrough) {
3966
+ return [];
3967
+ }
3968
+ return [];
3969
+ }, [enableWalletPassthrough]);
3970
+ const [showWalletStatus, setShowWalletStatus] = (0, import_react28.useState)({
3971
+ show: false,
3972
+ message: ""
3973
+ });
3974
+ const ShouldWrapWalletProvider = (0, import_react29.useMemo)(() => {
3975
+ return enableWalletPassthrough ? import_react28.default.Fragment : ({ children: children2 }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
3976
+ import_wallet_adapter4.UnifiedWalletProvider,
3977
+ {
3978
+ wallets,
3979
+ config: {
3980
+ env: "mainnet-beta",
3981
+ autoConnect: typeof autoConnect !== "undefined" ? autoConnect : true,
3982
+ metadata: {
3983
+ name: "Jupiter Plugin",
3984
+ url: "https://plugin.jup.ag",
3985
+ description: "An open-sourced, lite version of Jupiter that provides end-to-end swap flow by linking it in your HTML. Check out the visual demo for the various integration modes below. ",
3986
+ iconUrls: []
3987
+ },
3988
+ hardcodedWallets: [],
3989
+ walletPrecedence: [],
3990
+ notificationCallback: {
3991
+ onConnect: noop,
3992
+ onConnecting: noop,
3993
+ onDisconnect: noop,
3994
+ onNotInstalled: ({ walletName, metadata }) => {
3995
+ setShowWalletStatus({
3996
+ show: true,
3997
+ message: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)("p", { className: "space-y-1", children: [
3998
+ walletName,
3999
+ " is not installed.",
4000
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)("p", { className: "space-x-1", children: [
4001
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
4002
+ "a",
4003
+ {
4004
+ className: "underline font-semibold",
4005
+ target: "_blank",
4006
+ rel: "noopener noreferrer",
4007
+ href: metadata.url,
4008
+ children: [
4009
+ "Visit ",
4010
+ walletName,
4011
+ " website"
4012
+ ]
4013
+ }
4014
+ ),
4015
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("span", { children: "to install it." })
4016
+ ] })
4017
+ ] })
4018
+ });
4019
+ setTimeout(() => {
4020
+ setShowWalletStatus({
4021
+ show: false,
4022
+ message: ""
4023
+ });
4024
+ }, 5e3);
4025
+ }
4026
+ },
4027
+ theme: "jupiter"
4028
+ },
4029
+ children: children2
4030
+ }
4031
+ );
4032
+ }, [autoConnect, enableWalletPassthrough, wallets]);
4033
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, { children: [
4034
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(ShouldWrapWalletProvider, { children }),
4035
+ showWalletStatus.show && showWalletStatus.message ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "absolute bottom-2 w-full px-2", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "w-full h-full bg-white/10 rounded-lg p-2 text-warning text-xs", children: showWalletStatus.message }) }) : null
4036
+ ] });
4037
+ };
4038
+ var ContextProvider = (props) => {
4039
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_jsx_runtime49.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(WalletContextProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(PreferredExplorerProvider, { defaultExplorer: props.defaultExplorer, children: props.children }) })) });
4040
+ };
4041
+
4042
+ // src/index.tsx
4043
+ var import_react_query10 = require("@tanstack/react-query");
4044
+ var import_react30 = require("react");
4045
+ var import_jsx_runtime50 = require("react/jsx-runtime");
4046
+ var App = () => {
4047
+ const queryClient = (0, import_react30.useMemo)(() => new import_react_query10.QueryClient(), []);
4048
+ const [props] = (0, import_jotai4.useAtom)(appProps);
4049
+ if (!props) return null;
4050
+ return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_react_query10.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(ContextProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(WalletPassthroughProvider_default, { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(ScreenProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Jupiter_default, __spreadValues({}, props)) }) }) })) });
4051
+ };
4052
+ var RenderJupiter = () => {
4053
+ return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_jotai4.Provider, { store: typeof window !== "undefined" ? window.Jupiter.store : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(App, {}) });
4054
+ };
4055
+
4056
+ // src/npmlibary.tsx
4057
+ function init2(props) {
4058
+ return __async(this, null, function* () {
4059
+ window.Jupiter = { init: init2, resume, close, appProps, syncProps };
4060
+ window.JupiterRenderer = {
4061
+ RenderJupiter
4062
+ };
4063
+ yield init(props);
4064
+ });
4065
+ }
4066
+ // Annotate the CommonJS export names for ESM import in node:
4067
+ 0 && (module.exports = {
4068
+ appProps,
4069
+ close,
4070
+ init,
4071
+ resume,
4072
+ syncProps
4073
+ });
4074
+ //# sourceMappingURL=index.js.map