// eslint-disable-next-line no-restricted-imports import { t, Trans } from '@lingui/macro' import { Percent } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' import { sendEvent } from 'components/analytics' import { RedesignVariant, useRedesignFlag } from 'featureFlags/flags/redesign' import { isSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter' import { useRef, useState } from 'react' import { Settings, X } from 'react-feather' import { Text } from 'rebass' import styled, { useTheme } from 'styled-components/macro' import { useOnClickOutside } from '../../hooks/useOnClickOutside' import { useModalIsOpen, useToggleSettingsMenu } from '../../state/application/hooks' import { ApplicationModal } from '../../state/application/reducer' import { useClientSideRouter, useExpertModeManager } from '../../state/user/hooks' import { ThemedText } from '../../theme' import { ButtonError } from '../Button' import { AutoColumn } from '../Column' import Modal from '../Modal' import QuestionHelper from '../QuestionHelper' import { RowBetween, RowFixed } from '../Row' import Toggle from '../Toggle' import TransactionSettings from '../TransactionSettings' const StyledMenuIcon = styled(Settings)<{ redesignFlag: boolean }>` height: 20px; width: 20px; > * { stroke: ${({ theme, redesignFlag }) => (redesignFlag ? theme.textSecondary : theme.deprecated_text1)}; } ` const StyledCloseIcon = styled(X)<{ redesignFlag: boolean }>` height: 20px; width: 20px; :hover { cursor: pointer; } > * { stroke: ${({ theme, redesignFlag }) => (redesignFlag ? theme.textSecondary : theme.deprecated_text1)}; } ` const StyledMenuButton = styled.button<{ disabled: boolean }>` position: relative; width: 100%; height: 100%; border: none; background-color: transparent; margin: 0; padding: 0; border-radius: 0.5rem; height: 20px; ${({ disabled }) => !disabled && ` :hover, :focus { cursor: pointer; outline: none; opacity: 0.7; } `} ` const EmojiWrapper = styled.div` position: absolute; bottom: -6px; right: 0px; font-size: 14px; ` const StyledMenu = styled.div` margin-left: 0.5rem; display: flex; justify-content: center; align-items: center; position: relative; border: none; text-align: left; ` const MenuFlyout = styled.span<{ redesignFlag: boolean }>` min-width: 20.125rem; background-color: ${({ theme, redesignFlag }) => (redesignFlag ? theme.backgroundSurface : theme.deprecated_bg2)}; border: 1px solid ${({ theme, redesignFlag }) => (redesignFlag ? theme.backgroundOutline : theme.deprecated_bg3)}; box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.01), 0px 4px 8px rgba(0, 0, 0, 0.04), 0px 16px 24px rgba(0, 0, 0, 0.04), 0px 24px 32px rgba(0, 0, 0, 0.01); border-radius: 12px; display: flex; flex-direction: column; font-size: 1rem; position: absolute; top: 2rem; right: 0rem; z-index: 100; color: ${({ theme, redesignFlag }) => redesignFlag && theme.textPrimary}; ${({ theme }) => theme.deprecated_mediaWidth.deprecated_upToMedium` min-width: 18.125rem; `}; user-select: none; ` const Break = styled.div` width: 100%; height: 1px; background-color: ${({ theme }) => theme.deprecated_bg3}; ` const ModalContentWrapper = styled.div` display: flex; align-items: center; justify-content: center; padding: 2rem 0; background-color: ${({ theme }) => theme.deprecated_bg2}; border-radius: 20px; ` export default function SettingsTab({ placeholderSlippage }: { placeholderSlippage: Percent }) { const { chainId } = useWeb3React() const redesignFlag = useRedesignFlag() const redesignFlagEnabled = redesignFlag === RedesignVariant.Enabled const node = useRef() const open = useModalIsOpen(ApplicationModal.SETTINGS) const toggle = useToggleSettingsMenu() const theme = useTheme() const [expertMode, toggleExpertMode] = useExpertModeManager() const [clientSideRouter, setClientSideRouter] = useClientSideRouter() // show confirmation view before turning on const [showConfirmation, setShowConfirmation] = useState(false) useOnClickOutside(node, open ? toggle : undefined) return ( // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/30451 setShowConfirmation(false)} maxHeight={100}>
Are you sure? setShowConfirmation(false)} redesignFlag={redesignFlagEnabled} /> Expert mode turns off the confirm transaction prompt and allows high slippage trades that often result in bad rates and lost funds. ONLY USE THIS MODE IF YOU KNOW WHAT YOU ARE DOING. { const confirmWord = t`confirm` if (window.prompt(t`Please type the word "${confirmWord}" to enable expert mode.`) === confirmWord) { toggleExpertMode() setShowConfirmation(false) } }} > Turn On Expert Mode {expertMode ? ( 🧙 ) : null} {open && ( {redesignFlagEnabled ? 'Settings' : 'Transaction Settings'} Interface Settings {isSupportedChainId(chainId) && ( Auto Router API Use the Uniswap Labs API to get faster quotes.} /> { sendEvent({ category: 'Routing', action: clientSideRouter ? 'enable routing API' : 'disable routing API', }) setClientSideRouter(!clientSideRouter) }} /> )} Expert Mode Allow high price impact trades and skip the confirm screen. Use at your own risk. } /> { toggleExpertMode() setShowConfirmation(false) } : () => { toggle() setShowConfirmation(true) } } /> )} ) }