import { Currency, TradeType, Price, CurrencyAmount } from "@uniswap/sdk-core"; import { Trade } from "@uniswap/v2-sdk"; import React, { useState, useMemo } 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 } 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 { useGelatoStopLimitOrders, useGelatoStopLimitOrdersLib, } from "../../hooks/gelato"; 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, }: { trade?: Trade; recipient: string | null; showAcceptChanges: boolean; onAcceptChanges: () => void; }) { const theme = useTheme(); const [showInverted, setShowInverted] = useState(true); const { derivedOrderInfo: { price, parsedAmounts, rawAmounts }, } = useGelatoStopLimitOrders(); const library = useGelatoStopLimitOrdersLib(); const inputAmount = parsedAmounts.input; const outputAmount = parsedAmounts.output; const fiatValueInput = useUSDCValue(inputAmount); const fiatValueOutput = useUSDCValue(outputAmount); const rawOutputAmount = rawAmounts.output ?? "0"; const { minReturn } = useMemo(() => { if (!outputAmount || !library) return { minReturn: undefined, }; const { minReturn } = library.getFeeAndSlippageAdjustedMinReturn( rawOutputAmount ); const minReturnParsed = CurrencyAmount.fromRawAmount( outputAmount.currency, minReturn ); return { minReturn: minReturnParsed, }; }, [outputAmount, library, rawOutputAmount]); const limitPrice = useMemo( () => minReturn && minReturn.greaterThan(0) && inputAmount ? new Price({ quoteAmount: minReturn, baseAmount: inputAmount, }) : undefined, [inputAmount, minReturn] ); if (!inputAmount || !outputAmount || !outputAmount || !library) return null; return ( From {inputAmount.currency.symbol} {inputAmount.toSignificant(6)} To {outputAmount.currency.symbol} {outputAmount.toSignificant(6)} {"Stop Price:"} {"Limit Price:"} {showAcceptChanges ? ( Price Updated Accept ) : null} {recipient !== null ? ( Output will be sent to{" "} {isAddress(recipient) ? shortenAddress(recipient) : recipient} ) : null} ); }