@eos3/connect 0.1.13 → 0.2.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/ui.js ADDED
@@ -0,0 +1,662 @@
1
+ import { createEosConnect } from './index.js';
2
+ const EOS_CONNECT_DEFAULT_STYLES = `
3
+ :root {
4
+ --eos-connect-accent: #2f80ed;
5
+ --eos-connect-accent-strong: #1f6fd1;
6
+ --eos-connect-surface: #ffffff;
7
+ --eos-connect-surface-soft: #f5f7fb;
8
+ --eos-connect-border: #e5e7eb;
9
+ --eos-connect-text: #111827;
10
+ --eos-connect-muted: #6b7280;
11
+ --eos-connect-shadow: 0 18px 55px rgba(15, 23, 42, 0.18);
12
+ }
13
+ eos-connect-button,
14
+ eos-connect,
15
+ eos-connect-modal {
16
+ box-sizing: border-box;
17
+ color: var(--eos-connect-text);
18
+ font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
19
+ font-size: 16px;
20
+ line-height: 1.4;
21
+ -webkit-text-size-adjust: 100%;
22
+ text-size-adjust: 100%;
23
+ }
24
+ eos-connect *,
25
+ eos-connect *::before,
26
+ eos-connect *::after,
27
+ eos-connect-button *,
28
+ eos-connect-button *::before,
29
+ eos-connect-button *::after,
30
+ eos-connect-modal *,
31
+ eos-connect-modal *::before,
32
+ eos-connect-modal *::after {
33
+ box-sizing: border-box;
34
+ }
35
+ eos-connect-button[hidden],
36
+ eos-connect[hidden],
37
+ eos-connect-modal[hidden] {
38
+ display: none !important;
39
+ }
40
+ eos-connect,
41
+ eos-connect-modal {
42
+ position: fixed;
43
+ inset: 0;
44
+ z-index: 2147483000;
45
+ display: grid;
46
+ align-items: end;
47
+ justify-items: center;
48
+ min-width: 0;
49
+ padding: 12px 12px max(12px, env(safe-area-inset-bottom));
50
+ overflow: hidden;
51
+ }
52
+ eos-connect-button {
53
+ display: inline-block;
54
+ }
55
+ .eos-connect-button {
56
+ appearance: none;
57
+ -webkit-appearance: none;
58
+ min-height: 44px;
59
+ border: 0;
60
+ border-radius: 8px;
61
+ background: var(--eos-connect-accent);
62
+ color: #ffffff;
63
+ cursor: pointer;
64
+ font-family: inherit;
65
+ font-size: 15px;
66
+ line-height: 1.2;
67
+ font-weight: 700;
68
+ padding: 0 18px;
69
+ }
70
+ .eos-connect-sdk-backdrop {
71
+ appearance: none;
72
+ -webkit-appearance: none;
73
+ position: absolute;
74
+ inset: 0;
75
+ border: 0;
76
+ padding: 0;
77
+ background: rgba(15, 23, 42, 0.36);
78
+ cursor: pointer;
79
+ }
80
+ .eos-connect-sdk-sheet {
81
+ position: relative;
82
+ width: min(100%, 420px);
83
+ max-height: min(640px, calc(100dvh - 24px - env(safe-area-inset-bottom)));
84
+ border: 1px solid var(--eos-connect-border);
85
+ border-radius: 8px;
86
+ background: var(--eos-connect-surface);
87
+ box-shadow: var(--eos-connect-shadow);
88
+ padding: 16px;
89
+ overflow: auto;
90
+ -webkit-overflow-scrolling: touch;
91
+ }
92
+ .eos-connect-sdk-sheet--quick {
93
+ width: min(100%, 454px) !important;
94
+ border: 0 !important;
95
+ border-radius: 28px !important;
96
+ padding: 50px 24px 34px !important;
97
+ overflow: visible !important;
98
+ }
99
+ .eos-connect-sdk-close {
100
+ appearance: none;
101
+ -webkit-appearance: none;
102
+ position: absolute;
103
+ top: 24px !important;
104
+ right: 24px !important;
105
+ display: grid;
106
+ width: 48px !important;
107
+ height: 48px !important;
108
+ place-items: center;
109
+ border: 0 !important;
110
+ border-radius: 999px !important;
111
+ background: var(--eos-connect-surface-soft) !important;
112
+ color: #6b7280 !important;
113
+ cursor: pointer;
114
+ font-family: inherit !important;
115
+ font-size: 34px !important;
116
+ line-height: 1 !important;
117
+ font-weight: 300 !important;
118
+ padding: 0 !important;
119
+ }
120
+ .eos-connect-sdk-summary {
121
+ margin-bottom: 16px;
122
+ }
123
+ .eos-connect-sdk-summary--quick {
124
+ margin: 122px 0 38px !important;
125
+ text-align: center !important;
126
+ }
127
+ .eos-connect-sdk-summary h2 {
128
+ margin: 0 0 6px;
129
+ font-size: 22px;
130
+ line-height: 1.2;
131
+ }
132
+ .eos-connect-sdk-summary--quick h2 {
133
+ margin: 0 0 14px !important;
134
+ font-size: 28px !important;
135
+ line-height: 1.18 !important;
136
+ font-weight: 800 !important;
137
+ }
138
+ .eos-connect-sdk-summary p {
139
+ margin: 0;
140
+ color: var(--eos-connect-muted);
141
+ font-size: 15px;
142
+ line-height: 1.45;
143
+ }
144
+ .eos-connect-sdk-summary--quick p {
145
+ margin: 0 !important;
146
+ font-size: 17px !important;
147
+ line-height: 1.55 !important;
148
+ }
149
+ .eos-connect-sdk-summary--quick strong {
150
+ color: var(--eos-connect-text) !important;
151
+ }
152
+ .eos-connect-sdk-primary {
153
+ appearance: none;
154
+ -webkit-appearance: none;
155
+ display: flex;
156
+ width: 100%;
157
+ min-height: 58px;
158
+ align-items: center;
159
+ justify-content: space-between;
160
+ gap: 12px;
161
+ border: 0;
162
+ border-radius: 8px;
163
+ background: var(--eos-connect-accent);
164
+ color: #ffffff;
165
+ cursor: pointer;
166
+ font-family: inherit;
167
+ font-size: 15px;
168
+ line-height: 1.25;
169
+ font-weight: 700;
170
+ padding: 0 16px;
171
+ text-align: left;
172
+ }
173
+ .eos-connect-sdk-primary--quick {
174
+ display: grid !important;
175
+ min-height: 66px !important;
176
+ grid-template-columns: 54px minmax(0, 1fr) 54px !important;
177
+ align-items: center !important;
178
+ border-radius: 14px !important;
179
+ padding: 0 14px !important;
180
+ box-shadow: 0 14px 34px rgba(47, 128, 237, 0.26) !important;
181
+ font-family: inherit !important;
182
+ font-size: 18px !important;
183
+ line-height: 1.2 !important;
184
+ text-align: center !important;
185
+ }
186
+ .eos-connect-sdk-primary--quick[aria-busy="true"],
187
+ .eos-connect-sdk-primary--quick[disabled] {
188
+ opacity: 1 !important;
189
+ }
190
+ .eos-connect-sdk-primary--success {
191
+ background: #10b981 !important;
192
+ box-shadow: 0 14px 34px rgba(16, 185, 129, 0.22) !important;
193
+ }
194
+ .eos-connect-sdk-key-icon,
195
+ .eos-connect-sdk-send-icon,
196
+ .eos-connect-sdk-spinner-icon,
197
+ .eos-connect-sdk-success-icon,
198
+ .eos-connect-sdk-empty-icon {
199
+ display: grid !important;
200
+ width: 40px !important;
201
+ height: 40px !important;
202
+ place-items: center !important;
203
+ }
204
+ .eos-connect-sdk-key-icon {
205
+ border-radius: 11px !important;
206
+ background: #ffffff !important;
207
+ color: var(--eos-connect-accent) !important;
208
+ }
209
+ .eos-connect-sdk-spinner-icon,
210
+ .eos-connect-sdk-success-icon,
211
+ .eos-connect-sdk-empty-icon {
212
+ border-radius: 11px !important;
213
+ background: rgba(255, 255, 255, 0.18) !important;
214
+ color: #ffffff !important;
215
+ }
216
+ .eos-connect-sdk-spinner {
217
+ display: block !important;
218
+ width: 24px !important;
219
+ height: 24px !important;
220
+ border: 3px solid rgba(255, 255, 255, 0.42) !important;
221
+ border-top-color: #ffffff !important;
222
+ border-radius: 999px !important;
223
+ animation: eos-connect-sdk-spin 760ms linear infinite !important;
224
+ }
225
+ .eos-connect-sdk-success-icon svg {
226
+ width: 26px !important;
227
+ height: 26px !important;
228
+ fill: none !important;
229
+ stroke: currentColor !important;
230
+ stroke-width: 2.4 !important;
231
+ stroke-linecap: round !important;
232
+ stroke-linejoin: round !important;
233
+ }
234
+ .eos-connect-sdk-send-icon {
235
+ justify-self: end !important;
236
+ color: rgba(255, 255, 255, 0.86) !important;
237
+ }
238
+ .eos-connect-sdk-key-icon svg,
239
+ .eos-connect-sdk-send-icon svg {
240
+ width: 24px;
241
+ height: 24px;
242
+ fill: none;
243
+ stroke: currentColor;
244
+ stroke-width: 2;
245
+ stroke-linecap: round;
246
+ stroke-linejoin: round;
247
+ }
248
+ @keyframes eos-connect-sdk-spin {
249
+ to {
250
+ transform: rotate(360deg);
251
+ }
252
+ }
253
+ .eos-connect-sdk-primary span {
254
+ min-width: 0;
255
+ overflow-wrap: anywhere;
256
+ }
257
+ .eos-connect-sdk-primary[aria-disabled="true"] {
258
+ cursor: not-allowed;
259
+ opacity: 0.58;
260
+ }
261
+ @media (max-width: 480px) {
262
+ eos-connect,
263
+ eos-connect-modal {
264
+ padding: 8px 8px max(8px, env(safe-area-inset-bottom));
265
+ }
266
+ .eos-connect-sdk-sheet {
267
+ width: 100%;
268
+ max-height: min(620px, calc(100dvh - 16px - env(safe-area-inset-bottom)));
269
+ border-radius: 8px 8px 0 0;
270
+ padding: 14px;
271
+ }
272
+ .eos-connect-sdk-sheet--quick {
273
+ border-radius: 28px 28px 0 0 !important;
274
+ padding: 46px 24px 34px !important;
275
+ }
276
+ .eos-connect-sdk-close {
277
+ top: 22px !important;
278
+ right: 24px !important;
279
+ width: 48px !important;
280
+ height: 48px !important;
281
+ }
282
+ .eos-connect-sdk-summary {
283
+ margin-bottom: 14px;
284
+ }
285
+ .eos-connect-sdk-summary--quick {
286
+ margin: 118px 0 36px !important;
287
+ }
288
+ .eos-connect-sdk-summary h2 {
289
+ font-size: 20px;
290
+ }
291
+ .eos-connect-sdk-summary--quick h2 {
292
+ font-size: 28px !important;
293
+ }
294
+ .eos-connect-sdk-summary p {
295
+ font-size: 14px;
296
+ }
297
+ .eos-connect-sdk-summary--quick p {
298
+ font-size: 17px !important;
299
+ }
300
+ .eos-connect-sdk-primary {
301
+ min-height: 52px;
302
+ padding: 0 14px;
303
+ }
304
+ .eos-connect-sdk-primary--quick {
305
+ min-height: 66px !important;
306
+ grid-template-columns: 54px minmax(0, 1fr) 54px !important;
307
+ font-size: 18px !important;
308
+ }
309
+ }
310
+ `;
311
+ export function installEosConnectStyles(documentRef = globalThis.document) {
312
+ if (!documentRef || documentRef.querySelector('[data-eos-connect-ui-style]')) {
313
+ return;
314
+ }
315
+ const style = documentRef.createElement('style');
316
+ style.setAttribute('data-eos-connect-ui-style', '');
317
+ style.textContent = EOS_CONNECT_DEFAULT_STYLES;
318
+ documentRef.head.append(style);
319
+ }
320
+ function escapeHtml(value) {
321
+ return String(value ?? '')
322
+ .replace(/&/g, '&')
323
+ .replace(/</g, '&lt;')
324
+ .replace(/>/g, '&gt;')
325
+ .replace(/"/g, '&quot;');
326
+ }
327
+ const EOS_CONNECT_UI_MESSAGES = {
328
+ en: {
329
+ enableQuickPayment: 'Enable quick payment',
330
+ quickPaymentEnabled: 'Quick payment enabled',
331
+ quickPaymentChecking: 'Checking binding status...',
332
+ quickPaymentCheckingDescription: 'Finish binding in the opened page\nThis window will update automatically',
333
+ quickPaymentSuccess: 'Enabled successfully',
334
+ quickPaymentSuccessDescription: 'Quick payment is enabled\nYou can return to continue payment',
335
+ quickPaymentSetupDescription: 'Complete one binding\nEligible payments can be confirmed quickly',
336
+ localKeyMissingDescription: 'Complete one binding\nEligible payments can be confirmed quickly',
337
+ closeEosConnect: 'Close EOS Connect'
338
+ },
339
+ 'zh-CN': {
340
+ enableQuickPayment: '开启快捷支付',
341
+ quickPaymentEnabled: '快捷支付已开启',
342
+ quickPaymentChecking: '正在检测绑定状态...',
343
+ quickPaymentCheckingDescription: '请在打开的页面完成认证\n返回后会自动继续检测',
344
+ quickPaymentSuccess: '开启成功',
345
+ quickPaymentSuccessDescription: '快捷支付已开启\n可以返回继续支付',
346
+ quickPaymentSetupDescription: '完成一次绑定\n符合额度的支付可快速确认',
347
+ localKeyMissingDescription: '完成一次绑定\n符合额度的支付可快速确认',
348
+ closeEosConnect: '关闭 EOS Connect'
349
+ }
350
+ };
351
+ function normalizeEosConnectUiLocale(locale) {
352
+ return String(locale ?? '').toLowerCase().startsWith('zh') ? 'zh-CN' : 'en';
353
+ }
354
+ function browserLanguage() {
355
+ const maybeNavigator = globalThis;
356
+ return maybeNavigator.navigator?.language;
357
+ }
358
+ function telegramLanguageCode(app) {
359
+ const maybeApp = app;
360
+ return maybeApp?.initDataUnsafe?.user?.language_code;
361
+ }
362
+ function resolveEosConnectUiLocale(options = {}) {
363
+ return normalizeEosConnectUiLocale(options.locale ?? telegramLanguageCode(options.telegramWebApp) ?? browserLanguage());
364
+ }
365
+ function createTranslator(options = {}) {
366
+ const locale = resolveEosConnectUiLocale(options);
367
+ return (key, values = {}) => {
368
+ let text = options.messages?.[key] ??
369
+ (key === 'quickPaymentSetupDescription' ? options.messages?.localKeyMissingDescription : undefined) ??
370
+ EOS_CONNECT_UI_MESSAGES[locale][key];
371
+ for (const [name, value] of Object.entries(values)) {
372
+ text = text.replaceAll(`{${name}}`, value);
373
+ }
374
+ return text;
375
+ };
376
+ }
377
+ function formatMultilineText(value) {
378
+ return value
379
+ .split('\n')
380
+ .map((line) => escapeHtml(line))
381
+ .join('<br>');
382
+ }
383
+ export function renderEosConnectButton(client, options = {}) {
384
+ const snapshot = client.getSnapshot();
385
+ const t = createTranslator(options);
386
+ const label = snapshot.status === 'connected' && snapshot.canUse
387
+ ? t('quickPaymentEnabled')
388
+ : t('enableQuickPayment');
389
+ return `<button class="eos-connect-button" type="button">${escapeHtml(label)}</button>`;
390
+ }
391
+ function renderQuickPaymentSheet(provider, t, flowState = 'idle') {
392
+ const isChecking = flowState === 'checking';
393
+ const isSuccess = flowState === 'success';
394
+ const disabled = isChecking || isSuccess || provider?.state !== 'available';
395
+ const title = isSuccess ? t('quickPaymentSuccess') : t('enableQuickPayment');
396
+ const description = isSuccess
397
+ ? t('quickPaymentSuccessDescription')
398
+ : isChecking
399
+ ? t('quickPaymentCheckingDescription')
400
+ : t('quickPaymentSetupDescription');
401
+ const label = isSuccess
402
+ ? t('quickPaymentEnabled')
403
+ : isChecking
404
+ ? t('quickPaymentChecking')
405
+ : t('enableQuickPayment');
406
+ const leadingIcon = isSuccess
407
+ ? `<span class="eos-connect-sdk-success-icon" aria-hidden="true">
408
+ <svg viewBox="0 0 24 24" focusable="false">
409
+ <path d="m5 12.4 4.2 4.2L19 6.8" />
410
+ </svg>
411
+ </span>`
412
+ : isChecking
413
+ ? `<span class="eos-connect-sdk-spinner-icon" aria-hidden="true">
414
+ <span class="eos-connect-sdk-spinner"></span>
415
+ </span>`
416
+ : `<span class="eos-connect-sdk-key-icon" aria-hidden="true">
417
+ <svg viewBox="0 0 24 24" focusable="false">
418
+ <path d="M7.5 14.5a4 4 0 1 1 3.6-2.26L20 3.35 20.65 4 18 6.65 20 8.65 18.65 10 16.65 8 15 9.65 17 11.65 15.65 13 13.65 11 11.76 12.9A4 4 0 0 1 7.5 14.5Z" />
419
+ <circle cx="7.5" cy="10.5" r="1.45" />
420
+ </svg>
421
+ </span>`;
422
+ const trailingIcon = isChecking || isSuccess
423
+ ? '<span class="eos-connect-sdk-empty-icon" aria-hidden="true"></span>'
424
+ : `<span class="eos-connect-sdk-send-icon" aria-hidden="true">
425
+ <svg viewBox="0 0 24 24" focusable="false">
426
+ <path d="M20.9 3.35 3.75 10.72c-.85.36-.78 1.59.1 1.85l6.1 1.79 1.82 6.05c.27.88 1.5.94 1.86.09l7.28-17.15Z" />
427
+ <path d="m10.28 14.02 4.76-4.76" />
428
+ </svg>
429
+ </span>`;
430
+ return `
431
+ <button type="button" class="eos-connect-sdk-backdrop" data-eos-connect-close aria-label="${escapeHtml(t('closeEosConnect'))}"></button>
432
+ <section class="eos-connect-sdk-sheet eos-connect-sdk-sheet--quick" role="dialog" aria-modal="true">
433
+ <button type="button" class="eos-connect-sdk-close" data-eos-connect-close aria-label="${escapeHtml(t('closeEosConnect'))}">×</button>
434
+ <div class="eos-connect-sdk-summary eos-connect-sdk-summary--quick">
435
+ <h2>${escapeHtml(title)}</h2>
436
+ <p>${formatMultilineText(description)}</p>
437
+ </div>
438
+ <button
439
+ type="button"
440
+ class="eos-connect-sdk-primary eos-connect-sdk-primary--quick${isSuccess ? ' eos-connect-sdk-primary--success' : ''}"
441
+ data-provider="${escapeHtml(provider?.id ?? 'telegram')}"
442
+ aria-disabled="${disabled}"
443
+ ${isChecking ? 'aria-busy="true"' : ''}
444
+ ${disabled ? 'disabled' : ''}
445
+ >
446
+ ${leadingIcon}
447
+ <span>${escapeHtml(label)}</span>
448
+ ${trailingIcon}
449
+ </button>
450
+ </section>
451
+ `;
452
+ }
453
+ export function renderEosConnectSheet(client, options = {}) {
454
+ const snapshot = client.getSnapshot();
455
+ const providers = client.getProviders();
456
+ const primary = providers.find((provider) => provider.id === 'telegram') ?? providers[0];
457
+ const t = createTranslator(options);
458
+ const flowState = options.flowState === 'success' || options.flowState === 'checking'
459
+ ? options.flowState
460
+ : snapshot.status === 'connected' && snapshot.canUse
461
+ ? 'success'
462
+ : 'idle';
463
+ return renderQuickPaymentSheet(primary, t, flowState);
464
+ }
465
+ export async function connectEosProvider(client, _provider = 'telegram', options = {}) {
466
+ return client.startTelegramWalletFlow(options);
467
+ }
468
+ function isQuickPaymentReadyView(view) {
469
+ return view?.status === 'ready' && view.canPay === true;
470
+ }
471
+ function isQuickPaymentReadyState(state) {
472
+ return state.status === 'connected' && state.canUse === true;
473
+ }
474
+ function globalTelegramWebApp() {
475
+ const maybeWindow = globalThis;
476
+ return maybeWindow.window?.Telegram?.WebApp ?? maybeWindow.Telegram?.WebApp ?? null;
477
+ }
478
+ function networkFromAttribute(value) {
479
+ if (value === 'testnet' || value === 'mainnet') {
480
+ return value;
481
+ }
482
+ return undefined;
483
+ }
484
+ function resolveClient(host, configuredClient, options) {
485
+ if (configuredClient) {
486
+ return configuredClient;
487
+ }
488
+ const existing = host.__eosConnectClient;
489
+ if (existing) {
490
+ return existing;
491
+ }
492
+ const apiBaseUrl = host.getAttribute('api-base-url') ?? options.apiBaseUrl;
493
+ const botUsername = host.getAttribute('bot-username') ?? options.botUsername;
494
+ const network = networkFromAttribute(host.getAttribute('network')) ?? options.network;
495
+ const cacheKey = [network ?? '', apiBaseUrl ?? '', botUsername ?? ''].join('\u001f');
496
+ const clientCache = options.__eosConnectClientCache ?? new Map();
497
+ options.__eosConnectClientCache = clientCache;
498
+ const cachedClient = clientCache.get(cacheKey);
499
+ if (cachedClient) {
500
+ host.__eosConnectClient = cachedClient;
501
+ return cachedClient;
502
+ }
503
+ const client = createEosConnect({
504
+ ...(network ? { network } : {}),
505
+ ...(apiBaseUrl ? { apiBaseUrl } : {}),
506
+ ...(botUsername ? { botUsername } : {}),
507
+ telegramWebApp: options.telegramWebApp ?? globalTelegramWebApp()
508
+ });
509
+ clientCache.set(cacheKey, client);
510
+ host.__eosConnectClient = client;
511
+ return client;
512
+ }
513
+ function dispatchEosConnectError(host, detail) {
514
+ host.dispatchEvent(new CustomEvent('eos-connect-error', {
515
+ bubbles: true,
516
+ composed: true,
517
+ detail
518
+ }));
519
+ }
520
+ function defaultModalForButton(host) {
521
+ const root = host.getRootNode?.();
522
+ return root?.querySelector?.('eos-connect-modal,eos-connect') ?? globalThis.document?.querySelector?.('eos-connect-modal,eos-connect') ?? null;
523
+ }
524
+ function createButtonElement(options) {
525
+ const BaseElement = globalThis.HTMLElement ?? class {
526
+ };
527
+ return class EosConnectButton extends BaseElement {
528
+ unsubscribe = null;
529
+ client = null;
530
+ connectedCallback() {
531
+ this.client = resolveClient(this, options.client, options);
532
+ this.render();
533
+ this.unsubscribe = this.client.subscribe(() => this.render());
534
+ void this.client.checkWallet().catch((error) => {
535
+ dispatchEosConnectError(this, { error });
536
+ });
537
+ this.addEventListener('click', this.open);
538
+ }
539
+ disconnectedCallback() {
540
+ this.unsubscribe?.();
541
+ this.removeEventListener('click', this.open);
542
+ }
543
+ open = () => {
544
+ defaultModalForButton(this)?.removeAttribute('hidden');
545
+ this.dispatchEvent(new CustomEvent('eos-connect-open', {
546
+ bubbles: true,
547
+ composed: true
548
+ }));
549
+ };
550
+ render() {
551
+ if (!this.client)
552
+ return;
553
+ this.innerHTML = renderEosConnectButton(this.client, {
554
+ locale: options.locale,
555
+ messages: options.messages,
556
+ telegramWebApp: options.telegramWebApp ?? globalTelegramWebApp()
557
+ });
558
+ }
559
+ };
560
+ }
561
+ function createModalElement(options) {
562
+ const BaseElement = globalThis.HTMLElement ?? class {
563
+ };
564
+ return class EosConnectModal extends BaseElement {
565
+ unsubscribe = null;
566
+ client = null;
567
+ flowState = 'idle';
568
+ connectedCallback() {
569
+ this.client = resolveClient(this, options.client, options);
570
+ this.render();
571
+ this.unsubscribe = this.client.subscribe(() => this.render());
572
+ void this.client.checkWallet().catch((error) => {
573
+ dispatchEosConnectError(this, { error });
574
+ });
575
+ this.addEventListener('click', this.handleClick);
576
+ }
577
+ disconnectedCallback() {
578
+ this.unsubscribe?.();
579
+ this.removeEventListener('click', this.handleClick);
580
+ }
581
+ handleClick = (event) => {
582
+ const target = event.target;
583
+ if (target?.closest('[data-eos-connect-close]')) {
584
+ this.flowState = 'idle';
585
+ this.setAttribute('hidden', '');
586
+ this.dispatchEvent(new CustomEvent('eos-connect-close', { bubbles: true, composed: true }));
587
+ return;
588
+ }
589
+ const provider = target?.closest('[data-provider]')?.dataset.provider;
590
+ if (provider && this.client) {
591
+ const providerConfig = this.client.getProviders().find((item) => item.id === provider);
592
+ if (providerConfig?.state && providerConfig.state !== 'available') {
593
+ return;
594
+ }
595
+ if (provider === 'telegram') {
596
+ this.flowState = 'checking';
597
+ this.render();
598
+ }
599
+ void connectEosProvider(this.client, provider, {
600
+ ...options.telegramOptions,
601
+ botUsername: options.telegramOptions?.botUsername ?? options.botUsername,
602
+ assetLimits: options.telegramOptions?.assetLimits ?? options.assetLimits,
603
+ replaceWallet: options.telegramOptions?.replaceWallet ?? options.replaceWallet,
604
+ openExternal: options.openExternal
605
+ }).then((view) => {
606
+ if (provider === 'telegram') {
607
+ this.flowState = isQuickPaymentReadyView(view) || isQuickPaymentReadyState(this.client.getSnapshot())
608
+ ? 'success'
609
+ : 'idle';
610
+ this.render();
611
+ }
612
+ }).catch((error) => {
613
+ if (provider === 'telegram') {
614
+ this.flowState = 'idle';
615
+ this.render();
616
+ }
617
+ dispatchEosConnectError(this, { error, provider });
618
+ });
619
+ }
620
+ };
621
+ render() {
622
+ if (!this.client)
623
+ return;
624
+ this.innerHTML = renderEosConnectSheet(this.client, {
625
+ locale: options.locale,
626
+ messages: options.messages,
627
+ telegramWebApp: options.telegramWebApp ?? globalTelegramWebApp(),
628
+ flowState: this.flowState
629
+ });
630
+ }
631
+ };
632
+ }
633
+ export function defineEosConnectElements({ client, network, apiBaseUrl, botUsername, locale, messages, assetLimits, replaceWallet, telegramOptions, openExternal, telegramWebApp, injectStyles = true, customElements: registry = globalThis.customElements }) {
634
+ if (injectStyles) {
635
+ installEosConnectStyles();
636
+ }
637
+ if (!registry) {
638
+ throw new Error('CustomElementRegistry is not available');
639
+ }
640
+ const elementOptions = {
641
+ client,
642
+ network,
643
+ apiBaseUrl,
644
+ botUsername,
645
+ locale,
646
+ messages,
647
+ assetLimits,
648
+ replaceWallet,
649
+ telegramOptions,
650
+ openExternal,
651
+ telegramWebApp
652
+ };
653
+ if (!registry.get('eos-connect')) {
654
+ registry.define('eos-connect', createModalElement(elementOptions));
655
+ }
656
+ if (!registry.get('eos-connect-button')) {
657
+ registry.define('eos-connect-button', createButtonElement(elementOptions));
658
+ }
659
+ if (!registry.get('eos-connect-modal')) {
660
+ registry.define('eos-connect-modal', createModalElement(elementOptions));
661
+ }
662
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eos3/connect",
3
- "version": "0.1.13",
3
+ "version": "0.2.0",
4
4
  "description": "Framework-neutral browser SDK for EOS Passkey Connect in Telegram Mini Apps.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -13,9 +13,12 @@
13
13
  "types": "dist/index.d.ts",
14
14
  "files": [
15
15
  "dist",
16
- "README.md"
16
+ "README.md",
17
+ "styles.css"
18
+ ],
19
+ "sideEffects": [
20
+ "./styles.css"
17
21
  ],
18
- "sideEffects": false,
19
22
  "keywords": [
20
23
  "eos",
21
24
  "antelope",
@@ -28,17 +31,16 @@
28
31
  ".": {
29
32
  "types": "./dist/index.d.ts",
30
33
  "import": "./dist/index.js"
31
- }
34
+ },
35
+ "./styles.css": "./styles.css"
32
36
  },
33
37
  "scripts": {
34
- "prebuild": "npm run build -w @eos3/shared",
35
38
  "build": "tsc -p tsconfig.json",
36
39
  "test": "vitest run",
37
- "pretypecheck": "npm run build -w @eos3/shared",
38
40
  "typecheck": "tsc -p tsconfig.json --noEmit"
39
41
  },
40
42
  "dependencies": {
41
- "@eos3/shared": "0.1.0",
43
+ "@noble/hashes": "^2.2.0",
42
44
  "@wharfkit/antelope": "^1.2.0"
43
45
  },
44
46
  "devDependencies": {