import { isTonAddress as o } from "../chains/isTonAddress.js";
const l = async (t, a, e) => {
  if (t.symbol !== "TON")
    return null;
  const s = new URL("https://toncenter.com/api/v2/getAddressBalance");
  s.searchParams.set("address", a);
  const n = {
    "Content-Type": "application/json"
  };
  return e && (n["X-API-Key"] = e), (await (await fetch(s, { headers: n })).json()).result ?? "0";
}, i = async (t, a, e) => {
  const s = new URL("https://toncenter.com/api/v3/jetton/wallets");
  if (!t.contractAddress)
    return null;
  s.searchParams.set("owner_address", a), s.searchParams.set("jetton_address", t.contractAddress), s.searchParams.set("exclude_zero_balance", "false");
  const n = {};
  e && (n["X-Api-Key"] = e);
  const r = await (await fetch(s.toString(), { headers: n })).json();
  return r.jetton_wallets?.length ? r.jetton_wallets?.[0]?.balance ?? "0" : "0";
}, f = (t, a, e) => o(a) ? t.symbol === "TON" ? l(t, a, e) : i(t, a, e) : "0";
export {
  f as getTonTokenBalance
};
//# sourceMappingURL=getTonTokenBalance.js.map
