@nibgate/sdk 0.2.19 → 0.2.21
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/README.md +74 -2
- package/SKILL.md +93 -3
- package/dist/nibgate.js +782 -751
- package/dist/nibgate.js.map +4 -4
- package/dist/nibgate.min.js +76 -81
- package/dist/nibgate.min.js.map +4 -4
- package/package.json +1 -1
- package/src/browser/default-ui.js +79 -56
package/package.json
CHANGED
|
@@ -33,7 +33,6 @@ function inject() {
|
|
|
33
33
|
const s = h('style', { id: SID }, `
|
|
34
34
|
@keyframes nfade { from { opacity:0;transform:translateY(6px) } to { opacity:1;transform:translateY(0) } }
|
|
35
35
|
@keyframes nscale { from { opacity:0;transform:scale(0.96) } to { opacity:1;transform:scale(1) } }
|
|
36
|
-
@keyframes nshimmer { 0% { transform:translateX(-100%) } 100% { transform:translateX(100%) } }
|
|
37
36
|
|
|
38
37
|
.nui { font-family:var(--font-content,'Kumbh Sans','ABC Favorit',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif);color:${theme.fg};line-height:1.5;-webkit-font-smoothing:antialiased;font-size:19px }
|
|
39
38
|
.nui *,.nui *::before,.nui *::after { box-sizing:border-box }
|
|
@@ -75,60 +74,25 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
75
74
|
|
|
76
75
|
const card = el('div', { cls: 'nui', style: { animation: 'nfade .2s ease-out' } });
|
|
77
76
|
|
|
78
|
-
const
|
|
77
|
+
const unlockSVG = '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:middle;margin-right:6px"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 9.9-1"/></svg>';
|
|
79
78
|
|
|
80
79
|
card.innerHTML = `
|
|
81
|
-
<div style="display:flex;flex-direction:column;align-items:center;text-align:center;max-width:
|
|
82
|
-
<div
|
|
83
|
-
<div style="
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<div
|
|
87
|
-
<div data-nibgate-unlock-progress style="position:absolute;inset:0;width:0%;background:linear-gradient(90deg,rgba(255,255,255,0.1),rgba(255,255,255,0.45));border-radius:12px;transition:width .05s linear;z-index:2"></div>
|
|
88
|
-
<div data-nibgate-shimmer style="position:absolute;inset:0;width:100%;height:100%;background:linear-gradient(90deg,transparent,rgba(255,255,255,0.12),transparent);border-radius:12px;transform:translateX(-100%);z-index:3;pointer-events:none"></div>
|
|
89
|
-
<button type="button" data-nibgate-unlock disabled class="nui-btn nui-btn-primary" style="width:100%;padding:24px 32px;font-size:24px;position:relative;z-index:4;background:${theme.accent};transition:transform .1s,opacity .15s;display:flex">${lockSVG}Hold to pay ${esc(resource.price)} USDC</button></div>
|
|
90
|
-
<div class="nui-stat" style="text-align:center;margin-top:16px" data-nibgate-status></div>
|
|
80
|
+
<div style="display:flex;flex-direction:column;align-items:center;text-align:center;max-width:420px;margin:0 auto;padding:24px 20px">
|
|
81
|
+
<div data-nibgate-wallet-label class="nui-mono" style="font-size:15px;color:${theme.muted};margin-bottom:16px;min-height:24px">Connect wallet</div>
|
|
82
|
+
<div data-nibgate-unlock-wrap style="width:100%;position:relative;border-radius:10px;overflow:hidden;cursor:pointer">
|
|
83
|
+
<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>
|
|
84
|
+
<button type="button" data-nibgate-unlock disabled style="width:100%;padding:12px 0;font-size:16px;font-weight:500;line-height:19px;border:0;border-radius:10px;outline:none;cursor:pointer;position:relative;z-index:4;color:${theme.accent};background:rgba(124,154,109,0.08);transition:box-shadow .3s,transform .3s;font-family:inherit">${unlockSVG}Hold to pay</button></div>
|
|
85
|
+
<div class="nui-stat" style="text-align:center;margin-top:12px" data-nibgate-status></div>
|
|
91
86
|
</div>
|
|
92
|
-
<div data-nibgate-premium hidden style="margin-top:
|
|
87
|
+
<div data-nibgate-premium hidden style="margin-top:24px;border-top:1px solid ${theme.border};padding-top:24px">${options.premiumContentHTML || ''}</div>
|
|
93
88
|
`;
|
|
94
89
|
|
|
95
90
|
(typeof container === 'string' ? document.querySelector(container) : container)?.appendChild(card);
|
|
96
|
-
// Load Lottie animation
|
|
97
|
-
(function loadLottie() {
|
|
98
|
-
if (!document.getElementById('nibgate-lottie')) return;
|
|
99
|
-
|
|
100
|
-
function startAnim(data) {
|
|
101
|
-
var d = document.getElementById('nibgate-lottie');
|
|
102
|
-
if (d && window.lottie) {
|
|
103
|
-
window.lottie.loadAnimation({ container: d, animationData: data, loop: true, autoplay: true });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (window.lottie) {
|
|
108
|
-
if (window._lottieData) {
|
|
109
|
-
startAnim(window._lottieData);
|
|
110
|
-
} else {
|
|
111
|
-
fetch('/nibgate-unlock-key.json?t=1').then(function(r) { if (!r.ok) throw new Error(); return r.json(); }).then(function(d) { window._lottieData = d; startAnim(d); }).catch(function() {});
|
|
112
|
-
}
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (window._lottieLoading) return;
|
|
117
|
-
window._lottieLoading = true;
|
|
118
|
-
var s = document.createElement('script');
|
|
119
|
-
s.src = 'https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js';
|
|
120
|
-
s.onload = function() {
|
|
121
|
-
fetch('/nibgate-unlock-key.json?t=1').then(function(r) { if (!r.ok) throw new Error(); return r.json(); }).then(function(d) { window._lottieData = d; startAnim(d); }).catch(function() {});
|
|
122
|
-
};
|
|
123
|
-
document.head.appendChild(s);
|
|
124
|
-
})();
|
|
125
|
-
|
|
126
91
|
|
|
127
92
|
const st = card.querySelector('[data-nibgate-status]');
|
|
128
93
|
const label = card.querySelector('[data-nibgate-wallet-label]');
|
|
129
94
|
const wrap = card.querySelector('[data-nibgate-unlock-wrap]');
|
|
130
95
|
const prog = card.querySelector('[data-nibgate-unlock-progress]');
|
|
131
|
-
const shimmer = card.querySelector('[data-nibgate-shimmer]');
|
|
132
96
|
const btn = card.querySelector('[data-nibgate-unlock]');
|
|
133
97
|
|
|
134
98
|
const HOLD_MS = 1500;
|
|
@@ -169,21 +133,20 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
169
133
|
label.textContent = 'Connect wallet';
|
|
170
134
|
btn.disabled = true;
|
|
171
135
|
btn.style.cursor = 'default';
|
|
172
|
-
btn.innerHTML =
|
|
136
|
+
btn.innerHTML = unlockSVG + 'Hold to pay';
|
|
173
137
|
}
|
|
174
138
|
}
|
|
175
139
|
|
|
176
|
-
function setBtnText(t) { btn.innerHTML =
|
|
140
|
+
function setBtnText(t) { btn.innerHTML = unlockSVG + t; }
|
|
177
141
|
|
|
178
142
|
function resetHold() {
|
|
179
143
|
holdActive = false;
|
|
180
144
|
holdComplete = false;
|
|
181
145
|
holdTimer = null;
|
|
182
146
|
btn.style.transform = 'scale(1)';
|
|
147
|
+
btn.style.boxShadow = '0 4px 12px rgba(0,0,0,0.08)';
|
|
183
148
|
prog.style.width = '0%';
|
|
184
|
-
|
|
185
|
-
shimmer.style.transform = 'translateX(-100%)';
|
|
186
|
-
if (!btn.disabled) setBtnText('Hold to pay ' + esc(resource.price) + ' USDC');
|
|
149
|
+
if (!btn.disabled) setBtnText('Hold to pay');
|
|
187
150
|
}
|
|
188
151
|
|
|
189
152
|
function startHold(e) {
|
|
@@ -192,23 +155,19 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
192
155
|
holdActive = true;
|
|
193
156
|
holdComplete = false;
|
|
194
157
|
btn.style.transform = 'scale(.97)';
|
|
158
|
+
btn.style.boxShadow = '0 2px 6px rgba(0,0,0,0.12)';
|
|
195
159
|
prog.style.transition = 'none';
|
|
196
160
|
prog.style.width = '0%';
|
|
197
|
-
shimmer.style.animation = 'nshimmer 1s ease-in-out infinite';
|
|
198
|
-
shimmer.style.transform = 'none';
|
|
199
161
|
setBtnText('Hold\u2026');
|
|
200
162
|
requestAnimationFrame(() => {
|
|
201
163
|
prog.style.transition = 'width ' + HOLD_MS + 'ms linear';
|
|
202
164
|
prog.style.width = '100%';
|
|
203
165
|
});
|
|
204
|
-
const t1 = setTimeout(() => { if (holdActive && !holdComplete) setBtnText('Keep holding\u2026'); }, HOLD_MS * 0.4);
|
|
205
|
-
const t2 = setTimeout(() => { if (holdActive && !holdComplete) setBtnText('Almost there\u2026'); }, HOLD_MS * 0.75);
|
|
206
166
|
holdTimer = setTimeout(() => {
|
|
207
167
|
holdComplete = true;
|
|
208
168
|
holdActive = false;
|
|
209
|
-
clearTimeout(t1); clearTimeout(t2);
|
|
210
169
|
btn.style.transform = 'scale(1)';
|
|
211
|
-
|
|
170
|
+
btn.style.boxShadow = '0 4px 12px rgba(0,0,0,0.08)';
|
|
212
171
|
prog.style.transition = 'width .05s linear';
|
|
213
172
|
setBtnText('Processing\u2026');
|
|
214
173
|
btn.disabled = true;
|
|
@@ -241,7 +200,71 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
241
200
|
const cleanup = () => { document.removeEventListener('mouseup', cancelHold); document.removeEventListener('touchend', cancelHold); };
|
|
242
201
|
card.addEventListener('remove', cleanup);
|
|
243
202
|
|
|
244
|
-
|
|
203
|
+
// ── Gateway balance + deposit icon ─────────────────────────────────────
|
|
204
|
+
let gwOverlayEl = null;
|
|
205
|
+
let balTimer = null;
|
|
206
|
+
let balEl = null;
|
|
207
|
+
|
|
208
|
+
function depositIconHTML() {
|
|
209
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:baseline"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function showGatewayWallet() {
|
|
213
|
+
if (gwOverlayEl) return;
|
|
214
|
+
gwOverlayEl = el('div', { style: 'position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;padding:20px;animation:nfade .15s ease-out' });
|
|
215
|
+
const modal = el('div', { style: 'background:' + theme.bg + ';border-radius:16px;max-width:540px;width:100%;max-height:90vh;overflow:auto;position:relative;box-shadow:0 8px 32px rgba(0,0,0,0.12);animation:nscale .15s ease-out' });
|
|
216
|
+
const close = el('button', { style: 'position:absolute;top:12px;right:16px;z-index:20;background:none;border:none;font-size:28px;cursor:pointer;color:' + theme.muted + ';font-family:inherit;line-height:1' }, '\u00d7');
|
|
217
|
+
close.addEventListener('click', closeGatewayWallet);
|
|
218
|
+
modal.appendChild(close);
|
|
219
|
+
gwOverlayEl.appendChild(modal);
|
|
220
|
+
gwOverlayEl.addEventListener('click', (e) => { if (e.target === gwOverlayEl) closeGatewayWallet(); });
|
|
221
|
+
document.body.appendChild(gwOverlayEl);
|
|
222
|
+
document.addEventListener('keydown', onGwKey);
|
|
223
|
+
|
|
224
|
+
const gw = await import('./default-ui.js');
|
|
225
|
+
gw.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function closeGatewayWallet() {
|
|
229
|
+
if (!gwOverlayEl) return;
|
|
230
|
+
gwOverlayEl.remove();
|
|
231
|
+
gwOverlayEl = null;
|
|
232
|
+
document.removeEventListener('keydown', onGwKey);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function onGwKey(e) { if (e.key === 'Escape') closeGatewayWallet(); }
|
|
236
|
+
|
|
237
|
+
function ensureBalEl() {
|
|
238
|
+
if (balEl && balEl.isConnected) return balEl;
|
|
239
|
+
balEl = el('span', { 'data-nibgate-bal': '', style: 'margin-left:6px;cursor:pointer;white-space:nowrap' }, depositIconHTML() + ' <span data-nibgate-bal-text></span>');
|
|
240
|
+
balEl.addEventListener('click', showGatewayWallet);
|
|
241
|
+
if (label.parentNode) label.parentNode.insertBefore(balEl, label.nextSibling);
|
|
242
|
+
return balEl;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function refreshBalance() {
|
|
246
|
+
if (stateRef?.destroyed) return;
|
|
247
|
+
const addr = ctrl.getWalletAddress();
|
|
248
|
+
if (!addr) return;
|
|
249
|
+
const txt = ensureBalEl().querySelector('[data-nibgate-bal-text]');
|
|
250
|
+
if (options.gatewayBalanceUrl) {
|
|
251
|
+
try {
|
|
252
|
+
const res = await fetch(options.gatewayBalanceUrl + '?address=' + encodeURIComponent(addr));
|
|
253
|
+
const data = await res.json();
|
|
254
|
+
if (txt) txt.textContent = data?.balance || data?.availableBalance || '\u2026';
|
|
255
|
+
return;
|
|
256
|
+
} catch {}
|
|
257
|
+
}
|
|
258
|
+
if (txt) txt.textContent = '\u2026';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (window.ethereum) {
|
|
262
|
+
balTimer = setInterval(refreshBalance, 3000);
|
|
263
|
+
setTimeout(refreshBalance, 1000);
|
|
264
|
+
window.ethereum.on('accountsChanged', refreshBalance);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return { ...ctrl, element: card, destroy: () => { cleanup(); card.remove(); if (balTimer) clearInterval(balTimer); closeGatewayWallet(); } };
|
|
245
268
|
}
|
|
246
269
|
|
|
247
270
|
export function renderDefaultRatingUI(container, resource, options = {}) {
|