@nibgate/sdk 0.2.36 → 0.2.38
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 +70 -6
- package/dist/nibgate.js.map +2 -2
- package/dist/nibgate.min.js +21 -23
- package/dist/nibgate.min.js.map +3 -3
- package/package.json +1 -1
- package/src/browser/default-ui.js +66 -6
package/package.json
CHANGED
|
@@ -242,7 +242,7 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
242
242
|
card.addEventListener('remove', cleanup);
|
|
243
243
|
|
|
244
244
|
// ── Gateway balance + deposit icon ─────────────────────────────────────
|
|
245
|
-
let gwOverlay = null, balTimer = null;
|
|
245
|
+
let balEl = null, gwOverlay = null, balTimer = null;
|
|
246
246
|
|
|
247
247
|
function depIcon() {
|
|
248
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>';
|
|
@@ -259,7 +259,11 @@ export function renderDefaultUnlockUI(container, resource, options = {}) {
|
|
|
259
259
|
gwOverlay.addEventListener('click', (e) => { if (e.target === gwOverlay) { gwOverlay.remove(); gwOverlay = null; document.removeEventListener('keydown', onDepKey); } });
|
|
260
260
|
document.body.appendChild(gwOverlay);
|
|
261
261
|
document.addEventListener('keydown', onDepKey);
|
|
262
|
-
import('./default-ui.js').then(m => m.renderDefaultGatewayWalletUI(modal,
|
|
262
|
+
import('./default-ui.js').then(m => m.renderDefaultGatewayWalletUI(modal, {
|
|
263
|
+
address: ctrl.getWalletAddress(),
|
|
264
|
+
gatewayBalanceUrl: options.gatewayBalanceUrl,
|
|
265
|
+
...(options.gatewayOptions || {}),
|
|
266
|
+
})).catch(() => {});
|
|
263
267
|
}
|
|
264
268
|
function onDepKey(e) { if (e.key === 'Escape' && gwOverlay) { gwOverlay.remove(); gwOverlay = null; document.removeEventListener('keydown', onDepKey); } }
|
|
265
269
|
|
|
@@ -420,10 +424,8 @@ export function renderDefaultGatewayWalletUI(container, options = {}) {
|
|
|
420
424
|
wrap.innerHTML = `
|
|
421
425
|
<div style="display:flex;gap:12px;margin-bottom:20px">
|
|
422
426
|
<div data-gw-wallet-card style="flex:1;background:${theme.bg};border:1px solid ${theme.border};border-radius:12px;padding:16px">
|
|
423
|
-
<div style="
|
|
424
|
-
|
|
425
|
-
<button data-gw-connect style="font-size:12px;font-weight:600;cursor:pointer;border:1px solid ${theme.accent};background:transparent;color:${theme.accent};border-radius:8px;padding:4px 12px;font-family:inherit">Connect</button>
|
|
426
|
-
</div>
|
|
427
|
+
<div style="font-size:12px;font-weight:600;color:${theme.muted};margin-bottom:4px;letter-spacing:.02em">Wallet</div>
|
|
428
|
+
<div data-gw-wallet-addr class="nui-mono" style="font-size:13px;color:${theme.muted};margin-bottom:4px"></div>
|
|
427
429
|
<div data-gw-wallet-balance class="nui-mono" style="font-size:24px;font-weight:700;color:${theme.fg}">—</div>
|
|
428
430
|
</div>
|
|
429
431
|
<div style="flex:1;background:${theme.bg};border:1px solid ${theme.border};border-radius:12px;padding:16px">
|
|
@@ -442,6 +444,13 @@ export function renderDefaultGatewayWalletUI(container, options = {}) {
|
|
|
442
444
|
|
|
443
445
|
const formEl = wrap.querySelector('[data-gw-form]');
|
|
444
446
|
const tabs = wrap.querySelectorAll('[data-tab]');
|
|
447
|
+
const walletAddrEl = wrap.querySelector('[data-gw-wallet-addr]');
|
|
448
|
+
const walletBalEl = wrap.querySelector('[data-gw-wallet-balance]');
|
|
449
|
+
const gwBalEl = wrap.querySelector('[data-gw-balance]');
|
|
450
|
+
|
|
451
|
+
const ARC_RPC = 'https://arc-testnet.drpc.org';
|
|
452
|
+
const USDC = '0x3600000000000000000000000000000000000000';
|
|
453
|
+
const BALANCE_OF = '0x70a08231';
|
|
445
454
|
|
|
446
455
|
function select(btns, t) {
|
|
447
456
|
btns.forEach(b => {
|
|
@@ -471,8 +480,59 @@ export function renderDefaultGatewayWalletUI(container, options = {}) {
|
|
|
471
480
|
}
|
|
472
481
|
}
|
|
473
482
|
|
|
483
|
+
function shortAddress(a) { return a ? a.slice(0, 6) + '...' + a.slice(-4) : ''; }
|
|
484
|
+
|
|
485
|
+
async function updateWallet() {
|
|
486
|
+
if (!window.ethereum) return;
|
|
487
|
+
try {
|
|
488
|
+
const accts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
489
|
+
const addr = Array.isArray(accts) && accts[0] ? accts[0] : null;
|
|
490
|
+
if (addr) {
|
|
491
|
+
walletAddrEl.textContent = shortAddress(addr);
|
|
492
|
+
fetchWalletUsdc(addr);
|
|
493
|
+
fetchGwBal(addr);
|
|
494
|
+
}
|
|
495
|
+
} catch {}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
async function fetchWalletUsdc(addr) {
|
|
499
|
+
try {
|
|
500
|
+
const r = await fetch(ARC_RPC, {
|
|
501
|
+
method: 'POST',
|
|
502
|
+
headers: { 'Content-Type': 'application/json' },
|
|
503
|
+
body: JSON.stringify({
|
|
504
|
+
jsonrpc: '2.0', method: 'eth_call',
|
|
505
|
+
params: [{ to: USDC, data: BALANCE_OF + addr.slice(2).padStart(64, '0') }, 'latest'],
|
|
506
|
+
id: 1,
|
|
507
|
+
}),
|
|
508
|
+
});
|
|
509
|
+
const d = await r.json();
|
|
510
|
+
const bal = d.result ? parseInt(d.result, 16) / 1e6 : 0;
|
|
511
|
+
walletBalEl.textContent = bal.toFixed(2) + ' USDC';
|
|
512
|
+
} catch { walletBalEl.textContent = '—'; }
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async function fetchGwBal(addr) {
|
|
516
|
+
if (!options.gatewayBalanceUrl) { gwBalEl.textContent = '—'; return; }
|
|
517
|
+
try {
|
|
518
|
+
const r = await fetch(options.gatewayBalanceUrl, {
|
|
519
|
+
method: 'POST',
|
|
520
|
+
headers: { 'Content-Type': 'application/json' },
|
|
521
|
+
body: JSON.stringify({ address: addr }),
|
|
522
|
+
});
|
|
523
|
+
const data = await r.json();
|
|
524
|
+
gwBalEl.textContent = data?.balance || '0.00 USDC';
|
|
525
|
+
} catch { gwBalEl.textContent = '—'; }
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (window.ethereum) {
|
|
529
|
+
window.ethereum.on('accountsChanged', updateWallet);
|
|
530
|
+
}
|
|
531
|
+
|
|
474
532
|
render('deposit');
|
|
475
533
|
tabs.forEach(b => b.addEventListener('click', () => render(b.dataset.tab)));
|
|
476
534
|
|
|
535
|
+
setTimeout(updateWallet, 100);
|
|
536
|
+
|
|
477
537
|
return { element: wrap, destroy: () => wrap.remove(), switchTab: render };
|
|
478
538
|
}
|