Files
SHiNE-server/shine-UI/js/components/solana-rpc-mode.js
T

28 lines
1.2 KiB
JavaScript

import { t } from '../i18n/index.js';
import { rpcEndpointFromShineHttp } from '../services/solana-rpc-gateway.js';
export function createSolanaRpcMode({ draft, input, onChange }) {
const select = document.createElement('select');
select.className = 'input';
input.setAttribute('aria-label', t('screens.entry_settings_view.rpc_custom'));
select.setAttribute('aria-label', t('screens.entry_settings_view.rpc_mode'));
for (const [value, label] of [['gateway', t('screens.entry_settings_view.rpc_gateway')], ['custom', t('screens.entry_settings_view.rpc_custom')]]) {
const option = document.createElement('option');
option.value = value;
option.textContent = label;
select.append(option);
}
select.value = draft.solanaRpcMode;
const sync = () => {
const custom = select.value === 'custom';
draft.solanaRpcMode = select.value;
input.hidden = !custom;
input.disabled = !custom;
input.value = custom ? draft.customSolanaServer : '';
draft.solanaServer = custom ? input.value.trim() : rpcEndpointFromShineHttp(draft.shineServerHttp);
};
sync();
select.addEventListener('change', () => { sync(); onChange(); });
return select;
}