import { Box, chakra } from '@chakra-ui/react'; import { useRouter } from 'next/router'; import React from 'react'; import type { ItemProps } from './types'; import config from 'configs/app'; import * as mixpanel from 'lib/mixpanel/index'; import getQueryParamString from 'lib/router/getQueryParamString'; import { IconButton } from 'toolkit/chakra/icon-button'; import { MenuContent, MenuRoot, MenuTrigger } from 'toolkit/chakra/menu'; import { Skeleton } from 'toolkit/chakra/skeleton'; import IconSvg from 'ui/shared/IconSvg'; import MetadataUpdateMenuItem from './items/MetadataUpdateMenuItem'; import PrivateTagMenuItem from './items/PrivateTagMenuItem'; import PublicTagMenuItem from './items/PublicTagMenuItem'; import TokenInfoMenuItem from './items/TokenInfoMenuItem'; interface Props { isLoading?: boolean; className?: string; showUpdateMetadataItem?: boolean; } const AccountActionsMenu = ({ isLoading, className, showUpdateMetadataItem }: Props) => { const router = useRouter(); const hash = getQueryParamString(router.query.hash); const isTokenPage = router.pathname === '/token/[hash]'; const isTokenInstancePage = router.pathname === '/token/[hash]/instance/[id]'; const isTxPage = router.pathname === '/tx/[hash]'; const handleButtonClick = React.useCallback(() => { mixpanel.logEvent(mixpanel.EventTypes.PAGE_WIDGET, { Type: 'Address actions (more button)' }); }, []); const items = [ { render: (props: ItemProps) => , enabled: isTokenInstancePage && showUpdateMetadataItem, }, { render: (props: ItemProps) => , enabled: config.features.account.isEnabled && isTokenPage && config.features.addressVerification.isEnabled, }, { render: (props: ItemProps) => , enabled: config.features.account.isEnabled, }, { render: (props: ItemProps) => , enabled: config.features.account.isEnabled && !isTxPage && config.features.publicTagsSubmission.isEnabled, }, ].filter(({ enabled }) => enabled); if (items.length === 0) { return null; } if (isLoading) { return ; } if (items.length === 1) { return ( { items[0].render({ type: 'button', hash }) } ); } return ( { items.map(({ render }, index) => ( { render({ type: 'menu_item', hash }) } )) } ); }; export default React.memo(chakra(AccountActionsMenu));