@nibgate/sdk 0.2.38 → 0.2.40
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 +69 -2
- package/dist/nibgate.js.map +2 -2
- package/dist/nibgate.min.js +21 -19
- package/dist/nibgate.min.js.map +3 -3
- package/package.json +1 -1
- package/src/browser/default-ui.js +60 -2
package/package.json
CHANGED
|
@@ -424,8 +424,10 @@ export function renderDefaultGatewayWalletUI(container, options = {}) {
|
|
|
424
424
|
wrap.innerHTML = `
|
|
425
425
|
<div style="display:flex;gap:12px;margin-bottom:20px">
|
|
426
426
|
<div data-gw-wallet-card style="flex:1;background:${theme.bg};border:1px solid ${theme.border};border-radius:12px;padding:16px">
|
|
427
|
-
<div style="
|
|
428
|
-
|
|
427
|
+
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">
|
|
428
|
+
<div data-gw-wallet-addr class="nui-mono" style="font-size:13px;color:${theme.muted}"></div>
|
|
429
|
+
<span data-gw-connect-label style="font-size:12px;font-weight:600;color:${theme.accent}">Connected</span>
|
|
430
|
+
</div>
|
|
429
431
|
<div data-gw-wallet-balance class="nui-mono" style="font-size:24px;font-weight:700;color:${theme.fg}">—</div>
|
|
430
432
|
</div>
|
|
431
433
|
<div style="flex:1;background:${theme.bg};border:1px solid ${theme.border};border-radius:12px;padding:16px">
|
|
@@ -460,6 +462,60 @@ export function renderDefaultGatewayWalletUI(container, options = {}) {
|
|
|
460
462
|
});
|
|
461
463
|
}
|
|
462
464
|
|
|
465
|
+
const GATEWAY = '0x0077777d7EBA4688BDeF3E311b846F25870A19B9';
|
|
466
|
+
const SEL_APPROVE = '0x095ea7b3';
|
|
467
|
+
const SEL_DEPOSIT = '0x47e7ef24';
|
|
468
|
+
|
|
469
|
+
function parse6(v) {
|
|
470
|
+
const [w = '0', f = ''] = String(v).split('.');
|
|
471
|
+
return BigInt(w + f.padEnd(6, '0').slice(0, 6));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function addr32(a) { return '000000000000000000000000' + a.slice(2); }
|
|
475
|
+
|
|
476
|
+
function setTx(msg, ok) {
|
|
477
|
+
const el = formEl.querySelector('[data-gw-tx]');
|
|
478
|
+
if (!el) return;
|
|
479
|
+
el.style.display = 'block';
|
|
480
|
+
el.style.color = ok ? theme.accent : '#dc2626';
|
|
481
|
+
el.textContent = msg;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async function doDeposit() {
|
|
485
|
+
if (!window.ethereum) { setTx('No wallet found'); return; }
|
|
486
|
+
const input = formEl.querySelector('[data-gw-deposit-amount]');
|
|
487
|
+
const amt = input?.value;
|
|
488
|
+
if (!amt || Number(amt) <= 0) { setTx('Enter an amount'); return; }
|
|
489
|
+
const btn = formEl.querySelector('[data-gw-deposit]');
|
|
490
|
+
try {
|
|
491
|
+
btn.disabled = true;
|
|
492
|
+
btn.textContent = 'Approving\u2026';
|
|
493
|
+
const accts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
494
|
+
const addr = accts?.[0];
|
|
495
|
+
if (!addr) { setTx('Connect wallet'); btn.disabled = false; btn.textContent = 'Deposit'; return; }
|
|
496
|
+
const amount = parse6(amt).toString(16);
|
|
497
|
+
const approveTx = await window.ethereum.request({
|
|
498
|
+
method: 'eth_sendTransaction',
|
|
499
|
+
params: [{ from: addr, to: USDC, data: SEL_APPROVE + addr32(GATEWAY) + amount.padStart(64, '0') }],
|
|
500
|
+
});
|
|
501
|
+
setTx('Approved: ' + approveTx.slice(0, 10) + '\u2026', true);
|
|
502
|
+
btn.textContent = 'Depositing\u2026';
|
|
503
|
+
const depositTx = await window.ethereum.request({
|
|
504
|
+
method: 'eth_sendTransaction',
|
|
505
|
+
params: [{ from: addr, to: GATEWAY, data: SEL_DEPOSIT + addr32(USDC) + amount.padStart(64, '0') }],
|
|
506
|
+
});
|
|
507
|
+
setTx('Deposited: ' + depositTx.slice(0, 10) + '\u2026', true);
|
|
508
|
+
updateWallet();
|
|
509
|
+
btn.textContent = 'Deposit';
|
|
510
|
+
} catch (e) { setTx(e?.message || 'Deposit failed'); }
|
|
511
|
+
btn.disabled = false;
|
|
512
|
+
btn.textContent = 'Deposit';
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async function doWithdraw() {
|
|
516
|
+
setTx('Withdraw via admin dashboard', false);
|
|
517
|
+
}
|
|
518
|
+
|
|
463
519
|
function render(t) {
|
|
464
520
|
tab = t;
|
|
465
521
|
select(tabs, t);
|
|
@@ -470,6 +526,7 @@ export function renderDefaultGatewayWalletUI(container, options = {}) {
|
|
|
470
526
|
<button type="button" data-gw-deposit class="nui-btn nui-btn-primary" style="width:100%;padding:16px 28px;font-size:20px">Deposit</button>
|
|
471
527
|
<div data-gw-tx class="nui-mono" style="font-size:12px;color:${theme.muted};word-break:break-all;margin-top:12px;display:none"></div>
|
|
472
528
|
`;
|
|
529
|
+
formEl.querySelector('[data-gw-deposit]')?.addEventListener('click', doDeposit);
|
|
473
530
|
} else {
|
|
474
531
|
formEl.innerHTML = `
|
|
475
532
|
<label class="nui-label">Amount (USDC)</label>
|
|
@@ -477,6 +534,7 @@ export function renderDefaultGatewayWalletUI(container, options = {}) {
|
|
|
477
534
|
<button type="button" data-gw-withdraw class="nui-btn nui-btn-primary" style="width:100%;padding:16px 28px;font-size:20px">Withdraw to your wallet</button>
|
|
478
535
|
<div data-gw-tx class="nui-mono" style="font-size:12px;color:${theme.muted};word-break:break-all;margin-top:12px;display:none"></div>
|
|
479
536
|
`;
|
|
537
|
+
formEl.querySelector('[data-gw-withdraw]')?.addEventListener('click', doWithdraw);
|
|
480
538
|
}
|
|
481
539
|
}
|
|
482
540
|
|