@gardenfi/swap 0.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +65 -0
  2. package/dist/index.cjs +1 -0
  3. package/dist/index.js +5 -0
  4. package/dist/index10.cjs +1 -0
  5. package/dist/index10.js +33 -0
  6. package/dist/index11.cjs +1 -0
  7. package/dist/index11.js +36 -0
  8. package/dist/index12.cjs +1 -0
  9. package/dist/index12.js +65 -0
  10. package/dist/index13.cjs +1 -0
  11. package/dist/index13.js +33 -0
  12. package/dist/index14.cjs +1 -0
  13. package/dist/index14.js +190 -0
  14. package/dist/index15.cjs +1 -0
  15. package/dist/index15.js +51 -0
  16. package/dist/index16.cjs +1 -0
  17. package/dist/index16.js +313 -0
  18. package/dist/index17.cjs +1 -0
  19. package/dist/index17.js +29 -0
  20. package/dist/index18.cjs +1 -0
  21. package/dist/index18.js +17 -0
  22. package/dist/index19.cjs +1 -0
  23. package/dist/index19.js +229 -0
  24. package/dist/index20.cjs +1 -0
  25. package/dist/index20.js +15 -0
  26. package/dist/index21.cjs +1 -0
  27. package/dist/index21.js +92 -0
  28. package/dist/index22.cjs +1 -0
  29. package/dist/index22.js +143 -0
  30. package/dist/index23.cjs +1 -0
  31. package/dist/index23.js +22 -0
  32. package/dist/index24.cjs +1 -0
  33. package/dist/index24.js +20 -0
  34. package/dist/index25.cjs +1 -0
  35. package/dist/index25.js +108 -0
  36. package/dist/index26.cjs +1 -0
  37. package/dist/index26.js +85 -0
  38. package/dist/index27.cjs +1 -0
  39. package/dist/index27.js +15 -0
  40. package/dist/index28.cjs +1 -0
  41. package/dist/index28.js +54 -0
  42. package/dist/index29.cjs +1 -0
  43. package/dist/index29.js +63 -0
  44. package/dist/index3.cjs +1 -0
  45. package/dist/index3.js +7 -0
  46. package/dist/index30.cjs +1 -0
  47. package/dist/index30.js +44 -0
  48. package/dist/index31.cjs +1 -0
  49. package/dist/index31.js +43 -0
  50. package/dist/index4.cjs +1 -0
  51. package/dist/index4.js +26 -0
  52. package/dist/index5.cjs +1 -0
  53. package/dist/index5.js +250 -0
  54. package/dist/index6.cjs +1 -0
  55. package/dist/index6.js +98 -0
  56. package/dist/index7.cjs +1 -0
  57. package/dist/index7.js +51 -0
  58. package/dist/index8.cjs +1 -0
  59. package/dist/index8.js +51 -0
  60. package/dist/index9.cjs +1 -0
  61. package/dist/index9.js +101 -0
  62. package/dist/src/index.d.ts +2 -0
  63. package/dist/src/lib/GardenComponent.d.ts +6 -0
  64. package/dist/src/lib/common/AddressDetails.d.ts +8 -0
  65. package/dist/src/lib/common/ChainsToolTip.d.ts +8 -0
  66. package/dist/src/lib/common/Modal.d.ts +9 -0
  67. package/dist/src/lib/common/ModalComponent.d.ts +7 -0
  68. package/dist/src/lib/common/Navbar.d.ts +10 -0
  69. package/dist/src/lib/common/SwapInput.d.ts +17 -0
  70. package/dist/src/lib/components/CreateSwap.d.ts +4 -0
  71. package/dist/src/lib/components/SwapSavingsAndAddresses.d.ts +10 -0
  72. package/dist/src/lib/components/SwapWidget.d.ts +7 -0
  73. package/dist/src/lib/components/assetSelection/AssetModal.d.ts +8 -0
  74. package/dist/src/lib/components/assetSelection/AvailableChainsSidebar.d.ts +11 -0
  75. package/dist/src/lib/components/feesAndRateDetails/FeeAndRateDetails.d.ts +3 -0
  76. package/dist/src/lib/components/feesAndRateDetails/InputAddress.d.ts +3 -0
  77. package/dist/src/lib/components/feesAndRateDetails/InputAddressAndFeeRateDetails.d.ts +3 -0
  78. package/dist/src/lib/components/transactions/SwapInfo.d.ts +12 -0
  79. package/dist/src/lib/components/transactions/TransactionHistory.d.ts +7 -0
  80. package/dist/src/lib/components/transactions/TransactionRow.d.ts +11 -0
  81. package/dist/src/lib/components/transactions/TransactionSkeleton.d.ts +3 -0
  82. package/dist/src/lib/components/transactions/Transactions.d.ts +4 -0
  83. package/dist/src/lib/constants/animations.d.ts +7 -0
  84. package/dist/src/lib/constants/constants.d.ts +29 -0
  85. package/dist/src/lib/constants/network.d.ts +0 -0
  86. package/dist/src/lib/hooks/useSwap.d.ts +29 -0
  87. package/dist/src/lib/store/assetStore.d.ts +23 -0
  88. package/dist/src/lib/store/swapStore.d.ts +79 -0
  89. package/dist/src/lib/store/transactionHistoryStore.d.ts +17 -0
  90. package/dist/src/lib/store/viewPortStore.d.ts +17 -0
  91. package/dist/src/lib/types/types.d.ts +54 -0
  92. package/dist/src/lib/utils/utils.d.ts +14 -0
  93. package/dist/style.css +1 -0
  94. package/package.json +62 -0
@@ -0,0 +1,313 @@
1
+ import { useRef as dt, useMemo as S, useCallback as tt, useEffect as k } from "react";
2
+ import { swapStore as ht } from "./index5.js";
3
+ import { Errors as p, IOType as m } from "./index11.js";
4
+ import { isBitcoin as M, isSui as At, isSolana as bt, isStarknet as yt, isEVM as Et } from "@gardenfi/orderbook";
5
+ import wt from "lodash.debounce";
6
+ import { validateBTCAddress as rt } from "@gardenfi/core";
7
+ import { useGarden as vt } from "@gardenfi/react-hooks";
8
+ import P from "bignumber.js";
9
+ import { formatAmount as et } from "./index17.js";
10
+ const _t = () => {
11
+ var z;
12
+ const {
13
+ inputAmount: c,
14
+ outputAmount: A,
15
+ inputAsset: t,
16
+ outputAsset: n,
17
+ isSwapping: N,
18
+ isApproving: nt,
19
+ rate: ot,
20
+ error: I,
21
+ btcAddress: b,
22
+ tokenPrices: it,
23
+ isFetchingQuote: ut,
24
+ isEditBTCAddress: st,
25
+ networkFees: U,
26
+ setIsSwapping: B,
27
+ setAmount: l,
28
+ setRate: W,
29
+ setError: u,
30
+ swapAssets: ct,
31
+ setAsset: lt,
32
+ setIsFetchingQuote: g,
33
+ isComparisonVisible: Q,
34
+ setIsValidBitcoinAddress: T,
35
+ // setIsApproving,
36
+ setTokenPrices: d,
37
+ clearSwapState: V,
38
+ setBtcAddress: x,
39
+ setIsComparisonVisible: at,
40
+ currentNetwork: j
41
+ } = ht(), { swap: q, getQuote: L, garden: e } = vt(), f = dt(null), y = S(() => !!(t && n && (M(t.chain) || M(n.chain))), [t, n]), G = S(() => y ? b ? rt(b, j) : !1 : !0, [b, y]), R = S(() => !!(t && A && c && n && G && !I.inputError && !I.outputError && !I.liquidityError && !I.insufficientBalanceError), [
42
+ t,
43
+ A,
44
+ c,
45
+ n,
46
+ I,
47
+ G
48
+ ]), H = S(() => y ? !!(R && b) : R, [R, y, b]), { minAmount: E, maxAmount: w } = S(() => {
49
+ const r = {
50
+ minAmount: 0,
51
+ maxAmount: 0
52
+ };
53
+ return !t || !n || !t.min_amount || !t.max_amount ? r : {
54
+ minAmount: et(
55
+ t.min_amount,
56
+ t.decimals,
57
+ t.decimals
58
+ ),
59
+ maxAmount: et(
60
+ t.max_amount,
61
+ t.decimals,
62
+ t.decimals
63
+ )
64
+ };
65
+ }, [t, n]), v = S(
66
+ () => wt(
67
+ async (r, s, a, i) => {
68
+ var X, Y, Z, $, O;
69
+ if (!L || N) return;
70
+ g({ input: i, output: !i }), f.current && f.current.abort(), f.current = new AbortController();
71
+ const D = i ? a.decimals : s.decimals, h = new P(r).multipliedBy(
72
+ 10 ** D
73
+ ), o = await L({
74
+ fromAsset: s,
75
+ toAsset: a,
76
+ amount: h.toNumber(),
77
+ isExactOut: i,
78
+ options: {
79
+ request: {
80
+ signal: f.current.signal
81
+ }
82
+ }
83
+ });
84
+ if (!o || !o.ok) {
85
+ if ((X = o == null ? void 0 : o.error) != null && X.includes("AbortError")) {
86
+ u({ liquidityError: p.none }), g({ input: !1, output: !1 });
87
+ return;
88
+ } else (Y = o == null ? void 0 : o.error) != null && Y.includes("insufficient liquidity") ? (u({ liquidityError: p.insufficientLiquidity }), l(i ? m.input : m.output, "")) : (Z = o == null ? void 0 : o.error) != null && Z.includes("output amount too less") ? (u({ outputError: p.outLow }), l(m.input, "")) : ($ = o == null ? void 0 : o.error) != null && $.includes("output amount too high") ? (u({ outputError: p.outHigh }), l(m.input, "")) : (O = o == null ? void 0 : o.error) != null && O.includes("invalid from_asset") ? (u({ outputError: p.invalidFomAssset }), l(m.input, "")) : l(i ? m.input : m.output, "");
89
+ g({ input: !1, output: !1 }), d({ input: "0", output: "0" });
90
+ return;
91
+ }
92
+ const F = i ? o.val[0].source.display : o.val[0].destination.display;
93
+ let J = Number(F);
94
+ s.symbol === "USDC" && a.symbol === "USDC" && (J = Number(F) + U);
95
+ const ft = J / Number(r);
96
+ W(ft), l(i ? m.input : m.output, F), g({ input: !1, output: !1 }), d({
97
+ input: o.val[0].source.value.toString(),
98
+ output: o.val[0].destination.value.toString()
99
+ }), u({
100
+ liquidityError: p.none
101
+ });
102
+ },
103
+ 500
104
+ ),
105
+ [
106
+ L,
107
+ g,
108
+ W,
109
+ l,
110
+ d,
111
+ u,
112
+ N,
113
+ U
114
+ ]
115
+ ), C = tt(
116
+ async (r, s, a, i) => {
117
+ v(r, s, a, i);
118
+ },
119
+ [v]
120
+ ), _ = tt(
121
+ async (r) => {
122
+ l(m.input, r);
123
+ const s = Number(r);
124
+ if (!s) {
125
+ v.cancel(), f.current && f.current.abort(), l(m.output, ""), d({ input: "0", output: "0" }), u({ inputError: p.none, liquidityError: p.none });
126
+ return;
127
+ }
128
+ if (t && E && s < E) {
129
+ u({
130
+ inputError: p.minError(E.toString(), t == null ? void 0 : t.symbol)
131
+ }), l(m.output, ""), d({ input: "0", output: "0" }), v.cancel(), f.current && f.current.abort();
132
+ return;
133
+ }
134
+ if (t && w && s > w) {
135
+ u({
136
+ inputError: p.maxError(w.toString(), t == null ? void 0 : t.symbol)
137
+ }), l(m.output, ""), v.cancel(), f.current && f.current.abort();
138
+ return;
139
+ }
140
+ u({ inputError: p.none }), !(!t || !n || !Number(r)) && C(r, t, n, !1);
141
+ },
142
+ [
143
+ t,
144
+ n,
145
+ E,
146
+ w,
147
+ C,
148
+ v,
149
+ l,
150
+ u,
151
+ d
152
+ ]
153
+ ), mt = async (r) => {
154
+ l(m.output, r);
155
+ const s = Number(r);
156
+ if (!s) {
157
+ v.cancel(), f.current && f.current.abort(), l(m.input, ""), u({ outputError: p.none });
158
+ return;
159
+ }
160
+ u({ outputError: p.none }), !(!t || !n || !s) && C(r, t, n, !0);
161
+ }, K = S(() => {
162
+ var s, a, i, D;
163
+ if (!t || !n || !c || c === "0" || !A || A === "0")
164
+ return null;
165
+ const r = {
166
+ evm: {
167
+ check: (h) => Et(h),
168
+ address: (s = e == null ? void 0 : e.htlcs.evm) == null ? void 0 : s.htlcActorAddress
169
+ },
170
+ starknet: {
171
+ check: (h) => yt(h),
172
+ address: (a = e == null ? void 0 : e.htlcs.starknet) == null ? void 0 : a.htlcActorAddress
173
+ },
174
+ solana: {
175
+ check: (h) => bt(h),
176
+ address: (i = e == null ? void 0 : e.htlcs.solana) == null ? void 0 : i.htlcActorAddress
177
+ },
178
+ sui: {
179
+ check: (h) => At(h),
180
+ address: (D = e == null ? void 0 : e.htlcs.sui) == null ? void 0 : D.htlcActorAddress
181
+ }
182
+ };
183
+ for (const [h, { check: o, address: F }] of Object.entries(
184
+ r
185
+ ))
186
+ if ((o(t.chain) || o(n.chain)) && !F)
187
+ return h;
188
+ return null;
189
+ }, [t, n, c, A, e]), pt = async () => {
190
+ if (K || !H || !q || !t || !n) return;
191
+ B(!0);
192
+ const r = new P(c).multipliedBy(10 ** t.decimals).toFixed(), s = new P(A).multipliedBy(10 ** n.decimals).toFixed();
193
+ try {
194
+ const a = await q({
195
+ fromAsset: t,
196
+ toAsset: n,
197
+ sendAmount: r,
198
+ receiveAmount: s,
199
+ ...y && { addresses: { bitcoin: b } }
200
+ });
201
+ if (!a.ok) {
202
+ a.error.includes("destination amount too high") ? C(c, t, n, !1) : console.error("failed to create order ❌", a.error), B(!1);
203
+ return;
204
+ }
205
+ if (console.log("orderCreated ✅", a.val), M(t.chain)) {
206
+ const i = await (e == null ? void 0 : e.getOrder(a.val));
207
+ if (!(i != null && i.val) || i != null && i.error) {
208
+ console.error("failed to get order ❌", i == null ? void 0 : i.error), B(!1);
209
+ return;
210
+ }
211
+ if (e) {
212
+ V();
213
+ return;
214
+ }
215
+ B(!1), V();
216
+ return;
217
+ }
218
+ B(!1), V();
219
+ } catch (a) {
220
+ throw console.error("failed to create order ❌", a), B(!1), a;
221
+ }
222
+ };
223
+ return k(() => {
224
+ if (!t || !n || !c || N || Q)
225
+ return;
226
+ const r = setInterval(() => {
227
+ C(c, t, n, !1);
228
+ }, 5e3);
229
+ return () => clearInterval(r);
230
+ }, [
231
+ c,
232
+ t,
233
+ n,
234
+ C,
235
+ N,
236
+ Q
237
+ ]), k(() => {
238
+ !t || !n || (u({ inputError: "" }), _(c));
239
+ }, [t, _, u]), k(() => {
240
+ if (A == "0" || !A || c == "0" || !c) {
241
+ d({ input: "0", output: "0" });
242
+ return;
243
+ }
244
+ }, [c, A, d, u]), k(() => {
245
+ if (!c || !E || !w) return;
246
+ const r = Number(c);
247
+ if (r) {
248
+ if (r < E && t) {
249
+ u({
250
+ inputError: p.minError(E.toString(), t.symbol)
251
+ }), d({ input: "0", output: "0" }), l(m.output, "");
252
+ return;
253
+ }
254
+ if (r > w && t) {
255
+ u({
256
+ inputError: p.maxError(w.toString(), t.symbol)
257
+ }), d({ input: "0", output: "0" }), l(m.output, "");
258
+ return;
259
+ }
260
+ }
261
+ }, [
262
+ c,
263
+ E,
264
+ w,
265
+ t,
266
+ u,
267
+ d,
268
+ _,
269
+ l
270
+ ]), k(() => {
271
+ u({ insufficientBalanceError: p.none });
272
+ }, [u, t, n, c]), k(() => {
273
+ var r, s;
274
+ (r = e == null ? void 0 : e.htlcs.bitcoin) != null && r.htlcActorAddress && x((s = e == null ? void 0 : e.htlcs.bitcoin) == null ? void 0 : s.htlcActorAddress);
275
+ }, [(z = e == null ? void 0 : e.htlcs.bitcoin) == null ? void 0 : z.htlcActorAddress, x]), k(() => {
276
+ if (!y) {
277
+ T(!0);
278
+ return;
279
+ }
280
+ const r = b ? rt(b, j) : !1;
281
+ T(r);
282
+ }, [b, y, T]), {
283
+ inputAmount: c,
284
+ outputAmount: A,
285
+ inputAsset: t,
286
+ outputAsset: n,
287
+ tokenPrices: it,
288
+ rate: ot,
289
+ error: I,
290
+ isEditBTCAddress: st,
291
+ loading: ut,
292
+ validSwap: H,
293
+ isSwapping: N,
294
+ isApproving: nt,
295
+ isBitcoinSwap: y,
296
+ // inputTokenBalance,
297
+ needsWalletConnection: K,
298
+ btcAddress: b,
299
+ controller: f,
300
+ isComparisonVisible: Q,
301
+ setBtcAddress: x,
302
+ swapAssets: ct,
303
+ handleInputAmountChange: _,
304
+ handleOutputAmountChange: mt,
305
+ handleSwapClick: pt,
306
+ setAsset: lt,
307
+ clearSwapState: V,
308
+ setIsComparisonVisible: at
309
+ };
310
+ };
311
+ export {
312
+ _t as useSwap
313
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("bignumber.js"),f=e=>{const t=new Date().getTime()-new Date(e).getTime(),o=Math.floor(t/(1e3*3600*24)),n=Math.floor(t/(1e3*3600)),i=Math.floor(t/(1e3*60));return o>3?`on ${new Date(e).toLocaleDateString()}`:o>0?`${o} day${o>1?"s":""} ago`:n>0?`${n} hour${n>1?"s":""} ago`:i>0?`${i} minute${i>1?"s":""} ago`:"Just now"},m=(e,r)=>r&&r.find(t=>`${t.chain}:${t.symbol.toLowerCase()}`===e.asset),l=(e,r,t)=>{var a;const o=new c(e);if(o.isZero())return 0;const n=o.dividedBy(10**r),i=t||(Number(n)>1e4?2:4);let s=n.toFixed(i,c.ROUND_DOWN);for(;(a=s.split(".")[1])!=null&&a.split("").every(u=>u==="0")&&s.split(".")[1].length<8;)s=n.toFixed(s.split(".")[1].length+2,c.ROUND_DOWN);return Number(s)},g=(e,r=6,t=4)=>`${e.slice(0,r)}...${e.slice(-t)}`,d=e=>{const r=Number(e);if(isNaN(r))return"-";const t=Math.floor(r/3600),o=Math.floor(r%3600/60),n=(r%60).toFixed(0);return t>0?`${t}h ${o}m`:`${o}m ${n}s`},D=e=>e==="evm"?"EVM":e.charAt(0).toUpperCase()+e.slice(1);exports.capitalizeChain=D;exports.formatAmount=l;exports.formatTime=d;exports.getAssetFromSwap=m;exports.getDayDifference=f;exports.getTrimmedAddress=g;
@@ -0,0 +1,29 @@
1
+ import c from "bignumber.js";
2
+ const a = (e) => {
3
+ const t = (/* @__PURE__ */ new Date()).getTime() - new Date(e).getTime(), r = Math.floor(t / (1e3 * 3600 * 24)), n = Math.floor(t / (1e3 * 3600)), i = Math.floor(t / (1e3 * 60));
4
+ return r > 3 ? `on ${new Date(e).toLocaleDateString()}` : r > 0 ? `${r} day${r > 1 ? "s" : ""} ago` : n > 0 ? `${n} hour${n > 1 ? "s" : ""} ago` : i > 0 ? `${i} minute${i > 1 ? "s" : ""} ago` : "Just now";
5
+ }, l = (e, o) => o && o.find(
6
+ (t) => `${t.chain}:${t.symbol.toLowerCase()}` === e.asset
7
+ ), $ = (e, o, t) => {
8
+ var u;
9
+ const r = new c(e);
10
+ if (r.isZero()) return 0;
11
+ const n = r.dividedBy(10 ** o), i = t || (Number(n) > 1e4 ? 2 : 4);
12
+ let s = n.toFixed(i, c.ROUND_DOWN);
13
+ for (; (u = s.split(".")[1]) != null && u.split("").every((f) => f === "0") && s.split(".")[1].length < 8; )
14
+ s = n.toFixed(s.split(".")[1].length + 2, c.ROUND_DOWN);
15
+ return Number(s);
16
+ }, g = (e, o = 6, t = 4) => `${e.slice(0, o)}...${e.slice(-t)}`, h = (e) => {
17
+ const o = Number(e);
18
+ if (isNaN(o)) return "-";
19
+ const t = Math.floor(o / 3600), r = Math.floor(o % 3600 / 60), n = (o % 60).toFixed(0);
20
+ return t > 0 ? `${t}h ${r}m` : `${r}m ${n}s`;
21
+ }, D = (e) => e === "evm" ? "EVM" : e.charAt(0).toUpperCase() + e.slice(1);
22
+ export {
23
+ D as capitalizeChain,
24
+ $ as formatAmount,
25
+ h as formatTime,
26
+ l as getAssetFromSwap,
27
+ a as getDayDifference,
28
+ g as getTrimmedAddress
29
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),t=require("@gardenfi/garden-book"),i=require("./index23.cjs"),c=({open:o,onClose:r,children:l,opacityLevel:n="medium"})=>{const{isMobile:a}=i.viewPortStore();return e.createElement(e.Fragment,null,a?e.createElement(t.BottomSheet,{open:o,onOpenChange:r},l):e.createElement(t.Modal,{open:o,onClose:r},e.createElement(t.Modal.Children,{opacityLevel:n,className:"relative flex w-full max-w-[560px] flex-col gap-4 rounded-2xl p-3 overflow-hidden"},l)))};exports.ResponsiveModal=c;
@@ -0,0 +1,17 @@
1
+ import e from "react";
2
+ import { BottomSheet as n, Modal as l } from "@gardenfi/garden-book";
3
+ import { viewPortStore as i } from "./index23.js";
4
+ const f = ({ open: t, onClose: o, children: r, opacityLevel: m = "medium" }) => {
5
+ const { isMobile: a } = i();
6
+ return /* @__PURE__ */ e.createElement(e.Fragment, null, a ? /* @__PURE__ */ e.createElement(n, { open: t, onOpenChange: o }, r) : /* @__PURE__ */ e.createElement(l, { open: t, onClose: o }, /* @__PURE__ */ e.createElement(
7
+ l.Children,
8
+ {
9
+ opacityLevel: m,
10
+ className: "relative flex w-full max-w-[560px] flex-col gap-4 rounded-2xl p-3 overflow-hidden"
11
+ },
12
+ r
13
+ )));
14
+ };
15
+ export {
16
+ f as ResponsiveModal
17
+ };
@@ -0,0 +1 @@
1
+ "use strict";const t=require("react"),H=require("./index5.cjs"),U=require("./index6.cjs"),G=require("./index24.cjs"),i=require("@gardenfi/garden-book"),$=require("framer-motion"),P=require("./index25.cjs"),W=require("@gardenfi/utils"),D=require("./index17.cjs"),J=require("./index11.cjs"),K=({onSelect:I})=>{const{inputAsset:N,outputAsset:v,currentNetwork:L}=H.swapStore(),{allAssets:C,chains:r,modalOpenFor:S,isAssetModalOpen:h,closeAssetModal:k,setFilter:x}=U.assetInfoStore(),[s,d]=t.useState(),[g,A]=t.useState(""),[q,y]=t.useState(""),[m]=t.useState(7),b=t.useRef(null),[w,f]=t.useState(!1),E=typeof window<"u"?window.innerWidth<768:!1,l=t.useMemo(()=>{const e=["bitcoin","ethereum","solana","base","arbitrum","starknet"];return r?[...r].sort((a,c)=>{const o=e.findIndex(u=>a.chainName.toLowerCase().includes(u)),p=e.findIndex(u=>c.chainName.toLowerCase().includes(u));return o===-1?1:p===-1?-1:o-p}):[]},[r]),T=t.useMemo(()=>{let e=C;if(s&&(e=e.filter(a=>a.chain===s.chain)),g.trim()){const a=g.toLowerCase();e=e.filter(c=>c.symbol.toLowerCase().includes(a)||c.chain.toLowerCase().includes(a)||c.name.toLowerCase().includes(a))}const n=J.IOType.input?v:N;return n&&(e=e.filter(a=>`${a.chain}-${a.symbol}`!=`${n.chain}-${n.symbol}`)),e},[C,s,g,S,N,v]),M=t.useMemo(()=>[...T].sort((e,n)=>{const a=r==null?void 0:r.find(o=>o.chain===e.chain),c=r==null?void 0:r.find(o=>o.chain===n.chain);if(a&&c){const o=l.findIndex(u=>u.chain===a.chain),p=l.findIndex(u=>u.chain===c.chain);if(o!==p)return o-p}return e.symbol.localeCompare(n.symbol)}),[T,r,l]),z=t.useMemo(()=>{const e=l.slice(0,m);return s&&!e.find(n=>n.chain===s.chain)?[s,...e.slice(0,m-1)]:e},[l,m,s]),j=e=>{const n=e.target.value;A(n),x(n)},B=()=>f(!1),O=e=>{(s==null?void 0:s.chain)===e.chain?d(void 0):d(e),f(!1)},F=e=>{I(e),k(),f(!1)},R=()=>{k(),f(!1)};return t.useEffect(()=>{h||(d(void 0),A(""),x(""),y(""))},[h,x]),t.useEffect(()=>{h&&b.current&&setTimeout(()=>{var e;return(e=b.current)==null?void 0:e.focus()},100)},[h]),t.createElement(t.Fragment,null,t.createElement(P.AvailableChainsSidebar,{show:w,chains:[...l],hide:B,onClick:O}),t.createElement($.AnimatePresence,{mode:"wait"},t.createElement($.motion.div,{key:"assetModal",initial:{opacity:1},animate:{opacity:w?0:1},transition:{duration:w?.32:.45,delay:w?0:.25,ease:"easeOut"},className:`left-auto top-60 z-30 flex flex-col gap-3 rounded-[20px] sm:min-w-[468px] ${E?"":"m-1"}`},t.createElement("div",{className:"flex items-center justify-between p-1"},t.createElement(i.Typography,{size:"h4",weight:"medium"},`Select token to ${S?"send":"receive"}`),t.createElement(i.CloseIcon,{className:"hidden cursor-pointer sm:visible sm:block",onClick:R})),t.createElement("div",{className:"flex w-full flex-wrap gap-3"},t.createElement("div",{className:`flex w-full ${E?"gap-2":"gap-3"}`},z.map((e,n)=>t.createElement("button",{key:e.chainId,className:`relative flex h-12 flex-1 items-center justify-center gap-2 overflow-visible rounded-xl outline-none duration-300 ease-in-out ${!s||e.chain!==s.chain?"!bg-white/50":"!bg-white"}`,onMouseEnter:()=>y(e.chainName),onMouseLeave:()=>y(""),onClick:()=>s&&e.chain===s.chain?d(void 0):d(e)},t.createElement("img",{src:e.iconUrl,alt:e.chainName,className:"h-5 w-5 rounded-full"}),q===e.chainName&&t.createElement(G.ChainsTooltip,{chain:e.chainName,className:`${L===W.Network.TESTNET?n===0?"translate-x-7":l.length-m===0&&n===m-1&&E?"-translate-x-4":"":""}`}))),l.length>m&&t.createElement("button",{className:"h-12 w-12 cursor-pointer flex items-center justify-center rounded-xl !bg-white/50 p-4 duration-300 ease-in-out",onClick:()=>f(!0)},t.createElement(i.Typography,{size:"h4",weight:"regular",className:"!flex !cursor-pointer !items-center !text-mid-grey !text-center"},"+",l.length-m)))),t.createElement("div",{className:"flex w-full items-center justify-between rounded-2xl bg-white/50 px-4 py-[10px]"},t.createElement("div",{className:"flex flex-grow items-center"},t.createElement(i.Typography,{size:"h4",weight:"regular",className:"gf-w-full"},t.createElement("input",{ref:b,className:"w-full bg-transparent outline-none placeholder:text-mid-grey focus:outline-none",type:"text",value:g,placeholder:"Search assets",onChange:j}))),t.createElement(i.SearchIcon,null)),t.createElement("div",{className:"flex h-[316px] flex-col overflow-auto rounded-2xl !bg-white"},t.createElement("div",{className:"px-4 pb-2 pt-2"},t.createElement(i.Typography,{size:"h5",weight:"medium"},s?`Assets on ${s.chainName}`:"Assets")),t.createElement(i.GradientScroll,{height:272,gradientHeight:42,onClose:!h},M.length>0?t.createElement("div",{className:"space-y-1"},M.map(e=>{var n;return t.createElement("button",{key:`${e.chain}-${e.symbol}`,onClick:()=>F(e),className:"flex w-full cursor-pointer items-center justify-between !gap-2 !px-4 !py-1.5 hover:bg-[#f4f0fc]"},t.createElement("div",{className:"flex w-full items-center justify-start gap-2"},t.createElement("div",{className:"w-10"},t.createElement(i.TokenNetworkLogos,{tokenLogo:e.logo,chainLogo:(n=r==null?void 0:r.find(a=>a.chain===e.chain))==null?void 0:n.iconUrl})),t.createElement(i.Typography,{className:"w-2/3 !text-start",size:"h5",breakpoints:{sm:"h4"},weight:"regular"},e.name)),t.createElement("div",{className:"flex items-center gap-1"},e.price&&t.createElement(i.Typography,{size:"h5",breakpoints:{sm:"h4"},weight:"regular",className:"!text-mid-grey"},D.formatAmount(Number(e.price),0,Math.min(e.decimals,8))),t.createElement(i.Typography,{size:"h5",breakpoints:{sm:"h4"},weight:"regular",className:"!text-mid-grey"},e.symbol)))})):t.createElement("div",{className:"flex min-h-[274px] w-full items-center justify-center"},t.createElement(i.Typography,{size:"h4",weight:"regular"},"No assets found.")))))))};module.exports=K;
@@ -0,0 +1,229 @@
1
+ import t, { useState as w, useRef as P, useMemo as E, useEffect as M } from "react";
2
+ import { swapStore as W } from "./index5.js";
3
+ import { assetInfoStore as q } from "./index6.js";
4
+ import { ChainsTooltip as D } from "./index24.js";
5
+ import { Typography as c, CloseIcon as J, SearchIcon as K, GradientScroll as Q, TokenNetworkLogos as V } from "@gardenfi/garden-book";
6
+ import { AnimatePresence as X, motion as Y } from "framer-motion";
7
+ import { AvailableChainsSidebar as Z } from "./index25.js";
8
+ import { Network as _ } from "@gardenfi/utils";
9
+ import { formatAmount as ee } from "./index17.js";
10
+ import { IOType as te } from "./index11.js";
11
+ const de = ({ onSelect: T }) => {
12
+ const { inputAsset: C, outputAsset: k, currentNetwork: j } = W(), {
13
+ allAssets: A,
14
+ chains: r,
15
+ modalOpenFor: S,
16
+ isAssetModalOpen: d,
17
+ closeAssetModal: $,
18
+ setFilter: N
19
+ } = q(), [a, h] = w(), [g, I] = w(""), [O, b] = w(""), [m] = w(7), y = P(null), [x, f] = w(!1), v = typeof window < "u" ? window.innerWidth < 768 : !1, i = E(() => {
20
+ const e = [
21
+ "bitcoin",
22
+ "ethereum",
23
+ "solana",
24
+ "base",
25
+ "arbitrum",
26
+ "starknet"
27
+ ];
28
+ return r ? [...r].sort((s, o) => {
29
+ const l = e.findIndex(
30
+ (u) => s.chainName.toLowerCase().includes(u)
31
+ ), p = e.findIndex(
32
+ (u) => o.chainName.toLowerCase().includes(u)
33
+ );
34
+ return l === -1 ? 1 : p === -1 ? -1 : l - p;
35
+ }) : [];
36
+ }, [r]), L = E(() => {
37
+ let e = A;
38
+ if (a && (e = e.filter((s) => s.chain === a.chain)), g.trim()) {
39
+ const s = g.toLowerCase();
40
+ e = e.filter(
41
+ (o) => o.symbol.toLowerCase().includes(s) || o.chain.toLowerCase().includes(s) || o.name.toLowerCase().includes(s)
42
+ );
43
+ }
44
+ const n = te.input ? k : C;
45
+ return n && (e = e.filter(
46
+ (s) => `${s.chain}-${s.symbol}` != `${n.chain}-${n.symbol}`
47
+ )), e;
48
+ }, [
49
+ A,
50
+ a,
51
+ g,
52
+ S,
53
+ C,
54
+ k
55
+ ]), z = E(() => [...L].sort((e, n) => {
56
+ const s = r == null ? void 0 : r.find((l) => l.chain === e.chain), o = r == null ? void 0 : r.find((l) => l.chain === n.chain);
57
+ if (s && o) {
58
+ const l = i.findIndex((u) => u.chain === s.chain), p = i.findIndex((u) => u.chain === o.chain);
59
+ if (l !== p)
60
+ return l - p;
61
+ }
62
+ return e.symbol.localeCompare(n.symbol);
63
+ }), [L, r, i]), B = E(() => {
64
+ const e = i.slice(0, m);
65
+ return a && !e.find((n) => n.chain === a.chain) ? [a, ...e.slice(0, m - 1)] : e;
66
+ }, [i, m, a]), F = (e) => {
67
+ const n = e.target.value;
68
+ I(n), N(n);
69
+ }, R = () => f(!1), H = (e) => {
70
+ (a == null ? void 0 : a.chain) === e.chain ? h(void 0) : h(e), f(!1);
71
+ }, U = (e) => {
72
+ T(e), $(), f(!1);
73
+ }, G = () => {
74
+ $(), f(!1);
75
+ };
76
+ return M(() => {
77
+ d || (h(void 0), I(""), N(""), b(""));
78
+ }, [d, N]), M(() => {
79
+ d && y.current && setTimeout(() => {
80
+ var e;
81
+ return (e = y.current) == null ? void 0 : e.focus();
82
+ }, 100);
83
+ }, [d]), /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement(
84
+ Z,
85
+ {
86
+ show: x,
87
+ chains: [...i],
88
+ hide: R,
89
+ onClick: H
90
+ }
91
+ ), /* @__PURE__ */ t.createElement(X, { mode: "wait" }, /* @__PURE__ */ t.createElement(
92
+ Y.div,
93
+ {
94
+ key: "assetModal",
95
+ initial: { opacity: 1 },
96
+ animate: { opacity: x ? 0 : 1 },
97
+ transition: {
98
+ duration: x ? 0.32 : 0.45,
99
+ delay: x ? 0 : 0.25,
100
+ ease: "easeOut"
101
+ },
102
+ className: `left-auto top-60 z-30 flex flex-col gap-3 rounded-[20px] sm:min-w-[468px] ${v ? "" : "m-1"}`
103
+ },
104
+ /* @__PURE__ */ t.createElement("div", { className: "flex items-center justify-between p-1" }, /* @__PURE__ */ t.createElement(c, { size: "h4", weight: "medium" }, `Select token to ${S ? "send" : "receive"}`), /* @__PURE__ */ t.createElement(
105
+ J,
106
+ {
107
+ className: "hidden cursor-pointer sm:visible sm:block",
108
+ onClick: G
109
+ }
110
+ )),
111
+ /* @__PURE__ */ t.createElement("div", { className: "flex w-full flex-wrap gap-3" }, /* @__PURE__ */ t.createElement("div", { className: `flex w-full ${v ? "gap-2" : "gap-3"}` }, B.map((e, n) => /* @__PURE__ */ t.createElement(
112
+ "button",
113
+ {
114
+ key: e.chainId,
115
+ className: `relative flex h-12 flex-1 items-center justify-center gap-2 overflow-visible rounded-xl outline-none duration-300 ease-in-out ${!a || e.chain !== a.chain ? "!bg-white/50" : "!bg-white"}`,
116
+ onMouseEnter: () => b(e.chainName),
117
+ onMouseLeave: () => b(""),
118
+ onClick: () => a && e.chain === a.chain ? h(void 0) : h(e)
119
+ },
120
+ /* @__PURE__ */ t.createElement(
121
+ "img",
122
+ {
123
+ src: e.iconUrl,
124
+ alt: e.chainName,
125
+ className: "h-5 w-5 rounded-full"
126
+ }
127
+ ),
128
+ O === e.chainName && /* @__PURE__ */ t.createElement(
129
+ D,
130
+ {
131
+ chain: e.chainName,
132
+ className: `${j === _.TESTNET ? n === 0 ? "translate-x-7" : i.length - m === 0 && n === m - 1 && v ? "-translate-x-4" : "" : ""}`
133
+ }
134
+ )
135
+ )), i.length > m && /* @__PURE__ */ t.createElement(
136
+ "button",
137
+ {
138
+ className: "h-12 w-12 cursor-pointer flex items-center justify-center rounded-xl !bg-white/50 p-4 duration-300 ease-in-out",
139
+ onClick: () => f(!0)
140
+ },
141
+ /* @__PURE__ */ t.createElement(
142
+ c,
143
+ {
144
+ size: "h4",
145
+ weight: "regular",
146
+ className: "!flex !cursor-pointer !items-center !text-mid-grey !text-center"
147
+ },
148
+ "+",
149
+ i.length - m
150
+ )
151
+ ))),
152
+ /* @__PURE__ */ t.createElement("div", { className: "flex w-full items-center justify-between rounded-2xl bg-white/50 px-4 py-[10px]" }, /* @__PURE__ */ t.createElement("div", { className: "flex flex-grow items-center" }, /* @__PURE__ */ t.createElement(c, { size: "h4", weight: "regular", className: "gf-w-full" }, /* @__PURE__ */ t.createElement(
153
+ "input",
154
+ {
155
+ ref: y,
156
+ className: "w-full bg-transparent outline-none placeholder:text-mid-grey focus:outline-none",
157
+ type: "text",
158
+ value: g,
159
+ placeholder: "Search assets",
160
+ onChange: F
161
+ }
162
+ ))), /* @__PURE__ */ t.createElement(K, null)),
163
+ /* @__PURE__ */ t.createElement("div", { className: "flex h-[316px] flex-col overflow-auto rounded-2xl !bg-white" }, /* @__PURE__ */ t.createElement("div", { className: "px-4 pb-2 pt-2" }, /* @__PURE__ */ t.createElement(c, { size: "h5", weight: "medium" }, a ? `Assets on ${a.chainName}` : "Assets")), /* @__PURE__ */ t.createElement(
164
+ Q,
165
+ {
166
+ height: 272,
167
+ gradientHeight: 42,
168
+ onClose: !d
169
+ },
170
+ z.length > 0 ? /* @__PURE__ */ t.createElement("div", { className: "space-y-1" }, z.map((e) => {
171
+ var n;
172
+ return /* @__PURE__ */ t.createElement(
173
+ "button",
174
+ {
175
+ key: `${e.chain}-${e.symbol}`,
176
+ onClick: () => U(e),
177
+ className: "flex w-full cursor-pointer items-center justify-between !gap-2 !px-4 !py-1.5 hover:bg-[#f4f0fc]"
178
+ },
179
+ /* @__PURE__ */ t.createElement("div", { className: "flex w-full items-center justify-start gap-2" }, /* @__PURE__ */ t.createElement("div", { className: "w-10" }, /* @__PURE__ */ t.createElement(
180
+ V,
181
+ {
182
+ tokenLogo: e.logo,
183
+ chainLogo: (n = r == null ? void 0 : r.find((s) => s.chain === e.chain)) == null ? void 0 : n.iconUrl
184
+ }
185
+ )), /* @__PURE__ */ t.createElement(
186
+ c,
187
+ {
188
+ className: "w-2/3 !text-start",
189
+ size: "h5",
190
+ breakpoints: { sm: "h4" },
191
+ weight: "regular"
192
+ },
193
+ e.name
194
+ )),
195
+ /* @__PURE__ */ t.createElement("div", { className: "flex items-center gap-1" }, e.price && /* @__PURE__ */ t.createElement(
196
+ c,
197
+ {
198
+ size: "h5",
199
+ breakpoints: {
200
+ sm: "h4"
201
+ },
202
+ weight: "regular",
203
+ className: "!text-mid-grey"
204
+ },
205
+ ee(
206
+ Number(e.price),
207
+ 0,
208
+ Math.min(e.decimals, 8)
209
+ )
210
+ ), /* @__PURE__ */ t.createElement(
211
+ c,
212
+ {
213
+ size: "h5",
214
+ breakpoints: {
215
+ sm: "h4"
216
+ },
217
+ weight: "regular",
218
+ className: "!text-mid-grey"
219
+ },
220
+ e.symbol
221
+ ))
222
+ );
223
+ })) : /* @__PURE__ */ t.createElement("div", { className: "flex min-h-[274px] w-full items-center justify-center" }, /* @__PURE__ */ t.createElement(c, { size: "h4", weight: "regular" }, "No assets found."))
224
+ ))
225
+ )));
226
+ };
227
+ export {
228
+ de as default
229
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function u(r){var e,o,t="";if(typeof r=="string"||typeof r=="number")t+=r;else if(typeof r=="object")if(Array.isArray(r))for(e=0;e<r.length;e++)r[e]&&(o=u(r[e]))&&(t&&(t+=" "),t+=o);else for(e in r)r[e]&&(t&&(t+=" "),t+=e);return t}function f(){for(var r,e,o=0,t="";o<arguments.length;)(r=arguments[o++])&&(e=u(r))&&(t&&(t+=" "),t+=e);return t}exports.clsx=f;exports.default=f;
@@ -0,0 +1,15 @@
1
+ function o(r) {
2
+ var f, n, t = "";
3
+ if (typeof r == "string" || typeof r == "number") t += r;
4
+ else if (typeof r == "object") if (Array.isArray(r)) for (f = 0; f < r.length; f++) r[f] && (n = o(r[f])) && (t && (t += " "), t += n);
5
+ else for (f in r) r[f] && (t && (t += " "), t += f);
6
+ return t;
7
+ }
8
+ function a() {
9
+ for (var r, f, n = 0, t = ""; n < arguments.length; ) (r = arguments[n++]) && (f = o(r)) && (t && (t += " "), t += f);
10
+ return t;
11
+ }
12
+ export {
13
+ a as clsx,
14
+ a as default
15
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),u=require("@gardenfi/garden-book"),r=require("@gardenfi/orderbook"),A=require("@gardenfi/core"),w=require("./index5.cjs"),l=require("framer-motion"),x=()=>{const o=e.useRef(null),h=e.useId(),{inputAsset:t,outputAsset:i,btcAddress:s,setBtcAddress:m,currentNetwork:a}=w.swapStore(),p=!0,d="",c=e.useMemo(()=>!!(t&&r.isBitcoin(t.chain)),[t]),g=e.useMemo(()=>(t==null?void 0:t.chain)&&r.isBitcoin(t.chain)||(i==null?void 0:i.chain)&&r.isBitcoin(i.chain),[p,d,t,i]),v=B=>{let n=B.target.value;/^[a-zA-Z0-9]$/.test(n.at(-1)||"")||(n=n.slice(0,-1)),m(n)},y=s||d||"",f=e.useMemo(()=>s?A.validateBTCAddress(s,a):!0,[s,a]);return e.createElement(l.AnimatePresence,{mode:"wait"},g&&e.createElement(l.motion.div,{variants:{hidden:{opacity:0,height:0,marginBottom:"0",pointerEvents:"none",transition:{duration:.3,ease:"easeOut",height:{duration:.2,ease:"easeOut"}}},visible:{opacity:1,height:"auto",marginBottom:"12px",pointerEvents:"auto",transition:{duration:.3,ease:"easeOut",height:{duration:.2,ease:"easeOut"}}},exit:{opacity:0,height:0,marginBottom:"0",pointerEvents:"none",transition:{duration:.3,ease:"easeOut",opacity:{duration:.2,ease:"easeOut"}}}},initial:"hidden",animate:"visible",exit:"exit"},e.createElement("div",{className:"flex flex-col gap-2 rounded-2xl bg-white p-4"},e.createElement(u.Typography,{"data-tooltip-id":c?h:"",size:"h5",weight:"medium",onClick:()=>o.current.focus(),className:"w-fit"},c?"Refund":"Receive"," address"),e.createElement(u.Typography,{size:"h3",weight:"regular"},e.createElement("input",{ref:o,className:`w-full outline-none placeholder:text-mid-grey ${!f&&s?"text-red-500":""}`,type:"text",value:y,placeholder:"Your Bitcoin address",onChange:v})))))};exports.InputAddress=x;