@nibgate/sdk 0.2.35 → 0.2.36

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.35",
3
+ "version": "0.2.36",
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": [
@@ -82,9 +82,11 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
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
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
- <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:rgba(255,255,255,0.35);border-radius:10px;transition:width .05s linear;z-index:2"></div>
87
- <button type="button" data-nibgate-unlock 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>
85
+ <div data-nibgate-unlock-wrap style="width:100%;position:relative;border-radius:10px;cursor:pointer">
86
+ <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;overflow:hidden;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">
87
+ <div data-nibgate-unlock-progress style="position:absolute;inset:0;width:0%;background:rgba(255,255,255,0.55);border-radius:10px;transition:width .05s linear"></div>
88
+ <span data-nibgate-unlock-text style="position:relative;z-index:1;display:flex;align-items:center;justify-content:center;gap:8px">${unlockSVG}Hold to pay</span>
89
+ </button></div>
88
90
  <div class="nui-stat" style="text-align:center;margin-top:16px" data-nibgate-status></div>
89
91
  </div>
90
92
  <div data-nibgate-premium hidden style="margin-top:32px;border-top:1px solid ${theme.border};padding-top:32px">${options.premiumContentHTML || ''}</div>
@@ -118,6 +120,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
118
120
  const wrap = card.querySelector('[data-nibgate-unlock-wrap]');
119
121
  const prog = card.querySelector('[data-nibgate-unlock-progress]');
120
122
  const btn = card.querySelector('[data-nibgate-unlock]');
123
+ const textEl = card.querySelector('[data-nibgate-unlock-text]');
121
124
 
122
125
  const HOLD_MS = 1500;
123
126
  let holdTimer = null, holdActive = false, holdComplete = false;
@@ -153,13 +156,13 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
153
156
  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
157
  balEl = label.querySelector('[data-nibgate-bal]');
155
158
  balEl?.addEventListener('click', showDeposit);
156
- btn.style.opacity = '1';
159
+ btn.disabled = false;
157
160
  btn.style.cursor = 'pointer';
158
161
  } else {
159
162
  label.innerHTML = 'Connect wallet';
160
- btn.style.opacity = '0.6';
161
- btn.style.cursor = 'pointer';
162
- btn.innerHTML = unlockSVG + 'Hold to pay';
163
+ btn.disabled = true;
164
+ btn.style.cursor = 'default';
165
+ textEl.innerHTML = unlockSVG + 'Hold to pay';
163
166
  }
164
167
  }
165
168
 
@@ -169,7 +172,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
169
172
  if (b && !b._clickAttached) { b.addEventListener('click', showDeposit); b._clickAttached = true; }
170
173
  }
171
174
 
172
- function setBtnText(t) { btn.innerHTML = unlockSVG + (t || 'Hold to pay'); }
175
+ function setBtnText(t) { textEl.innerHTML = unlockSVG + t; }
173
176
 
174
177
  function resetHold() {
175
178
  holdActive = false;
@@ -178,23 +181,12 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
178
181
  btn.style.transform = '';
179
182
  btn.style.boxShadow = '';
180
183
  prog.style.width = '0%';
181
- setBtnText('Hold to pay');
184
+ if (!btn.disabled) setBtnText('Hold to pay');
182
185
  }
183
186
 
184
187
  function startHold(e) {
185
- if (holdActive) return;
188
+ if (btn.disabled || holdActive) return;
186
189
  e.preventDefault();
187
- // Auto-connect wallet if not connected, then start hold immediately
188
- if (!ctrl.getWalletAddress()) {
189
- setBtnText('Connecting\u2026');
190
- btn.style.opacity = '0.6';
191
- ctrl.connect().then(() => { updateLabel(); btn.style.opacity = '1'; setBtnText('Hold\u2026'); beginHold(); }).catch(() => { updateLabel(); btn.style.opacity = '1'; setBtnText('Hold to pay'); });
192
- return;
193
- }
194
- beginHold();
195
- }
196
-
197
- function beginHold() {
198
190
  holdActive = true;
199
191
  holdComplete = false;
200
192
  btn.style.transform = 'scale(0.96)';
@@ -213,7 +205,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
213
205
  btn.style.boxShadow = '';
214
206
  prog.style.transition = 'width .05s linear';
215
207
  setBtnText('Processing\u2026');
216
- btn.style.opacity = '0.6';
208
+ btn.disabled = true;
217
209
  setTimeout(() => ctrl.unlock().then(updateLabel).catch(updateLabel), 300);
218
210
  }, HOLD_MS);
219
211
  }
@@ -225,9 +217,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
225
217
  }
226
218
 
227
219
  label.addEventListener('click', (e) => {
228
- if (e.target.dataset.nibgateDisconnect !== undefined) {
229
- ctrl.disconnect().then(updateLabel);
230
- } else if (!ctrl.getWalletAddress()) {
220
+ if (!ctrl.getWalletAddress()) {
231
221
  ctrl.connect().then(updateLabel).catch(() => updateLabel());
232
222
  }
233
223
  });
@@ -238,13 +228,21 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
238
228
  document.addEventListener('touchend', cancelHold);
239
229
  wrap.addEventListener('mouseleave', cancelHold);
240
230
 
231
+ function pressIn() { if (!btn.style.transform || btn.style.transform === 'none' || btn.style.transform === '') btn.style.transform = 'scale(0.97)'; }
232
+ function pressOut() { if (!holdActive) btn.style.transform = ''; }
233
+ btn.addEventListener('mousedown', pressIn);
234
+ btn.addEventListener('touchstart', pressIn, { passive: true });
235
+ btn.addEventListener('mouseup', pressOut);
236
+ btn.addEventListener('touchend', pressOut);
237
+ btn.addEventListener('mouseleave', pressOut);
238
+
241
239
  setTimeout(updateLabel, 200);
242
240
 
243
241
  const cleanup = () => { document.removeEventListener('mouseup', cancelHold); document.removeEventListener('touchend', cancelHold); };
244
242
  card.addEventListener('remove', cleanup);
245
243
 
246
244
  // ── Gateway balance + deposit icon ─────────────────────────────────────
247
- let balEl = null, gwOverlay = null, balTimer = null;
245
+ let gwOverlay = null, balTimer = null;
248
246
 
249
247
  function depIcon() {
250
248
  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>';
@@ -285,7 +283,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
285
283
  }
286
284
 
287
285
  if (window.ethereum) {
288
- balTimer = setInterval(refreshBal, 15000);
286
+ balTimer = setInterval(refreshBal, 3000);
289
287
  setTimeout(refreshBal, 1000);
290
288
  window.ethereum.on('accountsChanged', refreshBal);
291
289
  }