From a1c3b0a7f28475698db72ddad01701193ed3ac2c Mon Sep 17 00:00:00 2001 From: Tien Nguyen Date: Wed, 4 Sep 2024 14:53:19 +0700 Subject: [PATCH] improve LO book mobile: re-layout table column (#2528) --- .../swapv2/LimitOrder/OrderBook/OrderItem.tsx | 54 +++------ .../LimitOrder/OrderBook/TableHeader.tsx | 113 ++++-------------- .../swapv2/LimitOrder/OrderBook/index.tsx | 14 +-- 3 files changed, 49 insertions(+), 132 deletions(-) diff --git a/src/components/swapv2/LimitOrder/OrderBook/OrderItem.tsx b/src/components/swapv2/LimitOrder/OrderBook/OrderItem.tsx index c43c6a083a..47e7bfcb44 100644 --- a/src/components/swapv2/LimitOrder/OrderBook/OrderItem.tsx +++ b/src/components/swapv2/LimitOrder/OrderBook/OrderItem.tsx @@ -19,8 +19,8 @@ export const ItemWrapper = styled.div` grid-template-columns: 1fr 2fr 2fr 2fr 1fr; padding: 12px; - ${({ theme }) => theme.mediaWidth.upToSmall` - grid-template-columns: 1.2fr 1.8fr 2fr 1fr; + ${({ theme }) => theme.mediaWidth.upToExtraSmall` + grid-template-columns: 1.2fr 1.8fr 2fr 1.8fr; `} ` @@ -40,15 +40,15 @@ const AmountInfo = ({ plus, amount, currency, - upToSmall, + upToExtraSmall, }: { plus?: boolean amount: string currency?: Currency - upToSmall?: boolean + upToExtraSmall?: boolean }) => ( - + {plus ? '+' : '-'} {amount} @@ -58,15 +58,13 @@ export default function OrderItem({ reverse, order, style, - showAmountOut, }: { reverse?: boolean order: LimitOrderFromTokenPairFormatted style: CSSProperties - showAmountOut: boolean }) { const theme = useTheme() - const upToSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToSmall}px)`) + const upToExtraSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToExtraSmall}px)`) const { currencyIn: makerCurrency, currencyOut: takerCurrency } = useLimitState() const { supportedChains } = useChainsConfig() @@ -79,33 +77,19 @@ export default function OrderItem({ {order.rate} - {!upToSmall ? ( - <> - - - - ) : ( - - )} - - {!upToSmall && 'Filled '} - {order.filled}% - + + + {!upToExtraSmall && Filled {order.filled}%} ) } diff --git a/src/components/swapv2/LimitOrder/OrderBook/TableHeader.tsx b/src/components/swapv2/LimitOrder/OrderBook/TableHeader.tsx index f8595613a4..69484975b0 100644 --- a/src/components/swapv2/LimitOrder/OrderBook/TableHeader.tsx +++ b/src/components/swapv2/LimitOrder/OrderBook/TableHeader.tsx @@ -1,11 +1,9 @@ import { Trans } from '@lingui/macro' import { rgba } from 'polished' -import { useState } from 'react' import { useMedia } from 'react-use' -import { Flex, Text } from 'rebass' +import { Text } from 'rebass' import styled from 'styled-components' -import { ReactComponent as DropdownSvg } from 'assets/svg/down.svg' import { useLimitState } from 'state/limit/hooks' import { MEDIA_WIDTHS } from 'theme' @@ -19,57 +17,11 @@ const Header = styled(ItemWrapper)` font-weight: 500; padding: 16px 12px; cursor: default; - /* :hover { - background-color: ${({ theme }) => rgba(theme.primary, 0.2)}; - } */ ` -const DropdownIcon = styled(DropdownSvg)<{ open: boolean }>` - color: ${({ theme }) => theme.subText}; - transform: rotate(${({ open }) => (open ? '180deg' : '0')}); - transition: transform 300ms; - min-width: 24px; -` - -const TabWrapper = styled.div` - overflow: hidden; - transition: 0.3s ease-in-out; - position: relative; - left: -14px; -` - -const TabContainer = styled.div` - display: flex; - background: ${({ theme }) => theme.buttonBlack}; - border: ${({ theme }) => `1px solid ${theme.border}`}; - width: fit-content; - border-radius: 999px; - padding: 1px; - margin-top: 12px; -` - -const TabItem = styled(Flex)<{ active?: boolean }>` - padding: 4px 8px; - align-items: center; - border-radius: 999px; - background: ${({ theme, active }) => (active ? theme.tabActive : 'transparent')}; - color: ${({ theme, active }) => (active ? theme.text : theme.subText)}; - transition: 0.2s ease-in-out; -` - -export default function TableHeader({ - showAmountOut, - setShowAmountOut, -}: { - showAmountOut: boolean - setShowAmountOut: (value: boolean) => void -}) { - const upToSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToSmall}px)`) +export default function TableHeader() { + const upToExtraSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToExtraSmall}px)`) const { currencyIn, currencyOut } = useLimitState() - const [openDropdown, setOpenDropdown] = useState(false) - - const onClickDropdown = () => setOpenDropdown(!openDropdown) - const onChangeDisplayedAmount = () => setShowAmountOut(!showAmountOut) return (
@@ -78,51 +30,34 @@ export default function TableHeader({ RATE {!!currencyIn && !!currencyOut && ( <> - {upToSmall ?
: ' '}({currencyIn?.symbol}/ + {upToExtraSmall ?
: ' '}({currencyIn?.symbol}/ {currencyOut?.symbol}) )} - {!upToSmall && ( - - AMOUNT - {!!currencyIn && ( - <> - {upToSmall ?
: ' '} - ({currencyIn?.symbol}) - - )} -
- )} -
- - - AMOUNT - {!!currencyIn && !!currencyOut && ( - <> - {upToSmall ?
: ' '} - ({!upToSmall || showAmountOut ? currencyOut?.symbol : currencyIn?.symbol}) - - )} -
- {upToSmall && } -
- {upToSmall && ( - - - - {currencyIn?.symbol} - - - {currencyOut?.symbol} - {' '} - - + + AMOUNT + {!!currencyIn && ( + <> + {upToExtraSmall ?
: ' '} + ({currencyIn?.symbol}) + )} -
+ - ORDER STATUS + AMOUNT + {!!currencyOut && ( + <> + {upToExtraSmall ?
: ' '} + ({currencyOut?.symbol}) + + )}
+ {!upToExtraSmall && ( + + ORDER STATUS + + )}
) } diff --git a/src/components/swapv2/LimitOrder/OrderBook/index.tsx b/src/components/swapv2/LimitOrder/OrderBook/index.tsx index 0c2ae726e2..b20cd97e75 100644 --- a/src/components/swapv2/LimitOrder/OrderBook/index.tsx +++ b/src/components/swapv2/LimitOrder/OrderBook/index.tsx @@ -1,7 +1,7 @@ import { Currency, CurrencyAmount, Token } from '@kyberswap/ks-sdk-core' import { Trans } from '@lingui/macro' import { rgba } from 'polished' -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { useCallback, useEffect, useMemo, useRef } from 'react' import { useMedia } from 'react-use' import { FixedSizeList } from 'react-window' import { Text } from 'rebass' @@ -59,8 +59,8 @@ const MarketPrice = styled.div` display: grid; grid-template-columns: 1fr 2fr 2fr 2fr 1fr; - ${({ theme }) => theme.mediaWidth.upToSmall` - grid-template-columns: 1.2fr 1.8fr 2fr 1fr; + ${({ theme }) => theme.mediaWidth.upToExtraSmall` + grid-template-columns: 1.2fr 1.8fr 2fr 1.8fr; `} ` @@ -184,8 +184,6 @@ export default function OrderBook() { refetch: refetchMarketRate, } = useBaseTradeInfoLimitOrder(makerCurrency, takerCurrency, chainId) - const [showAmountOut, setShowAmountOut] = useState(true) - const ordersWrapperRef = useRef>(null) const { @@ -269,7 +267,7 @@ export default function OrderBook() { )} - + {formattedOrders.length > 0 ? ( {({ index, style }: { index: number; style: CSSProperties }) => { const order = formattedOrders[index] - return + return }} ) : ( @@ -309,7 +307,7 @@ export default function OrderBook() { > {({ index, style }: { index: number; style: CSSProperties }) => { const order = formattedReversedOrders[index] - return + return }} ) : (