@fastnear/wallet-adapter
Version:
Wallet adapter implementations for Meteor Wallet and Near Mobile
88 lines • 3.64 kB
JavaScript
/* ⋈ 🏃🏻💨 FastNear Wallet Adapters - CJS (@fastnear/wallet-adapter version 1.2.0) */
/* https://www.npmjs.com/package/@fastnear/wallet-adapter/v/1.2.0 */
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var polling_exports = {};
__export(polling_exports, {
defaultPollingOptions: () => defaultPollingOptions,
visibilityAwarePoll: () => visibilityAwarePoll
});
module.exports = __toCommonJS(polling_exports);
var import_errors = require("./errors.js");
const sleep = /* @__PURE__ */ __name((ms) => new Promise((resolve) => setTimeout(resolve, ms)), "sleep");
const waitUntilVisible = /* @__PURE__ */ __name(async (checkIntervalMs, timeoutMs) => {
if (typeof document === "undefined") return;
if (!document.hidden) return;
const start = Date.now();
while (document.hidden) {
if (Date.now() - start >= timeoutMs) {
throw new import_errors.TransportError("VISIBILITY_TIMEOUT", "Browser tab stayed hidden for too long while polling");
}
await sleep(checkIntervalMs);
}
}, "waitUntilVisible");
const withTimeout = /* @__PURE__ */ __name(async (promise, timeoutMs, timeoutCode) => {
let timeoutId;
try {
return await Promise.race([
promise,
new Promise((_, reject) => {
timeoutId = setTimeout(() => {
reject(new import_errors.TransportError(timeoutCode, `Operation timed out after ${timeoutMs}ms`));
}, timeoutMs);
})
]);
} finally {
if (timeoutId != null) clearTimeout(timeoutId);
}
}, "withTimeout");
const visibilityAwarePoll = /* @__PURE__ */ __name(async (fn, isPending, options) => {
const start = Date.now();
let iteration = 0;
let delay = options.delayMs;
while (true) {
if (Date.now() - start > options.requestTimeoutMs) {
throw new import_errors.TransportError("POLLING_TIMEOUT", "Polling timed out");
}
await waitUntilVisible(options.backgroundVisibilityCheckIntervalMs, options.backgroundVisibilityCheckTimeoutMs);
const value = await withTimeout(fn(), options.requestCallTimeoutMs, "POLLING_REQUEST_TIMEOUT");
if (!isPending(value)) return value;
if (iteration >= options.maxIterations) {
throw new import_errors.TransportError("POLLING_MAX_ITERATIONS", "Polling reached the maximum number of iterations");
}
await sleep(delay);
delay = Math.min(5e3, Math.ceil(delay * 1.15));
iteration += 1;
}
}, "visibilityAwarePoll");
const defaultPollingOptions = {
delayMs: 1e3,
maxIterations: 1e3,
requestTimeoutMs: 10 * 60 * 1e3,
backgroundVisibilityCheckIntervalMs: 1e3,
backgroundVisibilityCheckTimeoutMs: 10 * 60 * 1e3,
requestCallTimeoutMs: 3e4
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defaultPollingOptions,
visibilityAwarePoll
});
//# sourceMappingURL=polling.cjs.map