@nibgate/sdk 0.2.23 → 0.2.25
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 +67 -46
- package/dist/nibgate.js.map +3 -3
- package/dist/nibgate.min.js +52 -52
- package/dist/nibgate.min.js.map +3 -3
- package/package.json +1 -1
- package/src/browser/default-ui.js +46 -46
package/package.json
CHANGED
|
@@ -225,70 +225,70 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
225
225
|
card.addEventListener('remove', cleanup);
|
|
226
226
|
|
|
227
227
|
// ── Gateway balance + deposit icon ─────────────────────────────────────
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
const ARC_RPC = 'https://arc-testnet.drpc.org';
|
|
229
|
+
const GATEWAY_WALLET = '0x0077777d7EBA4688BDeF3E311b846F25870A19B9';
|
|
230
|
+
const USDC_ADDRESS = '0x3600000000000000000000000000000000000000';
|
|
231
|
+
|
|
232
|
+
async function fetchBalance(addr) {
|
|
233
|
+
const sel = '0xdd62e1c6';
|
|
234
|
+
const pad = (a) => '000000000000000000000000' + a.slice(2).toLowerCase();
|
|
235
|
+
const data = sel + pad(USDC_ADDRESS) + pad(addr);
|
|
236
|
+
const r = await fetch(ARC_RPC, {
|
|
237
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
238
|
+
body: JSON.stringify({ jsonrpc: '2.0', method: 'eth_call', params: [{ to: GATEWAY_WALLET, data }, 'latest'], id: 1 }),
|
|
239
|
+
});
|
|
240
|
+
const j = await r.json();
|
|
241
|
+
return j?.result ? (Number(BigInt(j.result)) / 1_000_000).toFixed(2) + ' USDC' : '\u2014';
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
let balEl = null, gwOverlay = null, balTimer = null;
|
|
231
245
|
|
|
232
|
-
function
|
|
233
|
-
return '<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
246
|
+
function depIcon() {
|
|
247
|
+
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>';
|
|
234
248
|
}
|
|
235
249
|
|
|
236
|
-
|
|
237
|
-
if (
|
|
238
|
-
|
|
250
|
+
function showDeposit() {
|
|
251
|
+
if (gwOverlay) return;
|
|
252
|
+
gwOverlay = 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' });
|
|
239
253
|
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' });
|
|
240
254
|
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');
|
|
241
|
-
close.addEventListener('click',
|
|
255
|
+
close.addEventListener('click', () => { gwOverlay.remove(); gwOverlay = null; document.removeEventListener('keydown', onDepKey); });
|
|
242
256
|
modal.appendChild(close);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
document.body.appendChild(
|
|
246
|
-
document.addEventListener('keydown',
|
|
247
|
-
|
|
248
|
-
const gw = await import('./default-ui.js');
|
|
249
|
-
gw.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function closeGatewayWallet() {
|
|
253
|
-
if (!gwOverlayEl) return;
|
|
254
|
-
gwOverlayEl.remove();
|
|
255
|
-
gwOverlayEl = null;
|
|
256
|
-
document.removeEventListener('keydown', onGwKey);
|
|
257
|
+
gwOverlay.appendChild(modal);
|
|
258
|
+
gwOverlay.addEventListener('click', (e) => { if (e.target === gwOverlay) { gwOverlay.remove(); gwOverlay = null; document.removeEventListener('keydown', onDepKey); } });
|
|
259
|
+
document.body.appendChild(gwOverlay);
|
|
260
|
+
document.addEventListener('keydown', onDepKey);
|
|
261
|
+
import('./default-ui.js').then(m => m.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {})).catch(() => {});
|
|
257
262
|
}
|
|
263
|
+
function onDepKey(e) { if (e.key === 'Escape' && gwOverlay) { gwOverlay.remove(); gwOverlay = null; document.removeEventListener('keydown', onDepKey); } }
|
|
258
264
|
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
function ensureBalEl() {
|
|
265
|
+
function ensureBal() {
|
|
262
266
|
if (balEl && balEl.isConnected) return balEl;
|
|
263
|
-
balEl = el('span', { 'data-nibgate-bal': '', style: 'margin-left:
|
|
264
|
-
|
|
267
|
+
balEl = el('span', { 'data-nibgate-bal': '', style: 'margin-left:4px;cursor:pointer;white-space:nowrap;color:var(--accent,#7c9a6d)' },
|
|
268
|
+
'\u00b7\u00a0<span data-nibgate-bal-txt></span>\u00a0|\u00a0' + depIcon());
|
|
269
|
+
balEl.addEventListener('click', showDeposit);
|
|
265
270
|
if (label.parentNode) label.parentNode.insertBefore(balEl, label.nextSibling);
|
|
266
271
|
return balEl;
|
|
267
272
|
}
|
|
268
273
|
|
|
269
|
-
async function
|
|
270
|
-
if (!card.isConnected) return;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (txt) txt.textContent = data?.balance || data?.availableBalance || '\u2026';
|
|
279
|
-
return;
|
|
280
|
-
} catch {}
|
|
281
|
-
}
|
|
282
|
-
if (txt) txt.textContent = '\u2026';
|
|
274
|
+
async function refreshBal() {
|
|
275
|
+
if (!card.isConnected || !window.ethereum) return;
|
|
276
|
+
try {
|
|
277
|
+
const accts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
278
|
+
const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
|
|
279
|
+
if (!addr) return;
|
|
280
|
+
const t = ensureBal().querySelector('[data-nibgate-bal-txt]');
|
|
281
|
+
if (t) t.textContent = await fetchBalance(addr);
|
|
282
|
+
} catch {}
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
if (window.ethereum) {
|
|
286
|
-
balTimer = setInterval(
|
|
287
|
-
setTimeout(
|
|
288
|
-
window.ethereum.on('accountsChanged',
|
|
286
|
+
balTimer = setInterval(refreshBal, 3000);
|
|
287
|
+
setTimeout(refreshBal, 1000);
|
|
288
|
+
window.ethereum.on('accountsChanged', refreshBal);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
return { ...ctrl, element: card, destroy: () => { cleanup(); card.remove(); if (balTimer) clearInterval(balTimer);
|
|
291
|
+
return { ...ctrl, element: card, destroy: () => { cleanup(); card.remove(); if (balTimer) clearInterval(balTimer); if (gwOverlay) { gwOverlay.remove(); gwOverlay = null; } } };
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
export function renderDefaultRatingUI(container, resource, options = {}) {
|