@eos3/connect 0.1.10 → 0.1.12
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 +7 -5
- package/dist/index.d.ts +0 -2
- package/dist/index.js +51 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,8 +112,7 @@ renderQuickPay({
|
|
|
112
112
|
|
|
113
113
|
if (!quickPay.enabled) {
|
|
114
114
|
const next = await eosConnect.enableQuickPay({
|
|
115
|
-
pollIntervalMs: 1500
|
|
116
|
-
timeoutMs: 120_000
|
|
115
|
+
pollIntervalMs: 1500
|
|
117
116
|
});
|
|
118
117
|
renderQuickPay(next);
|
|
119
118
|
}
|
|
@@ -127,11 +126,14 @@ if (!quickPay.enabled) {
|
|
|
127
126
|
- opens an existing `pending` `bindUrl`;
|
|
128
127
|
- calls `connectTelegram({ replaceWallet: true })` when the current device is
|
|
129
128
|
missing the local payment key;
|
|
130
|
-
- polls wallet readiness until `ready
|
|
129
|
+
- polls wallet readiness until `ready` or another terminal state;
|
|
130
|
+
- pauses background polling when the page is hidden and checks immediately when
|
|
131
|
+
the Telegram Mini App returns to the foreground.
|
|
131
132
|
|
|
132
133
|
Advanced UIs can still call `getWalletView()` or `startTelegramWalletFlow()`
|
|
133
|
-
when they need debug-level states and labels.
|
|
134
|
-
|
|
134
|
+
when they need debug-level states and labels. Wallet setup always polls after
|
|
135
|
+
opening the binding page and returns when the wallet is ready or reaches another
|
|
136
|
+
terminal state.
|
|
135
137
|
|
|
136
138
|
## Connect a Telegram Wallet
|
|
137
139
|
|
package/dist/index.d.ts
CHANGED
|
@@ -98,9 +98,7 @@ export interface EosConnectTelegramOptions {
|
|
|
98
98
|
openLink?: boolean;
|
|
99
99
|
}
|
|
100
100
|
export interface EosConnectWalletFlowOptions extends EosConnectTelegramOptions {
|
|
101
|
-
waitForReady?: boolean;
|
|
102
101
|
pollIntervalMs?: number;
|
|
103
|
-
timeoutMs?: number;
|
|
104
102
|
openExternal?: (url: string) => void;
|
|
105
103
|
}
|
|
106
104
|
export type EosConnectWalletViewStatus = 'setup' | 'pending' | 'ready' | 'unsupported' | 'error';
|
package/dist/index.js
CHANGED
|
@@ -1270,6 +1270,56 @@ 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
|
+
}
|
|
1273
1323
|
function openFlowUrl(url, clientOptions, flowOptions, telegramWebApp) {
|
|
1274
1324
|
if (flowOptions.openExternal) {
|
|
1275
1325
|
flowOptions.openExternal(url);
|
|
@@ -1565,21 +1615,13 @@ export function createEosConnect(options) {
|
|
|
1565
1615
|
openedView = walletViewFromCapability(pendingWalletCapabilityFromState(next), message);
|
|
1566
1616
|
}
|
|
1567
1617
|
}
|
|
1568
|
-
if (flowOptions.waitForReady === false) {
|
|
1569
|
-
return openedView ?? this.refreshWallet();
|
|
1570
|
-
}
|
|
1571
|
-
const timeoutMs = flowOptions.timeoutMs ?? 120000;
|
|
1572
1618
|
const pollIntervalMs = flowOptions.pollIntervalMs ?? 1500;
|
|
1573
|
-
const deadline = Date.now() + Math.max(0, timeoutMs);
|
|
1574
1619
|
do {
|
|
1575
1620
|
capability = await this.checkWallet();
|
|
1576
1621
|
if (capability.status !== 'pending') {
|
|
1577
1622
|
return walletViewFromCapability(capability, message);
|
|
1578
1623
|
}
|
|
1579
|
-
|
|
1580
|
-
return walletViewFromCapability(capability, message);
|
|
1581
|
-
}
|
|
1582
|
-
await delay(pollIntervalMs);
|
|
1624
|
+
await waitForNextWalletPoll(pollIntervalMs);
|
|
1583
1625
|
} while (true);
|
|
1584
1626
|
}
|
|
1585
1627
|
catch (error) {
|