@nibgate/sdk 0.2.36 → 0.2.38

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
@@ -27526,7 +27526,7 @@ ${prettyStateOverride(stateOverride)}`;
27526
27526
  document.removeEventListener("touchend", cancelHold);
27527
27527
  };
27528
27528
  card.addEventListener("remove", cleanup);
27529
- let gwOverlay = null, balTimer = null;
27529
+ let balEl = null, gwOverlay = null, balTimer = null;
27530
27530
  function depIcon() {
27531
27531
  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>';
27532
27532
  }
@@ -27551,7 +27551,11 @@ ${prettyStateOverride(stateOverride)}`;
27551
27551
  });
27552
27552
  document.body.appendChild(gwOverlay);
27553
27553
  document.addEventListener("keydown", onDepKey);
27554
- Promise.resolve().then(() => (init_default_ui(), default_ui_exports)).then((m) => m.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {})).catch(() => {
27554
+ Promise.resolve().then(() => (init_default_ui(), default_ui_exports)).then((m) => m.renderDefaultGatewayWalletUI(modal, {
27555
+ address: ctrl.getWalletAddress(),
27556
+ gatewayBalanceUrl: options.gatewayBalanceUrl,
27557
+ ...options.gatewayOptions || {}
27558
+ })).catch(() => {
27555
27559
  });
27556
27560
  }
27557
27561
  function onDepKey(e) {
@@ -27744,10 +27748,8 @@ ${prettyStateOverride(stateOverride)}`;
27744
27748
  wrap3.innerHTML = `
27745
27749
  <div style="display:flex;gap:12px;margin-bottom:20px">
27746
27750
  <div data-gw-wallet-card style="flex:1;background:${theme.bg};border:1px solid ${theme.border};border-radius:12px;padding:16px">
27747
- <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">
27748
- <div style="font-size:12px;font-weight:600;color:${theme.muted};letter-spacing:.02em">Wallet</div>
27749
- <button data-gw-connect style="font-size:12px;font-weight:600;cursor:pointer;border:1px solid ${theme.accent};background:transparent;color:${theme.accent};border-radius:8px;padding:4px 12px;font-family:inherit">Connect</button>
27750
- </div>
27751
+ <div style="font-size:12px;font-weight:600;color:${theme.muted};margin-bottom:4px;letter-spacing:.02em">Wallet</div>
27752
+ <div data-gw-wallet-addr class="nui-mono" style="font-size:13px;color:${theme.muted};margin-bottom:4px"></div>
27751
27753
  <div data-gw-wallet-balance class="nui-mono" style="font-size:24px;font-weight:700;color:${theme.fg}">\u2014</div>
27752
27754
  </div>
27753
27755
  <div style="flex:1;background:${theme.bg};border:1px solid ${theme.border};border-radius:12px;padding:16px">
@@ -27764,6 +27766,12 @@ ${prettyStateOverride(stateOverride)}`;
27764
27766
  (typeof container === "string" ? document.querySelector(container) : container)?.appendChild(wrap3);
27765
27767
  const formEl = wrap3.querySelector("[data-gw-form]");
27766
27768
  const tabs = wrap3.querySelectorAll("[data-tab]");
27769
+ const walletAddrEl = wrap3.querySelector("[data-gw-wallet-addr]");
27770
+ const walletBalEl = wrap3.querySelector("[data-gw-wallet-balance]");
27771
+ const gwBalEl = wrap3.querySelector("[data-gw-balance]");
27772
+ const ARC_RPC = "https://arc-testnet.drpc.org";
27773
+ const USDC = "0x3600000000000000000000000000000000000000";
27774
+ const BALANCE_OF = "0x70a08231";
27767
27775
  function select(btns, t) {
27768
27776
  btns.forEach((b) => {
27769
27777
  const on = b.dataset.tab === t;
@@ -27790,8 +27798,64 @@ ${prettyStateOverride(stateOverride)}`;
27790
27798
  `;
27791
27799
  }
27792
27800
  }
27801
+ function shortAddress(a) {
27802
+ return a ? a.slice(0, 6) + "..." + a.slice(-4) : "";
27803
+ }
27804
+ async function updateWallet() {
27805
+ if (!window.ethereum) return;
27806
+ try {
27807
+ const accts = await window.ethereum.request({ method: "eth_accounts" });
27808
+ const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
27809
+ if (addr) {
27810
+ walletAddrEl.textContent = shortAddress(addr);
27811
+ fetchWalletUsdc(addr);
27812
+ fetchGwBal(addr);
27813
+ }
27814
+ } catch {
27815
+ }
27816
+ }
27817
+ async function fetchWalletUsdc(addr) {
27818
+ try {
27819
+ const r = await fetch(ARC_RPC, {
27820
+ method: "POST",
27821
+ headers: { "Content-Type": "application/json" },
27822
+ body: JSON.stringify({
27823
+ jsonrpc: "2.0",
27824
+ method: "eth_call",
27825
+ params: [{ to: USDC, data: BALANCE_OF + addr.slice(2).padStart(64, "0") }, "latest"],
27826
+ id: 1
27827
+ })
27828
+ });
27829
+ const d = await r.json();
27830
+ const bal = d.result ? parseInt(d.result, 16) / 1e6 : 0;
27831
+ walletBalEl.textContent = bal.toFixed(2) + " USDC";
27832
+ } catch {
27833
+ walletBalEl.textContent = "\u2014";
27834
+ }
27835
+ }
27836
+ async function fetchGwBal(addr) {
27837
+ if (!options.gatewayBalanceUrl) {
27838
+ gwBalEl.textContent = "\u2014";
27839
+ return;
27840
+ }
27841
+ try {
27842
+ const r = await fetch(options.gatewayBalanceUrl, {
27843
+ method: "POST",
27844
+ headers: { "Content-Type": "application/json" },
27845
+ body: JSON.stringify({ address: addr })
27846
+ });
27847
+ const data = await r.json();
27848
+ gwBalEl.textContent = data?.balance || "0.00 USDC";
27849
+ } catch {
27850
+ gwBalEl.textContent = "\u2014";
27851
+ }
27852
+ }
27853
+ if (window.ethereum) {
27854
+ window.ethereum.on("accountsChanged", updateWallet);
27855
+ }
27793
27856
  render("deposit");
27794
27857
  tabs.forEach((b) => b.addEventListener("click", () => render(b.dataset.tab)));
27858
+ setTimeout(updateWallet, 100);
27795
27859
  return { element: wrap3, destroy: () => wrap3.remove(), switchTab: render };
27796
27860
  }
27797
27861
  var SID, theme, css;