@nibgate/sdk 0.2.19 → 0.2.20
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 +768 -677
- package/dist/nibgate.js.map +4 -4
- package/dist/nibgate.min.js +74 -74
- package/dist/nibgate.min.js.map +4 -4
- package/package.json +1 -1
- package/src/browser/default-ui.js +65 -1
package/package.json
CHANGED
|
@@ -241,7 +241,71 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
241
241
|
const cleanup = () => { document.removeEventListener('mouseup', cancelHold); document.removeEventListener('touchend', cancelHold); };
|
|
242
242
|
card.addEventListener('remove', cleanup);
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
// ── Gateway balance + deposit icon ─────────────────────────────────────
|
|
245
|
+
let gwOverlayEl = null;
|
|
246
|
+
let balTimer = null;
|
|
247
|
+
let balEl = null;
|
|
248
|
+
|
|
249
|
+
function depositIconHTML() {
|
|
250
|
+
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>';
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function showGatewayWallet() {
|
|
254
|
+
if (gwOverlayEl) return;
|
|
255
|
+
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' });
|
|
256
|
+
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' });
|
|
257
|
+
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');
|
|
258
|
+
close.addEventListener('click', closeGatewayWallet);
|
|
259
|
+
modal.appendChild(close);
|
|
260
|
+
gwOverlayEl.appendChild(modal);
|
|
261
|
+
gwOverlayEl.addEventListener('click', (e) => { if (e.target === gwOverlayEl) closeGatewayWallet(); });
|
|
262
|
+
document.body.appendChild(gwOverlayEl);
|
|
263
|
+
document.addEventListener('keydown', onGwKey);
|
|
264
|
+
|
|
265
|
+
const gw = await import('./default-ui.js');
|
|
266
|
+
gw.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function closeGatewayWallet() {
|
|
270
|
+
if (!gwOverlayEl) return;
|
|
271
|
+
gwOverlayEl.remove();
|
|
272
|
+
gwOverlayEl = null;
|
|
273
|
+
document.removeEventListener('keydown', onGwKey);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function onGwKey(e) { if (e.key === 'Escape') closeGatewayWallet(); }
|
|
277
|
+
|
|
278
|
+
function ensureBalEl() {
|
|
279
|
+
if (balEl && balEl.isConnected) return balEl;
|
|
280
|
+
balEl = el('span', { 'data-nibgate-bal': '', style: 'margin-left:6px;cursor:pointer;white-space:nowrap' }, depositIconHTML() + ' <span data-nibgate-bal-text></span>');
|
|
281
|
+
balEl.addEventListener('click', showGatewayWallet);
|
|
282
|
+
if (label.parentNode) label.parentNode.insertBefore(balEl, label.nextSibling);
|
|
283
|
+
return balEl;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async function refreshBalance() {
|
|
287
|
+
if (stateRef?.destroyed) return;
|
|
288
|
+
const addr = ctrl.getWalletAddress();
|
|
289
|
+
if (!addr) return;
|
|
290
|
+
const txt = ensureBalEl().querySelector('[data-nibgate-bal-text]');
|
|
291
|
+
if (options.gatewayBalanceUrl) {
|
|
292
|
+
try {
|
|
293
|
+
const res = await fetch(options.gatewayBalanceUrl + '?address=' + encodeURIComponent(addr));
|
|
294
|
+
const data = await res.json();
|
|
295
|
+
if (txt) txt.textContent = data?.balance || data?.availableBalance || '\u2026';
|
|
296
|
+
return;
|
|
297
|
+
} catch {}
|
|
298
|
+
}
|
|
299
|
+
if (txt) txt.textContent = '\u2026';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (window.ethereum) {
|
|
303
|
+
balTimer = setInterval(refreshBalance, 3000);
|
|
304
|
+
setTimeout(refreshBalance, 1000);
|
|
305
|
+
window.ethereum.on('accountsChanged', refreshBalance);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return { ...ctrl, element: card, destroy: () => { cleanup(); card.remove(); if (balTimer) clearInterval(balTimer); closeGatewayWallet(); } };
|
|
245
309
|
}
|
|
246
310
|
|
|
247
311
|
export function renderDefaultRatingUI(container, resource, options = {}) {
|