2021-10-11 16:30:51 +03:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2021-05-29 08:16:57 +03:00
|
|
|
import { t, Trans } from '@lingui/macro'
|
2021-09-22 02:21:28 +03:00
|
|
|
import { Percent } from '@uniswap/sdk-core'
|
2022-07-01 02:38:02 +03:00
|
|
|
import { useWeb3React } from '@web3-react/core'
|
2022-06-10 23:36:44 +03:00
|
|
|
import { sendEvent } from 'components/analytics'
|
2022-08-15 17:09:26 +03:00
|
|
|
import { RedesignVariant, useRedesignFlag } from 'featureFlags/flags/redesign'
|
2022-07-12 17:48:03 +03:00
|
|
|
import { isSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter'
|
2022-08-17 19:55:58 +03:00
|
|
|
import { useRef, useState } from 'react'
|
2020-06-12 22:26:28 +03:00
|
|
|
import { Settings, X } from 'react-feather'
|
2020-09-24 19:18:57 +03:00
|
|
|
import { Text } from 'rebass'
|
2022-08-17 19:55:58 +03:00
|
|
|
import styled, { useTheme } from 'styled-components/macro'
|
2021-09-22 02:21:28 +03:00
|
|
|
|
feat(lists): allow selecting and adding token lists (#1023)
* more list stuff
Use the selected list instead of the default list, but also use the default list
start list selection code
* move token warning to a modal, fix the install issue
* add/remove/enter key
* handle enter on currency select for ETHER
* change slippage tolerance to be a slider
* make ui closer to the mocks
* commit slider changes
* back to tabs
* copy changes
* bump list version
* some styling for the list select
* bump uniswap default list version
* use contract calls to get ens names and addresses
* show list logo
* fix failing integration test
* .eth.link
* list introduction screen
* remove showSendWithSwap
* fix integration and unit tests
* resolve ENS names
* logos from ens
* fix the lint errors
* some refactoring to better support using a the library provider from the user for resolving ENS names
* load list info from the list url for the introduction page
* make it slightly harder to remove a list
* minor clean up, some help text and links
* remove icon from list update popup
* show added/removed tokens
* add GA everywhere, don't debounce contenthash lookups
* show tags
* fix tag key
* tag display, list rendering, needs optimization
* fix list fetching in firefox, style issue in safari
* sort the lists, clean up styling
* use client provider when possible
* show token warning for url loaded tokens
* improve the warning modal
* some refactoring to fix the list fetching on networks other than mainnet
* fix tests
* some minor improvements
* increase timeout to maybe fix integration tests which pass locally
* build for tests using the dev network url
* reset the lists if we deleted the other two copies
* improve how we handle updating the default list of lists
* fix integration test
* Update token list selection styles
* fix external links, reuse the on click outside code, show add errors
* show the list origin instead of the full url
* fix update list link
* show host instead of hostname
do not automatically dismiss major version upgrades for lists
* fix link to tokenlists.org
* add uma
* clean up styling in list rows
* bump token list version
* bump token list version again
* hover symbol to see currency name
* bump version
* add cmc lists, dharma list
Co-authored-by: Callil Capuozzo <callil.capuozzo@gmail.com>
2020-08-26 16:46:21 +03:00
|
|
|
import { useOnClickOutside } from '../../hooks/useOnClickOutside'
|
2022-07-11 22:55:59 +03:00
|
|
|
import { useModalIsOpen, useToggleSettingsMenu } from '../../state/application/hooks'
|
2021-10-14 20:40:19 +03:00
|
|
|
import { ApplicationModal } from '../../state/application/reducer'
|
2021-09-22 02:21:28 +03:00
|
|
|
import { useClientSideRouter, useExpertModeManager } from '../../state/user/hooks'
|
2021-12-02 21:35:39 +03:00
|
|
|
import { ThemedText } from '../../theme'
|
2021-01-18 22:40:42 +03:00
|
|
|
import { ButtonError } from '../Button'
|
2020-09-24 19:18:57 +03:00
|
|
|
import { AutoColumn } from '../Column'
|
2020-06-12 22:26:28 +03:00
|
|
|
import Modal from '../Modal'
|
2020-09-24 19:18:57 +03:00
|
|
|
import QuestionHelper from '../QuestionHelper'
|
|
|
|
import { RowBetween, RowFixed } from '../Row'
|
|
|
|
import Toggle from '../Toggle'
|
|
|
|
import TransactionSettings from '../TransactionSettings'
|
2020-06-12 22:26:28 +03:00
|
|
|
|
2022-08-15 17:09:26 +03:00
|
|
|
const StyledMenuIcon = styled(Settings)<{ redesignFlag: boolean }>`
|
2020-06-12 22:26:28 +03:00
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
|
|
|
|
> * {
|
2022-08-15 17:09:26 +03:00
|
|
|
stroke: ${({ theme, redesignFlag }) => (redesignFlag ? theme.textSecondary : theme.deprecated_text1)};
|
2020-06-12 22:26:28 +03:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2022-08-15 17:09:26 +03:00
|
|
|
const StyledCloseIcon = styled(X)<{ redesignFlag: boolean }>`
|
2020-06-12 22:26:28 +03:00
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
> * {
|
2022-08-15 17:09:26 +03:00
|
|
|
stroke: ${({ theme, redesignFlag }) => (redesignFlag ? theme.textSecondary : theme.deprecated_text1)};
|
2020-06-12 22:26:28 +03:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2022-07-21 00:29:37 +03:00
|
|
|
const StyledMenuButton = styled.button<{ disabled: boolean }>`
|
2020-06-12 22:26:28 +03:00
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
border: none;
|
|
|
|
background-color: transparent;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
border-radius: 0.5rem;
|
2021-04-27 04:59:56 +03:00
|
|
|
height: 20px;
|
2020-06-12 22:26:28 +03:00
|
|
|
|
2022-07-21 00:29:37 +03:00
|
|
|
${({ disabled }) =>
|
|
|
|
!disabled &&
|
|
|
|
`
|
|
|
|
:hover,
|
|
|
|
:focus {
|
|
|
|
cursor: pointer;
|
|
|
|
outline: none;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
`}
|
2020-06-12 22:26:28 +03:00
|
|
|
`
|
|
|
|
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;
|
|
|
|
`
|
|
|
|
|
2022-08-15 17:09:26 +03:00
|
|
|
const MenuFlyout = styled.span<{ redesignFlag: boolean }>`
|
2020-06-12 22:26:28 +03:00
|
|
|
min-width: 20.125rem;
|
2022-08-15 17:09:26 +03:00
|
|
|
background-color: ${({ theme, redesignFlag }) => (redesignFlag ? theme.backgroundSurface : theme.deprecated_bg2)};
|
|
|
|
border: 1px solid ${({ theme, redesignFlag }) => (redesignFlag ? theme.backgroundOutline : theme.deprecated_bg3)};
|
2020-06-12 22:26:28 +03:00
|
|
|
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);
|
2020-09-24 19:18:57 +03:00
|
|
|
border-radius: 12px;
|
2020-06-12 22:26:28 +03:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
font-size: 1rem;
|
|
|
|
position: absolute;
|
2021-05-03 23:32:40 +03:00
|
|
|
top: 2rem;
|
2020-06-12 22:26:28 +03:00
|
|
|
right: 0rem;
|
|
|
|
z-index: 100;
|
2022-08-15 17:09:26 +03:00
|
|
|
color: ${({ theme, redesignFlag }) => redesignFlag && theme.textPrimary};
|
2020-06-12 22:26:28 +03:00
|
|
|
|
2022-08-24 20:43:46 +03:00
|
|
|
${({ theme }) => theme.deprecated_mediaWidth.deprecated_upToMedium`
|
2020-09-24 19:18:57 +03:00
|
|
|
min-width: 18.125rem;
|
|
|
|
`};
|
2021-05-12 21:01:31 +03:00
|
|
|
|
|
|
|
user-select: none;
|
2020-06-12 22:26:28 +03:00
|
|
|
`
|
|
|
|
|
|
|
|
const Break = styled.div`
|
|
|
|
width: 100%;
|
|
|
|
height: 1px;
|
2022-07-20 23:18:38 +03:00
|
|
|
background-color: ${({ theme }) => theme.deprecated_bg3};
|
2020-06-12 22:26:28 +03:00
|
|
|
`
|
|
|
|
|
|
|
|
const ModalContentWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
padding: 2rem 0;
|
2022-07-20 23:18:38 +03:00
|
|
|
background-color: ${({ theme }) => theme.deprecated_bg2};
|
2020-06-12 22:26:28 +03:00
|
|
|
border-radius: 20px;
|
|
|
|
`
|
|
|
|
|
2021-05-11 20:00:42 +03:00
|
|
|
export default function SettingsTab({ placeholderSlippage }: { placeholderSlippage: Percent }) {
|
2022-07-01 02:38:02 +03:00
|
|
|
const { chainId } = useWeb3React()
|
2022-08-15 17:09:26 +03:00
|
|
|
const redesignFlag = useRedesignFlag()
|
|
|
|
const redesignFlagEnabled = redesignFlag === RedesignVariant.Enabled
|
2021-09-16 17:50:58 +03:00
|
|
|
|
2020-06-12 22:26:28 +03:00
|
|
|
const node = useRef<HTMLDivElement>()
|
2022-07-11 22:55:59 +03:00
|
|
|
const open = useModalIsOpen(ApplicationModal.SETTINGS)
|
2020-06-12 22:26:28 +03:00
|
|
|
const toggle = useToggleSettingsMenu()
|
|
|
|
|
2022-08-17 19:55:58 +03:00
|
|
|
const theme = useTheme()
|
2020-06-12 22:26:28 +03:00
|
|
|
|
|
|
|
const [expertMode, toggleExpertMode] = useExpertModeManager()
|
|
|
|
|
2021-09-16 17:50:58 +03:00
|
|
|
const [clientSideRouter, setClientSideRouter] = useClientSideRouter()
|
2021-01-13 01:36:57 +03:00
|
|
|
|
2020-06-12 22:26:28 +03:00
|
|
|
// show confirmation view before turning on
|
|
|
|
const [showConfirmation, setShowConfirmation] = useState(false)
|
|
|
|
|
feat(lists): allow selecting and adding token lists (#1023)
* more list stuff
Use the selected list instead of the default list, but also use the default list
start list selection code
* move token warning to a modal, fix the install issue
* add/remove/enter key
* handle enter on currency select for ETHER
* change slippage tolerance to be a slider
* make ui closer to the mocks
* commit slider changes
* back to tabs
* copy changes
* bump list version
* some styling for the list select
* bump uniswap default list version
* use contract calls to get ens names and addresses
* show list logo
* fix failing integration test
* .eth.link
* list introduction screen
* remove showSendWithSwap
* fix integration and unit tests
* resolve ENS names
* logos from ens
* fix the lint errors
* some refactoring to better support using a the library provider from the user for resolving ENS names
* load list info from the list url for the introduction page
* make it slightly harder to remove a list
* minor clean up, some help text and links
* remove icon from list update popup
* show added/removed tokens
* add GA everywhere, don't debounce contenthash lookups
* show tags
* fix tag key
* tag display, list rendering, needs optimization
* fix list fetching in firefox, style issue in safari
* sort the lists, clean up styling
* use client provider when possible
* show token warning for url loaded tokens
* improve the warning modal
* some refactoring to fix the list fetching on networks other than mainnet
* fix tests
* some minor improvements
* increase timeout to maybe fix integration tests which pass locally
* build for tests using the dev network url
* reset the lists if we deleted the other two copies
* improve how we handle updating the default list of lists
* fix integration test
* Update token list selection styles
* fix external links, reuse the on click outside code, show add errors
* show the list origin instead of the full url
* fix update list link
* show host instead of hostname
do not automatically dismiss major version upgrades for lists
* fix link to tokenlists.org
* add uma
* clean up styling in list rows
* bump token list version
* bump token list version again
* hover symbol to see currency name
* bump version
* add cmc lists, dharma list
Co-authored-by: Callil Capuozzo <callil.capuozzo@gmail.com>
2020-08-26 16:46:21 +03:00
|
|
|
useOnClickOutside(node, open ? toggle : undefined)
|
2020-06-12 22:26:28 +03:00
|
|
|
|
|
|
|
return (
|
2020-08-27 21:10:00 +03:00
|
|
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/30451
|
|
|
|
<StyledMenu ref={node as any}>
|
2020-07-13 17:49:04 +03:00
|
|
|
<Modal isOpen={showConfirmation} onDismiss={() => setShowConfirmation(false)} maxHeight={100}>
|
2020-06-12 22:26:28 +03:00
|
|
|
<ModalContentWrapper>
|
|
|
|
<AutoColumn gap="lg">
|
|
|
|
<RowBetween style={{ padding: '0 2rem' }}>
|
|
|
|
<div />
|
|
|
|
<Text fontWeight={500} fontSize={20}>
|
2021-05-29 08:16:57 +03:00
|
|
|
<Trans>Are you sure?</Trans>
|
2020-06-12 22:26:28 +03:00
|
|
|
</Text>
|
2022-08-15 17:09:26 +03:00
|
|
|
<StyledCloseIcon onClick={() => setShowConfirmation(false)} redesignFlag={redesignFlagEnabled} />
|
2020-06-12 22:26:28 +03:00
|
|
|
</RowBetween>
|
|
|
|
<Break />
|
|
|
|
<AutoColumn gap="lg" style={{ padding: '0 2rem' }}>
|
|
|
|
<Text fontWeight={500} fontSize={20}>
|
2021-05-29 08:16:57 +03:00
|
|
|
<Trans>
|
|
|
|
Expert mode turns off the confirm transaction prompt and allows high slippage trades that often result
|
|
|
|
in bad rates and lost funds.
|
|
|
|
</Trans>
|
2020-06-12 22:26:28 +03:00
|
|
|
</Text>
|
|
|
|
<Text fontWeight={600} fontSize={20}>
|
2021-05-29 08:16:57 +03:00
|
|
|
<Trans>ONLY USE THIS MODE IF YOU KNOW WHAT YOU ARE DOING.</Trans>
|
2020-06-12 22:26:28 +03:00
|
|
|
</Text>
|
|
|
|
<ButtonError
|
|
|
|
error={true}
|
|
|
|
padding={'12px'}
|
|
|
|
onClick={() => {
|
2021-05-29 08:16:57 +03:00
|
|
|
const confirmWord = t`confirm`
|
|
|
|
if (window.prompt(t`Please type the word "${confirmWord}" to enable expert mode.`) === confirmWord) {
|
2020-06-12 22:26:28 +03:00
|
|
|
toggleExpertMode()
|
|
|
|
setShowConfirmation(false)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2020-08-24 21:52:41 +03:00
|
|
|
<Text fontSize={20} fontWeight={500} id="confirm-expert-mode">
|
2021-05-29 08:16:57 +03:00
|
|
|
<Trans>Turn On Expert Mode</Trans>
|
2020-06-12 22:26:28 +03:00
|
|
|
</Text>
|
|
|
|
</ButtonError>
|
|
|
|
</AutoColumn>
|
|
|
|
</AutoColumn>
|
|
|
|
</ModalContentWrapper>
|
|
|
|
</Modal>
|
2022-07-21 00:29:37 +03:00
|
|
|
<StyledMenuButton
|
|
|
|
disabled={!isSupportedChainId(chainId)}
|
|
|
|
onClick={toggle}
|
|
|
|
id="open-settings-dialog-button"
|
|
|
|
aria-label={t`Transaction Settings`}
|
|
|
|
>
|
2022-08-15 17:09:26 +03:00
|
|
|
<StyledMenuIcon redesignFlag={redesignFlagEnabled} />
|
2021-01-18 22:40:42 +03:00
|
|
|
{expertMode ? (
|
|
|
|
<EmojiWrapper>
|
|
|
|
<span role="img" aria-label="wizard-icon">
|
|
|
|
🧙
|
|
|
|
</span>
|
|
|
|
</EmojiWrapper>
|
|
|
|
) : null}
|
2020-06-12 22:26:28 +03:00
|
|
|
</StyledMenuButton>
|
|
|
|
{open && (
|
2022-08-15 17:09:26 +03:00
|
|
|
<MenuFlyout redesignFlag={redesignFlagEnabled}>
|
2020-06-12 22:26:28 +03:00
|
|
|
<AutoColumn gap="md" style={{ padding: '1rem' }}>
|
|
|
|
<Text fontWeight={600} fontSize={14}>
|
2022-08-15 17:09:26 +03:00
|
|
|
<Trans>{redesignFlagEnabled ? 'Settings' : 'Transaction Settings'}</Trans>
|
2020-06-12 22:26:28 +03:00
|
|
|
</Text>
|
2021-05-11 20:00:42 +03:00
|
|
|
<TransactionSettings placeholderSlippage={placeholderSlippage} />
|
2020-06-12 22:26:28 +03:00
|
|
|
<Text fontWeight={600} fontSize={14}>
|
2021-05-29 08:16:57 +03:00
|
|
|
<Trans>Interface Settings</Trans>
|
2020-06-12 22:26:28 +03:00
|
|
|
</Text>
|
2022-07-12 17:48:03 +03:00
|
|
|
{isSupportedChainId(chainId) && (
|
2021-09-16 17:50:58 +03:00
|
|
|
<RowBetween>
|
|
|
|
<RowFixed>
|
2022-07-27 00:14:43 +03:00
|
|
|
<ThemedText.DeprecatedBlack fontWeight={400} fontSize={14} color={theme.deprecated_text2}>
|
2021-12-16 22:44:03 +03:00
|
|
|
<Trans>Auto Router API</Trans>
|
2022-07-27 00:14:43 +03:00
|
|
|
</ThemedText.DeprecatedBlack>
|
2021-12-16 22:44:03 +03:00
|
|
|
<QuestionHelper text={<Trans>Use the Uniswap Labs API to get faster quotes.</Trans>} />
|
2021-09-16 17:50:58 +03:00
|
|
|
</RowFixed>
|
|
|
|
<Toggle
|
|
|
|
id="toggle-optimized-router-button"
|
|
|
|
isActive={!clientSideRouter}
|
|
|
|
toggle={() => {
|
2022-06-10 23:36:44 +03:00
|
|
|
sendEvent({
|
2021-09-16 17:50:58 +03:00
|
|
|
category: 'Routing',
|
|
|
|
action: clientSideRouter ? 'enable routing API' : 'disable routing API',
|
|
|
|
})
|
|
|
|
setClientSideRouter(!clientSideRouter)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</RowBetween>
|
|
|
|
)}
|
2020-06-12 22:26:28 +03:00
|
|
|
<RowBetween>
|
|
|
|
<RowFixed>
|
2022-07-27 00:14:43 +03:00
|
|
|
<ThemedText.DeprecatedBlack fontWeight={400} fontSize={14} color={theme.deprecated_text2}>
|
2021-09-16 17:50:58 +03:00
|
|
|
<Trans>Expert Mode</Trans>
|
2022-07-27 00:14:43 +03:00
|
|
|
</ThemedText.DeprecatedBlack>
|
2021-05-29 08:16:57 +03:00
|
|
|
<QuestionHelper
|
2021-05-30 22:05:37 +03:00
|
|
|
text={
|
|
|
|
<Trans>Allow high price impact trades and skip the confirm screen. Use at your own risk.</Trans>
|
|
|
|
}
|
2021-05-29 08:16:57 +03:00
|
|
|
/>
|
2020-06-12 22:26:28 +03:00
|
|
|
</RowFixed>
|
|
|
|
<Toggle
|
2020-08-24 21:52:41 +03:00
|
|
|
id="toggle-expert-mode-button"
|
2020-06-12 22:26:28 +03:00
|
|
|
isActive={expertMode}
|
|
|
|
toggle={
|
|
|
|
expertMode
|
|
|
|
? () => {
|
|
|
|
toggleExpertMode()
|
|
|
|
setShowConfirmation(false)
|
|
|
|
}
|
2020-07-13 17:49:04 +03:00
|
|
|
: () => {
|
|
|
|
toggle()
|
|
|
|
setShowConfirmation(true)
|
|
|
|
}
|
2020-06-12 22:26:28 +03:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
</RowBetween>
|
|
|
|
</AutoColumn>
|
|
|
|
</MenuFlyout>
|
|
|
|
)}
|
|
|
|
</StyledMenu>
|
|
|
|
)
|
|
|
|
}
|