import { Trade, TradeType } from 'moonbeamswap' import React, { useContext, useMemo } from 'react' import { ArrowDown, AlertTriangle } from 'react-feather' import { Text } from 'rebass' import { ThemeContext } from 'styled-components' import { Field } from '../../state/swap/actions' import { TYPE } from '../../theme' import { ButtonPrimary } from '../Button' import { isAddress, shortenAddress } from '../../utils' import { computeSlippageAdjustedAmounts, computeTradePriceBreakdown, warningSeverity } from '../../utils/prices' import { AutoColumn } from '../Column' import CurrencyLogo from '../CurrencyLogo' import { RowBetween, RowFixed } from '../Row' import { TruncatedText, SwapShowAcceptChanges } from './styleds' export default function SwapModalHeader({ trade, allowedSlippage, recipient, showAcceptChanges, onAcceptChanges }: { trade: Trade allowedSlippage: number recipient: string | null showAcceptChanges: boolean onAcceptChanges: () => void }) { const slippageAdjustedAmounts = useMemo(() => computeSlippageAdjustedAmounts(trade, allowedSlippage), [ trade, allowedSlippage ]) const { priceImpactWithoutFee } = useMemo(() => computeTradePriceBreakdown(trade), [trade]) const priceImpactSeverity = warningSeverity(priceImpactWithoutFee) const theme = useContext(ThemeContext) return ( {trade.inputAmount.toSignificant(6)} {trade.inputAmount.currency.symbol} 2 ? theme.red1 : showAcceptChanges && trade.tradeType === TradeType.EXACT_INPUT ? theme.primary1 : '' } > {trade.outputAmount.toSignificant(6)} {trade.outputAmount.currency.symbol} {showAcceptChanges ? ( Price Updated Accept ) : null} {trade.tradeType === TradeType.EXACT_INPUT ? ( {`Output is estimated. You will receive at least `} {slippageAdjustedAmounts[Field.OUTPUT]?.toSignificant(6)} {trade.outputAmount.currency.symbol} {' or the transaction will revert.'} ) : ( {`Input is estimated. You will sell at most `} {slippageAdjustedAmounts[Field.INPUT]?.toSignificant(6)} {trade.inputAmount.currency.symbol} {' or the transaction will revert.'} )} {recipient !== null ? ( Output will be sent to{' '} {isAddress(recipient) ? shortenAddress(recipient) : recipient} ) : null} ) }