import { useState } from 'react'; import { Box, ButtonBase, Card, MenuItem, Popover, Tooltip, Typography, useTheme, } from '@mui/material'; import NotificationsIcon from '@mui/icons-material/Notifications'; import AccountBalanceWalletIcon from '@mui/icons-material/AccountBalanceWallet'; import { formatDate } from '../utils/time'; import { useHandlePaymentNotification } from '../hooks/useHandlePaymentNotification'; import { executeEvent } from '../utils/events'; import { useTranslation } from 'react-i18next'; export const GeneralNotifications = ({ address }) => { const [anchorEl, setAnchorEl] = useState(null); const { latestTx, getNameOrAddressOfSenderMiddle, hasNewPayment, setLastEnteredTimestampPayment, nameAddressOfSender, } = useHandlePaymentNotification(address); const handlePopupClick = (event) => { event.stopPropagation(); // Prevent parent onClick from firing setAnchorEl(event.currentTarget); }; const { t } = useTranslation(['core']); const theme = useTheme(); return ( <> { handlePopupClick(e); }} style={{}} > {t('core:payment_notification')} } placement="left" arrow sx={{ fontSize: '24' }} slotProps={{ tooltip: { sx: { color: theme.palette.text.primary, backgroundColor: theme.palette.background.paper, }, }, arrow: { sx: { color: theme.palette.text.primary, }, }, }} > { if (hasNewPayment) { setLastEnteredTimestampPayment(Date.now()); } setAnchorEl(null); }} // Close popover on click outside > {!hasNewPayment && ( {t('core:message.generic.no_notifications')} )} {hasNewPayment && ( { setAnchorEl(null); executeEvent('openWalletsApp', {}); }} > {' '} {formatDate(latestTx?.timestamp)} {latestTx?.amount} {nameAddressOfSender.current[latestTx?.creatorAddress] || getNameOrAddressOfSenderMiddle(latestTx?.creatorAddress)} )} ); };