chore(trading): make markets in dropdown unique (#2979)
This commit is contained in:
parent
0c26d99ce2
commit
6f4a5b9097
@ -6,6 +6,7 @@ import {
|
|||||||
} from '@vegaprotocol/react-helpers';
|
} from '@vegaprotocol/react-helpers';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||||
import compact from 'lodash/compact';
|
import compact from 'lodash/compact';
|
||||||
|
import uniqBy from 'lodash/uniqBy';
|
||||||
import type { ChangeEvent } from 'react';
|
import type { ChangeEvent } from 'react';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import type { AccountHistoryQuery } from './__generated__/AccountHistory';
|
import type { AccountHistoryQuery } from './__generated__/AccountHistory';
|
||||||
@ -134,15 +135,9 @@ const AccountHistoryManager = ({
|
|||||||
?.filter((item: Account) => Boolean(item && item.market))
|
?.filter((item: Account) => Boolean(item && item.market))
|
||||||
.map<Market>((item) => item.market as Market) ?? null;
|
.map<Market>((item) => item.market as Market) ?? null;
|
||||||
return arr
|
return arr
|
||||||
? Array.from(
|
? uniqBy(arr.filter(marketFilterCb), 'id').sort((a, b) =>
|
||||||
new Set(
|
a.tradableInstrument.instrument.code.localeCompare(
|
||||||
arr
|
b.tradableInstrument.instrument.code
|
||||||
.filter(marketFilterCb)
|
|
||||||
.sort((a, b) =>
|
|
||||||
a.tradableInstrument.instrument.code.localeCompare(
|
|
||||||
b.tradableInstrument.instrument.code
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
@ -240,6 +235,11 @@ const AccountHistoryManager = ({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DropdownMenuContent>
|
<DropdownMenuContent>
|
||||||
|
{market && (
|
||||||
|
<DropdownMenuItem key="0" onClick={() => setMarket(null)}>
|
||||||
|
{t('All markets')}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
{markets?.map((m) => (
|
{markets?.map((m) => (
|
||||||
<DropdownMenuItem key={m.id} onClick={() => resolveMarket(m)}>
|
<DropdownMenuItem key={m.id} onClick={() => resolveMarket(m)}>
|
||||||
{m.tradableInstrument.instrument.code}
|
{m.tradableInstrument.instrument.code}
|
||||||
@ -253,14 +253,12 @@ const AccountHistoryManager = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
accountType !== Schema.AccountType.ACCOUNT_TYPE_MARGIN ||
|
accountType !== Schema.AccountType.ACCOUNT_TYPE_MARGIN ||
|
||||||
(asset &&
|
market?.tradableInstrument.instrument.product.settlementAsset.id !==
|
||||||
market &&
|
asset?.id
|
||||||
market.tradableInstrument.instrument.product.settlementAsset.id !==
|
|
||||||
asset.id)
|
|
||||||
) {
|
) {
|
||||||
setMarket(null);
|
setMarket(null);
|
||||||
}
|
}
|
||||||
}, [accountType, asset, market]);
|
}, [accountType, asset?.id, market]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full w-full flex flex-col gap-8">
|
<div className="h-full w-full flex flex-col gap-8">
|
||||||
|
Loading…
Reference in New Issue
Block a user