Skip to content
Open
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
15 changes: 13 additions & 2 deletions src/components/MarketSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useMediaQuery,
useTheme,
} from '@mui/material';
import React, { useMemo, useRef, useState } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { ArrowUpRightIcon } from 'src/components/icons/ArrowUpRightIcon';
import { ChevronUpDownIcon } from 'src/components/icons/ChevronUpDownIcon';
import { FAVOURITE_STAR_COLOR, StarIcon } from 'src/components/icons/StarIcon';
Expand Down Expand Up @@ -294,7 +294,6 @@ export const MarketSwitcher = ({ hideDescription }: MarketSwitcherProps) => {
const [hovered, setHovered] = useState(false);
const [focused, setFocused] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const [showLegacy, setShowLegacy] = useState(false);
const searchRef = useRef<HTMLInputElement>(null);
const triggerRowRef = useRef<HTMLDivElement>(null);

Expand All @@ -307,6 +306,18 @@ export const MarketSwitcher = ({ hideDescription }: MarketSwitcherProps) => {
const toggleFavoriteMarket = useRootStore((store) => store.toggleFavoriteMarket);
const favoriteMarkets = useRootStore((store) => store.favoriteMarkets);

// A legacy market the user is actually on must not be missing from the list: the legacy
Comment thread
shivam-V8 marked this conversation as resolved.
Resolved
// group is only rendered while this is on, so default it from the market being viewed.
const [showLegacy, setShowLegacy] = useState(() => getMarketCategory(currentMarket) === 'legacy');

// The header stays mounted across shallow market changes, and the store hydrates `marketName`
// from the URL after the initial render, so the initialiser alone can latch a stale `false`.
useEffect(() => {
if (getMarketCategory(currentMarket) === 'legacy') {
setShowLegacy(true);
}
}, [currentMarket]);

const handleOpen = () => {
setOpen(true);
};
Expand Down