Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
torztomasz committed Aug 3, 2023
1 parent b9b764e commit bf141ed
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 14 deletions.
21 changes: 11 additions & 10 deletions packages/frontend/src/view/components/page/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import { NavLink, NavLinkTitle } from './NavLink'
interface NavbarProps {
readonly context: PageContext
readonly searchBar: boolean
readonly path: string
readonly activeNavItem: NavLinkTitle | undefined
}

export function Navbar({ searchBar = true, context, path }: NavbarProps) {
export function Navbar({
searchBar = true,
context,
activeNavItem,
}: NavbarProps) {
const { user, instanceName, tradingMode, chainId } = context
const isMainnet = chainId === 1
const navItems = getNavLinks(context.showL2Transactions)
Expand All @@ -35,11 +39,8 @@ export function Navbar({ searchBar = true, context, path }: NavbarProps) {
</a>
<div className="absolute top-1/2 left-1/2 hidden -translate-x-1/2 -translate-y-1/2 transform items-center xl:flex">
{navItems.map((item) => {
const isSelected =
path.startsWith(item.href) ||
(item.activeOn
? item.activeOn.some((link) => path.startsWith(link))
: false)
const isSelected = item.title === activeNavItem

return (
<NavLink
key={item.title}
Expand Down Expand Up @@ -89,8 +90,9 @@ export function Navbar({ searchBar = true, context, path }: NavbarProps) {
}

function getNavLinks(showL2Transactions: boolean) {
const navItems: { href: string; title: NavLinkTitle; activeOn?: string[] }[] =
[{ href: '/home', title: 'Home' }]
const navItems: { href: string; title: NavLinkTitle }[] = [
{ href: '/', title: 'Home' },
]

if (showL2Transactions) {
navItems.push({ href: '/l2-transactions', title: 'Live transactions' })
Expand All @@ -101,7 +103,6 @@ function getNavLinks(showL2Transactions: boolean) {
{
href: '/forced-transactions',
title: 'Forced transactions',
activeOn: ['/transactions'],
},
{ href: '/offers', title: 'Offers' }
)
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/src/view/components/page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Footer } from './Footer'
import { FreezeBanner } from './FreezeBanner'
import { Head } from './Head'
import { Navbar } from './Navbar'
import { NavLinkTitle } from './NavLink'

interface Props {
context: PageContext | PageContextWithUser
activeNavItem?: NavLinkTitle
withoutSearch?: boolean
description: string
image?: string
Expand Down Expand Up @@ -46,7 +48,7 @@ export function Page(props: Props) {
<Navbar
searchBar={!props.withoutSearch}
context={props.context}
path={props.path}
activeNavItem={props.activeNavItem}
/>
<FreezeBanner freezeStatus={props.context.freezeStatus} />
{props.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function HomeL2TransactionsPage(props: HomeL2TransactionsPageProps) {
return (
<Page
path={L2_TRANSACTIONS_TABLE_PROPS.path}
activeNavItem="Live transactions"
description="Live transactions"
context={props.context}
>
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/view/pages/home/HomeOffersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function HomeOffersPage(props: HomeOffersPageProps) {
return (
<Page
path={OFFER_TABLE_PROPS.path}
activeNavItem="Offers"
description="All available trade offers"
context={props.context}
>
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/view/pages/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function HomePage(props: HomePageProps) {

return (
<Page
path="/home"
path="/"
activeNavItem="Home"
description="This explorer allows you to view everything happening on dYdX from the perspective of the Ethereum blockchain. Browse positions, forced transaction and submit your own forced trades and withdrawals."
context={props.context}
withoutSearch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function HomeStateUpdatesPage(props: HomeStateUpdatesPageProps) {
return (
<Page
path={STATE_UPDATE_TABLE_PROPS.path}
activeNavItem="State updates"
description="Latest state updates"
context={props.context}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function HomeTransactionsPage(props: HomeTransactionsPageProps) {
return (
<Page
path={FORCED_TRANSACTION_TABLE_PROPS.path}
activeNavItem="Forced transactions"
description="All forced transactions"
context={props.context}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function StateUpdatePage(props: StateUpdatePageProps) {
return (
<Page
path={`/state-updates/${props.id}`}
activeNavItem="State updates"
description="Show state update details, including balance changes, transactions and prices"
context={props.context}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function OfferAndForcedTradePage(props: OfferAndForcedTradePageProps) {
return (
<Page
context={props.context}
activeNavItem={common.activeNavItem}
path={common.path}
description={common.description}
>
Expand Down Expand Up @@ -262,13 +263,15 @@ function getCommon(transactionHash?: Hash256, offerId?: string) {
return {
path: `/transactions/${transactionHash.toString()}`,
description: `Details of the ${transactionHash.toString()} forced trade transaction`,
}
activeNavItem: 'Forced transactions',
} as const
}
if (offerId) {
return {
path: `/offers/${offerId}`,
description: `Details of the ${offerId} forced trade offer`,
}
activeNavItem: 'Offers',
} as const
}
throw new Error('No transaction hash or offer id')
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function PerpetualForcedWithdrawalPage(
return (
<Page
context={props.context}
activeNavItem="Forced transactions"
path={`/transactions/${props.transactionHash.toString()}`}
description={`Details of the ${props.transactionHash.toString()} forced withdrawal transaction`}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function RegularWithdrawalPage(props: RegularWithdrawalPageProps) {
return (
<Page
context={props.context}
activeNavItem="Forced transactions"
path={`/transactions/${props.transactionHash.toString()}`}
description={`Details of the ${props.transactionHash.toString()} withdrawal transaction`}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function SpotForcedWithdrawalPage(props: SpotForcedWithdrawalPageProps) {
return (
<Page
context={props.context}
activeNavItem="Forced transactions"
path={`/transactions/${props.transactionHash.toString()}`}
description={`Details of the ${props.transactionHash.toString()} forced withdrawal transaction`}
>
Expand Down

0 comments on commit bf141ed

Please sign in to comment.