@eos3/connect 0.1.11 → 0.1.13
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 +15 -15
- package/dist/index.d.ts +1 -2
- package/dist/index.js +64 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ await eosConnect.bootstrapTelegram();
|
|
|
56
56
|
const quickPay = await eosConnect.checkQuickPay();
|
|
57
57
|
|
|
58
58
|
if (!quickPay.enabled) {
|
|
59
|
+
// Requires <eos-connect-modal hidden></eos-connect-modal> from @eos3/connect-ui.
|
|
59
60
|
await eosConnect.enableQuickPay();
|
|
60
61
|
}
|
|
61
62
|
```
|
|
@@ -95,10 +96,10 @@ const eosConnect = createEosConnect({
|
|
|
95
96
|
|
|
96
97
|
## Quick Payment Flow
|
|
97
98
|
|
|
98
|
-
For app UIs,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
For app UIs, use `checkQuickPay()` for readiness and `enableQuickPay()` for the
|
|
100
|
+
button click. `enableQuickPay()` does not start binding directly; it opens the
|
|
101
|
+
SDK-owned `<eos-connect-modal>` from `@eos3/connect-ui` so users always see the
|
|
102
|
+
quick payment setup sheet first:
|
|
102
103
|
|
|
103
104
|
```ts
|
|
104
105
|
const quickPay = await eosConnect.checkQuickPay();
|
|
@@ -111,15 +112,12 @@ renderQuickPay({
|
|
|
111
112
|
});
|
|
112
113
|
|
|
113
114
|
if (!quickPay.enabled) {
|
|
114
|
-
const next = await eosConnect.enableQuickPay(
|
|
115
|
-
pollIntervalMs: 1500,
|
|
116
|
-
timeoutMs: 120_000
|
|
117
|
-
});
|
|
115
|
+
const next = await eosConnect.enableQuickPay();
|
|
118
116
|
renderQuickPay(next);
|
|
119
117
|
}
|
|
120
118
|
```
|
|
121
119
|
|
|
122
|
-
|
|
120
|
+
The modal's primary action performs the common Telegram setup sequence:
|
|
123
121
|
|
|
124
122
|
- loads Telegram's WebApp SDK when needed;
|
|
125
123
|
- initializes `BiometricManager` and checks SecureStorage support;
|
|
@@ -127,12 +125,14 @@ if (!quickPay.enabled) {
|
|
|
127
125
|
- opens an existing `pending` `bindUrl`;
|
|
128
126
|
- calls `connectTelegram({ replaceWallet: true })` when the current device is
|
|
129
127
|
missing the local payment key;
|
|
130
|
-
- polls wallet readiness until `ready
|
|
128
|
+
- polls wallet readiness until `ready` or another terminal state;
|
|
129
|
+
- pauses background polling when the page is hidden and checks immediately when
|
|
130
|
+
the Telegram Mini App returns to the foreground.
|
|
131
131
|
|
|
132
132
|
Advanced UIs can still call `getWalletView()` or `startTelegramWalletFlow()`
|
|
133
|
-
when they need debug-level states and labels. Wallet setup
|
|
134
|
-
opening the binding page and returns when the wallet is ready
|
|
135
|
-
|
|
133
|
+
inside SDK-owned UI when they need debug-level states and labels. Wallet setup
|
|
134
|
+
always polls after opening the binding page and returns when the wallet is ready
|
|
135
|
+
or reaches another terminal state.
|
|
136
136
|
|
|
137
137
|
## Connect a Telegram Wallet
|
|
138
138
|
|
|
@@ -284,8 +284,8 @@ await fetch('https://wallet.example.com/api/market/push', {
|
|
|
284
284
|
- `checkEosConnectTelegramPayStorage(app)`: initializes Telegram biometrics and returns secure storage diagnostics.
|
|
285
285
|
- `client.connectTelegram(options)`: starts or resumes Telegram binding.
|
|
286
286
|
- `client.connectTokenPocket(options)`: starts TokenPocket binding.
|
|
287
|
-
- `client.startTelegramWalletFlow(options)`: runs the high-level Telegram wallet setup flow.
|
|
288
|
-
- `client.enableQuickPay(
|
|
287
|
+
- `client.startTelegramWalletFlow(options)`: runs the high-level Telegram wallet setup flow from SDK-owned UI.
|
|
288
|
+
- `client.enableQuickPay()`: opens the SDK-owned `<eos-connect-modal>` and returns current quick payment readiness.
|
|
289
289
|
- `client.pay(options)`: builds, signs, confirms, and pushes a paylimit payment.
|
|
290
290
|
- `client.disconnect()`: removes the local Telegram payment key from
|
|
291
291
|
SecureStorage, clears the biometric token, and resets the SDK state.
|
package/dist/index.d.ts
CHANGED
|
@@ -99,7 +99,6 @@ export interface EosConnectTelegramOptions {
|
|
|
99
99
|
}
|
|
100
100
|
export interface EosConnectWalletFlowOptions extends EosConnectTelegramOptions {
|
|
101
101
|
pollIntervalMs?: number;
|
|
102
|
-
timeoutMs?: number;
|
|
103
102
|
openExternal?: (url: string) => void;
|
|
104
103
|
}
|
|
105
104
|
export type EosConnectWalletViewStatus = 'setup' | 'pending' | 'ready' | 'unsupported' | 'error';
|
|
@@ -140,7 +139,7 @@ export interface EosConnectClient {
|
|
|
140
139
|
connectTelegram(options?: EosConnectTelegramOptions): Promise<EosConnectState>;
|
|
141
140
|
connectTokenPocket(options?: EosConnectTelegramOptions): Promise<EosConnectState>;
|
|
142
141
|
startTelegramWalletFlow(options?: EosConnectWalletFlowOptions): Promise<EosConnectWalletView>;
|
|
143
|
-
enableQuickPay(
|
|
142
|
+
enableQuickPay(): Promise<EosConnectQuickPayStatus>;
|
|
144
143
|
pay(options: EosConnectPayOptions): Promise<EosConnectPayResult>;
|
|
145
144
|
disconnect(): Promise<EosConnectState>;
|
|
146
145
|
}
|
package/dist/index.js
CHANGED
|
@@ -1270,6 +1270,64 @@ function mergeTelegramConnectOptions(defaults, overrides) {
|
|
|
1270
1270
|
function delay(ms) {
|
|
1271
1271
|
return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
1272
1272
|
}
|
|
1273
|
+
function isVisibleDocument(documentRef) {
|
|
1274
|
+
return !documentRef.visibilityState || documentRef.visibilityState === 'visible';
|
|
1275
|
+
}
|
|
1276
|
+
function waitForVisibleDocument(documentRef) {
|
|
1277
|
+
if (isVisibleDocument(documentRef)) {
|
|
1278
|
+
return Promise.resolve();
|
|
1279
|
+
}
|
|
1280
|
+
return new Promise((resolve) => {
|
|
1281
|
+
const onVisibilityChange = () => {
|
|
1282
|
+
if (!isVisibleDocument(documentRef)) {
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
documentRef.removeEventListener('visibilitychange', onVisibilityChange);
|
|
1286
|
+
resolve();
|
|
1287
|
+
};
|
|
1288
|
+
documentRef.addEventListener('visibilitychange', onVisibilityChange);
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
function waitForNextWalletPoll(ms) {
|
|
1292
|
+
const documentRef = globalThis.document;
|
|
1293
|
+
if (!documentRef?.addEventListener || !documentRef.removeEventListener) {
|
|
1294
|
+
return delay(ms);
|
|
1295
|
+
}
|
|
1296
|
+
if (!isVisibleDocument(documentRef)) {
|
|
1297
|
+
return waitForVisibleDocument(documentRef);
|
|
1298
|
+
}
|
|
1299
|
+
return new Promise((resolve) => {
|
|
1300
|
+
let settled = false;
|
|
1301
|
+
const finish = () => {
|
|
1302
|
+
if (settled) {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
settled = true;
|
|
1306
|
+
clearTimeout(timer);
|
|
1307
|
+
documentRef.removeEventListener('visibilitychange', onVisibilityChange);
|
|
1308
|
+
resolve();
|
|
1309
|
+
};
|
|
1310
|
+
const timer = setTimeout(() => {
|
|
1311
|
+
if (isVisibleDocument(documentRef)) {
|
|
1312
|
+
finish();
|
|
1313
|
+
}
|
|
1314
|
+
}, Math.max(0, ms));
|
|
1315
|
+
const onVisibilityChange = () => {
|
|
1316
|
+
if (isVisibleDocument(documentRef)) {
|
|
1317
|
+
finish();
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
documentRef.addEventListener('visibilitychange', onVisibilityChange);
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
function openEosConnectUiModal() {
|
|
1324
|
+
const modal = globalThis.document?.querySelector?.('eos-connect-modal,eos-connect');
|
|
1325
|
+
if (!modal) {
|
|
1326
|
+
return false;
|
|
1327
|
+
}
|
|
1328
|
+
modal.removeAttribute('hidden');
|
|
1329
|
+
return true;
|
|
1330
|
+
}
|
|
1273
1331
|
function openFlowUrl(url, clientOptions, flowOptions, telegramWebApp) {
|
|
1274
1332
|
if (flowOptions.openExternal) {
|
|
1275
1333
|
flowOptions.openExternal(url);
|
|
@@ -1565,18 +1623,13 @@ export function createEosConnect(options) {
|
|
|
1565
1623
|
openedView = walletViewFromCapability(pendingWalletCapabilityFromState(next), message);
|
|
1566
1624
|
}
|
|
1567
1625
|
}
|
|
1568
|
-
const timeoutMs = flowOptions.timeoutMs ?? 120000;
|
|
1569
1626
|
const pollIntervalMs = flowOptions.pollIntervalMs ?? 1500;
|
|
1570
|
-
const deadline = Date.now() + Math.max(0, timeoutMs);
|
|
1571
1627
|
do {
|
|
1572
1628
|
capability = await this.checkWallet();
|
|
1573
1629
|
if (capability.status !== 'pending') {
|
|
1574
1630
|
return walletViewFromCapability(capability, message);
|
|
1575
1631
|
}
|
|
1576
|
-
|
|
1577
|
-
return walletViewFromCapability(capability, message);
|
|
1578
|
-
}
|
|
1579
|
-
await delay(pollIntervalMs);
|
|
1632
|
+
await waitForNextWalletPoll(pollIntervalMs);
|
|
1580
1633
|
} while (true);
|
|
1581
1634
|
}
|
|
1582
1635
|
catch (error) {
|
|
@@ -1589,8 +1642,11 @@ export function createEosConnect(options) {
|
|
|
1589
1642
|
return walletViewFromError(normalized, message);
|
|
1590
1643
|
}
|
|
1591
1644
|
},
|
|
1592
|
-
async enableQuickPay(
|
|
1593
|
-
|
|
1645
|
+
async enableQuickPay() {
|
|
1646
|
+
if (!openEosConnectUiModal()) {
|
|
1647
|
+
throw new Error('EOS Connect UI modal is required to enable quick payment');
|
|
1648
|
+
}
|
|
1649
|
+
return this.checkQuickPay();
|
|
1594
1650
|
},
|
|
1595
1651
|
async connectTokenPocket(tokenPocketOptions = {}) {
|
|
1596
1652
|
const paymentKey = await generateEosConnectPaymentKey();
|