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