@nibgate/sdk 0.2.35 → 0.2.37
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 +27 -33
- package/dist/nibgate.js.map +2 -2
- package/dist/nibgate.min.js +29 -27
- package/dist/nibgate.min.js.map +3 -3
- package/package.json +1 -1
- package/src/browser/default-ui.js +24 -26
package/package.json
CHANGED
|
@@ -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;
|
|
86
|
-
<
|
|
87
|
-
|
|
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.
|
|
159
|
+
btn.disabled = false;
|
|
157
160
|
btn.style.cursor = 'pointer';
|
|
158
161
|
} else {
|
|
159
162
|
label.innerHTML = 'Connect wallet';
|
|
160
|
-
btn.
|
|
161
|
-
btn.style.cursor = '
|
|
162
|
-
|
|
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) {
|
|
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.
|
|
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 (
|
|
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,6 +228,14 @@ 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); };
|
|
@@ -285,7 +283,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
285
283
|
}
|
|
286
284
|
|
|
287
285
|
if (window.ethereum) {
|
|
288
|
-
balTimer = setInterval(refreshBal,
|
|
286
|
+
balTimer = setInterval(refreshBal, 3000);
|
|
289
287
|
setTimeout(refreshBal, 1000);
|
|
290
288
|
window.ethereum.on('accountsChanged', refreshBal);
|
|
291
289
|
}
|