@eos3/connect 0.1.2 → 0.1.4
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 +20 -1
- package/dist/index.d.ts +17 -2
- package/dist/index.js +53 -11
- package/package.json +1 -1
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
|
|
|
@@ -61,6 +62,23 @@ verification.
|
|
|
61
62
|
generate that URL from its `WEB_BASE_URL`, so users leave the Mini App and finish
|
|
62
63
|
passkey authentication on the hosted passkey binding page.
|
|
63
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
|
+
|
|
64
82
|
## Connect a Telegram Wallet
|
|
65
83
|
|
|
66
84
|
```ts
|
|
@@ -208,7 +226,8 @@ await fetch('https://wallet.example.com/api/market/push', {
|
|
|
208
226
|
- `client.connectTelegram(options)`: starts or resumes Telegram binding.
|
|
209
227
|
- `client.connectTokenPocket(options)`: starts TokenPocket binding.
|
|
210
228
|
- `client.pay(options)`: builds, signs, confirms, and pushes a paylimit payment.
|
|
211
|
-
- `client.
|
|
229
|
+
- `client.disconnect()`: removes the local Telegram payment key from
|
|
230
|
+
SecureStorage, clears the biometric token, and resets the SDK state.
|
|
212
231
|
|
|
213
232
|
## Network Presets
|
|
214
233
|
|
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;
|
|
@@ -130,7 +137,7 @@ export interface EosConnectClient {
|
|
|
130
137
|
connectTelegram(options?: EosConnectTelegramOptions): Promise<EosConnectState>;
|
|
131
138
|
connectTokenPocket(options?: EosConnectTelegramOptions): Promise<EosConnectState>;
|
|
132
139
|
pay(options: EosConnectPayOptions): Promise<EosConnectPayResult>;
|
|
133
|
-
|
|
140
|
+
disconnect(): Promise<EosConnectState>;
|
|
134
141
|
}
|
|
135
142
|
export interface EosConnectBalanceAsset {
|
|
136
143
|
tokenContract: string;
|
|
@@ -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[];
|
|
@@ -225,7 +241,6 @@ export declare function loadEosConnectPaymentSigningKey(app?: EosConnectTelegram
|
|
|
225
241
|
publicKey: string;
|
|
226
242
|
storedPublicKey: string | null;
|
|
227
243
|
}>;
|
|
228
|
-
export declare function removeEosConnectPaymentKey(app?: EosConnectTelegramWebApp | null): Promise<void>;
|
|
229
244
|
export declare function signEosConnectTransaction(transaction: Record<string, unknown>, context: {
|
|
230
245
|
telegramWebApp?: EosConnectTelegramWebApp | null;
|
|
231
246
|
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
|
|
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"
|
|
683
|
-
<button type="button" class="eos-connect-payment-confirm-close" aria-label="
|
|
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
|
|
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
|
|
692
|
-
<strong>${escapeConfirmHtml(details.memo || '
|
|
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"
|
|
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) => {
|
|
@@ -957,7 +994,7 @@ export async function loadEosConnectPaymentSigningKey(app) {
|
|
|
957
994
|
storedPublicKey: envelope.publicKey ?? null
|
|
958
995
|
};
|
|
959
996
|
}
|
|
960
|
-
|
|
997
|
+
async function disconnectEosConnectPaymentKey(app) {
|
|
961
998
|
const telegram = requireSecureTelegramStorage(app);
|
|
962
999
|
await Promise.all([
|
|
963
1000
|
secureStorageRemove(telegram, EOS_CONNECT_PRIVATE_KEY_STORAGE),
|
|
@@ -1432,7 +1469,11 @@ export function createEosConnect(options) {
|
|
|
1432
1469
|
symbol: payOptions.symbol
|
|
1433
1470
|
})
|
|
1434
1471
|
});
|
|
1435
|
-
const
|
|
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) {
|
|
@@ -1455,7 +1496,8 @@ export function createEosConnect(options) {
|
|
|
1455
1496
|
})
|
|
1456
1497
|
});
|
|
1457
1498
|
},
|
|
1458
|
-
|
|
1499
|
+
async disconnect() {
|
|
1500
|
+
await disconnectEosConnectPaymentKey(telegramWebApp());
|
|
1459
1501
|
return publish({ ...idleState });
|
|
1460
1502
|
}
|
|
1461
1503
|
};
|