2021-05-12 16:52:17 +03:00
|
|
|
import { Currency, Percent, TradeType } from '@uniswap/sdk-core'
|
2021-04-27 03:35:27 +03:00
|
|
|
import { Trade as V2Trade } from '@uniswap/v2-sdk'
|
|
|
|
import { Trade as V3Trade } from '@uniswap/v3-sdk'
|
2021-05-03 23:32:40 +03:00
|
|
|
import React, { useContext, useState } from 'react'
|
2020-08-07 02:18:43 +03:00
|
|
|
import { ArrowDown, AlertTriangle } from 'react-feather'
|
2020-05-17 00:55:22 +03:00
|
|
|
import { Text } from 'rebass'
|
2021-05-03 23:32:40 +03:00
|
|
|
import styled, { ThemeContext } from 'styled-components'
|
2021-05-04 16:38:47 +03:00
|
|
|
import { useUSDCValue } from '../../hooks/useUSDCPrice'
|
2020-05-17 00:55:22 +03:00
|
|
|
import { TYPE } from '../../theme'
|
2020-08-07 02:18:43 +03:00
|
|
|
import { ButtonPrimary } from '../Button'
|
2021-05-05 01:51:01 +03:00
|
|
|
import { isAddress, shortenAddress } from '../../utils'
|
|
|
|
import { computeFiatValuePriceImpact } from '../../utils/computeFiatValuePriceImpact'
|
2020-05-17 00:55:22 +03:00
|
|
|
import { AutoColumn } from '../Column'
|
2021-05-04 16:38:47 +03:00
|
|
|
import { FiatValue } from '../CurrencyInputPanel/FiatValue'
|
2020-07-20 14:48:42 +03:00
|
|
|
import CurrencyLogo from '../CurrencyLogo'
|
2020-08-07 02:18:43 +03:00
|
|
|
import { RowBetween, RowFixed } from '../Row'
|
|
|
|
import { TruncatedText, SwapShowAcceptChanges } from './styleds'
|
2020-05-17 00:55:22 +03:00
|
|
|
|
2021-05-03 23:32:40 +03:00
|
|
|
import { AdvancedSwapDetails } from './AdvancedSwapDetails'
|
|
|
|
import { LightCard } from '../Card'
|
|
|
|
|
|
|
|
import { DarkGreyCard } from '../Card'
|
|
|
|
import TradePrice from '../swap/TradePrice'
|
|
|
|
|
|
|
|
export const ArrowWrapper = styled.div`
|
|
|
|
padding: 4px;
|
|
|
|
border-radius: 12px;
|
|
|
|
height: 32px;
|
|
|
|
width: 32px;
|
|
|
|
position: relative;
|
|
|
|
margin-top: -18px;
|
|
|
|
margin-bottom: -18px;
|
|
|
|
left: calc(50% - 16px);
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
background-color: ${({ theme }) => theme.bg1};
|
|
|
|
z-index: 2;
|
|
|
|
`
|
|
|
|
|
2020-05-17 00:55:22 +03:00
|
|
|
export default function SwapModalHeader({
|
2020-08-07 02:18:43 +03:00
|
|
|
trade,
|
|
|
|
allowedSlippage,
|
|
|
|
recipient,
|
|
|
|
showAcceptChanges,
|
2021-02-16 11:46:17 +03:00
|
|
|
onAcceptChanges,
|
2020-05-17 00:55:22 +03:00
|
|
|
}: {
|
2021-05-12 16:52:17 +03:00
|
|
|
trade: V2Trade<Currency, Currency, TradeType> | V3Trade<Currency, Currency, TradeType>
|
2021-05-01 06:38:24 +03:00
|
|
|
allowedSlippage: Percent
|
2020-07-09 06:06:29 +03:00
|
|
|
recipient: string | null
|
2020-08-07 02:18:43 +03:00
|
|
|
showAcceptChanges: boolean
|
|
|
|
onAcceptChanges: () => void
|
2020-05-17 00:55:22 +03:00
|
|
|
}) {
|
|
|
|
const theme = useContext(ThemeContext)
|
2020-06-06 01:40:02 +03:00
|
|
|
|
2021-05-03 23:32:40 +03:00
|
|
|
const [showInverted, setShowInverted] = useState<boolean>(false)
|
|
|
|
|
2021-05-14 15:15:53 +03:00
|
|
|
const fiatValueInput = useUSDCValue(trade.inputAmount)
|
|
|
|
const fiatValueOutput = useUSDCValue(trade.outputAmount)
|
2021-05-04 16:38:47 +03:00
|
|
|
|
2020-05-17 00:55:22 +03:00
|
|
|
return (
|
2021-05-03 23:32:40 +03:00
|
|
|
<AutoColumn gap={'4px'} style={{ marginTop: '1rem' }}>
|
|
|
|
<DarkGreyCard padding="0.75rem 1rem">
|
|
|
|
<AutoColumn gap={'8px'}>
|
|
|
|
<RowBetween>
|
|
|
|
<TYPE.body color={theme.text3} fontWeight={500} fontSize={14}>
|
2021-05-04 16:38:47 +03:00
|
|
|
From
|
2021-05-03 23:32:40 +03:00
|
|
|
</TYPE.body>
|
2021-05-04 16:38:47 +03:00
|
|
|
<FiatValue fiatValue={fiatValueInput} />
|
2021-05-03 23:32:40 +03:00
|
|
|
</RowBetween>
|
|
|
|
<RowBetween align="center">
|
|
|
|
<RowFixed gap={'0px'}>
|
|
|
|
<CurrencyLogo currency={trade.inputAmount.currency} size={'20px'} style={{ marginRight: '12px' }} />
|
|
|
|
<Text fontSize={20} fontWeight={500}>
|
|
|
|
{trade.inputAmount.currency.symbol}
|
|
|
|
</Text>
|
|
|
|
</RowFixed>
|
|
|
|
<RowFixed gap={'0px'}>
|
|
|
|
<TruncatedText
|
|
|
|
fontSize={24}
|
|
|
|
fontWeight={500}
|
|
|
|
color={showAcceptChanges && trade.tradeType === TradeType.EXACT_OUTPUT ? theme.primary1 : ''}
|
|
|
|
>
|
2021-05-14 15:15:53 +03:00
|
|
|
{trade.inputAmount.toSignificant(6)}
|
2021-05-03 23:32:40 +03:00
|
|
|
</TruncatedText>
|
|
|
|
</RowFixed>
|
|
|
|
</RowBetween>
|
|
|
|
</AutoColumn>
|
|
|
|
</DarkGreyCard>
|
|
|
|
<ArrowWrapper>
|
|
|
|
<ArrowDown size="16" color={theme.text2} />
|
|
|
|
</ArrowWrapper>
|
|
|
|
<DarkGreyCard padding="0.75rem 1rem" style={{ marginBottom: '0.25rem' }}>
|
|
|
|
<AutoColumn gap={'8px'}>
|
|
|
|
<RowBetween>
|
|
|
|
<TYPE.body color={theme.text3} fontWeight={500} fontSize={14}>
|
2021-05-04 16:38:47 +03:00
|
|
|
To
|
2021-05-03 23:32:40 +03:00
|
|
|
</TYPE.body>
|
|
|
|
<TYPE.body fontSize={14} color={theme.text3}>
|
2021-05-04 16:38:47 +03:00
|
|
|
<FiatValue
|
|
|
|
fiatValue={fiatValueOutput}
|
|
|
|
priceImpact={computeFiatValuePriceImpact(fiatValueInput, fiatValueOutput)}
|
|
|
|
/>
|
2021-05-03 23:32:40 +03:00
|
|
|
</TYPE.body>
|
|
|
|
</RowBetween>
|
|
|
|
<RowBetween align="flex-end">
|
|
|
|
<RowFixed gap={'0px'}>
|
|
|
|
<CurrencyLogo currency={trade.outputAmount.currency} size={'20px'} style={{ marginRight: '12px' }} />
|
|
|
|
<Text fontSize={20} fontWeight={500}>
|
|
|
|
{trade.outputAmount.currency.symbol}
|
|
|
|
</Text>
|
|
|
|
</RowFixed>
|
|
|
|
<RowFixed gap={'0px'}>
|
|
|
|
<TruncatedText fontSize={24} fontWeight={500}>
|
2021-05-14 15:15:53 +03:00
|
|
|
{trade.outputAmount.toSignificant(6)}
|
2021-05-03 23:32:40 +03:00
|
|
|
</TruncatedText>
|
|
|
|
</RowFixed>
|
|
|
|
</RowBetween>
|
|
|
|
</AutoColumn>
|
|
|
|
</DarkGreyCard>
|
|
|
|
<RowBetween style={{ marginTop: '0.25rem', padding: '0 1rem' }}>
|
|
|
|
<TYPE.body color={theme.text2} fontWeight={500} fontSize={14}>
|
|
|
|
{'Price:'}
|
|
|
|
</TYPE.body>
|
2021-05-14 15:15:53 +03:00
|
|
|
<TradePrice price={trade.executionPrice} showInverted={showInverted} setShowInverted={setShowInverted} />
|
2020-05-17 00:55:22 +03:00
|
|
|
</RowBetween>
|
2021-05-03 23:32:40 +03:00
|
|
|
|
|
|
|
<LightCard style={{ padding: '.75rem', marginTop: '0.5rem' }}>
|
2021-05-11 20:00:42 +03:00
|
|
|
<AdvancedSwapDetails trade={trade} allowedSlippage={allowedSlippage} />
|
2021-05-03 23:32:40 +03:00
|
|
|
</LightCard>
|
|
|
|
|
2020-08-07 02:18:43 +03:00
|
|
|
{showAcceptChanges ? (
|
|
|
|
<SwapShowAcceptChanges justify="flex-start" gap={'0px'}>
|
|
|
|
<RowBetween>
|
|
|
|
<RowFixed>
|
|
|
|
<AlertTriangle size={20} style={{ marginRight: '8px', minWidth: 24 }} />
|
|
|
|
<TYPE.main color={theme.primary1}> Price Updated</TYPE.main>
|
|
|
|
</RowFixed>
|
|
|
|
<ButtonPrimary
|
|
|
|
style={{ padding: '.5rem', width: 'fit-content', fontSize: '0.825rem', borderRadius: '12px' }}
|
|
|
|
onClick={onAcceptChanges}
|
|
|
|
>
|
|
|
|
Accept
|
|
|
|
</ButtonPrimary>
|
|
|
|
</RowBetween>
|
|
|
|
</SwapShowAcceptChanges>
|
|
|
|
) : null}
|
2021-05-03 23:32:40 +03:00
|
|
|
|
2021-05-14 15:15:53 +03:00
|
|
|
<AutoColumn justify="flex-start" gap="sm" style={{ padding: '.75rem 1rem' }}>
|
2020-08-07 02:18:43 +03:00
|
|
|
{trade.tradeType === TradeType.EXACT_INPUT ? (
|
2021-05-03 23:32:40 +03:00
|
|
|
<TYPE.italic fontWeight={400} textAlign="left" style={{ width: '100%' }}>
|
2020-05-17 00:55:22 +03:00
|
|
|
{`Output is estimated. You will receive at least `}
|
|
|
|
<b>
|
2021-05-14 15:15:53 +03:00
|
|
|
{trade.minimumAmountOut(allowedSlippage).toSignificant(6)} {trade.outputAmount.currency.symbol}
|
2020-05-17 00:55:22 +03:00
|
|
|
</b>
|
|
|
|
{' or the transaction will revert.'}
|
|
|
|
</TYPE.italic>
|
|
|
|
) : (
|
2021-05-03 23:32:40 +03:00
|
|
|
<TYPE.italic fontWeight={400} textAlign="left" style={{ width: '100%' }}>
|
2020-05-17 00:55:22 +03:00
|
|
|
{`Input is estimated. You will sell at most `}
|
|
|
|
<b>
|
2021-05-14 15:15:53 +03:00
|
|
|
{trade.maximumAmountIn(allowedSlippage).toSignificant(6)} {trade.inputAmount.currency.symbol}
|
2020-05-17 00:55:22 +03:00
|
|
|
</b>
|
|
|
|
{' or the transaction will revert.'}
|
|
|
|
</TYPE.italic>
|
|
|
|
)}
|
2021-05-14 15:15:53 +03:00
|
|
|
</AutoColumn>
|
2020-07-09 06:06:29 +03:00
|
|
|
{recipient !== null ? (
|
|
|
|
<AutoColumn justify="flex-start" gap="sm" style={{ padding: '12px 0 0 0px' }}>
|
|
|
|
<TYPE.main>
|
|
|
|
Output will be sent to{' '}
|
|
|
|
<b title={recipient}>{isAddress(recipient) ? shortenAddress(recipient) : recipient}</b>
|
|
|
|
</TYPE.main>
|
|
|
|
</AutoColumn>
|
|
|
|
) : null}
|
2020-05-17 00:55:22 +03:00
|
|
|
</AutoColumn>
|
|
|
|
)
|
|
|
|
}
|