Files
SHiNE-server/shine-UI/js/pages/devnet-topup-view.js
T

29 lines
2.0 KiB
JavaScript

import { createTopBar } from '../components/topbar.js';
import { formatSol, getBalanceSol } from '../services/solana-wallet-service.js';
export const pageMeta = {id:'devnet-topup-view', title:'Пополнение DEVNET', showAppChrome:false};
const DEVNET_ENDPOINT='https://api.devnet.solana.com';
function readWalletFromUrl() {
try { return new URL(window.location.href).searchParams.get('wallet')?.trim() || ''; }
catch { return ''; }
}
export function render() {
const screen=document.createElement('section');screen.className='stack registration-screen';
const card=document.createElement('div');card.className='card stack';
const title=document.createElement('h3');title.textContent='Пополнение DEVNET';
const note=document.createElement('p');note.className='meta-muted';
note.textContent='Автоматическое пополнение из браузера отключено: приватный ключ отправителя нельзя публиковать в приложении. Используйте внешний доверенный Solana devnet faucet.';
const wallet=readWalletFromUrl();
const input=document.createElement('input');input.className='input';input.readOnly=true;input.value=wallet;
const copy=document.createElement('button');copy.className='secondary-btn';copy.textContent='Скопировать адрес';
copy.addEventListener('click',()=>navigator.clipboard.writeText(input.value).catch(()=>{}));
const balance=document.createElement('p');balance.className='meta-muted';
balance.textContent=wallet?'Проверяем баланс…':'Не передан параметр wallet';
if(wallet)void getBalanceSol({endpoint:DEVNET_ENDPOINT,address:wallet})
.then(value=>balance.textContent=`Баланс: ${formatSol(value.sol,6)} SOL`)
.catch(()=>balance.textContent='Баланс недоступен; проверьте адрес и сеть');
card.append(title,note,input,copy,balance);
screen.append(createTopBar({title:'Пополнение DEVNET'}),card);
return screen;
}