2023-05-16 16:57:36 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownMenuCheckboxItem,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuItemIndicator,
|
|
|
|
DropdownMenuTrigger,
|
2023-05-17 01:45:17 +00:00
|
|
|
DropdownMenuSeparator,
|
2023-05-16 16:57:36 +00:00
|
|
|
} from '@vegaprotocol/ui-toolkit';
|
|
|
|
|
|
|
|
export const AssetDropdown = ({
|
|
|
|
assets,
|
|
|
|
checkedAssets,
|
|
|
|
onSelect,
|
|
|
|
onReset,
|
|
|
|
}: {
|
|
|
|
assets: Array<{ id: string; symbol: string }> | undefined;
|
|
|
|
checkedAssets: string[];
|
|
|
|
onSelect: (id: string, checked: boolean) => void;
|
|
|
|
onReset: () => void;
|
|
|
|
}) => {
|
|
|
|
if (!assets?.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DropdownMenu
|
|
|
|
trigger={
|
2023-05-17 01:45:17 +00:00
|
|
|
<DropdownMenuTrigger data-testid="asset-trigger">
|
|
|
|
<span className="px-1">$</span>
|
|
|
|
</DropdownMenuTrigger>
|
2023-05-16 16:57:36 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem onClick={onReset}>{t('Reset')}</DropdownMenuItem>
|
2023-05-17 01:45:17 +00:00
|
|
|
<DropdownMenuSeparator />
|
2023-05-16 16:57:36 +00:00
|
|
|
{assets?.map((a) => {
|
|
|
|
return (
|
|
|
|
<DropdownMenuCheckboxItem
|
|
|
|
key={a.id}
|
|
|
|
checked={checkedAssets.includes(a.id)}
|
|
|
|
onCheckedChange={(checked) => {
|
|
|
|
if (typeof checked === 'boolean') {
|
|
|
|
onSelect(a.id, checked);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
data-testid={`asset-id-${a.id}`}
|
|
|
|
>
|
|
|
|
{a.symbol}
|
|
|
|
<DropdownMenuItemIndicator />
|
|
|
|
</DropdownMenuCheckboxItem>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
|
|
|
);
|
|
|
|
};
|