@nibgate/sdk 0.2.28 → 0.2.30

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,7 +27505,7 @@ ${prettyStateOverride(stateOverride)}`;
27505
27505
  document.removeEventListener("touchend", cancelHold);
27506
27506
  };
27507
27507
  card.addEventListener("remove", cleanup);
27508
- let gwOverlay = null;
27508
+ let balEl = null, gwOverlay = null, balTimer = null;
27509
27509
  function depIcon() {
27510
27510
  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>';
27511
27511
  }
@@ -27540,29 +27540,44 @@ ${prettyStateOverride(stateOverride)}`;
27540
27540
  document.removeEventListener("keydown", onDepKey);
27541
27541
  }
27542
27542
  }
27543
- let balEl = null;
27544
27543
  function ensureBal() {
27545
27544
  if (balEl && balEl.isConnected) return balEl;
27546
27545
  balEl = el(
27547
27546
  "span",
27548
27547
  { "data-nibgate-bal": "", style: "margin-left:4px;cursor:pointer;white-space:nowrap;color:var(--accent,#7c9a6d)" },
27549
- "\xB7\xA0|\xA0" + depIcon()
27548
+ "\xB7\xA0<span data-nibgate-bal-txt></span>\xA0|\xA0" + depIcon()
27550
27549
  );
27551
27550
  balEl.addEventListener("click", showDeposit);
27552
- if (label.parentNode) label.parentNode.insertBefore(balEl, label.nextSibling);
27551
+ label.appendChild(balEl);
27553
27552
  return balEl;
27554
27553
  }
27555
- if (window.ethereum) {
27556
- setTimeout(() => {
27557
- const accts = window.ethereum.request({ method: "eth_accounts" }).catch(() => []);
27558
- accts.then((a) => {
27559
- if (Array.isArray(a) && a[0]) ensureBal();
27554
+ async function refreshBal() {
27555
+ if (!card.isConnected || !window.ethereum || !options.gatewayBalanceUrl) return;
27556
+ try {
27557
+ const accts = await window.ethereum.request({ method: "eth_accounts" });
27558
+ const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
27559
+ if (!addr) return;
27560
+ const t = ensureBal().querySelector("[data-nibgate-bal-txt]");
27561
+ if (!t) return;
27562
+ const r = await fetch(options.gatewayBalanceUrl, {
27563
+ method: "POST",
27564
+ headers: { "Content-Type": "application/json" },
27565
+ body: JSON.stringify({ address: addr })
27560
27566
  });
27561
- }, 1e3);
27567
+ const data = await r.json();
27568
+ t.textContent = data?.balance || "";
27569
+ } catch {
27570
+ }
27571
+ }
27572
+ if (window.ethereum) {
27573
+ balTimer = setInterval(refreshBal, 3e3);
27574
+ setTimeout(refreshBal, 1e3);
27575
+ window.ethereum.on("accountsChanged", refreshBal);
27562
27576
  }
27563
27577
  return { ...ctrl, element: card, destroy: () => {
27564
27578
  cleanup();
27565
27579
  card.remove();
27580
+ if (balTimer) clearInterval(balTimer);
27566
27581
  if (gwOverlay) {
27567
27582
  gwOverlay.remove();
27568
27583
  gwOverlay = null;