// Copyright 2019-2020 @polkadot/extension-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 import { Theme, ThemeProps } from '../types'; import settings from '@polkadot/ui-settings'; import { faExpand } from '@fortawesome/free-solid-svg-icons'; import React, { useCallback, useContext, useEffect, useState, useMemo } from 'react'; import styled, { ThemeContext } from 'styled-components'; import { ActionText, Checkbox, Dropdown, Menu, MenuDivider, MenuItem, Svg, Switch, ThemeSwitchContext, themes } from '../components'; import useIsPopup from '../hooks/useIsPopup'; import useTranslation from '../hooks/useTranslation'; import { windowOpen } from '../messaging'; import getLanguageOptions from '../util/getLanguageOptions'; interface Option { text: string; value: string; } interface Props extends ThemeProps { className?: string; reference: React.MutableRefObject; } const prefixOptions = settings.availablePrefixes .filter(({ value }) => value !== -1) .map(({ text, value }): Option => ({ text, value: `${value}` })); function MenuSettings ({ className, reference }: Props): React.ReactElement { const { t } = useTranslation(); const [camera, setCamera] = useState(settings.camera === 'on'); const [prefix, setPrefix] = useState(`${settings.prefix === -1 ? 42 : settings.prefix}`); const themeContext = useContext(ThemeContext); const setTheme = useContext(ThemeSwitchContext); const isPopup = useIsPopup(); const languageOptions = useMemo(() => getLanguageOptions(), []); useEffect(() => { settings.set({ camera: camera ? 'on' : 'off' }); }, [camera]); const _onChangePrefix = useCallback( (value: string): void => { setPrefix(value); settings.set({ prefix: parseInt(value, 10) }); }, [] ); const _onChangeTheme = useCallback( (checked: boolean): void => setTheme(checked ? 'dark' : 'light'), [setTheme] ); const _onWindowOpen = useCallback( () => windowOpen('/'), [] ); const _onChangeLang = useCallback( (value: string): void => { settings.set({ i18nLang: value }); }, [] ); return ( ('External QR accounts and Access')} > ('Allow Camera Access')} onChange={setCamera} /> ('Display address format For')} > ('Language')} > {isPopup && ( <> ('Open extension in new window')} /> )} ); } export default React.memo(styled(MenuSettings)(({ theme }: Props) => ` margin-top: 50px; right: 24px; user-select: none; .openWindow { span { color: ${theme.textColor}; font-size: ${theme.fontSize}; line-height: ${theme.lineHeight}; text-decoration: none; } ${Svg} { background: ${theme.textColor}; height: 20px; top: 4px; width: 20px; } } > .setting { > .checkbox { color: ${theme.textColor}; line-height: 20px; font-size: 15px; margin-bottom: 0; label { color: ${theme.textColor}; } } > .dropdown { background: ${theme.background}; margin-bottom: 0; margin-top: 9px; margin-right: 0; width: 100%; } } `));