Skip to content

Commit

Permalink
feat: ✨ disable export on disconnection state
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSegullo committed Jun 28, 2024
1 parent f1be5fe commit 1b29b36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/components/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Separator,
Trigger,
type DropdownMenuProps as RadixDropdownMenuProps,
type DropdownMenuTriggerProps as RadixDropdownMenuTriggerProps,
} from '@radix-ui/react-dropdown-menu';
import styled from 'styled-components';

Expand Down Expand Up @@ -39,7 +40,11 @@ type ElementProps<T> = {
slotTopContent?: React.ReactNode;
};

export type DropdownMenuProps<T> = StyleProps & ElementProps<T> & RadixDropdownMenuProps;
export type DropdownMenuProps<T> = StyleProps &
ElementProps<T> &
RadixDropdownMenuProps & {
triggerOptions?: RadixDropdownMenuTriggerProps;
};

export const DropdownMenu = forwardRefFn(
<T extends string>(
Expand All @@ -51,13 +56,14 @@ export const DropdownMenu = forwardRefFn(
slotTopContent,
side = 'bottom',
sideOffset = 8,
triggerOptions,
...rest
}: DropdownMenuProps<T>,
ref: Ref<HTMLButtonElement>
) => {
return (
<Root {...rest}>
<$Trigger ref={ref} className={className}>
<$Trigger ref={ref} className={className} {...triggerOptions}>
{children}
<$DropdownIcon aria-hidden="true">
<Icon iconName={IconName.Triangle} aria-hidden="true" />
Expand Down
6 changes: 5 additions & 1 deletion src/views/ExportHistoryDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DropdownMenu } from '@/components/DropdownMenu';
import { Icon, IconName } from '@/components/Icon';
import { OutputType, formatNumber } from '@/components/Output';

import { getSubaccountId } from '@/state/accountSelectors';
import { getIsAccountConnected, getSubaccountId } from '@/state/accountSelectors';
import { useAppSelector } from '@/state/appTypes';
import { getSelectedLocale } from '@/state/localizationSelectors';

Expand All @@ -37,6 +37,7 @@ export const ExportHistoryDropdown = (props: ExportHistoryDropdownProps) => {
const stringGetter = useStringGetter();
const subaccountNumber = useAppSelector(getSubaccountId);
const { dydxAddress } = useAccounts();
const isAccountConnected = useAppSelector(getIsAccountConnected);
const { requestAllAccountFills, requestAllAccountTransfers } = useDydxClient();
const [checkedTrades, setCheckedTrades] = useState(true);
const [checkedTransfers, setCheckedTransfers] = useState(true);
Expand Down Expand Up @@ -294,6 +295,9 @@ export const ExportHistoryDropdown = (props: ExportHistoryDropdownProps) => {
onSelect: exportData,
},
]}
triggerOptions={{
disabled: !isAccountConnected,
}}
{...props}
>
<Icon iconName={IconName.Download} />
Expand Down

0 comments on commit 1b29b36

Please sign in to comment.