@latchprotocol/widgets 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +649 -0
  3. package/dist/adapters/binDistribution.d.ts +19 -0
  4. package/dist/adapters/binDistribution.d.ts.map +1 -0
  5. package/dist/adapters/protocol.d.ts +409 -0
  6. package/dist/adapters/protocol.d.ts.map +1 -0
  7. package/dist/adapters/sale.d.ts +142 -0
  8. package/dist/adapters/sale.d.ts.map +1 -0
  9. package/dist/adapters/viem.d.ts +89 -0
  10. package/dist/adapters/viem.d.ts.map +1 -0
  11. package/dist/callpath/constants.d.ts +218 -0
  12. package/dist/callpath/constants.d.ts.map +1 -0
  13. package/dist/callpath/launch.d.ts +1979 -0
  14. package/dist/callpath/launch.d.ts.map +1 -0
  15. package/dist/callpath/liquidity.d.ts +103 -0
  16. package/dist/callpath/liquidity.d.ts.map +1 -0
  17. package/dist/callpath/plan.d.ts +34 -0
  18. package/dist/callpath/plan.d.ts.map +1 -0
  19. package/dist/callpath/swap.d.ts +129 -0
  20. package/dist/callpath/swap.d.ts.map +1 -0
  21. package/dist/chunks/SwapWidget-DgyHAVc8.js +2404 -0
  22. package/dist/chunks/SwapWidget-DgyHAVc8.js.map +1 -0
  23. package/dist/chunks/scan-Dhu7f4Nl.js +2497 -0
  24. package/dist/chunks/scan-Dhu7f4Nl.js.map +1 -0
  25. package/dist/chunks/useLocker-D1c_NTk-.js +1613 -0
  26. package/dist/chunks/useLocker-D1c_NTk-.js.map +1 -0
  27. package/dist/components/LaunchWidget.d.ts +117 -0
  28. package/dist/components/LaunchWidget.d.ts.map +1 -0
  29. package/dist/components/LiquidityWidget.d.ts +33 -0
  30. package/dist/components/LiquidityWidget.d.ts.map +1 -0
  31. package/dist/components/LockerWidget.d.ts +51 -0
  32. package/dist/components/LockerWidget.d.ts.map +1 -0
  33. package/dist/components/LocksWidgets.d.ts +61 -0
  34. package/dist/components/LocksWidgets.d.ts.map +1 -0
  35. package/dist/components/SwapWidget.d.ts +165 -0
  36. package/dist/components/SwapWidget.d.ts.map +1 -0
  37. package/dist/components/TokenTrustPanel.d.ts +32 -0
  38. package/dist/components/TokenTrustPanel.d.ts.map +1 -0
  39. package/dist/components/lockCharts.d.ts +29 -0
  40. package/dist/components/lockCharts.d.ts.map +1 -0
  41. package/dist/components/portal.d.ts +10 -0
  42. package/dist/components/portal.d.ts.map +1 -0
  43. package/dist/components/primitives.d.ts +139 -0
  44. package/dist/components/primitives.d.ts.map +1 -0
  45. package/dist/components/swap/SwapSettings.d.ts +12 -0
  46. package/dist/components/swap/SwapSettings.d.ts.map +1 -0
  47. package/dist/components/swap/TokenSelect.d.ts +61 -0
  48. package/dist/components/swap/TokenSelect.d.ts.map +1 -0
  49. package/dist/components/swap/state.d.ts +208 -0
  50. package/dist/components/swap/state.d.ts.map +1 -0
  51. package/dist/config/chain.d.ts +163 -0
  52. package/dist/config/chain.d.ts.map +1 -0
  53. package/dist/config/integrator.d.ts +121 -0
  54. package/dist/config/integrator.d.ts.map +1 -0
  55. package/dist/context/WidgetProvider.d.ts +78 -0
  56. package/dist/context/WidgetProvider.d.ts.map +1 -0
  57. package/dist/core/clMath.d.ts +98 -0
  58. package/dist/core/clMath.d.ts.map +1 -0
  59. package/dist/core/errors.d.ts +18 -0
  60. package/dist/core/errors.d.ts.map +1 -0
  61. package/dist/core/format.d.ts +47 -0
  62. package/dist/core/format.d.ts.map +1 -0
  63. package/dist/core/liquidityGuards.d.ts +53 -0
  64. package/dist/core/liquidityGuards.d.ts.map +1 -0
  65. package/dist/core/liquidityRefresh.d.ts +35 -0
  66. package/dist/core/liquidityRefresh.d.ts.map +1 -0
  67. package/dist/core/math.d.ts +129 -0
  68. package/dist/core/math.d.ts.map +1 -0
  69. package/dist/core/pool.d.ts +33 -0
  70. package/dist/core/pool.d.ts.map +1 -0
  71. package/dist/core/tokenLists.d.ts +46 -0
  72. package/dist/core/tokenLists.d.ts.map +1 -0
  73. package/dist/embed/iframe.d.ts +185 -0
  74. package/dist/embed/iframe.d.ts.map +1 -0
  75. package/dist/embed/lockBadge.d.ts +55 -0
  76. package/dist/embed/lockBadge.d.ts.map +1 -0
  77. package/dist/embed/webComponent.d.ts +83 -0
  78. package/dist/embed/webComponent.d.ts.map +1 -0
  79. package/dist/embed.d.ts +25 -0
  80. package/dist/embed.d.ts.map +1 -0
  81. package/dist/embed.js +543 -0
  82. package/dist/embed.js.map +1 -0
  83. package/dist/headless.d.ts +60 -0
  84. package/dist/headless.d.ts.map +1 -0
  85. package/dist/headless.js +223 -0
  86. package/dist/headless.js.map +1 -0
  87. package/dist/hooks/useAsyncResource.d.ts +38 -0
  88. package/dist/hooks/useAsyncResource.d.ts.map +1 -0
  89. package/dist/hooks/useLaunch.d.ts +140 -0
  90. package/dist/hooks/useLaunch.d.ts.map +1 -0
  91. package/dist/hooks/useLiquidity.d.ts +91 -0
  92. package/dist/hooks/useLiquidity.d.ts.map +1 -0
  93. package/dist/hooks/useLocker.d.ts +77 -0
  94. package/dist/hooks/useLocker.d.ts.map +1 -0
  95. package/dist/hooks/useLocks.d.ts +33 -0
  96. package/dist/hooks/useLocks.d.ts.map +1 -0
  97. package/dist/hooks/useSwapExecute.d.ts +46 -0
  98. package/dist/hooks/useSwapExecute.d.ts.map +1 -0
  99. package/dist/hooks/useSwapQuote.d.ts +51 -0
  100. package/dist/hooks/useSwapQuote.d.ts.map +1 -0
  101. package/dist/hooks/useTokenLists.d.ts +26 -0
  102. package/dist/hooks/useTokenLists.d.ts.map +1 -0
  103. package/dist/hooks/useTokenTrust.d.ts +40 -0
  104. package/dist/hooks/useTokenTrust.d.ts.map +1 -0
  105. package/dist/hooks/useTokens.d.ts +15 -0
  106. package/dist/hooks/useTokens.d.ts.map +1 -0
  107. package/dist/index.d.ts +59 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +1052 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/latch-embed.d.ts +19 -0
  112. package/dist/latch-embed.d.ts.map +1 -0
  113. package/dist/latch-embed.js +950 -0
  114. package/dist/latch-embed.js.map +1 -0
  115. package/dist/latch-embed.mjs +13162 -0
  116. package/dist/latch-embed.mjs.map +1 -0
  117. package/dist/locker/model.d.ts +73 -0
  118. package/dist/locker/model.d.ts.map +1 -0
  119. package/dist/locks/embedModel.d.ts +22 -0
  120. package/dist/locks/embedModel.d.ts.map +1 -0
  121. package/dist/locks/fetch.d.ts +60 -0
  122. package/dist/locks/fetch.d.ts.map +1 -0
  123. package/dist/locks/model.d.ts +143 -0
  124. package/dist/locks/model.d.ts.map +1 -0
  125. package/dist/locks/scan.d.ts +25 -0
  126. package/dist/locks/scan.d.ts.map +1 -0
  127. package/dist/styles/css.d.ts +32 -0
  128. package/dist/styles/css.d.ts.map +1 -0
  129. package/dist/styles.css +895 -0
  130. package/dist/trust/model.d.ts +48 -0
  131. package/dist/trust/model.d.ts.map +1 -0
  132. package/package.json +102 -0
package/dist/embed.js ADDED
@@ -0,0 +1,543 @@
1
+ import { createElement as v } from "react";
2
+ import { createRoot as N } from "react-dom/client";
3
+ import { y as S, bp as M, ao as P, b8 as B, ap as $, bw as q, aV as W, F as O, av as R } from "./chunks/scan-Dhu7f4Nl.js";
4
+ import { L as F, a as D, S as U, W as _ } from "./chunks/SwapWidget-DgyHAVc8.js";
5
+ import { i as Le } from "./chunks/SwapWidget-DgyHAVc8.js";
6
+ import { http as G, createClient as H, isAddress as V } from "viem";
7
+ import { getLogs as z, getBlockNumber as j, getBlock as J, readContract as K } from "viem/actions";
8
+ import { getDeployment as Q } from "@latchprotocol/sdk/deployments";
9
+ import { latchTransport as X } from "@latchprotocol/sdk";
10
+ const y = [
11
+ "integrator",
12
+ "theme",
13
+ "slippage-bps",
14
+ "title-text"
15
+ ];
16
+ function Y(a, e) {
17
+ if (a === null || a.trim() === "") return null;
18
+ try {
19
+ return JSON.parse(a);
20
+ } catch (n) {
21
+ throw new Error(
22
+ `[@latchprotocol/widgets] the ${e} attribute is not valid JSON: ${String(n)}`
23
+ );
24
+ }
25
+ }
26
+ const Z = typeof HTMLElement > "u" ? class {
27
+ } : HTMLElement;
28
+ class C extends Z {
29
+ #e = null;
30
+ #n = null;
31
+ #t = null;
32
+ #i = null;
33
+ /** Observed attributes, extended by each subclass. */
34
+ static get observedAttributes() {
35
+ return y;
36
+ }
37
+ /** The adapter, when set imperatively. Takes precedence over the attribute. */
38
+ get adapter() {
39
+ return this.#t;
40
+ }
41
+ set adapter(e) {
42
+ this.#t = e, this.#o();
43
+ }
44
+ connectedCallback() {
45
+ if (this.#n === null) {
46
+ this.#n = this.attachShadow({ mode: "open" });
47
+ const e = document.createElement("style");
48
+ e.textContent = _, this.#n.appendChild(e);
49
+ const n = document.createElement("div");
50
+ this.#n.appendChild(n), this.#e = N(n);
51
+ }
52
+ this.#o();
53
+ }
54
+ disconnectedCallback() {
55
+ const e = this.#e;
56
+ this.#e = null, e !== null && queueMicrotask(() => e.unmount());
57
+ }
58
+ attributeChangedCallback() {
59
+ this.#o();
60
+ }
61
+ /** Extra props derived from element attributes. */
62
+ widgetProps() {
63
+ const e = this.getAttribute("title-text");
64
+ return e === null ? {} : { title: e };
65
+ }
66
+ #r() {
67
+ return this.#t;
68
+ }
69
+ #o() {
70
+ if (this.#e !== null)
71
+ try {
72
+ const e = this.#r();
73
+ if (e === null) {
74
+ this.#e.render(
75
+ v(
76
+ "div",
77
+ { className: "latch-widget" },
78
+ v(
79
+ "p",
80
+ { className: "latch-error", role: "alert" },
81
+ "No adapter. Set the element's `adapter` property to a live adapter (createViemAdapter)."
82
+ )
83
+ )
84
+ );
85
+ return;
86
+ }
87
+ const n = Y(
88
+ this.getAttribute("integrator"),
89
+ "integrator"
90
+ ), t = this.getAttribute("theme") ?? "system", s = this.getAttribute("slippage-bps");
91
+ this.#i = null, this.#e.render(
92
+ v(S, {
93
+ adapter: e,
94
+ theme: t,
95
+ ...n === null ? {} : { integrator: n },
96
+ ...s === null ? {} : { defaultSlippageBps: Number(s) },
97
+ children: v(this.component(), this.widgetProps())
98
+ })
99
+ );
100
+ } catch (e) {
101
+ this.#i = e instanceof Error ? e.message : String(e), this.#e.render(
102
+ v(
103
+ "div",
104
+ { className: "latch-widget" },
105
+ v("p", { className: "latch-error", role: "alert" }, this.#i)
106
+ )
107
+ );
108
+ }
109
+ }
110
+ }
111
+ class ee extends C {
112
+ static get observedAttributes() {
113
+ return [...y, "token-in", "token-out", "account", "variant"];
114
+ }
115
+ component() {
116
+ return U;
117
+ }
118
+ widgetProps() {
119
+ const e = this.getAttribute("token-in"), n = this.getAttribute("token-out"), t = this.getAttribute("variant");
120
+ return {
121
+ ...super.widgetProps(),
122
+ ...e === null ? {} : { defaultTokenIn: e },
123
+ ...n === null ? {} : { defaultTokenOut: n },
124
+ ...t === "compact" ? { variant: "compact" } : {}
125
+ };
126
+ }
127
+ }
128
+ class te extends C {
129
+ static get observedAttributes() {
130
+ return [...y, "pool-id", "mode", "account"];
131
+ }
132
+ component() {
133
+ return D;
134
+ }
135
+ widgetProps() {
136
+ const e = this.getAttribute("pool-id"), n = this.getAttribute("mode");
137
+ return {
138
+ ...super.widgetProps(),
139
+ ...e === null ? {} : { defaultPoolId: e },
140
+ ...n === "remove" || n === "add" ? { defaultMode: n } : {}
141
+ };
142
+ }
143
+ }
144
+ class ne extends C {
145
+ static get observedAttributes() {
146
+ return [...y, "pool-id", "account"];
147
+ }
148
+ component() {
149
+ return F;
150
+ }
151
+ widgetProps() {
152
+ const e = this.getAttribute("pool-id");
153
+ return {
154
+ ...super.widgetProps(),
155
+ ...e === null ? {} : { poolId: e }
156
+ };
157
+ }
158
+ }
159
+ const E = {
160
+ swap: "latch-swap-widget",
161
+ liquidity: "latch-liquidity-widget",
162
+ launch: "latch-launch-widget"
163
+ };
164
+ function ge() {
165
+ if (typeof customElements > "u") return;
166
+ const a = [
167
+ [E.swap, ee],
168
+ [E.liquidity, te],
169
+ [E.launch, ne]
170
+ ];
171
+ for (const [e, n] of a)
172
+ customElements.get(e) === void 0 && customElements.define(e, n);
173
+ }
174
+ const b = "latch-widget", w = 1;
175
+ function I(a) {
176
+ if (typeof a != "object" || a === null) return !1;
177
+ const e = a;
178
+ return e.channel === b && e.version === w && typeof e.type == "string";
179
+ }
180
+ function ke(a) {
181
+ const { iframe: e, widgetOrigin: n, adapter: t } = a;
182
+ if (n === "*" || n.trim() === "")
183
+ throw new Error(
184
+ '[@latchprotocol/widgets] widgetOrigin must be an exact origin, never "*". A wildcard origin lets any framed page impersonate the widget.'
185
+ );
186
+ const s = (r) => {
187
+ e.contentWindow?.postMessage(r, n);
188
+ }, l = async (r) => {
189
+ if (r.origin !== n || r.source !== e.contentWindow || !I(r.data)) return;
190
+ const d = r.data;
191
+ if (d.type === "ready") {
192
+ s({
193
+ channel: b,
194
+ version: w,
195
+ type: "init",
196
+ widget: a.widget,
197
+ integrator: a.integrator ?? null,
198
+ theme: a.theme ?? "system",
199
+ chain: {
200
+ chainId: t.chain.chainId,
201
+ name: t.chain.name,
202
+ nativeCurrency: t.chain.nativeCurrency,
203
+ ...t.chain.blockExplorerUrl === void 0 ? {} : { blockExplorerUrl: t.chain.blockExplorerUrl }
204
+ },
205
+ isMock: t.isMock
206
+ });
207
+ return;
208
+ }
209
+ if (d.type === "resize") {
210
+ a.onResize?.(d.height);
211
+ return;
212
+ }
213
+ if (d.type === "event") {
214
+ a.onEvent?.(d);
215
+ return;
216
+ }
217
+ if (d.type === "invoke")
218
+ try {
219
+ if (d.method === "sendTransaction" && a.approveTransaction !== void 0) {
220
+ const o = d.args[0];
221
+ if (!await a.approveTransaction(o))
222
+ throw new Error("The host refused this transaction");
223
+ }
224
+ const p = t[d.method];
225
+ if (typeof p != "function")
226
+ throw new Error(`Unknown bridge method: ${String(d.method)}`);
227
+ const i = await p.apply(t, [...d.args]);
228
+ s({
229
+ channel: b,
230
+ version: w,
231
+ type: "result",
232
+ id: d.id,
233
+ ok: !0,
234
+ value: i
235
+ });
236
+ } catch (p) {
237
+ const i = p instanceof Error ? p : new Error(String(p));
238
+ s({
239
+ channel: b,
240
+ version: w,
241
+ type: "result",
242
+ id: d.id,
243
+ ok: !1,
244
+ error: { name: i.name, message: i.message }
245
+ });
246
+ }
247
+ }, u = (r) => {
248
+ l(r);
249
+ };
250
+ return window.addEventListener("message", u), () => window.removeEventListener("message", u);
251
+ }
252
+ async function fe(a) {
253
+ const { hostOrigin: e } = a, n = a.timeoutMs ?? 6e4;
254
+ if (e === "*" || e.trim() === "")
255
+ throw new Error('[@latchprotocol/widgets] hostOrigin must be an exact origin, never "*"');
256
+ const t = /* @__PURE__ */ new Map();
257
+ let s = 0, l = null;
258
+ const u = new Promise((c) => {
259
+ l = c;
260
+ }), r = (c) => {
261
+ if (c.origin !== e || !I(c.data)) return;
262
+ const h = c.data;
263
+ if (h.type === "init") {
264
+ l?.(h);
265
+ return;
266
+ }
267
+ if (h.type !== "result") return;
268
+ const k = t.get(h.id);
269
+ if (k !== void 0)
270
+ if (t.delete(h.id), h.ok) k.resolve(h.value);
271
+ else {
272
+ const g = new Error(h.error.message);
273
+ g.name = h.error.name, k.reject(g);
274
+ }
275
+ };
276
+ window.addEventListener("message", r);
277
+ const d = (c) => {
278
+ window.parent.postMessage(c, e);
279
+ }, p = (c, h) => {
280
+ s += 1;
281
+ const k = `${Date.now().toString(36)}-${s}`;
282
+ return new Promise((g, f) => {
283
+ const T = setTimeout(() => {
284
+ t.delete(k), f(new Error(`[@latchprotocol/widgets] host did not answer ${c} in ${n}ms`));
285
+ }, n);
286
+ t.set(k, {
287
+ resolve: (L) => {
288
+ clearTimeout(T), g(L);
289
+ },
290
+ reject: (L) => {
291
+ clearTimeout(T), f(L);
292
+ }
293
+ }), d({
294
+ channel: b,
295
+ version: w,
296
+ type: "invoke",
297
+ id: k,
298
+ method: c,
299
+ args: h
300
+ });
301
+ });
302
+ };
303
+ d({ channel: b, version: w, type: "ready" });
304
+ const i = await u, o = (c) => (...h) => p(c, h);
305
+ return {
306
+ adapter: {
307
+ kind: "iframe-bridge",
308
+ isMock: i.isMock,
309
+ chain: {
310
+ chainId: i.chain.chainId,
311
+ name: i.chain.name,
312
+ nativeCurrency: i.chain.nativeCurrency,
313
+ // The bridge deliberately carries no addresses: the widget never builds
314
+ // calldata itself, the host does.
315
+ contracts: { vault: "0x0000000000000000000000000000000000000000" },
316
+ ...i.chain.blockExplorerUrl === void 0 ? {} : { blockExplorerUrl: i.chain.blockExplorerUrl }
317
+ },
318
+ getAccount: o("getAccount"),
319
+ listTokens: o("listTokens"),
320
+ getToken: o("getToken"),
321
+ getBalance: o("getBalance"),
322
+ listPools: o("listPools"),
323
+ getPoolState: o("getPoolState"),
324
+ getApprovalRequirements: o("getApprovalRequirements"),
325
+ buildApproval: o("buildApproval"),
326
+ quoteSwap: o("quoteSwap"),
327
+ buildSwap: o("buildSwap"),
328
+ quoteAddLiquidity: o("quoteAddLiquidity"),
329
+ buildAddLiquidity: o("buildAddLiquidity"),
330
+ listPositions: o("listPositions"),
331
+ quoteRemoveLiquidity: o("quoteRemoveLiquidity"),
332
+ buildRemoveLiquidity: o("buildRemoveLiquidity"),
333
+ listLaunches: o("listLaunches"),
334
+ getLaunch: o("getLaunch"),
335
+ getLaunchesForToken: o("getLaunchesForToken"),
336
+ sendTransaction: o("sendTransaction"),
337
+ waitForTransaction: o("waitForTransaction")
338
+ },
339
+ init: i,
340
+ dispose: () => {
341
+ window.removeEventListener("message", r), t.clear();
342
+ }
343
+ };
344
+ }
345
+ function be(a, e) {
346
+ const n = () => {
347
+ const s = {
348
+ channel: b,
349
+ version: w,
350
+ type: "resize",
351
+ height: Math.ceil(e.getBoundingClientRect().height)
352
+ };
353
+ window.parent.postMessage(s, a);
354
+ };
355
+ if (n(), typeof ResizeObserver > "u") return () => {
356
+ };
357
+ const t = new ResizeObserver(n);
358
+ return t.observe(e), () => t.disconnect();
359
+ }
360
+ const x = "latch-lock-badge", oe = `
361
+ :host { display: inline-block; max-width: 100%; vertical-align: middle; }
362
+ .latch-embed-badge[data-latch-theme] {
363
+ --latch-accent: var(--latch-brand-accent, #0A63E0);
364
+ --latch-font: var(--latch-brand-font, "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif);
365
+ --latch-font-mono: var(--latch-brand-font-mono, "IBM Plex Mono", ui-monospace, monospace);
366
+ }
367
+ .latch-embed-badge[data-latch-theme="dark"] { --latch-accent: var(--latch-brand-accent, #2B8BFF); --latch-success: var(--latch-brand-success, #5FD39A); }
368
+ @media (prefers-color-scheme: dark) {
369
+ .latch-embed-badge[data-latch-theme="system"] { --latch-accent: var(--latch-brand-accent, #2B8BFF); --latch-success: var(--latch-brand-success, #5FD39A); }
370
+ }
371
+ :host([hidden]) { display: none; }
372
+ .latch-embed-badge { gap: 4px; }
373
+ .latch-embed-badge__retry { font: inherit; font-size: 11px; background: none; border: 0; padding: 0; color: var(--latch-accent); cursor: pointer; text-decoration: underline; }
374
+ `, ie = typeof HTMLElement > "u" ? class {
375
+ } : HTMLElement, A = /* @__PURE__ */ new Map();
376
+ function re(a) {
377
+ const e = Number(a("chain") ?? "");
378
+ if (!Number.isInteger(e) || e <= 0) return { ok: !1, message: 'Set the chain attribute to a chain id, e.g. chain="4663".' };
379
+ const n = a("pool"), t = a("token");
380
+ if (n !== null && n !== "") {
381
+ if (!/^0x[0-9a-fA-F]{64}$/.test(n)) return { ok: !1, message: "The pool attribute is not a 32-byte pool id." };
382
+ const s = (a("pool-type") ?? "cl").toLowerCase();
383
+ return { ok: !0, chainId: e, target: { kind: "pool", poolId: n, poolType: s === "bin" ? "bin" : "cl" } };
384
+ }
385
+ return t !== null && t !== "" ? V(t, { strict: !1 }) ? { ok: !0, chainId: e, target: { kind: "token", token: t } } : { ok: !1, message: "The token attribute is not an address." } : { ok: !1, message: "Set a pool or a token attribute." };
386
+ }
387
+ class ae extends ie {
388
+ static get observedAttributes() {
389
+ return ["chain", "pool", "token", "pool-type", "rpc", "site", "theme", "refresh"];
390
+ }
391
+ #e = null;
392
+ #n = null;
393
+ #t = { k: "loading" };
394
+ #i = 0;
395
+ #r = null;
396
+ #o = null;
397
+ #s = null;
398
+ connectedCallback() {
399
+ if (this.#e === null) {
400
+ this.#e = this.attachShadow({ mode: "open" });
401
+ const e = document.createElement("style");
402
+ e.textContent = `${_}
403
+ ${oe}`, this.#e.appendChild(e), this.#n = document.createElement("div"), this.#e.appendChild(this.#n);
404
+ }
405
+ this.#c();
406
+ }
407
+ disconnectedCallback() {
408
+ this.#d(), this.#i += 1;
409
+ }
410
+ attributeChangedCallback() {
411
+ this.#e !== null && this.isConnected && this.#c();
412
+ }
413
+ #d() {
414
+ this.#r !== null && clearInterval(this.#r), this.#o !== null && clearInterval(this.#o), this.#r = null, this.#o = null;
415
+ }
416
+ #c() {
417
+ this.#d(), this.#t = { k: "loading" }, this.#l(), this.#h();
418
+ const e = Number(this.getAttribute("refresh") ?? "60");
419
+ Number.isFinite(e) && e > 0 && (this.#r = setInterval(() => void this.#h(), Math.max(15, e) * 1e3)), this.#o = setInterval(() => {
420
+ this.#t.k === "ready" && this.#t.view.countdownTo !== null && this.#l();
421
+ }, 1e3);
422
+ }
423
+ #u(e) {
424
+ const n = this.getAttribute("rpc"), t = `${e}|${n ?? ""}`;
425
+ if (this.#s?.key === t) return this.#s.client;
426
+ const s = n !== null && n.trim() !== "" ? G(n.trim()) : X(e), l = H({ transport: s }), u = {
427
+ ...l,
428
+ readContract: (r) => K(l, r),
429
+ getBlock: (r) => J(l, r),
430
+ getBlockNumber: (r) => j(l, r),
431
+ getLogs: (r) => z(l, r)
432
+ };
433
+ return this.#s = { key: t, client: u }, u;
434
+ }
435
+ async #h() {
436
+ const e = ++this.#i, n = re((p) => this.getAttribute(p));
437
+ if (!n.ok) return this.#a(e, { k: "message", tone: "error", text: n.message, retry: !1 });
438
+ const t = Q(n.chainId);
439
+ if (t === void 0) return this.#a(e, { k: "message", tone: "none", text: `Latch does not support chain ${n.chainId}.`, retry: !1 });
440
+ const s = { symbol: t.nativeCurrency.symbol, decimals: t.nativeCurrency.decimals }, l = t.launchpadV2.clLPLocker, u = t.launchpadV2.binLPLocker, r = n.target;
441
+ if (!(r.kind === "pool" ? r.poolType === "bin" ? u !== null : t.positionLock !== null || l !== null : t.tokenLock !== null || l !== null || u !== null)) return this.#a(e, { k: "message", tone: "none", text: `Latch locks are coming soon on ${t.name}.`, retry: !1 });
442
+ try {
443
+ const p = this.#u(n.chainId);
444
+ let i = [];
445
+ if (l !== null && !(r.kind === "pool" && r.poolType === "bin")) {
446
+ const g = `${n.chainId}|${l.toLowerCase()}|${this.getAttribute("rpc") ?? ""}`;
447
+ let f = A.get(g);
448
+ f === void 0 && (f = M(p, l, { fromBlock: t.deployedAtBlock }), A.set(g, f), f.catch(() => A.delete(g))), i = await f;
449
+ }
450
+ const o = {
451
+ ...l !== null ? { lpLocker: l, lpLockerTokenIds: i } : {},
452
+ ...u !== null ? { binLpLocker: u } : {}
453
+ };
454
+ let m, c;
455
+ if (r.kind === "pool") {
456
+ const g = await P(p, t.positionLock, r.poolId, { native: s, lp: { ...o, poolType: r.poolType } });
457
+ m = g, c = B(g);
458
+ } else {
459
+ const g = await $(p, t.tokenLock, r.token, { native: s, lp: o });
460
+ m = g, c = q(g);
461
+ }
462
+ const h = this.getAttribute("site"), k = h === null || h.trim() === "" ? null : W(h.trim(), r.kind === "pool" ? { kind: "pool", poolId: r.poolId } : { kind: "token", token: r.token }, { pathBase: "/locks", query: `net=${t.key}` });
463
+ this.#a(e, { k: "ready", view: c, chainNow: m.chainNow, readAtMs: m.readAtMs, href: k });
464
+ } catch {
465
+ if (this.#t.k === "ready") return;
466
+ this.#a(e, { k: "message", tone: "error", text: "Locks could not be read: the chain did not answer.", retry: !0 });
467
+ }
468
+ }
469
+ #a(e, n) {
470
+ e === this.#i && (this.#t = n, this.#l());
471
+ }
472
+ #l() {
473
+ const e = this.#n;
474
+ if (e === null) return;
475
+ const n = this.getAttribute("theme"), t = this.#t, s = document.createElement("div");
476
+ s.className = "latch-widget latch-locks latch-locks--badge latch-embed-badge", s.dataset.latchTheme = n === "light" || n === "dark" ? n : "system";
477
+ const l = (i, o, m) => {
478
+ const c = document.createElement("p");
479
+ if (c.className = i, m !== void 0) {
480
+ const k = document.createElement("span");
481
+ k.className = `latch-locks__dot latch-locks__dot--${m}`, k.setAttribute("aria-hidden", "true"), c.appendChild(k);
482
+ }
483
+ const h = document.createElement("span");
484
+ return h.textContent = o, c.appendChild(h), c;
485
+ };
486
+ if (t.k === "loading")
487
+ s.appendChild(l("latch-locks__headline latch-locks__headline--muted", "Reading locks…")), s.setAttribute("role", "status");
488
+ else if (t.k === "message") {
489
+ const i = l(`latch-locks__headline${t.tone === "error" ? " latch-locks__headline--error" : ""}`, t.text, t.tone === "none" ? "none" : void 0);
490
+ if (s.appendChild(i), t.retry) {
491
+ const o = document.createElement("button");
492
+ o.type = "button", o.className = "latch-embed-badge__retry", o.textContent = "Retry", o.addEventListener("click", () => this.#c()), s.appendChild(o);
493
+ }
494
+ } else {
495
+ const i = l("latch-locks__headline", t.view.headline, t.view.tone);
496
+ if (i.title = t.view.detail ?? "", s.dataset.tone = t.view.tone, s.appendChild(i), t.view.countdownTo !== null) {
497
+ const o = O(t.chainNow, t.readAtMs, Date.now()), m = document.createElement("p");
498
+ m.className = "latch-locks__countdown";
499
+ const c = document.createElement("span");
500
+ c.className = "latch-locks__timer", c.textContent = R(t.view.countdownTo - o), m.append(c, ` to ${t.view.countdownLabel ?? "the next unlock"}`), s.appendChild(m);
501
+ }
502
+ }
503
+ const u = document.createElement("p");
504
+ u.className = "latch-brand";
505
+ const r = this.getAttribute("site");
506
+ if (r !== null && r.trim() !== "") {
507
+ const i = document.createElement("img");
508
+ i.className = "latch-brand__mark";
509
+ const o = s.dataset.latchTheme, c = o === "light" || o === "system" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-color-scheme: light)").matches ? "-onlight" : "";
510
+ i.src = `${r.trim().replace(/\/+$/, "")}/brand/masters/latch-mark${c}.svg`, i.width = 665, i.height = 765, i.alt = "Latch", u.appendChild(i);
511
+ }
512
+ const d = document.createElement("span");
513
+ d.textContent = "Read from chain", u.appendChild(d);
514
+ const p = document.createElement("span");
515
+ if (p.className = "latch-brand__spacer", u.appendChild(p), t.k === "ready" && t.href !== null) {
516
+ const i = document.createElement("a");
517
+ i.className = "latch-locks__link", i.href = t.href, i.target = "_blank", i.rel = "noopener", i.textContent = "Lock details →", u.appendChild(i);
518
+ }
519
+ s.appendChild(u), e.replaceChildren(s);
520
+ }
521
+ }
522
+ function we() {
523
+ typeof customElements > "u" || customElements.get(x) === void 0 && customElements.define(x, ae);
524
+ }
525
+ export {
526
+ x as LOCK_BADGE_TAG,
527
+ ne as LatchLaunchWidgetElement,
528
+ te as LatchLiquidityWidgetElement,
529
+ ae as LatchLockBadgeElement,
530
+ ee as LatchSwapWidgetElement,
531
+ b as WIDGET_CHANNEL,
532
+ _ as WIDGET_CSS,
533
+ w as WIDGET_PROTOCOL_VERSION,
534
+ E as WIDGET_TAG_NAMES,
535
+ fe as createIframeBridgeAdapter,
536
+ we as defineLatchLockBadge,
537
+ ge as defineLatchWidgets,
538
+ Le as injectWidgetStyles,
539
+ re as parseLockBadgeAttributes,
540
+ be as reportWidgetHeight,
541
+ ke as serveWidgetIframe
542
+ };
543
+ //# sourceMappingURL=embed.js.map