import { Currency, TradeType } from "@uniswap/sdk-core"; import { Trade } from "@uniswap/v2-sdk"; import React, { Dispatch, useState, SetStateAction, useEffect } from "react"; import { ArrowDown, AlertTriangle } from "react-feather"; import { Text } from "rebass"; import styled from "styled-components"; import { useUSDCValue } from "../../hooks/useUSDCPrice"; import { TYPE } from "../../theme"; import { ButtonPrimary } from "../Button"; import { isAddress, shortenAddress } from "../../utils"; import { computeFiatValuePriceImpact } from "../../utils/computeFiatValuePriceImpact"; import { AutoColumn } from "../Column"; import { FiatValue } from "../CurrencyInputPanel/FiatValue"; import CurrencyLogo from "../CurrencyLogo"; import { RowBetween, RowFixed } from "../Row"; import { TruncatedText, SwapShowAcceptChanges, DisclaimerText, } from "./styleds"; import { AdvancedSwapDetails } from "./AdvancedSwapDetails"; import { LightCard } from "../Card"; import { DarkGreyCard } from "../Card"; import TradePrice from "../order/TradePrice"; import useTheme from "../../hooks/useTheme"; import { useGelatoLimitOrders } from "../../hooks/gelato"; import Toggle from "react-styled-toggle"; export const AnimatedCard = styled(LightCard)<{ expand: boolean }>` padding: 0.75rem; margin-top: 0.5rem; `; 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; `; export default function SwapModalHeader({ trade, recipient, showAcceptChanges, onAcceptChanges, onDisclaimerChange, }: { trade?: Trade; recipient: string | null; showAcceptChanges: boolean; onAcceptChanges: () => void; onDisclaimerChange: Dispatch>; }) { const theme = useTheme(); const [showInverted, setShowInverted] = useState(false); const [showDisclaimer, setShowDisclaimer] = useState(true); const [disclaimer, setDisclaimer] = useState(false); const { derivedOrderInfo: { price, parsedAmounts }, } = useGelatoLimitOrders(); const inputAmount = parsedAmounts.input; const outputAmount = parsedAmounts.output; const fiatValueInput = useUSDCValue(inputAmount); const fiatValueOutput = useUSDCValue(outputAmount); useEffect(() => { onDisclaimerChange(disclaimer); }, []); if (!inputAmount || !outputAmount) return null; const handleDisclaimer = (value: boolean) => { onDisclaimerChange(value); setDisclaimer(value); }; return ( From {inputAmount.currency.symbol} {inputAmount.toSignificant(6)} To {outputAmount.currency.symbol} {outputAmount.toSignificant(6)} {"Limit Price:"} {showDisclaimer && ( )} setShowDisclaimer(!showDisclaimer)} > {!showDisclaimer ? "Show Disclaimer" : "Hide Disclaimer"} handleDisclaimer(!disclaimer)} labelLeft={"Accept Disclaimer"} labelRight={""} height={24} sliderHeight={16} width={44} sliderWidth={16} translate={22} /> {showAcceptChanges ? ( Price Updated Accept ) : null} {/* {trade.tradeType === TradeType.EXACT_INPUT ? ( {`Output is estimated.You will receive at least `} {trade.minimumAmountOut(allowedSlippage).toSignificant(6)}{" "} {outputAmount.currency.symbol} {" or the transaction will revert."} ) : ( {`Input is estimated.You will sell at most`} {trade.maximumAmountIn(allowedSlippage).toSignificant(6)}{" "} {inputAmount.currency.symbol} {" or the transaction will revert."} )} */} {recipient !== null ? ( Output will be sent to{" "} {isAddress(recipient) ? shortenAddress(recipient) : recipient} ) : null} ); }