@nibgate/sdk 0.2.37 → 0.2.39

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
@@ -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) {
@@ -27745,9 +27749,10 @@ ${prettyStateOverride(stateOverride)}`;
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
27751
  <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>
27752
+ <div></div>
27753
+ <span data-gw-connect-label style="font-size:12px;font-weight:600;color:${theme.accent}">Connected</span>
27750
27754
  </div>
27755
+ <div data-gw-wallet-addr class="nui-mono" style="font-size:13px;color:${theme.muted};margin-bottom:4px"></div>
27751
27756
  <div data-gw-wallet-balance class="nui-mono" style="font-size:24px;font-weight:700;color:${theme.fg}">\u2014</div>
27752
27757
  </div>
27753
27758
  <div style="flex:1;background:${theme.bg};border:1px solid ${theme.border};border-radius:12px;padding:16px">
@@ -27764,6 +27769,12 @@ ${prettyStateOverride(stateOverride)}`;
27764
27769
  (typeof container === "string" ? document.querySelector(container) : container)?.appendChild(wrap3);
27765
27770
  const formEl = wrap3.querySelector("[data-gw-form]");
27766
27771
  const tabs = wrap3.querySelectorAll("[data-tab]");
27772
+ const walletAddrEl = wrap3.querySelector("[data-gw-wallet-addr]");
27773
+ const walletBalEl = wrap3.querySelector("[data-gw-wallet-balance]");
27774
+ const gwBalEl = wrap3.querySelector("[data-gw-balance]");
27775
+ const ARC_RPC = "https://arc-testnet.drpc.org";
27776
+ const USDC = "0x3600000000000000000000000000000000000000";
27777
+ const BALANCE_OF = "0x70a08231";
27767
27778
  function select(btns, t) {
27768
27779
  btns.forEach((b) => {
27769
27780
  const on = b.dataset.tab === t;
@@ -27771,6 +27782,69 @@ ${prettyStateOverride(stateOverride)}`;
27771
27782
  b.style.borderBottomColor = on ? theme.accent : "transparent";
27772
27783
  });
27773
27784
  }
27785
+ const GATEWAY = "0x0077777d7EBA4688BDeF3E311b846F25870A19B9";
27786
+ const SEL_APPROVE = "0x095ea7b3";
27787
+ const SEL_DEPOSIT = "0x47e7ef24";
27788
+ function parse6(v) {
27789
+ const [w = "0", f = ""] = String(v).split(".");
27790
+ return BigInt(w + f.padEnd(6, "0").slice(0, 6));
27791
+ }
27792
+ function addr32(a) {
27793
+ return "000000000000000000000000" + a.slice(2);
27794
+ }
27795
+ function setTx(msg, ok) {
27796
+ const el2 = formEl.querySelector("[data-gw-tx]");
27797
+ if (!el2) return;
27798
+ el2.style.display = "block";
27799
+ el2.style.color = ok ? theme.accent : "#dc2626";
27800
+ el2.textContent = msg;
27801
+ }
27802
+ async function doDeposit() {
27803
+ if (!window.ethereum) {
27804
+ setTx("No wallet found");
27805
+ return;
27806
+ }
27807
+ const input = formEl.querySelector("[data-gw-deposit-amount]");
27808
+ const amt = input?.value;
27809
+ if (!amt || Number(amt) <= 0) {
27810
+ setTx("Enter an amount");
27811
+ return;
27812
+ }
27813
+ const btn = formEl.querySelector("[data-gw-deposit]");
27814
+ try {
27815
+ btn.disabled = true;
27816
+ btn.textContent = "Approving\u2026";
27817
+ const accts = await window.ethereum.request({ method: "eth_accounts" });
27818
+ const addr = accts?.[0];
27819
+ if (!addr) {
27820
+ setTx("Connect wallet");
27821
+ btn.disabled = false;
27822
+ btn.textContent = "Deposit";
27823
+ return;
27824
+ }
27825
+ const amount = parse6(amt).toString(16);
27826
+ const approveTx = await window.ethereum.request({
27827
+ method: "eth_sendTransaction",
27828
+ params: [{ from: addr, to: USDC, data: SEL_APPROVE + addr32(GATEWAY) + amount.padStart(64, "0") }]
27829
+ });
27830
+ setTx("Approved: " + approveTx.slice(0, 10) + "\u2026", true);
27831
+ btn.textContent = "Depositing\u2026";
27832
+ const depositTx = await window.ethereum.request({
27833
+ method: "eth_sendTransaction",
27834
+ params: [{ from: addr, to: GATEWAY, data: SEL_DEPOSIT + addr32(USDC) + amount.padStart(64, "0") }]
27835
+ });
27836
+ setTx("Deposited: " + depositTx.slice(0, 10) + "\u2026", true);
27837
+ updateWallet();
27838
+ btn.textContent = "Deposit";
27839
+ } catch (e) {
27840
+ setTx(e?.message || "Deposit failed");
27841
+ }
27842
+ btn.disabled = false;
27843
+ btn.textContent = "Deposit";
27844
+ }
27845
+ async function doWithdraw() {
27846
+ setTx("Withdraw via admin dashboard", false);
27847
+ }
27774
27848
  function render(t) {
27775
27849
  tab = t;
27776
27850
  select(tabs, t);
@@ -27781,6 +27855,7 @@ ${prettyStateOverride(stateOverride)}`;
27781
27855
  <button type="button" data-gw-deposit class="nui-btn nui-btn-primary" style="width:100%;padding:16px 28px;font-size:20px">Deposit</button>
27782
27856
  <div data-gw-tx class="nui-mono" style="font-size:12px;color:${theme.muted};word-break:break-all;margin-top:12px;display:none"></div>
27783
27857
  `;
27858
+ formEl.querySelector("[data-gw-deposit]")?.addEventListener("click", doDeposit);
27784
27859
  } else {
27785
27860
  formEl.innerHTML = `
27786
27861
  <label class="nui-label">Amount (USDC)</label>
@@ -27788,10 +27863,67 @@ ${prettyStateOverride(stateOverride)}`;
27788
27863
  <button type="button" data-gw-withdraw class="nui-btn nui-btn-primary" style="width:100%;padding:16px 28px;font-size:20px">Withdraw to your wallet</button>
27789
27864
  <div data-gw-tx class="nui-mono" style="font-size:12px;color:${theme.muted};word-break:break-all;margin-top:12px;display:none"></div>
27790
27865
  `;
27866
+ formEl.querySelector("[data-gw-withdraw]")?.addEventListener("click", doWithdraw);
27867
+ }
27868
+ }
27869
+ function shortAddress(a) {
27870
+ return a ? a.slice(0, 6) + "..." + a.slice(-4) : "";
27871
+ }
27872
+ async function updateWallet() {
27873
+ if (!window.ethereum) return;
27874
+ try {
27875
+ const accts = await window.ethereum.request({ method: "eth_accounts" });
27876
+ const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
27877
+ if (addr) {
27878
+ walletAddrEl.textContent = shortAddress(addr);
27879
+ fetchWalletUsdc(addr);
27880
+ fetchGwBal(addr);
27881
+ }
27882
+ } catch {
27883
+ }
27884
+ }
27885
+ async function fetchWalletUsdc(addr) {
27886
+ try {
27887
+ const r = await fetch(ARC_RPC, {
27888
+ method: "POST",
27889
+ headers: { "Content-Type": "application/json" },
27890
+ body: JSON.stringify({
27891
+ jsonrpc: "2.0",
27892
+ method: "eth_call",
27893
+ params: [{ to: USDC, data: BALANCE_OF + addr.slice(2).padStart(64, "0") }, "latest"],
27894
+ id: 1
27895
+ })
27896
+ });
27897
+ const d = await r.json();
27898
+ const bal = d.result ? parseInt(d.result, 16) / 1e6 : 0;
27899
+ walletBalEl.textContent = bal.toFixed(2) + " USDC";
27900
+ } catch {
27901
+ walletBalEl.textContent = "\u2014";
27902
+ }
27903
+ }
27904
+ async function fetchGwBal(addr) {
27905
+ if (!options.gatewayBalanceUrl) {
27906
+ gwBalEl.textContent = "\u2014";
27907
+ return;
27791
27908
  }
27909
+ try {
27910
+ const r = await fetch(options.gatewayBalanceUrl, {
27911
+ method: "POST",
27912
+ headers: { "Content-Type": "application/json" },
27913
+ body: JSON.stringify({ address: addr })
27914
+ });
27915
+ const data = await r.json();
27916
+ gwBalEl.textContent = data?.balance || "0.00 USDC";
27917
+ } catch {
27918
+ gwBalEl.textContent = "\u2014";
27919
+ }
27920
+ }
27921
+ if (window.ethereum) {
27922
+ window.ethereum.on("accountsChanged", updateWallet);
27792
27923
  }
27793
27924
  render("deposit");
27794
27925
  tabs.forEach((b) => b.addEventListener("click", () => render(b.dataset.tab)));
27926
+ setTimeout(updateWallet, 100);
27795
27927
  return { element: wrap3, destroy: () => wrap3.remove(), switchTab: render };
27796
27928
  }
27797
27929
  var SID, theme, css;