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-02-07 21:12:45 +03:00
|
|
|
import { AUTO_ROUTER_SUPPORTED_CHAINS } from 'lib/hooks/routing/clientSideSmartOrderRouter'
|
2021-06-25 17:52:49 +03:00
|
|
|
import { useContext, 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'
|
2021-07-07 18:45:47 +03:00
|
|
|
import styled, { ThemeContext } 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'
|
2020-09-24 19:18:57 +03:00
|
|
|
import { useModalOpen, 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
|
|
|
|
|
|
|
const StyledMenuIcon = styled(Settings)`
|
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
|
|
|
|
> * {
|
2021-12-16 22:44:03 +03:00
|
|
|
stroke: ${({ theme }) => theme.text1};
|
2020-06-12 22:26:28 +03:00
|
|
|
}
|
2021-01-18 22:40:42 +03:00
|
|
|
|
|
|
|
:hover {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2020-06-12 22:26:28 +03:00
|
|
|
`
|
|
|
|
|
|
|
|
const StyledCloseIcon = styled(X)`
|
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
> * {
|
|
|
|
stroke: ${({ theme }) => theme.text1};
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const StyledMenuButton = styled.button`
|
|
|
|
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
|
|
|
|
|
|
|
:hover,
|
|
|
|
:focus {
|
|
|
|
cursor: pointer;
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
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`
|
|
|
|
min-width: 20.125rem;
|
2020-09-24 19:18:57 +03:00
|
|
|
background-color: ${({ theme }) => theme.bg2};
|
2021-05-03 23:32:40 +03:00
|
|
|
border: 1px solid ${({ theme }) => theme.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;
|
|
|
|
|
2020-09-24 19:18:57 +03:00
|
|
|
${({ theme }) => theme.mediaWidth.upToMedium`
|
|
|
|
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;
|
|
|
|
background-color: ${({ theme }) => theme.bg3};
|
|
|
|
`
|
|
|
|
|
|
|
|
const ModalContentWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
padding: 2rem 0;
|
|
|
|
background-color: ${({ theme }) => theme.bg2};
|
|
|
|
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()
|
2021-09-16 17:50:58 +03:00
|
|
|
|
2020-06-12 22:26:28 +03:00
|
|
|
const node = useRef<HTMLDivElement>()
|
2020-09-24 19:18:57 +03:00
|
|
|
const open = useModalOpen(ApplicationModal.SETTINGS)
|
2020-06-12 22:26:28 +03:00
|
|
|
const toggle = useToggleSettingsMenu()
|
|
|
|
|
|
|
|
const theme = useContext(ThemeContext)
|
|
|
|
|
|
|
|
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>
|
|
|
|
<StyledCloseIcon onClick={() => setShowConfirmation(false)} />
|
|
|
|
</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>
|
2021-08-17 01:30:52 +03:00
|
|
|
<StyledMenuButton onClick={toggle} id="open-settings-dialog-button" aria-label={t`Transaction Settings`}>
|
2021-01-18 22:40:42 +03:00
|
|
|
<StyledMenuIcon />
|
|
|
|
{expertMode ? (
|
|
|
|
<EmojiWrapper>
|
|
|
|
<span role="img" aria-label="wizard-icon">
|
|
|
|
🧙
|
|
|
|
</span>
|
|
|
|
</EmojiWrapper>
|
|
|
|
) : null}
|
2020-06-12 22:26:28 +03:00
|
|
|
</StyledMenuButton>
|
|
|
|
{open && (
|
|
|
|
<MenuFlyout>
|
|
|
|
<AutoColumn gap="md" style={{ padding: '1rem' }}>
|
|
|
|
<Text fontWeight={600} fontSize={14}>
|
2021-05-29 08:16:57 +03:00
|
|
|
<Trans>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>
|
2021-12-16 22:44:03 +03:00
|
|
|
{chainId && AUTO_ROUTER_SUPPORTED_CHAINS.includes(chainId) && (
|
2021-09-16 17:50:58 +03:00
|
|
|
<RowBetween>
|
|
|
|
<RowFixed>
|
2021-12-02 21:35:39 +03:00
|
|
|
<ThemedText.Black fontWeight={400} fontSize={14} color={theme.text2}>
|
2021-12-16 22:44:03 +03:00
|
|
|
<Trans>Auto Router API</Trans>
|
2021-12-02 21:35:39 +03:00
|
|
|
</ThemedText.Black>
|
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>
|
2021-12-02 21:35:39 +03:00
|
|
|
<ThemedText.Black fontWeight={400} fontSize={14} color={theme.text2}>
|
2021-09-16 17:50:58 +03:00
|
|
|
<Trans>Expert Mode</Trans>
|
2021-12-02 21:35:39 +03:00
|
|
|
</ThemedText.Black>
|
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>
|
|
|
|
)
|
|
|
|
}
|