import { noop as c } from "@tanstack/react-query";
import { l as o } from "../../localstorage-DVS0q1yC.js";
import { logger as m } from "../../logger.js";
import { nearSingleRpcClient as f } from "./rpc.js";
const p = 300, s = /* @__PURE__ */ new Map();
let r = null;
const E = (e) => {
  const t = new Set(o.getItem("verifiedNearAccounts"));
  t.add(e), o.setItem("verifiedNearAccounts", [...t]);
}, N = async (e) => {
  try {
    return await f.query({
      request_type: "view_account",
      account_id: e,
      finality: "final"
    }), E(e), s.set(e, !0), !0;
  } catch (t) {
    const i = /doesn.t exist|does not exist|UNKNOWN_ACCOUNT|AccountDoesNotExist/i, n = t instanceof Error ? `${t.message} ${String(t)}` : String(t);
    return i.test(n) ? (s.set(e, !1), !1) : (m.error(new Error("NEAR RPC check failed", { cause: t })), !0);
  }
}, y = async (e) => {
  if (s.has(e))
    return s.get(e) ?? !1;
  if (new Set(o.getItem("verifiedNearAccounts")).has(e))
    return s.set(e, !0), !0;
  if (r?.accountId === e)
    return r.promise;
  r && (clearTimeout(r.timer), r.reject(new Error("ACCOUNT_CHECK_SUPERSEDED")), r = null);
  let t = c, i = c;
  const n = new Promise((l, u) => {
    t = l, i = u;
  }), a = setTimeout(async () => {
    r = null, t(await N(e));
  }, p);
  return r = {
    accountId: e,
    promise: n,
    timer: a,
    resolve: t,
    reject: i
  }, n;
};
export {
  y as checkNearAccountExists
};
//# sourceMappingURL=checkNearAccountExists.js.map
