@nibgate/sdk 0.2.23 → 0.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nibgate.js CHANGED
@@ -27505,70 +27505,91 @@ ${prettyStateOverride(stateOverride)}`;
27505
27505
  document.removeEventListener("touchend", cancelHold);
27506
27506
  };
27507
27507
  card.addEventListener("remove", cleanup);
27508
- let gwOverlayEl = null;
27509
- let balTimer = null;
27510
- let balEl = null;
27511
- function depositIconHTML() {
27512
- return '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:baseline"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>';
27513
- }
27514
- async function showGatewayWallet() {
27515
- if (gwOverlayEl) return;
27516
- gwOverlayEl = el("div", { style: "position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;padding:20px;animation:nfade .15s ease-out" });
27508
+ const ARC_RPC = "https://arc-testnet.drpc.org";
27509
+ const GATEWAY_WALLET = "0x0077777d7EBA4688BDeF3E311b846F25870A19B9";
27510
+ const USDC_ADDRESS = "0x3600000000000000000000000000000000000000";
27511
+ async function fetchBalance(addr) {
27512
+ const sel = "0xdd62e1c6";
27513
+ const pad4 = (a) => "000000000000000000000000" + a.slice(2).toLowerCase();
27514
+ const data = sel + pad4(USDC_ADDRESS) + pad4(addr);
27515
+ const r = await fetch(ARC_RPC, {
27516
+ method: "POST",
27517
+ headers: { "Content-Type": "application/json" },
27518
+ body: JSON.stringify({ jsonrpc: "2.0", method: "eth_call", params: [{ to: GATEWAY_WALLET, data }, "latest"], id: 1 })
27519
+ });
27520
+ const j = await r.json();
27521
+ return j?.result ? (Number(BigInt(j.result)) / 1e6).toFixed(2) + " USDC" : "\u2014";
27522
+ }
27523
+ let balEl = null, gwOverlay = null, balTimer = null;
27524
+ function depIcon() {
27525
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>';
27526
+ }
27527
+ function showDeposit() {
27528
+ if (gwOverlay) return;
27529
+ gwOverlay = el("div", { style: "position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;padding:20px;animation:nfade .15s ease-out" });
27517
27530
  const modal = el("div", { style: "background:" + theme.bg + ";border-radius:16px;max-width:540px;width:100%;max-height:90vh;overflow:auto;position:relative;box-shadow:0 8px 32px rgba(0,0,0,0.12);animation:nscale .15s ease-out" });
27518
27531
  const close = el("button", { style: "position:absolute;top:12px;right:16px;z-index:20;background:none;border:none;font-size:28px;cursor:pointer;color:" + theme.muted + ";font-family:inherit;line-height:1" }, "\xD7");
27519
- close.addEventListener("click", closeGatewayWallet);
27532
+ close.addEventListener("click", () => {
27533
+ gwOverlay.remove();
27534
+ gwOverlay = null;
27535
+ document.removeEventListener("keydown", onDepKey);
27536
+ });
27520
27537
  modal.appendChild(close);
27521
- gwOverlayEl.appendChild(modal);
27522
- gwOverlayEl.addEventListener("click", (e) => {
27523
- if (e.target === gwOverlayEl) closeGatewayWallet();
27538
+ gwOverlay.appendChild(modal);
27539
+ gwOverlay.addEventListener("click", (e) => {
27540
+ if (e.target === gwOverlay) {
27541
+ gwOverlay.remove();
27542
+ gwOverlay = null;
27543
+ document.removeEventListener("keydown", onDepKey);
27544
+ }
27545
+ });
27546
+ document.body.appendChild(gwOverlay);
27547
+ document.addEventListener("keydown", onDepKey);
27548
+ Promise.resolve().then(() => (init_default_ui(), default_ui_exports)).then((m) => m.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {})).catch(() => {
27524
27549
  });
27525
- document.body.appendChild(gwOverlayEl);
27526
- document.addEventListener("keydown", onGwKey);
27527
- const gw = await Promise.resolve().then(() => (init_default_ui(), default_ui_exports));
27528
- gw.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {});
27529
- }
27530
- function closeGatewayWallet() {
27531
- if (!gwOverlayEl) return;
27532
- gwOverlayEl.remove();
27533
- gwOverlayEl = null;
27534
- document.removeEventListener("keydown", onGwKey);
27535
27550
  }
27536
- function onGwKey(e) {
27537
- if (e.key === "Escape") closeGatewayWallet();
27551
+ function onDepKey(e) {
27552
+ if (e.key === "Escape" && gwOverlay) {
27553
+ gwOverlay.remove();
27554
+ gwOverlay = null;
27555
+ document.removeEventListener("keydown", onDepKey);
27556
+ }
27538
27557
  }
27539
- function ensureBalEl() {
27558
+ function ensureBal() {
27540
27559
  if (balEl && balEl.isConnected) return balEl;
27541
- balEl = el("span", { "data-nibgate-bal": "", style: "margin-left:6px;cursor:pointer;white-space:nowrap" }, depositIconHTML() + " <span data-nibgate-bal-text></span>");
27542
- balEl.addEventListener("click", showGatewayWallet);
27560
+ balEl = el(
27561
+ "span",
27562
+ { "data-nibgate-bal": "", style: "margin-left:4px;cursor:pointer;white-space:nowrap;color:var(--accent,#7c9a6d)" },
27563
+ "\xB7\xA0<span data-nibgate-bal-txt></span>\xA0|\xA0" + depIcon()
27564
+ );
27565
+ balEl.addEventListener("click", showDeposit);
27543
27566
  if (label.parentNode) label.parentNode.insertBefore(balEl, label.nextSibling);
27544
27567
  return balEl;
27545
27568
  }
27546
- async function refreshBalance() {
27547
- if (!card.isConnected) return;
27548
- const addr = ctrl.getWalletAddress();
27549
- if (!addr) return;
27550
- const txt = ensureBalEl().querySelector("[data-nibgate-bal-text]");
27551
- if (options.gatewayBalanceUrl) {
27552
- try {
27553
- const res = await fetch(options.gatewayBalanceUrl + "?address=" + encodeURIComponent(addr));
27554
- const data = await res.json();
27555
- if (txt) txt.textContent = data?.balance || data?.availableBalance || "\u2026";
27556
- return;
27557
- } catch {
27558
- }
27569
+ async function refreshBal() {
27570
+ if (!card.isConnected || !window.ethereum) return;
27571
+ try {
27572
+ const accts = await window.ethereum.request({ method: "eth_accounts" });
27573
+ const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
27574
+ if (!addr) return;
27575
+ const t = ensureBal().querySelector("[data-nibgate-bal-txt]");
27576
+ if (t) t.textContent = await fetchBalance(addr);
27577
+ } catch {
27559
27578
  }
27560
- if (txt) txt.textContent = "\u2026";
27561
27579
  }
27562
27580
  if (window.ethereum) {
27563
- balTimer = setInterval(refreshBalance, 3e3);
27564
- setTimeout(refreshBalance, 1e3);
27565
- window.ethereum.on("accountsChanged", refreshBalance);
27581
+ balTimer = setInterval(refreshBal, 3e3);
27582
+ setTimeout(refreshBal, 1e3);
27583
+ window.ethereum.on("accountsChanged", refreshBal);
27566
27584
  }
27567
27585
  return { ...ctrl, element: card, destroy: () => {
27568
27586
  cleanup();
27569
27587
  card.remove();
27570
27588
  if (balTimer) clearInterval(balTimer);
27571
- closeGatewayWallet();
27589
+ if (gwOverlay) {
27590
+ gwOverlay.remove();
27591
+ gwOverlay = null;
27592
+ }
27572
27593
  } };
27573
27594
  }
27574
27595
  function renderDefaultRatingUI(container, resource, options = {}) {