@nibgate/sdk 0.2.30 → 0.2.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nibgate/sdk",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "Framework-agnostic browser and server package for creator-owned gated content, unlock events, and receipts.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -150,17 +150,25 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
150
150
  function updateLabel() {
151
151
  const addr = ctrl.getWalletAddress();
152
152
  if (addr) {
153
- label.innerHTML = shortAddress(addr) + ' <span data-nibgate-disconnect style="cursor:pointer">· Disconnect</span>';
153
+ label.innerHTML = shortAddress(addr) + ' <span data-nibgate-disconnect style="cursor:pointer">· Disconnect</span> <span data-nibgate-bal style="margin-left:4px;cursor:pointer;white-space:nowrap;color:var(--accent,#7c9a6d)">· <span data-nibgate-bal-txt></span> | ' + depIcon() + '</span>';
154
+ balEl = label.querySelector('[data-nibgate-bal]');
155
+ balEl?.addEventListener('click', showDeposit);
154
156
  btn.disabled = false;
155
157
  btn.style.cursor = 'pointer';
156
158
  } else {
157
- label.textContent = 'Connect wallet';
159
+ label.innerHTML = 'Connect wallet';
158
160
  btn.disabled = true;
159
161
  btn.style.cursor = 'default';
160
162
  btn.innerHTML = unlockSVG + 'Hold to pay';
161
163
  }
162
164
  }
163
165
 
166
+ // Re-attach bal click handler after refreshBal updates the text
167
+ function attachBalClick() {
168
+ const b = label.querySelector('[data-nibgate-bal]');
169
+ if (b && !b._clickAttached) { b.addEventListener('click', showDeposit); b._clickAttached = true; }
170
+ }
171
+
164
172
  function setBtnText(t) { btn.innerHTML = unlockSVG + t; }
165
173
 
166
174
  function resetHold() {
@@ -206,9 +214,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
206
214
  }
207
215
 
208
216
  label.addEventListener('click', (e) => {
209
- if (e.target.dataset.nibgateDisconnect !== undefined) {
210
- ctrl.disconnect().then(updateLabel);
211
- } else if (!ctrl.getWalletAddress()) {
217
+ if (!ctrl.getWalletAddress()) {
212
218
  ctrl.connect().then(updateLabel).catch(() => updateLabel());
213
219
  }
214
220
  });
@@ -225,7 +231,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
225
231
  card.addEventListener('remove', cleanup);
226
232
 
227
233
  // ── Gateway balance + deposit icon ─────────────────────────────────────
228
- let balEl = null, gwOverlay = null, balTimer = null;
234
+ let gwOverlay = null, balTimer = null;
229
235
 
230
236
  function depIcon() {
231
237
  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>';
@@ -246,22 +252,14 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
246
252
  }
247
253
  function onDepKey(e) { if (e.key === 'Escape' && gwOverlay) { gwOverlay.remove(); gwOverlay = null; document.removeEventListener('keydown', onDepKey); } }
248
254
 
249
- function ensureBal() {
250
- if (balEl && balEl.isConnected) return balEl;
251
- balEl = el('span', { 'data-nibgate-bal': '', style: 'margin-left:4px;cursor:pointer;white-space:nowrap;color:var(--accent,#7c9a6d)' },
252
- '\u00b7\u00a0<span data-nibgate-bal-txt></span>\u00a0|\u00a0' + depIcon());
253
- balEl.addEventListener('click', showDeposit);
254
- label.appendChild(balEl);
255
- return balEl;
256
- }
257
-
258
255
  async function refreshBal() {
259
256
  if (!card.isConnected || !window.ethereum || !options.gatewayBalanceUrl) return;
260
257
  try {
261
258
  const accts = await window.ethereum.request({ method: 'eth_accounts' });
262
259
  const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
263
260
  if (!addr) return;
264
- const t = ensureBal().querySelector('[data-nibgate-bal-txt]');
261
+ attachBalClick();
262
+ const t = label.querySelector('[data-nibgate-bal-txt]');
265
263
  if (!t) return;
266
264
  const r = await fetch(options.gatewayBalanceUrl, {
267
265
  method: 'POST',