Commit 206e8457 authored by Noah Zinsmeister's avatar Noah Zinsmeister Committed by GitHub

add route visualization (#808)

* add route visualization

* add border, only show if >2 tokens in the path

* fix flex styles

* more flex tweaks
parent 1e7072d5
import React, { useState, useEffect, useRef, useCallback } from 'react' import React, { useState, useEffect, useRef, useCallback, useContext } from 'react'
import styled, { css } from 'styled-components' import styled, { ThemeContext } from 'styled-components'
import QuestionHelper from '../Question' import QuestionHelper from '../Question'
import { Text } from 'rebass' import { Text } from 'rebass'
...@@ -57,27 +57,9 @@ const Input = styled.input<{ active?: boolean }>` ...@@ -57,27 +57,9 @@ const Input = styled.input<{ active?: boolean }>`
&::-webkit-inner-spin-button { &::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
} }
cursor: inherit; color: ${({ active, theme, color }) => (color === 'red' ? theme.red1 : active ? 'initial' : theme.text1)};
color: ${({ theme }) => theme.text1}; cursor: ${({ active }) => (active ? 'initial' : 'inherit')};
text-align: left; text-align: ${({ active }) => (active ? 'right' : 'left')};
${({ active }) =>
active &&
css`
color: initial;
cursor: initial;
text-align: right;
`}
${({ placeholder }) =>
placeholder !== 'Custom' &&
css`
text-align: right;
color: ${({ theme }) => theme.text1};
`}
${({ color }) =>
color === 'red' &&
css`
color: ${({ theme }) => theme.red1};
`}
` `
const BottomError = styled(Text)<{ show?: boolean }>` const BottomError = styled(Text)<{ show?: boolean }>`
...@@ -109,18 +91,9 @@ const SlippageSelector = styled.div` ...@@ -109,18 +91,9 @@ const SlippageSelector = styled.div`
` `
const Percent = styled.div` const Percent = styled.div`
color: inherit; color: ${({ color, theme }) => (color === 'faded' ? theme.bg1 : color === 'red' ? theme.red1 : 'inherit')};
font-size: 0, 8rem; font-size: 0, 8rem;
flex-grow: 0; flex-grow: 0;
${({ color, theme }) =>
(color === 'faded' &&
css`
color: ${theme.bg1};
`) ||
(color === 'red' &&
css`
color: ${theme.red1};
`)};
` `
export interface SlippageTabsProps { export interface SlippageTabsProps {
...@@ -131,6 +104,7 @@ export interface SlippageTabsProps { ...@@ -131,6 +104,7 @@ export interface SlippageTabsProps {
} }
export default function SlippageTabs({ setRawSlippage, rawSlippage, deadline, setDeadline }: SlippageTabsProps) { export default function SlippageTabs({ setRawSlippage, rawSlippage, deadline, setDeadline }: SlippageTabsProps) {
const theme = useContext(ThemeContext)
const [activeIndex, setActiveIndex] = useState(2) const [activeIndex, setActiveIndex] = useState(2)
const [warningType, setWarningType] = useState(WARNING_TYPE.none) const [warningType, setWarningType] = useState(WARNING_TYPE.none)
...@@ -360,7 +334,9 @@ export default function SlippageTabs({ setRawSlippage, rawSlippage, deadline, se ...@@ -360,7 +334,9 @@ export default function SlippageTabs({ setRawSlippage, rawSlippage, deadline, se
</SlippageSelector> </SlippageSelector>
<AutoColumn gap="sm"> <AutoColumn gap="sm">
<RowFixed padding={'0 20px'}> <RowFixed padding={'0 20px'}>
<TYPE.body fontSize={14}>Deadline</TYPE.body> <TYPE.black fontSize={14} color={theme.text2}>
Deadline
</TYPE.black>
<QuestionHelper text="Deadline in minutes. If your transaction takes longer than this it will revert." /> <QuestionHelper text="Deadline in minutes. If your transaction takes longer than this it will revert." />
</RowFixed> </RowFixed>
<RowFixed padding={'0 20px'}> <RowFixed padding={'0 20px'}>
......
import { Trade, TradeType } from '@uniswap/sdk' import { Trade, TradeType } from '@uniswap/sdk'
import React, { useContext } from 'react' import React, { useContext } from 'react'
import { ChevronUp } from 'react-feather' import { ChevronUp, ChevronRight } from 'react-feather'
import { Text } from 'rebass' import { Text, Flex } from 'rebass'
import { ThemeContext } from 'styled-components' import { ThemeContext } from 'styled-components'
import { Field } from '../../state/swap/actions' import { Field } from '../../state/swap/actions'
import { CursorPointer, TYPE } from '../../theme' import { CursorPointer, TYPE } from '../../theme'
...@@ -12,6 +12,7 @@ import QuestionHelper from '../Question' ...@@ -12,6 +12,7 @@ import QuestionHelper from '../Question'
import { RowBetween, RowFixed } from '../Row' import { RowBetween, RowFixed } from '../Row'
import SlippageTabs, { SlippageTabsProps } from '../SlippageTabs' import SlippageTabs, { SlippageTabsProps } from '../SlippageTabs'
import FormattedPriceImpact from './FormattedPriceImpact' import FormattedPriceImpact from './FormattedPriceImpact'
import TokenLogo from '../TokenLogo'
export interface AdvancedSwapDetailsProps extends SlippageTabsProps { export interface AdvancedSwapDetailsProps extends SlippageTabsProps {
trade: Trade trade: Trade
...@@ -66,6 +67,7 @@ export function AdvancedSwapDetails({ trade, onDismiss, ...slippageTabProps }: A ...@@ -66,6 +67,7 @@ export function AdvancedSwapDetails({ trade, onDismiss, ...slippageTabProps }: A
</RowFixed> </RowFixed>
<FormattedPriceImpact priceImpact={priceImpactWithoutFee} /> <FormattedPriceImpact priceImpact={priceImpactWithoutFee} />
</RowBetween> </RowBetween>
<RowBetween> <RowBetween>
<RowFixed> <RowFixed>
<TYPE.black fontSize={14} fontWeight={400} color={theme.text2}> <TYPE.black fontSize={14} fontWeight={400} color={theme.text2}>
...@@ -78,7 +80,9 @@ export function AdvancedSwapDetails({ trade, onDismiss, ...slippageTabProps }: A ...@@ -78,7 +80,9 @@ export function AdvancedSwapDetails({ trade, onDismiss, ...slippageTabProps }: A
</TYPE.black> </TYPE.black>
</RowBetween> </RowBetween>
</AutoColumn> </AutoColumn>
<SectionBreak /> <SectionBreak />
<RowFixed padding={'0 20px'}> <RowFixed padding={'0 20px'}>
<TYPE.black fontWeight={400} fontSize={14} color={theme.text2}> <TYPE.black fontWeight={400} fontSize={14} color={theme.text2}>
Set slippage tolerance Set slippage tolerance
...@@ -86,6 +90,49 @@ export function AdvancedSwapDetails({ trade, onDismiss, ...slippageTabProps }: A ...@@ -86,6 +90,49 @@ export function AdvancedSwapDetails({ trade, onDismiss, ...slippageTabProps }: A
<QuestionHelper text="Your transaction will revert if the execution price changes by more than this amount after you submit your trade." /> <QuestionHelper text="Your transaction will revert if the execution price changes by more than this amount after you submit your trade." />
</RowFixed> </RowFixed>
<SlippageTabs {...slippageTabProps} /> <SlippageTabs {...slippageTabProps} />
{trade.route.path.length > 2 && (
<AutoColumn style={{ padding: '0 20px' }}>
<RowFixed>
<TYPE.black fontSize={14} fontWeight={400} color={theme.text2}>
Route
</TYPE.black>
<QuestionHelper text="Routing through these tokens resulted in the best price for your trade." />
</RowFixed>
<Flex
px="1rem"
py="0.5rem"
my="0.5rem"
style={{ border: `1px solid ${theme.bg3}`, borderRadius: '1rem' }}
flexWrap="wrap"
width="100%"
justifyContent="space-evenly"
alignItems="center"
>
{trade.route.path
// add a null in-between each item
.flatMap((token, i, array) => {
const lastItem = i === array.length - 1
return lastItem ? [token] : [token, null]
})
.map((token, i) => {
// use null as an indicator to insert chevrons
if (token === null) {
return <ChevronRight key={i} color={theme.text2} />
} else {
return (
<Flex my="0.5rem" alignItems="center" key={token.address} style={{ flexShrink: 0 }}>
<TokenLogo address={token.address} size="1.5rem" />
<TYPE.black fontSize={14} color={theme.text1} ml="0.5rem">
{token.symbol}
</TYPE.black>
</Flex>
)
}
})}
</Flex>
</AutoColumn>
)}
</AutoColumn> </AutoColumn>
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment