import ButtonGroup from '@components/forms/ButtonGroup' import Input from '@components/forms/Input' import Button from '@components/shared/Button' import Switch from '@components/forms/Switch' import { useWallet } from '@solana/wallet-adapter-react' import mangoStore from '@store/mangoStore' import useLocalStorageState from 'hooks/useLocalStorageState' import { useTranslation } from 'next-i18next' import { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react' import { PRIORITY_FEE_KEY, RPC_PROVIDER_KEY, USE_ORDERBOOK_FEED_KEY, } from 'utils/constants' import Tooltip from '@components/shared/Tooltip' const RPC_URLS = [ { label: 'Triton Shared', value: process.env.NEXT_PUBLIC_ENDPOINT || 'https://mango.rpcpool.com/946ef7337da3f5b8d3e4a34e7f88', }, { label: 'Triton Dedicated', value: process.env.TRITON_TOKEN ? `https://mango.rpcpool.com/${process.env.TRITON_TOKEN}` : 'https://mango.rpcpool.com/946ef7337da3f5b8d3e4a34e7f88', }, // { // label: 'Genesys Go', // value: 'https://mango.genesysgo.net', // }, { label: 'Custom', value: '' }, ] export const PRIORITY_FEES = [ { label: 'None', value: 0 }, { label: 'Low', value: 50000 }, { label: 'High', value: 100000 }, ] export const DEFAULT_PRIORITY_FEE = PRIORITY_FEES[1] const RpcSettings = () => { const { t } = useTranslation('settings') const actions = mangoStore.getState().actions const { wallet } = useWallet() const [customUrl, setCustomUrl] = useState('') const [showCustomForm, setShowCustomForm] = useState(false) const [rpcEndpointProvider, setRpcEndpointProvider] = useLocalStorageState( RPC_PROVIDER_KEY, RPC_URLS[0].value ) const [storedPriorityFee, setStoredPriorityFee] = useLocalStorageState( PRIORITY_FEE_KEY, DEFAULT_PRIORITY_FEE.value ) const [storedUseOrderbookFeed, setStoredUseOrderbookFeed] = useLocalStorageState(USE_ORDERBOOK_FEED_KEY, true) const rpcEndpoint = useMemo(() => { return ( RPC_URLS.find((node) => node.value === rpcEndpointProvider) || { label: 'Custom', value: rpcEndpointProvider, } ) }, [rpcEndpointProvider]) const priorityFee = useMemo(() => { return ( PRIORITY_FEES.find((node) => node.value === storedPriorityFee) || DEFAULT_PRIORITY_FEE ) }, [storedPriorityFee]) const handleSetEndpointProvider = (provider: string) => { const endpointProvider = RPC_URLS.find( (node) => node.label === provider ) || { label: 'Custom', value: rpcEndpointProvider } setRpcEndpointProvider(endpointProvider.value) if (provider !== 'Custom') { setShowCustomForm(false) actions.updateConnection(endpointProvider.value) } } const handlePriorityFee = useCallback( (label: string) => { const fee = PRIORITY_FEES.find((fee) => fee.label === label) if (fee) { setStoredPriorityFee(fee?.value) if (wallet) { actions.connectMangoClientWithWallet(wallet) } } }, [setStoredPriorityFee, actions, wallet] ) useEffect(() => { if (rpcEndpoint.label === 'Custom') { setShowCustomForm(true) setCustomUrl(rpcEndpoint.value) } }, [rpcEndpoint]) const handleSaveCustomEndpoint = () => { if (!customUrl) return setRpcEndpointProvider(customUrl) actions.updateConnection(customUrl) } return ( <>

{t('rpc')}

{t('rpc-provider')}

handleSetEndpointProvider(v)} values={RPC_URLS.map((val) => val.label)} /> {showCustomForm ? (
) => setCustomUrl(e.target.value) } />
) : null}

Priority Fee

handlePriorityFee(v)} values={PRIORITY_FEES.map((val) => val.label)} /> {/* {showCustomForm ? (
) => setCustomUrl(e.target.value) } />
) : null} */}

{t('settings:orderbook-bandwidth-saving')}

setStoredUseOrderbookFeed(!storedUseOrderbookFeed)} />
) } export default RpcSettings