Skip to content
Closed
Show file tree
Hide file tree
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
30 changes: 7 additions & 23 deletions app/markets/components/markets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SupplyModalV2 } from '@/components/SupplyModalV2';
import { useLocalStorage } from '@/hooks/useLocalStorage';
import { useMarkets } from '@/hooks/useMarkets';
import { usePagination } from '@/hooks/usePagination';
import { useStaredMarkets } from '@/hooks/useStaredMarkets';
import { useStyledToast } from '@/hooks/useStyledToast';
import { SupportedNetworks } from '@/utils/networks';
import { OracleVendors, parseOracleVendors } from '@/utils/oracle';
Expand All @@ -41,17 +42,20 @@ const defaultSortColumn = Object.values(SortColumn).includes(storedSortColumn)
: SortColumn.Supply;

const defaultSortDirection = Number(storage.getItem(keys.MarketSortDirectionKey) ?? '-1');
const defaultStaredMarkets = JSON.parse(
storage.getItem(keys.MarketFavoritesKey) ?? '[]',
) as string[];

/**
* Displays a list of financial markets with advanced filtering, sorting, search, and pagination features.
*
* Integrates user preferences, starred markets, and modal dialogs for market settings and supply actions. Synchronizes filter state with URL parameters and persists user settings in local storage.
*/
export default function Markets() {
const router = useRouter();
const searchParams = useSearchParams();

const toast = useStyledToast();

const { loading, markets: rawMarkets, refetch, isRefetching } = useMarkets();
const { staredIds, starMarket, unstarMarket } = useStaredMarkets();

const {
isOpen: isSettingsModalOpen,
Expand Down Expand Up @@ -82,8 +86,6 @@ export default function Markets() {
const [showSupplyModal, setShowSupplyModal] = useState(false);
const [selectedMarket, setSelectedMarket] = useState<Market | undefined>(undefined);

const [staredIds, setStaredIds] = useState<string[]>(defaultStaredMarkets);

const [filteredMarkets, setFilteredMarkets] = useState<Market[]>([]);

const prevParamsRef = useRef<string>('');
Expand Down Expand Up @@ -129,24 +131,6 @@ export default function Markets() {
}
}, [searchParams]);

const starMarket = useCallback(
(id: string) => {
setStaredIds([...staredIds, id]);
storage.setItem(keys.MarketFavoritesKey, JSON.stringify([...staredIds, id]));
toast.success('Market starred', 'Market added to favorites', { icon: <span>🌟</span> });
},
[staredIds, toast],
);

const unstarMarket = useCallback(
(id: string) => {
setStaredIds(staredIds.filter((i) => i !== id));
storage.setItem(keys.MarketFavoritesKey, JSON.stringify(staredIds.filter((i) => i !== id)));
toast.success('Market unstarred', 'Market removed from favorites', { icon: <span>🌟</span> });
},
[staredIds, toast],
);

useEffect(() => {
// return if no markets
if (!rawMarkets) return;
Expand Down
Loading