diff --git a/src/components/CurrencyInputPanel/FiatValue.tsx b/src/components/CurrencyInputPanel/FiatValue.tsx index 2e9ae6ca..81d292c2 100644 --- a/src/components/CurrencyInputPanel/FiatValue.tsx +++ b/src/components/CurrencyInputPanel/FiatValue.tsx @@ -10,20 +10,28 @@ import { ThemedText } from 'theme/components' import { NumberType, useFormatter } from 'utils/formatNumbers' import { warningSeverity } from 'utils/prices' -const FiatLoadingBubble = styled(LoadingBubble)` - border-radius: 4px; - width: 4rem; - height: 1rem; +const USDPriceContainer = styled.div` + display: flex; ` -export function FiatValue({ fiatValue, priceImpact }: { fiatValue: number; priceImpact?: Percent }) { +const USDPriceDifferenceText = styled.div<{ difference: number }>` + color: ${({ difference }) => (difference > 0 ? 'green' : 'red')}; + margin-left: 2px; +` + +export function FiatValue({ fiatValue, usdPriceDifference }: { fiatValue: number; usdPriceDifference?: number }) { const { formatNumber } = useFormatter() return ( {fiatValue ? ( - formatNumber({ input: fiatValue, type: NumberType.FiatTokenPrice }) + + {formatNumber({ input: fiatValue, type: NumberType.FiatTokenPrice })}{' '} + {usdPriceDifference && ( + ({usdPriceDifference}%) + )} + ) : ( Not enough liquidity to show accurate USD value.}>- )} diff --git a/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx b/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx index 0688206e..410c78b5 100644 --- a/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx +++ b/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx @@ -222,6 +222,7 @@ interface SwapCurrencyInputPanelProps { pair?: Pair | null hideInput?: boolean otherCurrency?: Currency | null + usdPriceDifference?: number | undefined fiatValue?: number priceImpact?: Percent id: string @@ -249,6 +250,7 @@ const SwapCurrencyInputPanel = forwardRef setTooltipVisible(false), [currency]) @@ -398,7 +400,9 @@ const SwapCurrencyInputPanel = forwardRef )} - {fiatValue === 0 ? 'N/A' : fiatValue && } + {fiatValue === 0 + ? 'N/A' + : fiatValue && } diff --git a/src/pages/Swap/index.tsx b/src/pages/Swap/index.tsx index f719d685..b1769cf4 100644 --- a/src/pages/Swap/index.tsx +++ b/src/pages/Swap/index.tsx @@ -599,6 +599,14 @@ export function Swap({ } }, [separatedFiatValueofLiquidity]) + const usdPriceDifference = useMemo(() => { + if (!token0usdPrice || !token1usdPrice) return undefined + else + return parseFloat( + (((token1usdPrice - token0usdPrice) / ((token0usdPrice + token1usdPrice) / 2)) * 100).toFixed(2) + ) + }, [token0usdPrice, token1usdPrice]) + const amountToApprove = useMemo( () => (trade ? trade.maximumAmountIn(allowedSlippage) : undefined), [trade, allowedSlippage] @@ -961,6 +969,7 @@ export function Swap({ currency={currencies[Field.OUTPUT] ?? null} onCurrencySelect={handleOutputSelect} otherCurrency={currencies[Field.INPUT]} + usdPriceDifference={usdPriceDifference} showCommonBases id={InterfaceSectionName.CURRENCY_OUTPUT_PANEL} loading={independentField === Field.INPUT && routeIsSyncing}