@renegade-fi/core
Version:
VanillaJS library for Renegade
26 lines • 1.05 kB
JavaScript
import { BaseError } from "../errors/base.js";
import { getWalletFromRelayer } from "./getWalletFromRelayer.js";
export async function waitForWalletIndexing(config, parameters) {
const { onComplete, onFailure, timeout = 60000, isLookup } = parameters;
const pollingInterval = config.renegadeKeyType === "internal" ? config.pollingInterval : 5000;
const startTime = Date.now();
while (true) {
if (Date.now() - startTime >= timeout) {
onFailure?.();
throw new BaseError(`Timed out while ${isLookup ? "looking up" : "creating"} wallet`);
}
try {
const wallet = await getWalletFromRelayer(config);
if (wallet) {
onComplete?.(wallet);
break;
}
}
catch (_) {
// Do nothing, just continue the loop
}
// Sleep for a bit before polling again
await new Promise((resolve) => setTimeout(resolve, pollingInterval / 2));
}
}
//# sourceMappingURL=waitForWalletIndexing.js.map