@eos3/connect 0.1.11 → 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 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,12 +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`, another terminal state, or timeout.
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
134
  when they need debug-level states and labels. Wallet setup always polls after
134
- opening the binding page and returns when the wallet is ready, reaches another
135
- terminal state, or times out.
135
+ opening the binding page and returns when the wallet is ready or reaches another
136
+ terminal state.
136
137
 
137
138
  ## Connect a Telegram Wallet
138
139
 
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';
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,18 +1615,13 @@ export function createEosConnect(options) {
1565
1615
  openedView = walletViewFromCapability(pendingWalletCapabilityFromState(next), message);
1566
1616
  }
1567
1617
  }
1568
- const timeoutMs = flowOptions.timeoutMs ?? 120000;
1569
1618
  const pollIntervalMs = flowOptions.pollIntervalMs ?? 1500;
1570
- const deadline = Date.now() + Math.max(0, timeoutMs);
1571
1619
  do {
1572
1620
  capability = await this.checkWallet();
1573
1621
  if (capability.status !== 'pending') {
1574
1622
  return walletViewFromCapability(capability, message);
1575
1623
  }
1576
- if (Date.now() >= deadline) {
1577
- return walletViewFromCapability(capability, message);
1578
- }
1579
- await delay(pollIntervalMs);
1624
+ await waitForNextWalletPoll(pollIntervalMs);
1580
1625
  } while (true);
1581
1626
  }
1582
1627
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eos3/connect",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Framework-neutral browser SDK for EOS Passkey Connect in Telegram Mini Apps.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",