Skip to content

Commit

Permalink
feat: show current market leverage in dropdown (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Jul 22, 2024
1 parent b476b7c commit 6e677ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/state/perpetualsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ export const getCurrentMarketNextFundingRate = createAppSelector(
*/
export const getMarketMaxLeverage = () =>
createAppSelector(
[(state: RootState, marketId: string) => getMarketConfig(state, marketId)],
[
(state: RootState, marketId?: string) =>
marketId != null ? getMarketConfig(state, marketId) : undefined,
],
(marketConfig) => {
const { effectiveInitialMarginFraction, initialMarginFraction } = orEmptyObj(marketConfig);

Expand Down
12 changes: 12 additions & 0 deletions src/views/MarketsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MarketFilters, type MarketData } from '@/constants/markets';
import { AppRoute, MarketsRoute } from '@/constants/routes';

import { useMarketsData } from '@/hooks/useMarketsData';
import { useParameterizedSelector } from '@/hooks/useParameterizedSelector';
import { usePotentialMarkets } from '@/hooks/usePotentialMarkets';
import { useStringGetter } from '@/hooks/useStringGetter';

Expand All @@ -24,6 +25,8 @@ import { ColumnDef, Table } from '@/components/Table';
import { Tag } from '@/components/Tag';
import { Toolbar } from '@/components/Toolbar';

import { getMarketMaxLeverage } from '@/state/perpetualsSelectors';

import { calculateMarketMaxLeverage } from '@/lib/marketsHelpers';
import { MustBigNumber } from '@/lib/numbers';

Expand Down Expand Up @@ -188,6 +191,14 @@ export const MarketsDropdown = memo(
const [isOpen, setIsOpen] = useState(false);
const stringGetter = useStringGetter();
const navigate = useNavigate();
const marketMaxLeverage = useParameterizedSelector(getMarketMaxLeverage, currentMarketId);

const leverageTag =
currentMarketId != null ? (
<Tag>
<Output type={OutputType.Multiple} value={marketMaxLeverage} fractionDigits={0} />
</Tag>
) : undefined;

return (
<$Popover
Expand All @@ -202,6 +213,7 @@ export const MarketsDropdown = memo(
<div>
<AssetIcon symbol={symbol} />
<h2>{currentMarketId}</h2>
{leverageTag}
</div>
)}
<p>
Expand Down

0 comments on commit 6e677ae

Please sign in to comment.