Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e77fcd21dc | ||
|
|
0b7846ee1d | ||
|
|
f450d34d69 | ||
|
|
76ab349b9e | ||
|
|
5c3c1c67f5 | ||
|
|
9efd5da1f7 | ||
|
|
8fd894f2d1 |
2
.github/ISSUE_TEMPLATE/config.yml
vendored
2
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,7 +1,7 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Support
|
||||
url: https://discord.gg/EwFs3Pp
|
||||
url: https://discord.gg/FCfyBSbCU5
|
||||
about: Please ask and answer questions here
|
||||
- name: List a token
|
||||
url: https://github.com/Uniswap/default-token-list#adding-a-token
|
||||
|
||||
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
@@ -3,10 +3,10 @@ name: Lint
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request_target:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
run-linters:
|
||||
|
||||
4
.github/workflows/tests.yaml
vendored
4
.github/workflows/tests.yaml
vendored
@@ -2,10 +2,10 @@ name: Tests
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
integration-tests:
|
||||
|
||||
@@ -12,7 +12,7 @@ An open source interface for Uniswap -- a protocol for decentralized exchange of
|
||||
- Twitter: [@UniswapProtocol](https://twitter.com/UniswapProtocol)
|
||||
- Reddit: [/r/Uniswap](https://www.reddit.com/r/Uniswap/)
|
||||
- Email: [contact@uniswap.org](mailto:contact@uniswap.org)
|
||||
- Discord: [Uniswap](https://discord.gg/Y7TF6QA)
|
||||
- Discord: [Uniswap](https://discord.gg/FCfyBSbCU5)
|
||||
- Whitepaper: [Link](https://hackmd.io/C-DvwDSfSxuh-Gd4WKE_ig)
|
||||
|
||||
## Accessing the Uniswap Interface
|
||||
|
||||
BIN
src/assets/images/tokenlistsgrouped.png
Normal file
BIN
src/assets/images/tokenlistsgrouped.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
30
src/assets/svg/tokenlist.svg
Normal file
30
src/assets/svg/tokenlist.svg
Normal file
@@ -0,0 +1,30 @@
|
||||
<svg width="225" height="225" viewBox="0 0 225 225" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M74.8125 190.529C65.7561 190.513 55.5298 183.748 51.9715 175.42L19.9417 100.456C16.3834 92.1277 20.8404 85.39 29.8968 85.4068L111.417 85.5579C120.473 85.5747 130.699 92.3395 134.258 100.668L166.288 175.632C169.846 183.96 165.389 190.697 156.332 190.681L74.8125 190.529Z" fill="#131313"/>
|
||||
<path d="M92.1541 164.065C83.0977 164.049 72.8715 157.284 69.3132 148.956L28.3003 52.9672C24.7419 44.6391 29.199 37.9015 38.2554 37.9182L142.638 38.1117C151.695 38.1285 161.921 44.8933 165.479 53.2214L206.492 149.21C210.051 157.538 205.594 164.276 196.537 164.259L92.1541 164.065Z" fill="white"/>
|
||||
<path d="M92.1541 164.065C83.0977 164.049 72.8715 157.284 69.3132 148.956L28.3003 52.9672C24.7419 44.6391 29.199 37.9015 38.2554 37.9182L142.638 38.1117C151.695 38.1285 161.921 44.8933 165.479 53.2214L206.492 149.21C210.051 157.538 205.594 164.276 196.537 164.259L92.1541 164.065Z" fill="url(#paint0_radial)"/>
|
||||
<path d="M92.1541 164.065C83.0977 164.049 72.8715 157.284 69.3132 148.956L28.3003 52.9672C24.7419 44.6391 29.199 37.9015 38.2554 37.9182L142.638 38.1117C151.695 38.1285 161.921 44.8933 165.479 53.2214L206.492 149.21C210.051 157.538 205.594 164.276 196.537 164.259L92.1541 164.065Z" fill="url(#paint1_radial)"/>
|
||||
<path d="M92.1541 164.065C83.0977 164.049 72.8715 157.284 69.3132 148.956L28.3003 52.9672C24.7419 44.6391 29.199 37.9015 38.2554 37.9182L142.638 38.1117C151.695 38.1285 161.921 44.8933 165.479 53.2214L206.492 149.21C210.051 157.538 205.594 164.276 196.537 164.259L92.1541 164.065Z" fill="url(#paint2_radial)"/>
|
||||
<path d="M92.1541 164.065C83.0977 164.049 72.8715 157.284 69.3132 148.956L28.3003 52.9672C24.7419 44.6391 29.199 37.9015 38.2554 37.9182L142.638 38.1117C151.695 38.1285 161.921 44.8933 165.479 53.2214L206.492 149.21C210.051 157.538 205.594 164.276 196.537 164.259L92.1541 164.065Z" fill="url(#paint3_radial)"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M92.958 165.95C82.7695 165.931 71.265 158.321 67.2619 148.952L26.2489 52.9632C22.2458 43.5941 27.26 36.0143 37.4485 36.0332L141.832 36.2266C152.02 36.2455 163.525 43.8559 167.528 53.225L208.541 149.214C212.544 158.583 207.53 166.163 197.341 166.144L92.958 165.95ZM71.3614 148.959C74.475 156.246 83.4229 162.166 91.3473 162.18L195.73 162.374C203.655 162.388 207.555 156.493 204.441 149.206L163.428 53.2174C160.315 45.9304 151.367 40.0111 143.442 39.9964L39.0592 39.803C31.1349 39.7883 27.2349 45.6837 30.3485 52.9708L71.3614 148.959Z" fill="#131313"/>
|
||||
<path d="M68.565 53.3425C81.1781 53.3659 95.4205 62.7875 100.376 74.3862C105.332 85.985 99.1246 95.3687 86.5115 95.3454C73.8984 95.322 59.6559 85.9004 54.7001 74.3016C49.7443 62.7028 55.9518 53.3191 68.565 53.3425Z" fill="#131313"/>
|
||||
<path d="M90.6891 104.981C103.302 105.004 117.545 114.425 122.5 126.024C127.456 137.623 121.249 147.007 108.636 146.983C96.0225 146.96 81.7801 137.538 76.8243 125.94C71.8685 114.341 78.076 104.957 90.6891 104.981Z" fill="#131313"/>
|
||||
<path d="M147.538 105.142C160.151 105.166 174.394 114.587 179.349 126.186C184.305 137.785 178.098 147.168 165.485 147.145C152.871 147.122 138.629 137.7 133.673 126.101C128.717 114.503 134.925 105.119 147.538 105.142Z" fill="#131313"/>
|
||||
<defs>
|
||||
<radialGradient id="paint0_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(134.41 68.3006) rotate(-33.9533) scale(90.6795 83.3208)">
|
||||
<stop offset="0.661458" stop-color="#C4FCF8"/>
|
||||
<stop offset="1" stop-color="white" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<radialGradient id="paint1_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(42.7873 129.218) rotate(-24.1606) scale(213.359 196.045)">
|
||||
<stop stop-color="#FF0099" stop-opacity="0.9"/>
|
||||
<stop offset="0.770833" stop-color="white" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<radialGradient id="paint2_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(176.854 148.655) rotate(-53.4908) scale(107.342 98.6309)">
|
||||
<stop stop-color="#FFEC43"/>
|
||||
<stop offset="0.805707" stop-color="#FFF6A8" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<radialGradient id="paint3_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(57.5443 53.4752) rotate(20.3896) scale(137.027 125.907)">
|
||||
<stop offset="0.125" stop-color="#5886FE" stop-opacity="0.46"/>
|
||||
<stop offset="0.673044" stop-color="white" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.4 KiB |
@@ -18,6 +18,10 @@ export const LightCard = styled(Card)`
|
||||
background-color: ${({ theme }) => theme.bg1};
|
||||
`
|
||||
|
||||
export const LightGreyCard = styled(Card)`
|
||||
background-color: ${({ theme }) => theme.bg2};
|
||||
`
|
||||
|
||||
export const GreyCard = styled(Card)`
|
||||
background-color: ${({ theme }) => theme.bg3};
|
||||
`
|
||||
|
||||
@@ -7,7 +7,7 @@ import useHttpLocations from '../../hooks/useHttpLocations'
|
||||
import { WrappedTokenInfo } from '../../state/lists/hooks'
|
||||
import Logo from '../Logo'
|
||||
|
||||
const getTokenLogoURL = (address: string) =>
|
||||
export const getTokenLogoURL = (address: string) =>
|
||||
`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/${address}/logo.png`
|
||||
|
||||
const StyledEthereumLogo = styled.img<{ size: string }>`
|
||||
@@ -43,7 +43,6 @@ export default function CurrencyLogo({
|
||||
if (currency instanceof WrappedTokenInfo) {
|
||||
return [...uriLocations, getTokenLogoURL(currency.address)]
|
||||
}
|
||||
|
||||
return [getTokenLogoURL(currency.address)]
|
||||
}
|
||||
return []
|
||||
|
||||
@@ -83,7 +83,11 @@ const HeaderControls = styled.div`
|
||||
const HeaderElement = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
/* addresses safari's lack of support for "gap" */
|
||||
& > *:not(:first-child) {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
${({ theme }) => theme.mediaWidth.upToMedium`
|
||||
flex-direction: row-reverse;
|
||||
|
||||
@@ -117,7 +117,7 @@ export default function Menu() {
|
||||
<Code size={14} />
|
||||
Code
|
||||
</MenuItem>
|
||||
<MenuItem id="link" href="https://discord.gg/EwFs3Pp">
|
||||
<MenuItem id="link" href="https://discord.gg/FCfyBSbCU5">
|
||||
<MessageCircle size={14} />
|
||||
Discord
|
||||
</MenuItem>
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useCurrencyBalance } from '../../state/wallet/hooks'
|
||||
import { TYPE } from '../../theme'
|
||||
import { useIsUserAddedToken, useAllInactiveTokens } from '../../hooks/Tokens'
|
||||
import Column from '../Column'
|
||||
import { RowFixed } from '../Row'
|
||||
import { RowFixed, RowBetween } from '../Row'
|
||||
import CurrencyLogo from '../CurrencyLogo'
|
||||
import { MouseoverTooltip } from '../Tooltip'
|
||||
import { MenuItem } from './styleds'
|
||||
@@ -17,6 +17,10 @@ import Loader from '../Loader'
|
||||
import { isTokenOnList } from '../../utils'
|
||||
import ImportRow from './ImportRow'
|
||||
import { wrappedCurrency } from 'utils/wrappedCurrency'
|
||||
import { LightGreyCard } from 'components/Card'
|
||||
import TokenListLogo from '../../assets/svg/tokenlist.svg'
|
||||
import QuestionHelper from 'components/QuestionHelper'
|
||||
import useTheme from 'hooks/useTheme'
|
||||
|
||||
function currencyKey(currency: Currency): string {
|
||||
return currency instanceof Token ? currency.address : currency === ETHER ? 'ETHER' : ''
|
||||
@@ -43,6 +47,14 @@ const Tag = styled.div`
|
||||
margin-right: 4px;
|
||||
`
|
||||
|
||||
const FixedContentRow = styled.div`
|
||||
padding: 4px 20px;
|
||||
height: 56px;
|
||||
display: grid;
|
||||
grid-gap: 16px;
|
||||
align-items: center;
|
||||
`
|
||||
|
||||
function Balance({ balance }: { balance: CurrencyAmount }) {
|
||||
return <StyledBalanceText title={balance.toExact()}>{balance.toSignificant(4)}</StyledBalanceText>
|
||||
}
|
||||
@@ -52,6 +64,10 @@ const TagContainer = styled.div`
|
||||
justify-content: flex-end;
|
||||
`
|
||||
|
||||
const TokenListLogoWrapper = styled.img`
|
||||
height: 20px;
|
||||
`
|
||||
|
||||
function TokenTags({ currency }: { currency: Currency }) {
|
||||
if (!(currency instanceof WrappedTokenInfo)) {
|
||||
return <span />
|
||||
@@ -136,7 +152,8 @@ export default function CurrencyList({
|
||||
fixedListRef,
|
||||
showETH,
|
||||
showImportView,
|
||||
setImportToken
|
||||
setImportToken,
|
||||
breakIndex
|
||||
}: {
|
||||
height: number
|
||||
currencies: Currency[]
|
||||
@@ -147,10 +164,18 @@ export default function CurrencyList({
|
||||
showETH: boolean
|
||||
showImportView: () => void
|
||||
setImportToken: (token: Token) => void
|
||||
breakIndex: number | undefined
|
||||
}) {
|
||||
const itemData = useMemo(() => (showETH ? [Currency.ETHER, ...currencies] : currencies), [currencies, showETH])
|
||||
const itemData: (Currency | undefined)[] = useMemo(() => {
|
||||
let formatted: (Currency | undefined)[] = showETH ? [Currency.ETHER, ...currencies] : currencies
|
||||
if (breakIndex !== undefined) {
|
||||
formatted = [...formatted.slice(0, breakIndex), undefined, ...formatted.slice(breakIndex, formatted.length)]
|
||||
}
|
||||
return formatted
|
||||
}, [breakIndex, currencies, showETH])
|
||||
|
||||
const { chainId } = useActiveWeb3React()
|
||||
const theme = useTheme()
|
||||
|
||||
const inactiveTokens: {
|
||||
[address: string]: Token
|
||||
@@ -167,6 +192,24 @@ export default function CurrencyList({
|
||||
|
||||
const showImport = inactiveTokens && token && Object.keys(inactiveTokens).includes(token.address)
|
||||
|
||||
if (index === breakIndex || !data) {
|
||||
return (
|
||||
<FixedContentRow style={style}>
|
||||
<LightGreyCard padding="8px 12px" borderRadius="8px">
|
||||
<RowBetween>
|
||||
<RowFixed>
|
||||
<TokenListLogoWrapper src={TokenListLogo} />
|
||||
<TYPE.main ml="6px" fontSize="12px" color={theme.text1}>
|
||||
Expanded results from inactive Token Lists
|
||||
</TYPE.main>
|
||||
</RowFixed>
|
||||
<QuestionHelper text="Tokens from inactive lists. Import specific tokens below or click 'Manage' to activate more lists." />
|
||||
</RowBetween>
|
||||
</LightGreyCard>
|
||||
</FixedContentRow>
|
||||
)
|
||||
}
|
||||
|
||||
if (showImport && token) {
|
||||
return (
|
||||
<ImportRow
|
||||
@@ -189,7 +232,17 @@ export default function CurrencyList({
|
||||
)
|
||||
}
|
||||
},
|
||||
[chainId, inactiveTokens, onCurrencySelect, otherCurrency, selectedCurrency, setImportToken, showImportView]
|
||||
[
|
||||
chainId,
|
||||
inactiveTokens,
|
||||
onCurrencySelect,
|
||||
otherCurrency,
|
||||
selectedCurrency,
|
||||
setImportToken,
|
||||
showImportView,
|
||||
breakIndex,
|
||||
theme.text1
|
||||
]
|
||||
)
|
||||
|
||||
const itemKey = useCallback((index: number, data: any) => currencyKey(data[index]), [])
|
||||
|
||||
@@ -12,7 +12,7 @@ import Column from '../Column'
|
||||
import Row, { RowBetween, RowFixed } from '../Row'
|
||||
import CommonBases from './CommonBases'
|
||||
import CurrencyList from './CurrencyList'
|
||||
import { filterTokens } from './filtering'
|
||||
import { filterTokens, useSortedTokensByQuery } from './filtering'
|
||||
import { useTokenComparator } from './sorting'
|
||||
import { PaddedColumn, SearchInput, Separator } from './styleds'
|
||||
import AutoSizer from 'react-virtualized-auto-sizer'
|
||||
@@ -22,7 +22,7 @@ import { useOnClickOutside } from 'hooks/useOnClickOutside'
|
||||
import useTheme from 'hooks/useTheme'
|
||||
import ImportRow from './ImportRow'
|
||||
import { Edit } from 'react-feather'
|
||||
import { ButtonLight } from 'components/Button'
|
||||
import useDebounce from 'hooks/useDebounce'
|
||||
|
||||
const ContentWrapper = styled(Column)`
|
||||
width: 100%;
|
||||
@@ -71,14 +71,15 @@ export function CurrencySearch({
|
||||
const fixedList = useRef<FixedSizeList>()
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState<string>('')
|
||||
const debouncedQuery = useDebounce(searchQuery, 200)
|
||||
|
||||
const [invertSearchOrder] = useState<boolean>(false)
|
||||
|
||||
const allTokens = useAllTokens()
|
||||
// const inactiveTokens: Token[] | undefined = useFoundOnInactiveList(searchQuery)
|
||||
|
||||
// if they input an address, use it
|
||||
const isAddressSearch = isAddress(searchQuery)
|
||||
const searchToken = useToken(searchQuery)
|
||||
const isAddressSearch = isAddress(debouncedQuery)
|
||||
const searchToken = useToken(debouncedQuery)
|
||||
const searchTokenIsAdded = useIsUserAddedToken(searchToken)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -92,46 +93,21 @@ export function CurrencySearch({
|
||||
}, [isAddressSearch])
|
||||
|
||||
const showETH: boolean = useMemo(() => {
|
||||
const s = searchQuery.toLowerCase().trim()
|
||||
const s = debouncedQuery.toLowerCase().trim()
|
||||
return s === '' || s === 'e' || s === 'et' || s === 'eth'
|
||||
}, [searchQuery])
|
||||
}, [debouncedQuery])
|
||||
|
||||
const tokenComparator = useTokenComparator(invertSearchOrder)
|
||||
|
||||
const filteredTokens: Token[] = useMemo(() => {
|
||||
return filterTokens(Object.values(allTokens), searchQuery)
|
||||
}, [allTokens, searchQuery])
|
||||
return filterTokens(Object.values(allTokens), debouncedQuery)
|
||||
}, [allTokens, debouncedQuery])
|
||||
|
||||
const filteredSortedTokens: Token[] = useMemo(() => {
|
||||
const sorted = filteredTokens.sort(tokenComparator)
|
||||
const symbolMatch = searchQuery
|
||||
.toLowerCase()
|
||||
.split(/\s+/)
|
||||
.filter(s => s.length > 0)
|
||||
const sortedTokens: Token[] = useMemo(() => {
|
||||
return filteredTokens.sort(tokenComparator)
|
||||
}, [filteredTokens, tokenComparator])
|
||||
|
||||
if (symbolMatch.length > 1) {
|
||||
return sorted
|
||||
}
|
||||
|
||||
return [
|
||||
// sort any exact symbol matches first
|
||||
...sorted.filter(token => token.symbol?.toLowerCase() === symbolMatch[0]),
|
||||
|
||||
// sort by tokens whos symbols start with search substrng
|
||||
...sorted.filter(
|
||||
token =>
|
||||
token.symbol?.toLowerCase().startsWith(searchQuery.toLowerCase().trim()) &&
|
||||
token.symbol?.toLowerCase() !== symbolMatch[0]
|
||||
),
|
||||
|
||||
// rest that dont match upove
|
||||
...sorted.filter(
|
||||
token =>
|
||||
!token.symbol?.toLowerCase().startsWith(searchQuery.toLowerCase().trim()) &&
|
||||
token.symbol?.toLowerCase() !== symbolMatch[0]
|
||||
)
|
||||
]
|
||||
}, [filteredTokens, searchQuery, tokenComparator])
|
||||
const filteredSortedTokens = useSortedTokensByQuery(sortedTokens, debouncedQuery)
|
||||
|
||||
const handleCurrencySelect = useCallback(
|
||||
(currency: Currency) => {
|
||||
@@ -158,12 +134,12 @@ export function CurrencySearch({
|
||||
const handleEnter = useCallback(
|
||||
(e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === 'Enter') {
|
||||
const s = searchQuery.toLowerCase().trim()
|
||||
const s = debouncedQuery.toLowerCase().trim()
|
||||
if (s === 'eth') {
|
||||
handleCurrencySelect(ETHER)
|
||||
} else if (filteredSortedTokens.length > 0) {
|
||||
if (
|
||||
filteredSortedTokens[0].symbol?.toLowerCase() === searchQuery.trim().toLowerCase() ||
|
||||
filteredSortedTokens[0].symbol?.toLowerCase() === debouncedQuery.trim().toLowerCase() ||
|
||||
filteredSortedTokens.length === 1
|
||||
) {
|
||||
handleCurrencySelect(filteredSortedTokens[0])
|
||||
@@ -171,7 +147,7 @@ export function CurrencySearch({
|
||||
}
|
||||
}
|
||||
},
|
||||
[filteredSortedTokens, handleCurrencySelect, searchQuery]
|
||||
[filteredSortedTokens, handleCurrencySelect, debouncedQuery]
|
||||
)
|
||||
|
||||
// menu ui
|
||||
@@ -180,15 +156,8 @@ export function CurrencySearch({
|
||||
useOnClickOutside(node, open ? toggle : undefined)
|
||||
|
||||
// if no results on main list, show option to expand into inactive
|
||||
const [showExpanded, setShowExpanded] = useState(false)
|
||||
const inactiveTokens = useFoundOnInactiveList(searchQuery)
|
||||
|
||||
// reset expanded results on query reset
|
||||
useEffect(() => {
|
||||
if (searchQuery === '') {
|
||||
setShowExpanded(false)
|
||||
}
|
||||
}, [setShowExpanded, searchQuery])
|
||||
const inactiveTokens = useFoundOnInactiveList(debouncedQuery)
|
||||
const filteredInactiveTokens: Token[] = useSortedTokensByQuery(inactiveTokens, debouncedQuery)
|
||||
|
||||
return (
|
||||
<ContentWrapper>
|
||||
@@ -220,7 +189,7 @@ export function CurrencySearch({
|
||||
<Column style={{ padding: '20px 0', height: '100%' }}>
|
||||
<ImportRow token={searchToken} showImportView={showImportView} setImportToken={setImportToken} />
|
||||
</Column>
|
||||
) : filteredSortedTokens?.length > 0 || (showExpanded && inactiveTokens && inactiveTokens.length > 0) ? (
|
||||
) : filteredSortedTokens?.length > 0 || filteredInactiveTokens?.length > 0 ? (
|
||||
<div style={{ flex: '1' }}>
|
||||
<AutoSizer disableWidth>
|
||||
{({ height }) => (
|
||||
@@ -228,8 +197,9 @@ export function CurrencySearch({
|
||||
height={height}
|
||||
showETH={showETH}
|
||||
currencies={
|
||||
showExpanded && inactiveTokens ? filteredSortedTokens.concat(inactiveTokens) : filteredSortedTokens
|
||||
filteredInactiveTokens ? filteredSortedTokens.concat(filteredInactiveTokens) : filteredSortedTokens
|
||||
}
|
||||
breakIndex={inactiveTokens && filteredSortedTokens ? filteredSortedTokens.length : undefined}
|
||||
onCurrencySelect={handleCurrencySelect}
|
||||
otherCurrency={otherSelectedCurrency}
|
||||
selectedCurrency={selectedCurrency}
|
||||
@@ -243,49 +213,10 @@ export function CurrencySearch({
|
||||
) : (
|
||||
<Column style={{ padding: '20px', height: '100%' }}>
|
||||
<TYPE.main color={theme.text3} textAlign="center" mb="20px">
|
||||
No results found in active lists.
|
||||
No results found.
|
||||
</TYPE.main>
|
||||
{inactiveTokens &&
|
||||
inactiveTokens.length > 0 &&
|
||||
!(searchToken && !searchTokenIsAdded) &&
|
||||
searchQuery.length > 1 &&
|
||||
filteredSortedTokens?.length === 0 && (
|
||||
// expand button in line with no results
|
||||
<Row align="center" width="100%" justify="center">
|
||||
<ButtonLight
|
||||
width="fit-content"
|
||||
borderRadius="12px"
|
||||
padding="8px 12px"
|
||||
onClick={() => setShowExpanded(!showExpanded)}
|
||||
>
|
||||
{!showExpanded
|
||||
? `Show ${inactiveTokens.length} more inactive ${inactiveTokens.length === 1 ? 'token' : 'tokens'}`
|
||||
: 'Hide expanded search'}
|
||||
</ButtonLight>
|
||||
</Row>
|
||||
)}
|
||||
</Column>
|
||||
)}
|
||||
|
||||
{inactiveTokens &&
|
||||
inactiveTokens.length > 0 &&
|
||||
!(searchToken && !searchTokenIsAdded) &&
|
||||
(searchQuery.length > 1 || showExpanded) &&
|
||||
(filteredSortedTokens?.length !== 0 || showExpanded) && (
|
||||
// button fixed to bottom
|
||||
<Row align="center" width="100%" justify="center" style={{ position: 'absolute', bottom: '80px', left: 0 }}>
|
||||
<ButtonLight
|
||||
width="fit-content"
|
||||
borderRadius="12px"
|
||||
padding="8px 12px"
|
||||
onClick={() => setShowExpanded(!showExpanded)}
|
||||
>
|
||||
{!showExpanded
|
||||
? `Show ${inactiveTokens.length} more inactive ${inactiveTokens.length === 1 ? 'token' : 'tokens'}`
|
||||
: 'Hide expanded search'}
|
||||
</ButtonLight>
|
||||
</Row>
|
||||
)}
|
||||
<Footer>
|
||||
<Row justify="center">
|
||||
<ButtonText onClick={showManageView} color={theme.blue1} className="list-token-manage-button">
|
||||
|
||||
@@ -21,7 +21,7 @@ const TokenSection = styled.div<{ dim?: boolean }>`
|
||||
grid-gap: 16px;
|
||||
align-items: center;
|
||||
|
||||
opacity: ${({ dim }) => (dim ? '0.6' : '1')};
|
||||
opacity: ${({ dim }) => (dim ? '0.4' : '1')};
|
||||
`
|
||||
|
||||
const CheckIcon = styled(CheckCircle)`
|
||||
@@ -103,7 +103,6 @@ export default function ImportRow({
|
||||
<TYPE.main color={theme.green1}>Active</TYPE.main>
|
||||
</RowFixed>
|
||||
)}
|
||||
{/* </RowBetween> */}
|
||||
</TokenSection>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useMemo } from 'react'
|
||||
import { isAddress } from '../../utils'
|
||||
import { Token } from '@uniswap/sdk'
|
||||
|
||||
@@ -32,13 +33,38 @@ export function filterTokens(tokens: Token[], search: string): Token[] {
|
||||
const { symbol, name } = token
|
||||
return (symbol && matchesSearch(symbol)) || (name && matchesSearch(name))
|
||||
})
|
||||
// .sort((t0: Token, t1: Token) => {
|
||||
// if (t0.symbol && matchesSearch(t0.symbol) && t1.symbol && !matchesSearch(t1.symbol)) {
|
||||
// return -1
|
||||
// }
|
||||
// if (t0.symbol && !matchesSearch(t0.symbol) && t1.symbol && matchesSearch(t1.symbol)) {
|
||||
// return 1
|
||||
// }
|
||||
// return 0
|
||||
// })
|
||||
}
|
||||
|
||||
export function useSortedTokensByQuery(tokens: Token[] | undefined, searchQuery: string): Token[] {
|
||||
return useMemo(() => {
|
||||
if (!tokens) {
|
||||
return []
|
||||
}
|
||||
|
||||
const symbolMatch = searchQuery
|
||||
.toLowerCase()
|
||||
.split(/\s+/)
|
||||
.filter(s => s.length > 0)
|
||||
|
||||
if (symbolMatch.length > 1) {
|
||||
return tokens
|
||||
}
|
||||
|
||||
const exactMatches: Token[] = []
|
||||
const symbolSubtrings: Token[] = []
|
||||
const rest: Token[] = []
|
||||
|
||||
// sort tokens by exact match -> subtring on symbol match -> rest
|
||||
tokens.map(token => {
|
||||
if (token.symbol?.toLowerCase() === symbolMatch[0]) {
|
||||
return exactMatches.push(token)
|
||||
} else if (token.symbol?.toLowerCase().startsWith(searchQuery.toLowerCase().trim())) {
|
||||
return symbolSubtrings.push(token)
|
||||
} else {
|
||||
return rest.push(token)
|
||||
}
|
||||
})
|
||||
|
||||
return [...exactMatches, ...symbolSubtrings, ...rest]
|
||||
}, [tokens, searchQuery])
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import { ChainId } from '@uniswap/sdk'
|
||||
import { ChainId, Currency } from '@uniswap/sdk'
|
||||
import React, { useContext } from 'react'
|
||||
import styled, { ThemeContext } from 'styled-components'
|
||||
import Modal from '../Modal'
|
||||
import { ExternalLink } from '../../theme'
|
||||
import { Text } from 'rebass'
|
||||
import { CloseIcon, CustomLightSpinner } from '../../theme/components'
|
||||
import { RowBetween } from '../Row'
|
||||
import { AlertTriangle, ArrowUpCircle } from 'react-feather'
|
||||
import { ButtonPrimary } from '../Button'
|
||||
import { RowBetween, RowFixed } from '../Row'
|
||||
import { AlertTriangle, ArrowUpCircle, CheckCircle } from 'react-feather'
|
||||
import { ButtonPrimary, ButtonLight } from '../Button'
|
||||
import { AutoColumn, ColumnCenter } from '../Column'
|
||||
import Circle from '../../assets/images/blue-loader.svg'
|
||||
|
||||
import MetaMaskLogo from '../../assets/images/metamask.png'
|
||||
import { getEtherscanLink } from '../../utils'
|
||||
import { useActiveWeb3React } from '../../hooks'
|
||||
import useAddTokenToMetamask from 'hooks/useAddTokenToMetamask'
|
||||
|
||||
const Wrapper = styled.div`
|
||||
width: 100%;
|
||||
@@ -31,6 +32,12 @@ const ConfirmedIcon = styled(ColumnCenter)`
|
||||
padding: 60px 0;
|
||||
`
|
||||
|
||||
const StyledLogo = styled.img`
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
margin-left: 6px;
|
||||
`
|
||||
|
||||
function ConfirmationPendingContent({ onDismiss, pendingText }: { onDismiss: () => void; pendingText: string }) {
|
||||
return (
|
||||
<Wrapper>
|
||||
@@ -63,14 +70,20 @@ function ConfirmationPendingContent({ onDismiss, pendingText }: { onDismiss: ()
|
||||
function TransactionSubmittedContent({
|
||||
onDismiss,
|
||||
chainId,
|
||||
hash
|
||||
hash,
|
||||
currencyToAdd
|
||||
}: {
|
||||
onDismiss: () => void
|
||||
hash: string | undefined
|
||||
chainId: ChainId
|
||||
currencyToAdd?: Currency | undefined
|
||||
}) {
|
||||
const theme = useContext(ThemeContext)
|
||||
|
||||
const { library } = useActiveWeb3React()
|
||||
|
||||
const { addToken, success } = useAddTokenToMetamask(currencyToAdd)
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<Section>
|
||||
@@ -92,6 +105,20 @@ function TransactionSubmittedContent({
|
||||
</Text>
|
||||
</ExternalLink>
|
||||
)}
|
||||
{currencyToAdd && library?.provider?.isMetaMask && (
|
||||
<ButtonLight mt="12px" padding="6px 12px" width="fit-content" onClick={addToken}>
|
||||
{!success ? (
|
||||
<RowFixed>
|
||||
Add {currencyToAdd.symbol} to Metamask <StyledLogo src={MetaMaskLogo} />
|
||||
</RowFixed>
|
||||
) : (
|
||||
<RowFixed>
|
||||
Added {currencyToAdd.symbol}{' '}
|
||||
<CheckCircle size={'16px'} stroke={theme.green1} style={{ marginLeft: '6px' }} />
|
||||
</RowFixed>
|
||||
)}
|
||||
</ButtonLight>
|
||||
)}
|
||||
<ButtonPrimary onClick={onDismiss} style={{ margin: '20px 0 0 0' }}>
|
||||
<Text fontWeight={500} fontSize={20}>
|
||||
Close
|
||||
@@ -162,6 +189,7 @@ interface ConfirmationModalProps {
|
||||
content: () => React.ReactNode
|
||||
attemptingTxn: boolean
|
||||
pendingText: string
|
||||
currencyToAdd?: Currency | undefined
|
||||
}
|
||||
|
||||
export default function TransactionConfirmationModal({
|
||||
@@ -170,7 +198,8 @@ export default function TransactionConfirmationModal({
|
||||
attemptingTxn,
|
||||
hash,
|
||||
pendingText,
|
||||
content
|
||||
content,
|
||||
currencyToAdd
|
||||
}: ConfirmationModalProps) {
|
||||
const { chainId } = useActiveWeb3React()
|
||||
|
||||
@@ -182,7 +211,12 @@ export default function TransactionConfirmationModal({
|
||||
{attemptingTxn ? (
|
||||
<ConfirmationPendingContent onDismiss={onDismiss} pendingText={pendingText} />
|
||||
) : hash ? (
|
||||
<TransactionSubmittedContent chainId={chainId} hash={hash} onDismiss={onDismiss} />
|
||||
<TransactionSubmittedContent
|
||||
chainId={chainId}
|
||||
hash={hash}
|
||||
onDismiss={onDismiss}
|
||||
currencyToAdd={currencyToAdd}
|
||||
/>
|
||||
) : (
|
||||
content()
|
||||
)}
|
||||
|
||||
@@ -104,6 +104,7 @@ export default function ConfirmSwapModal({
|
||||
hash={txHash}
|
||||
content={confirmationContent}
|
||||
pendingText={pendingText}
|
||||
currencyToAdd={trade?.outputAmount.currency}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -210,5 +210,6 @@ export const BLOCKED_ADDRESSES: string[] = [
|
||||
'0x7F367cC41522cE07553e823bf3be79A889DEbe1B',
|
||||
'0xd882cFc20F52f2599D84b8e8D58C7FB62cfE344b',
|
||||
'0x901bb9583b24D97e995513C6778dc6888AB6870e',
|
||||
'0xA7e5d5A720f06526557c513402f2e6B5fA20b008'
|
||||
'0xA7e5d5A720f06526557c513402f2e6B5fA20b008',
|
||||
'0x8576aCC5C05D6Ce88f4e49bf65BdF0C62F91353C'
|
||||
]
|
||||
|
||||
43
src/hooks/useAddTokenToMetamask.ts
Normal file
43
src/hooks/useAddTokenToMetamask.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { getTokenLogoURL } from './../components/CurrencyLogo/index'
|
||||
import { wrappedCurrency } from 'utils/wrappedCurrency'
|
||||
import { Currency, Token } from '@uniswap/sdk'
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useActiveWeb3React } from 'hooks'
|
||||
|
||||
export default function useAddTokenToMetamask(
|
||||
currencyToAdd: Currency | undefined
|
||||
): { addToken: () => void; success: boolean | undefined } {
|
||||
const { library, chainId } = useActiveWeb3React()
|
||||
|
||||
const token: Token | undefined = wrappedCurrency(currencyToAdd, chainId)
|
||||
|
||||
const [success, setSuccess] = useState<boolean | undefined>()
|
||||
|
||||
const addToken = useCallback(() => {
|
||||
if (library && library.provider.isMetaMask && library.provider.request && token) {
|
||||
library.provider
|
||||
.request({
|
||||
method: 'wallet_watchAsset',
|
||||
params: {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
||||
//@ts-ignore // need this for incorrect ethers provider type
|
||||
type: 'ERC20',
|
||||
options: {
|
||||
address: token.address,
|
||||
symbol: token.symbol,
|
||||
decimals: token.decimals,
|
||||
image: getTokenLogoURL(token.address)
|
||||
}
|
||||
}
|
||||
})
|
||||
.then(success => {
|
||||
setSuccess(success)
|
||||
})
|
||||
.catch(() => setSuccess(false))
|
||||
} else {
|
||||
setSuccess(false)
|
||||
}
|
||||
}, [library, token])
|
||||
|
||||
return { addToken, success }
|
||||
}
|
||||
@@ -328,6 +328,7 @@ export default function AddLiquidity({
|
||||
/>
|
||||
)}
|
||||
pendingText={pendingText}
|
||||
currencyToAdd={pair?.liquidityToken}
|
||||
/>
|
||||
<AutoColumn gap="20px">
|
||||
{noLiquidity ||
|
||||
|
||||
@@ -4800,9 +4800,9 @@ caniuse-api@^3.0.0:
|
||||
lodash.uniq "^4.5.0"
|
||||
|
||||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001097:
|
||||
version "1.0.30001105"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001105.tgz#d2cb0b31e5cf2f3ce845033b61c5c01566549abf"
|
||||
integrity sha512-JupOe6+dGMr7E20siZHIZQwYqrllxotAhiaej96y6x00b/48rPt42o+SzOSCPbrpsDWvRja40Hwrj0g0q6LZJg==
|
||||
version "1.0.30001183"
|
||||
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001183.tgz"
|
||||
integrity sha512-7JkwTEE1hlRKETbCFd8HDZeLiQIUcl8rC6JgNjvHCNaxOeNmQ9V4LvQXRUsKIV2CC73qKxljwVhToaA3kLRqTw==
|
||||
|
||||
capture-exit@^2.0.0:
|
||||
version "2.0.0"
|
||||
|
||||
Reference in New Issue
Block a user