@eos3/connect 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -37,6 +37,7 @@ const eosConnect = createEosConnect({
37
37
  network: 'testnet',
38
38
  apiBaseUrl: 'https://your-wallet-api.example.com',
39
39
  botUsername: 'your_bot',
40
+ locale: 'zh-CN',
40
41
  telegramWebApp
41
42
  });
42
43
 
@@ -50,11 +51,34 @@ await eosConnect.checkWallet();
50
51
  `network` can be `testnet` or `mainnet`. It selects browser signing RPC
51
52
  failover list, chain id metadata, and balance asset. The SDK does not include a
52
53
  hosted wallet API or a Telegram bot. If `apiBaseUrl` is omitted, requests use
53
- same-origin paths such as `/api/tg-wallet/me`.
54
+ same-origin paths such as `/api/tg-wallet/me`. `apiBaseUrl` points to the EOS
55
+ Passkey API or to your same-origin proxy for that API; it is not the passkey bind
56
+ page URL.
54
57
  When `botUsername` is set, the SDK sends it as `x-telegram-bot-username` so a
55
58
  shared backend can choose the correct Telegram bot token for `initData`
56
59
  verification.
57
60
 
61
+ `connectTelegram()` opens the `bindUrl` returned by the API. The API should
62
+ generate that URL from its `WEB_BASE_URL`, so users leave the Mini App and finish
63
+ passkey authentication on the hosted passkey binding page.
64
+
65
+ ## Internationalization
66
+
67
+ The built-in payment confirmation sheet supports English and Simplified Chinese.
68
+ The SDK uses explicit `locale`, then Telegram `language_code`, then
69
+ `navigator.language`, and falls back to English:
70
+
71
+ ```ts
72
+ const eosConnect = createEosConnect({
73
+ telegramWebApp,
74
+ locale: 'zh-CN',
75
+ messages: {
76
+ paymentConfirmTitle: '确认付款',
77
+ paymentConfirmAction: '支付'
78
+ }
79
+ });
80
+ ```
81
+
58
82
  ## Connect a Telegram Wallet
59
83
 
60
84
  ```ts
package/dist/index.d.ts CHANGED
@@ -14,6 +14,11 @@ export interface EosConnectProvider {
14
14
  }
15
15
  export interface EosConnectTelegramWebApp {
16
16
  initData?: string;
17
+ initDataUnsafe?: {
18
+ user?: {
19
+ language_code?: string;
20
+ };
21
+ };
17
22
  platform?: string;
18
23
  version?: string;
19
24
  openLink?(url: string): void;
@@ -98,6 +103,8 @@ export interface EosConnectOptions {
98
103
  apiBaseUrl?: string;
99
104
  botUsername?: string;
100
105
  deviceLabel?: string;
106
+ locale?: string;
107
+ messages?: EosConnectMessages;
101
108
  balanceAsset?: EosConnectBalanceAsset;
102
109
  rpcUrls?: string | string[];
103
110
  signTransaction?: EosConnectTransactionSigner;
@@ -186,6 +193,15 @@ export interface EosConnectPaymentDetails {
186
193
  }
187
194
  export type EosConnectSignedTransaction = SignedTransferPayload;
188
195
  export type EosConnectPaymentConfirmer = (details: EosConnectPaymentDetails) => boolean | Promise<boolean>;
196
+ export interface EosConnectMessages {
197
+ paymentConfirmTitle?: string;
198
+ paymentConfirmClose?: string;
199
+ paymentConfirmRecipient?: string;
200
+ paymentConfirmMemo?: string;
201
+ paymentConfirmGas?: string;
202
+ paymentConfirmAction?: string;
203
+ emptyMemo?: string;
204
+ }
189
205
  export type EosConnectTransactionSigner = (transaction: Record<string, unknown>, context: {
190
206
  telegramWebApp?: EosConnectTelegramWebApp | null;
191
207
  rpcUrls: string[];
package/dist/index.js CHANGED
@@ -546,6 +546,42 @@ function rawErrorMessage(error) {
546
546
  }
547
547
  return 'EOS Connect request failed';
548
548
  }
549
+ const EOS_CONNECT_MESSAGES = {
550
+ en: {
551
+ paymentConfirmTitle: 'Payment details',
552
+ paymentConfirmClose: 'Close',
553
+ paymentConfirmRecipient: 'Recipient',
554
+ paymentConfirmMemo: 'Memo',
555
+ paymentConfirmGas: 'Gas',
556
+ paymentConfirmAction: 'Confirm',
557
+ emptyMemo: '-'
558
+ },
559
+ 'zh-CN': {
560
+ paymentConfirmTitle: '交易详情',
561
+ paymentConfirmClose: '关闭',
562
+ paymentConfirmRecipient: '收款地址',
563
+ paymentConfirmMemo: '备注',
564
+ paymentConfirmGas: 'Gas',
565
+ paymentConfirmAction: '确定',
566
+ emptyMemo: '-'
567
+ }
568
+ };
569
+ function normalizeEosConnectLocale(locale) {
570
+ return String(locale ?? '').toLowerCase().startsWith('zh') ? 'zh-CN' : 'en';
571
+ }
572
+ function telegramLanguageCode(app) {
573
+ return app?.initDataUnsafe?.user?.language_code;
574
+ }
575
+ function browserLanguage() {
576
+ const maybeNavigator = globalThis;
577
+ return maybeNavigator.navigator?.language;
578
+ }
579
+ function resolveEosConnectLocale(explicitLocale, telegramWebApp) {
580
+ return normalizeEosConnectLocale(explicitLocale ?? telegramLanguageCode(telegramWebApp) ?? browserLanguage());
581
+ }
582
+ function eosConnectMessage(key, locale, overrides) {
583
+ return overrides?.[key] ?? EOS_CONNECT_MESSAGES[locale][key];
584
+ }
549
585
  function ensurePaymentConfirmStyle(documentRef) {
550
586
  if (documentRef.querySelector('[data-eos-connect-payment-confirm-style]'))
551
587
  return;
@@ -658,11 +694,12 @@ function ensurePaymentConfirmStyle(documentRef) {
658
694
  `;
659
695
  documentRef.head.appendChild(style);
660
696
  }
661
- function defaultConfirmPayment(details) {
697
+ function defaultConfirmPayment(details, options) {
662
698
  const documentRef = globalThis.document;
663
699
  if (!documentRef?.body)
664
700
  return Promise.resolve(true);
665
701
  ensurePaymentConfirmStyle(documentRef);
702
+ const message = (key) => eosConnectMessage(key, options.locale, options.messages);
666
703
  const backdrop = documentRef.createElement('div');
667
704
  backdrop.className = 'eos-connect-payment-confirm-backdrop';
668
705
  backdrop.setAttribute('role', 'presentation');
@@ -670,7 +707,7 @@ function defaultConfirmPayment(details) {
670
707
  .slice(1)
671
708
  .map((payment) => `
672
709
  <div class="eos-connect-payment-confirm-row">
673
- <span>Gas</span>
710
+ <span>${escapeConfirmHtml(message('paymentConfirmGas'))}</span>
674
711
  <strong>${escapeConfirmHtml(payment.quantity)}</strong>
675
712
  </div>
676
713
  `)
@@ -679,20 +716,20 @@ function defaultConfirmPayment(details) {
679
716
  <section class="eos-connect-payment-confirm-sheet" role="dialog" aria-modal="true" aria-labelledby="eos-connect-payment-confirm-title">
680
717
  <header class="eos-connect-payment-confirm-header">
681
718
  <span></span>
682
- <h2 id="eos-connect-payment-confirm-title">交易详情</h2>
683
- <button type="button" class="eos-connect-payment-confirm-close" aria-label="关闭">×</button>
719
+ <h2 id="eos-connect-payment-confirm-title">${escapeConfirmHtml(message('paymentConfirmTitle'))}</h2>
720
+ <button type="button" class="eos-connect-payment-confirm-close" aria-label="${escapeConfirmHtml(message('paymentConfirmClose'))}">×</button>
684
721
  </header>
685
722
  <div class="eos-connect-payment-confirm-amount">-${escapeConfirmHtml(details.quantity)}</div>
686
723
  <div class="eos-connect-payment-confirm-row">
687
- <span>收款地址</span>
724
+ <span>${escapeConfirmHtml(message('paymentConfirmRecipient'))}</span>
688
725
  <strong>${escapeConfirmHtml(details.to)}</strong>
689
726
  </div>
690
727
  <div class="eos-connect-payment-confirm-row">
691
- <span>备注</span>
692
- <strong>${escapeConfirmHtml(details.memo || '-')}</strong>
728
+ <span>${escapeConfirmHtml(message('paymentConfirmMemo'))}</span>
729
+ <strong>${escapeConfirmHtml(details.memo || message('emptyMemo'))}</strong>
693
730
  </div>
694
731
  ${serviceRows}
695
- <button type="button" class="eos-connect-payment-confirm-action">确定</button>
732
+ <button type="button" class="eos-connect-payment-confirm-action">${escapeConfirmHtml(message('paymentConfirmAction'))}</button>
696
733
  </section>
697
734
  `;
698
735
  return new Promise((resolve) => {
@@ -1432,7 +1469,11 @@ export function createEosConnect(options) {
1432
1469
  symbol: payOptions.symbol
1433
1470
  })
1434
1471
  });
1435
- const confirmPayment = options.confirmPayment === false ? null : options.confirmPayment ?? defaultConfirmPayment;
1472
+ const defaultPaymentConfirmer = (details) => defaultConfirmPayment(details, {
1473
+ locale: resolveEosConnectLocale(options.locale, telegramWebApp()),
1474
+ messages: options.messages
1475
+ });
1476
+ const confirmPayment = options.confirmPayment === false ? null : options.confirmPayment ?? defaultPaymentConfirmer;
1436
1477
  if (confirmPayment) {
1437
1478
  const confirmed = await confirmPayment(paymentDetailsFromBuiltTransfer(built));
1438
1479
  if (!confirmed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eos3/connect",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Framework-neutral browser SDK for EOS Passkey Connect in Telegram Mini Apps.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",