import type { NextPage } from 'next' import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { useTheme } from 'next-themes' import { useRouter } from 'next/router' import ButtonGroup from '../components/forms/ButtonGroup' import useLocalStorageState from '../hooks/useLocalStorageState' import dayjs from 'dayjs' import { NOTIFICATION_POSITION_KEY, ORDERBOOK_FLASH_KEY, PREFERRED_EXPLORER_KEY, TRADE_FORM_UI_KEY, } from 'utils/constants' import Switch from '@components/forms/Switch' import { useCallback, useMemo } from 'react' import { CheckCircleIcon } from '@heroicons/react/20/solid' import Image from 'next/legacy/image' require('dayjs/locale/en') require('dayjs/locale/es') require('dayjs/locale/zh') require('dayjs/locale/zh-tw') export async function getStaticProps({ locale }: { locale: string }) { return { props: { ...(await serverSideTranslations(locale, [ 'common', 'onboarding', 'profile', 'settings', ])), }, } } export const LANGS = [ { locale: 'en', name: 'english', description: 'english' }, { locale: 'ru', name: 'russian', description: 'russian' }, { locale: 'es', name: 'spanish', description: 'spanish' }, { locale: 'zh_tw', name: 'chinese-traditional', description: 'traditional chinese', }, { locale: 'zh', name: 'chinese', description: 'simplified chinese' }, ] export const EXPLORERS = [ { name: 'solana-explorer', url: 'https://explorer.solana.com/tx/' }, { name: 'solscan', url: 'https://solscan.io/tx/' }, { name: 'solana-beach', url: 'https://solanabeach.io/transaction/' }, { name: 'solanafm', url: 'https://solana.fm/tx/' }, ] const NOTIFICATION_POSITIONS = [ 'bottom-left', 'bottom-right', 'top-left', 'top-right', ] const Settings: NextPage = () => { const { t } = useTranslation(['common', 'settings']) const { theme, setTheme } = useTheme() const [savedLanguage, setSavedLanguage] = useLocalStorageState('language', '') const [notificationPosition, setNotificationPosition] = useLocalStorageState( NOTIFICATION_POSITION_KEY, 'bottom-left' ) const router = useRouter() const { pathname, asPath, query } = router const [showOrderbookFlash, setShowOrderbookFlash] = useLocalStorageState( ORDERBOOK_FLASH_KEY, true ) const [preferredExplorer, setPreferredExplorer] = useLocalStorageState( PREFERRED_EXPLORER_KEY, EXPLORERS[0] ) const [tradeFormUi, setTradeFormUi] = useLocalStorageState( TRADE_FORM_UI_KEY, 'Slider' ) const themes = useMemo(() => { return [t('settings:light'), t('settings:mango'), t('settings:dark')] }, [t]) const handleLangChange = useCallback( (l: string) => { setSavedLanguage(l) router.push({ pathname, query }, asPath, { locale: l }) dayjs.locale(l == 'zh_tw' ? 'zh-tw' : l) }, [router] ) return (

{t('settings:display')}

{t('settings:theme')}

setTheme(t)} values={themes} // large={!isMobile} />

{t('settings:language')}

handleLangChange(l)} values={LANGS.map((val) => val.locale)} names={LANGS.map((val) => t(`settings:${val.name}`))} // large={!isMobile} />

{t('settings:notification-position')}

setNotificationPosition(p)} values={NOTIFICATION_POSITIONS} names={NOTIFICATION_POSITIONS.map((val) => t(`settings:${val}`) )} // large={!isMobile} />

{t('settings:trade-size-ui')}

setTradeFormUi(v)} values={[t('settings:slider'), t('settings:buttons')]} // large={!isMobile} />

{t('settings:orderbook-flash')}

setShowOrderbookFlash(checked)} />

{t('settings:preferred-explorer')}

{EXPLORERS.map((ex) => ( ))}
) } export default Settings