import React, { useState } from 'react' import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/solid' import useMangoGroupConfig from '../hooks/useMangoGroupConfig' import Modal from './Modal' import { ElementTitle } from './styles' import Button from './Button' import Input from './Input' import useMangoStore from '../stores/useMangoStore' import useLocalStorageState from '../hooks/useLocalStorageState' import Select from './Select' import { useTranslation } from 'next-i18next' const NODE_URLS = [ { label: 'Mango Node', value: 'https://mango.rpcpool.com' }, { label: 'Genesys Go', value: 'https://lokidfxnwlabdq.main.genesysgo.net:8899/', }, { label: 'Project Serum', value: 'https://solana-api.projectserum.com/', }, { label: 'Custom', value: '' }, ] const CUSTOM_NODE = NODE_URLS.find((n) => n.label === 'Custom') export const NODE_URL_KEY = 'node-url-key-0.4' export const DEFAULT_MARKET_KEY = 'defaultMarket' export const initialMarket = { base: 'BTC', kind: 'perp', name: 'BTC-PERP', path: '/perp/BTC', } const SettingsModal = ({ isOpen, onClose }) => { const { t } = useTranslation('common') const [settingsView, setSettingsView] = useState('') const [rpcEndpointUrl] = useLocalStorageState( NODE_URL_KEY, NODE_URLS[0].value ) const [defaultMarket] = useLocalStorageState( DEFAULT_MARKET_KEY, initialMarket ) const rpcEndpoint = NODE_URLS.find((node) => node.value === rpcEndpointUrl) || CUSTOM_NODE return ( {settingsView !== '' ? ( ) : null} {t('settings')} {!settingsView ? (
) : null} {!settingsView ? (
) : null}
) } export default React.memo(SettingsModal) const SettingsContent = ({ settingsView, setSettingsView }) => { switch (settingsView) { case 'Default Market': return case 'RPC Endpoint': return case '': return null } } const DefaultMarketSettings = ({ setSettingsView }) => { const { t } = useTranslation('common') const groupConfig = useMangoGroupConfig() const allMarkets = [ ...groupConfig.spotMarkets, ...groupConfig.perpMarkets, ].sort((a, b) => a.name.localeCompare(b.name)) const [defaultMarket, setDefaultMarket] = useLocalStorageState( DEFAULT_MARKET_KEY, { base: 'BTC', kind: 'perp', name: 'BTC-PERP', path: '/perp/BTC', } ) const handleSetDefaultMarket = (market) => { const base = market.slice(0, -5) const kind = market.includes('PERP') ? 'perp' : 'spot' const defaultMarket = market.includes('PERP') ? `/perp/${base}` : `/spot/${base}` setDefaultMarket({ base: base, kind: kind, name: market, path: defaultMarket, }) } const parsedDefaultMarket = defaultMarket return (
) } const RpcEndpointSettings = ({ setSettingsView }) => { const { t } = useTranslation('common') const actions = useMangoStore((s) => s.actions) const [rpcEndpointUrl, setRpcEndpointUrl] = useLocalStorageState( NODE_URL_KEY, NODE_URLS[0].value ) const rpcEndpoint = NODE_URLS.find((node) => node.value === rpcEndpointUrl) || CUSTOM_NODE const handleSetEndpointUrl = (endpointUrl) => { setRpcEndpointUrl(endpointUrl) actions.updateConnection(endpointUrl) setSettingsView('') } const handleSelectEndpointUrl = (url) => { setRpcEndpointUrl(url) } return (
{rpcEndpoint.label === 'Custom' ? (
setRpcEndpointUrl(e.target.value)} />
) : null}
) }