Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useColorModeValue,
} from '@chakra-ui/react'
import type { JSX } from 'react'
import { useCallback, useMemo, useState } from 'react'
import React, { useCallback, useMemo, useState } from 'react'
import { LuChevronsUpDown } from 'react-icons/lu'
import { useTranslate } from 'react-polyglot'

Expand All @@ -21,6 +21,30 @@ import { useFeatureFlag } from '@/hooks/useFeatureFlag/useFeatureFlag'

const selectorIcon = <LuChevronsUpDown fontSize='1em' />

type ToggleSwitcherProps = {
label: string
onClick: () => void
}

const ToggleSwitcher: React.FC<ToggleSwitcherProps> = ({ label, onClick }) => (
<Flex alignItems='center' mt={4}>
<Divider borderColor='border.subtle' />
<Button
variant='outline'
size='sm'
borderRadius='full'
px={4}
flexShrink={0}
rightIcon={selectorIcon}
fontWeight='medium'
onClick={onClick}
>
{label}
</Button>
<Divider borderColor='border.subtle' />
</Flex>
)

type SharedTradeInputHeaderProps = {
initialTab: TradeInputTab
isStandalone?: boolean
Expand Down Expand Up @@ -90,10 +114,6 @@ export const SharedTradeInputHeader = ({
handleChangeTab(TradeInputTab.Trade)
}, [handleChangeTab])

const handleClickLimitOrder = useCallback(() => {
handleChangeTab(TradeInputTab.LimitOrder)
}, [handleChangeTab])

const handleToggleOrderType = useCallback(() => {
if (selectedTab === TradeInputTab.LimitOrder) {
handleChangeTab(TradeInputTab.Trade)
Expand All @@ -106,10 +126,6 @@ export const SharedTradeInputHeader = ({
handleChangeTab(TradeInputTab.BuyFiat)
}, [handleChangeTab])

const handleClickSellFiat = useCallback(() => {
handleChangeTab(TradeInputTab.SellFiat)
}, [handleChangeTab])

const handleToggleBuySell = useCallback(() => {
if (selectedTab === TradeInputTab.SellFiat) {
handleChangeTab(TradeInputTab.BuyFiat)
Expand Down Expand Up @@ -174,40 +190,10 @@ export const SharedTradeInputHeader = ({
</Flex>
</Flex>
{showOrderTypeSwitcher && (
<Flex alignItems='center' mt={4}>
<Divider borderColor='border.subtle' />
<Button
variant='outline'
size='sm'
borderRadius='full'
px={4}
flexShrink={0}
rightIcon={selectorIcon}
fontWeight='medium'
onClick={handleToggleOrderType}
>
{orderTypeLabel}
</Button>
<Divider borderColor='border.subtle' />
</Flex>
<ToggleSwitcher label={orderTypeLabel} onClick={handleToggleOrderType} />
)}
{showBuySellSwitcher && (
<Flex alignItems='center' mt={4}>
<Divider borderColor='border.subtle' />
<Button
variant='outline'
size='sm'
borderRadius='full'
px={4}
flexShrink={0}
rightIcon={selectorIcon}
fontWeight='medium'
onClick={handleToggleBuySell}
>
{buySellLabel}
</Button>
<Divider borderColor='border.subtle' />
</Flex>
<ToggleSwitcher label={buySellLabel} onClick={handleToggleBuySell} />
)}
</Display.Desktop>
<Display.Mobile>
Expand All @@ -227,64 +213,30 @@ export const SharedTradeInputHeader = ({
px={6}
py={2}
borderRadius='full'
bg={selectedTab === TradeInputTab.Trade ? activeBgColor : 'none'}
color={selectedTab === TradeInputTab.Trade ? activeTextColor : 'text.subtle'}
bg={isSwapOrLimit ? activeBgColor : 'none'}
color={isSwapOrLimit ? activeTextColor : 'text.subtle'}
fontWeight='bold'
fontSize='sm'
onClick={handleClickTrade}
type='button'
>
{translate('navBar.swap')}
</Box>
{enableLimitOrders && !isStandalone && (
<Box
as='button'
px={6}
py={2}
borderRadius='full'
bg={selectedTab === TradeInputTab.LimitOrder ? activeBgColor : 'none'}
color={selectedTab === TradeInputTab.LimitOrder ? activeTextColor : 'text.subtle'}
fontWeight='bold'
fontSize='sm'
ml={-2}
onClick={handleClickLimitOrder}
type='button'
>
{translate('limitOrder.heading')}
</Box>
)}
{enableSwapperFiatRamps && !isStandalone && (
<Box
as='button'
px={6}
py={2}
borderRadius='full'
bg={selectedTab === TradeInputTab.BuyFiat ? activeBgColor : 'none'}
color={selectedTab === TradeInputTab.BuyFiat ? activeTextColor : 'text.subtle'}
bg={isBuyOrSell ? activeBgColor : 'none'}
color={isBuyOrSell ? activeTextColor : 'text.subtle'}
fontWeight='bold'
fontSize='sm'
ml={-2}
onClick={handleClickBuyFiat}
type='button'
>
{translate('fiatRamps.buy')}
</Box>
)}
{enableSwapperFiatRamps && !isStandalone && (
<Box
as='button'
px={6}
py={2}
borderRadius='full'
bg={selectedTab === TradeInputTab.SellFiat ? activeBgColor : 'none'}
color={selectedTab === TradeInputTab.SellFiat ? activeTextColor : 'text.subtle'}
fontWeight='bold'
fontSize='sm'
ml={-2}
onClick={handleClickSellFiat}
type='button'
>
{translate('fiatRamps.sell')}
{translate('navBar.buyCryptoShort')}
</Box>
)}
{enableEarnTab && !isStandalone && (
Expand All @@ -306,6 +258,12 @@ export const SharedTradeInputHeader = ({
)}
</Flex>
</Flex>
{showOrderTypeSwitcher && (
<ToggleSwitcher label={orderTypeLabel} onClick={handleToggleOrderType} />
)}
{showBuySellSwitcher && (
<ToggleSwitcher label={buySellLabel} onClick={handleToggleBuySell} />
)}
</Display.Mobile>
</CardHeader>
)
Expand Down
Loading