Skip to content

Commit

Permalink
fix: add new label to Hooks tab
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Oct 16, 2024
1 parent 60b87ef commit 6bd7efc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 63 deletions.
9 changes: 8 additions & 1 deletion apps/cowswap-frontend/src/common/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export const Routes = {
export type RoutesKeys = keyof typeof Routes
export type RoutesValues = (typeof Routes)[RoutesKeys]

export const MENU_ITEMS: { route: RoutesValues; label: string; fullLabel?: string; description: string }[] = [
export const MENU_ITEMS: {
route: RoutesValues
label: string
fullLabel?: string
description: string
badge?: string
}[] = [
{ route: Routes.SWAP, label: 'Swap', description: 'Trade tokens' },
{ route: Routes.LIMIT_ORDER, label: 'Limit', fullLabel: 'Limit order', description: 'Set your own price' },
{ route: Routes.ADVANCED_ORDERS, label: 'TWAP', description: 'Place orders with a time-weighted average price' },
Expand All @@ -47,4 +53,5 @@ export const HOOKS_STORE_MENU_ITEM = {
route: Routes.HOOKS,
label: 'Hooks',
description: 'Powerful tool to generate pre/post interaction for CoW Protocol',
badge: 'New',
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useMemo, useState } from 'react'

import { Command } from '@cowprotocol/types'
import { BadgeType } from '@cowprotocol/ui'
import type { TradeType } from '@cowprotocol/widget-lib'

import { Trans } from '@lingui/macro'
Expand All @@ -23,6 +22,7 @@ import { parameterizeTradeRoute } from '../../utils/parameterizeTradeRoute'
interface MenuItemConfig {
route: RoutesValues
label: string
badge?: string
}

const TRADE_TYPE_TO_ROUTE: Record<TradeType, string> = {
Expand All @@ -32,16 +32,10 @@ const TRADE_TYPE_TO_ROUTE: Record<TradeType, string> = {
}

interface TradeWidgetLinksProps {
highlightedBadgeText?: string
highlightedBadgeType?: BadgeType
isDropdown?: boolean
}

export function TradeWidgetLinks({
highlightedBadgeText,
highlightedBadgeType,
isDropdown = false,
}: TradeWidgetLinksProps) {
export function TradeWidgetLinks({ isDropdown = false }: TradeWidgetLinksProps) {
const tradeContext = useTradeRouteContext()
const location = useLocation()
const [isDropdownVisible, setDropdownVisible] = useState(false)
Expand Down Expand Up @@ -72,23 +66,12 @@ export function TradeWidgetLinks({
routePath={routePath}
item={item}
isActive={isActive}
badgeText={highlightedBadgeText}
badgeType={highlightedBadgeType}
onClick={() => handleMenuItemClick(item)}
isDropdownVisible={isDropdown && isDropdownVisible}
/>
)
})
}, [
isDropdown,
isDropdownVisible,
enabledItems,
tradeContext,
location.pathname,
highlightedBadgeText,
highlightedBadgeType,
handleMenuItemClick,
])
}, [isDropdown, isDropdownVisible, enabledItems, tradeContext, location.pathname, handleMenuItemClick])

const singleMenuItem = menuItemsElements.length === 1

Expand Down Expand Up @@ -122,25 +105,21 @@ const MenuItem = ({
routePath,
item,
isActive,
badgeText,
badgeType,
onClick,
isDropdownVisible,
}: {
routePath: string
item: MenuItemConfig
isActive: boolean
badgeText?: string
badgeType?: BadgeType
onClick: Command
isDropdownVisible: boolean
}) => (
<styledEl.MenuItem isActive={isActive} onClick={onClick} isDropdownVisible={isDropdownVisible}>
<styledEl.Link to={routePath}>
<Trans>{item.label}</Trans>
{!isActive && badgeText && (
<styledEl.Badge type={badgeType}>
<Trans>{badgeText}</Trans>
{!isActive && item.badge && (
<styledEl.Badge type="information">
<Trans>{item.badge}</Trans>
</styledEl.Badge>
)}
</styledEl.Link>
Expand Down

0 comments on commit 6bd7efc

Please sign in to comment.