@pushchain/ui-kit
Version:
Push Chain is a true universal L1 that is 100% EVM compatible. It allows developers to deploy once and make their apps instantly compatible with users from all other L1s (Ethereum, Solana, etc) with zero on-chain code change.
44 lines • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForTxHashFromPendingTxId = exports.ensureWaapTxListeners = void 0;
const inflight = new Map();
let listenersAttached = false;
const isHexHash = (v) => typeof v === "string" && /^0x[0-9a-fA-F]{64}$/.test(v);
const ensureWaapTxListeners = (waap) => {
if (listenersAttached)
return;
listenersAttached = true;
waap.on("waap_tx_pending", (data) => {
if (!data?.pendingTxId || !isHexHash(data.txHash))
return;
const entry = inflight.get(data.pendingTxId);
if (!entry)
return;
clearTimeout(entry.timer);
inflight.delete(data.pendingTxId);
entry.resolve(data.txHash);
});
waap.on("waap_tx_failed", (data) => {
if (!data?.pendingTxId)
return;
const entry = inflight.get(data.pendingTxId);
if (!entry)
return;
clearTimeout(entry.timer);
inflight.delete(data.pendingTxId);
entry.reject(new Error(`WaaP tx failed${data.stage ? ` (${data.stage})` : ""}: ${data.error}`));
});
};
exports.ensureWaapTxListeners = ensureWaapTxListeners;
const waitForTxHashFromPendingTxId = (waap, pendingTxId, timeoutMs = 90_000) => {
(0, exports.ensureWaapTxListeners)(waap);
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
inflight.delete(pendingTxId);
reject(new Error(`Timed out waiting for txHash (pendingTxId=${pendingTxId})`));
}, timeoutMs);
inflight.set(pendingTxId, { resolve, reject, timer });
});
};
exports.waitForTxHashFromPendingTxId = waitForTxHashFromPendingTxId;
//# sourceMappingURL=waapEvents.js.map