@nibgate/sdk 0.2.31 → 0.2.33

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.31",
3
+ "version": "0.2.33",
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": [
@@ -81,10 +81,10 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
81
81
  <div id="nibgate-lottie" style="width:165px;height:168px;margin-bottom:24px"></div>
82
82
  <div style="font-size:50px;font-weight:700;letter-spacing:-.03em;color:${theme.fg};margin-bottom:12px">${esc(resource.price)} USDC</div>
83
83
  <div style="font-size:21px;color:${theme.muted};margin-bottom:48px">Pay to unlock this content</div>
84
- <div data-nibgate-wallet-label class="nui-mono" style="font-size:18px;color:${theme.muted};margin-bottom:40px;min-height:28px">Connect wallet <span data-nibgate-bal style="display:none"><span data-nibgate-bal-txt></span></span></div>
84
+ <div data-nibgate-wallet-label class="nui-mono" style="font-size:18px;color:${theme.muted};margin-bottom:40px;min-height:28px">Connect wallet</div>
85
85
  <div data-nibgate-unlock-wrap style="width:100%;position:relative;border-radius:10px;overflow:hidden;cursor:pointer">
86
- <div data-nibgate-unlock-progress style="position:absolute;inset:0;width:0%;background:${theme.accent};opacity:0.15;border-radius:10px;transition:width .05s linear;z-index:2"></div>
87
- <button type="button" data-nibgate-unlock disabled style="width:100%;padding:14px 0;font-size:17px;font-weight:600;line-height:1;border:0;border-radius:10px;outline:none;cursor:pointer;position:relative;z-index:4;color:#fff;background:${theme.accent};transition:box-shadow .3s,transform .3s;font-family:inherit;display:flex;align-items:center;justify-content:center">${unlockSVG}Hold to pay</button></div>
86
+ <div data-nibgate-unlock-progress style="position:absolute;inset:0;width:0%;background:rgba(255,255,255,0.35);border-radius:10px;transition:width .05s linear;z-index:2"></div>
87
+ <button type="button" data-nibgate-unlock disabled style="width:100%;padding:14px 0;font-size:17px;font-weight:600;line-height:1;border:0;border-radius:10px;outline:none;cursor:pointer;position:relative;z-index:4;color:#fff;background:${theme.accent};box-shadow:0 4px 12px rgba(0,0,0,0.15);transition:transform .1s,box-shadow .1s;font-family:inherit;display:flex;align-items:center;justify-content:center">${unlockSVG}Hold to pay</button></div>
88
88
  <div class="nui-stat" style="text-align:center;margin-top:16px" data-nibgate-status></div>
89
89
  </div>
90
90
  <div data-nibgate-premium hidden style="margin-top:32px;border-top:1px solid ${theme.border};padding-top:32px">${options.premiumContentHTML || ''}</div>
@@ -149,33 +149,34 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
149
149
 
150
150
  function updateLabel() {
151
151
  const addr = ctrl.getWalletAddress();
152
- // Clear all children, keep text nodes
153
- while (label.firstChild) label.removeChild(label.firstChild);
154
152
  if (addr) {
155
- label.appendChild(document.createTextNode(shortAddress(addr) + ' '));
156
- const dc = el('span', { 'data-nibgate-disconnect': '', style: 'cursor:pointer' }, '\u00b7 Disconnect');
157
- dc.addEventListener('click', (e) => { if (e.target.dataset.nibgateDisconnect !== undefined) ctrl.disconnect().then(updateLabel); });
158
- label.appendChild(dc);
159
- // Re-add balance element if it exists
160
- if (balEl?.isConnected) label.appendChild(balEl);
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);
161
156
  btn.disabled = false;
162
157
  btn.style.cursor = 'pointer';
163
158
  } else {
164
- label.appendChild(document.createTextNode('Connect wallet'));
159
+ label.innerHTML = 'Connect wallet';
165
160
  btn.disabled = true;
166
161
  btn.style.cursor = 'default';
167
162
  btn.innerHTML = unlockSVG + 'Hold to pay';
168
163
  }
169
164
  }
170
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
+
171
172
  function setBtnText(t) { btn.innerHTML = unlockSVG + t; }
172
173
 
173
174
  function resetHold() {
174
175
  holdActive = false;
175
176
  holdComplete = false;
176
177
  holdTimer = null;
177
- btn.style.transform = 'scale(1)';
178
- btn.style.boxShadow = '0 4px 12px rgba(0,0,0,0.08)';
178
+ btn.style.transform = '';
179
+ btn.style.boxShadow = '';
179
180
  prog.style.width = '0%';
180
181
  if (!btn.disabled) setBtnText('Hold to pay');
181
182
  }
@@ -185,8 +186,8 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
185
186
  e.preventDefault();
186
187
  holdActive = true;
187
188
  holdComplete = false;
188
- btn.style.transform = 'scale(.97)';
189
- btn.style.boxShadow = '0 2px 6px rgba(0,0,0,0.12)';
189
+ btn.style.transform = 'scale(0.96)';
190
+ btn.style.boxShadow = '0 2px 8px rgba(0,0,0,0.2)';
190
191
  prog.style.transition = 'none';
191
192
  prog.style.width = '0%';
192
193
  setBtnText('Hold\u2026');
@@ -197,8 +198,8 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
197
198
  holdTimer = setTimeout(() => {
198
199
  holdComplete = true;
199
200
  holdActive = false;
200
- btn.style.transform = 'scale(1)';
201
- btn.style.boxShadow = '0 4px 12px rgba(0,0,0,0.08)';
201
+ btn.style.transform = '';
202
+ btn.style.boxShadow = '';
202
203
  prog.style.transition = 'width .05s linear';
203
204
  setBtnText('Processing\u2026');
204
205
  btn.disabled = true;
@@ -230,7 +231,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
230
231
  card.addEventListener('remove', cleanup);
231
232
 
232
233
  // ── Gateway balance + deposit icon ─────────────────────────────────────
233
- let balEl = null, gwOverlay = null, balTimer = null;
234
+ let gwOverlay = null, balTimer = null;
234
235
 
235
236
  function depIcon() {
236
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>';
@@ -251,28 +252,14 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
251
252
  }
252
253
  function onDepKey(e) { if (e.key === 'Escape' && gwOverlay) { gwOverlay.remove(); gwOverlay = null; document.removeEventListener('keydown', onDepKey); } }
253
254
 
254
- function ensureBal() {
255
- if (balEl && balEl.isConnected) return balEl;
256
- balEl = label.querySelector('[data-nibgate-bal]');
257
- if (balEl) {
258
- balEl.style.display = '';
259
- balEl.style.marginLeft = '4px';
260
- balEl.style.cursor = 'pointer';
261
- balEl.style.whiteSpace = 'nowrap';
262
- balEl.style.color = 'var(--accent,#7c9a6d)';
263
- balEl.innerHTML = '\u00b7\u00a0<span data-nibgate-bal-txt></span>\u00a0|\u00a0' + depIcon();
264
- balEl.addEventListener('click', showDeposit);
265
- }
266
- return balEl;
267
- }
268
-
269
255
  async function refreshBal() {
270
256
  if (!card.isConnected || !window.ethereum || !options.gatewayBalanceUrl) return;
271
257
  try {
272
258
  const accts = await window.ethereum.request({ method: 'eth_accounts' });
273
259
  const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
274
260
  if (!addr) return;
275
- const t = ensureBal().querySelector('[data-nibgate-bal-txt]');
261
+ attachBalClick();
262
+ const t = label.querySelector('[data-nibgate-bal-txt]');
276
263
  if (!t) return;
277
264
  const r = await fetch(options.gatewayBalanceUrl, {
278
265
  method: 'POST',