uniswap-interface-uncensored/src/components/swap/SwapModalHeader.tsx

176 lines
6.5 KiB
TypeScript
Raw Normal View History

import { Trans } from '@lingui/macro'
import { Currency, Percent, TradeType } from '@uniswap/sdk-core'
import { useContext, useState } from 'react'
import { AlertTriangle, ArrowDown } from 'react-feather'
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
import { Text } from 'rebass'
import { InterfaceTrade } from 'state/routing/types'
import styled, { ThemeContext } from 'styled-components/macro'
import { useUSDCValue } from '../../hooks/useUSDCPrice'
import { ThemedText } from '../../theme'
import { isAddress, shortenAddress } from '../../utils'
import { computeFiatValuePriceImpact } from '../../utils/computeFiatValuePriceImpact'
import { ButtonPrimary } from '../Button'
import { LightCard } from '../Card'
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
import { AutoColumn } from '../Column'
import { FiatValue } from '../CurrencyInputPanel/FiatValue'
import CurrencyLogo from '../CurrencyLogo'
import { RowBetween, RowFixed } from '../Row'
import TradePrice from '../swap/TradePrice'
import { AdvancedSwapDetails } from './AdvancedSwapDetails'
import { SwapShowAcceptChanges, TruncatedText } from './styleds'
2021-07-07 00:08:40 +03:00
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};
border: 4px solid;
border-color: ${({ theme }) => theme.bg0};
z-index: 2;
`
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
export default function SwapModalHeader({
trade,
allowedSlippage,
recipient,
showAcceptChanges,
2021-02-16 11:46:17 +03:00
onAcceptChanges,
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
}: {
trade: InterfaceTrade<Currency, Currency, TradeType>
2021-05-01 06:38:24 +03:00
allowedSlippage: Percent
recipient: string | null
showAcceptChanges: boolean
onAcceptChanges: () => void
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
}) {
const theme = useContext(ThemeContext)
const [showInverted, setShowInverted] = useState<boolean>(false)
const fiatValueInput = useUSDCValue(trade.inputAmount)
const fiatValueOutput = useUSDCValue(trade.outputAmount)
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
return (
<AutoColumn gap={'4px'} style={{ marginTop: '1rem' }}>
<LightCard padding="0.75rem 1rem">
<AutoColumn gap={'8px'}>
<RowBetween align="center">
<RowFixed gap={'0px'}>
<TruncatedText
fontSize={24}
fontWeight={500}
color={showAcceptChanges && trade.tradeType === TradeType.EXACT_OUTPUT ? theme.primary1 : ''}
>
{trade.inputAmount.toSignificant(6)}
</TruncatedText>
</RowFixed>
<RowFixed gap={'0px'}>
<CurrencyLogo currency={trade.inputAmount.currency} size={'20px'} style={{ marginRight: '12px' }} />
<Text fontSize={20} fontWeight={500}>
{trade.inputAmount.currency.symbol}
</Text>
</RowFixed>
</RowBetween>
<RowBetween>
<FiatValue fiatValue={fiatValueInput} />
</RowBetween>
</AutoColumn>
</LightCard>
<ArrowWrapper>
<ArrowDown size="16" color={theme.text2} />
</ArrowWrapper>
<LightCard padding="0.75rem 1rem" style={{ marginBottom: '0.25rem' }}>
<AutoColumn gap={'8px'}>
<RowBetween align="flex-end">
<RowFixed gap={'0px'}>
<TruncatedText fontSize={24} fontWeight={500}>
{trade.outputAmount.toSignificant(6)}
</TruncatedText>
</RowFixed>
<RowFixed gap={'0px'}>
<CurrencyLogo currency={trade.outputAmount.currency} size={'20px'} style={{ marginRight: '12px' }} />
<Text fontSize={20} fontWeight={500}>
{trade.outputAmount.currency.symbol}
</Text>
</RowFixed>
</RowBetween>
<RowBetween>
<ThemedText.Body fontSize={14} color={theme.text3}>
<FiatValue
fiatValue={fiatValueOutput}
priceImpact={computeFiatValuePriceImpact(fiatValueInput, fiatValueOutput)}
/>
</ThemedText.Body>
</RowBetween>
</AutoColumn>
</LightCard>
<RowBetween style={{ marginTop: '0.25rem', padding: '0 1rem' }}>
<TradePrice price={trade.executionPrice} showInverted={showInverted} setShowInverted={setShowInverted} />
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
</RowBetween>
<LightCard style={{ padding: '.75rem', marginTop: '0.5rem' }}>
<AdvancedSwapDetails trade={trade} allowedSlippage={allowedSlippage} />
</LightCard>
{showAcceptChanges ? (
<SwapShowAcceptChanges justify="flex-start" gap={'0px'}>
<RowBetween>
<RowFixed>
<AlertTriangle size={20} style={{ marginRight: '8px', minWidth: 24 }} />
<ThemedText.Main color={theme.primary1}>
2021-05-29 03:10:56 +03:00
<Trans>Price Updated</Trans>
</ThemedText.Main>
</RowFixed>
<ButtonPrimary
style={{ padding: '.5rem', width: 'fit-content', fontSize: '0.825rem', borderRadius: '12px' }}
onClick={onAcceptChanges}
>
2021-05-29 03:10:56 +03:00
<Trans>Accept</Trans>
</ButtonPrimary>
</RowBetween>
</SwapShowAcceptChanges>
) : null}
<AutoColumn justify="flex-start" gap="sm" style={{ padding: '.75rem 1rem' }}>
{trade.tradeType === TradeType.EXACT_INPUT ? (
<ThemedText.Italic fontWeight={400} textAlign="left" style={{ width: '100%' }}>
2021-05-29 03:10:56 +03:00
<Trans>
Output is estimated. You will receive at least{' '}
<b>
{trade.minimumAmountOut(allowedSlippage).toSignificant(6)} {trade.outputAmount.currency.symbol}
</b>{' '}
or the transaction will revert.
</Trans>
</ThemedText.Italic>
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
) : (
<ThemedText.Italic fontWeight={400} textAlign="left" style={{ width: '100%' }}>
2021-05-29 03:10:56 +03:00
<Trans>
Input is estimated. You will sell at most{' '}
<b>
{trade.maximumAmountIn(allowedSlippage).toSignificant(6)} {trade.inputAmount.currency.symbol}
</b>{' '}
or the transaction will revert.
</Trans>
</ThemedText.Italic>
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
)}
</AutoColumn>
{recipient !== null ? (
<AutoColumn justify="flex-start" gap="sm" style={{ padding: '12px 0 0 0px' }}>
<ThemedText.Main>
2021-05-29 03:10:56 +03:00
<Trans>
Output will be sent to{' '}
<b title={recipient}>{isAddress(recipient) ? shortenAddress(recipient) : recipient}</b>
</Trans>
</ThemedText.Main>
</AutoColumn>
) : null}
Refactor ExchangePage into Swap and Send pages (#774) * Part 1, separate swap and send, move duplicate code into separate files * Move some more constants out of the swap/send * Support defaults from URL parameters * Implement query string parsing via a redux action * Finish merging the changes * Fix the slippage warnings * Clean up some other files * More refactoring * Move the price bar out of the component * Move advanced details and some computations into utilities * Make same improvements to send * Approval hook * Swap page functional with swap callback hook * Swap/send page functional with swap callback hook * Fix lint * Move styleds.ts * Fix integration test * Fix error state in swap and move some things around * Move send callback out of send page * Make send behave more like current behavior * Differentiate swap w/o send on send page from swap w/o send on swap page * Remove userAdvanced which was always false * Remove the price bar which is not used in the new UI * Delete the file * Fix null in the send dialog and move another component out of send * Move the swap modal header out to another file * Include change after merge * Add recipient to swap message * Keep input token selected if user has no balance and clicks send with swap * Move the modal footer out of send component * Remove the hard coded estimated time * Fix the label/action for swap/sends * Share the swap modal footer between swap and send * Fix integration test * remove margin from popper to suppress warnings fix missing ENS name recipient link default deadline to 15 minutes * ensure useApproveCallback returns accurate data * clean up callbacks * extra space * Re-apply ignored changes from v2 branch ExchangePage file Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
2020-05-17 00:55:22 +03:00
</AutoColumn>
)
}