import ContentCopyRounded from '@mui/icons-material/ContentCopyRounded' import DeleteOutline from '@mui/icons-material/DeleteOutline' import History from '@mui/icons-material/History' import MoreHoriz from '@mui/icons-material/MoreHoriz' import OpenInNewRounded from '@mui/icons-material/OpenInNewRounded' import TurnedInNot from '@mui/icons-material/TurnedInNot' import { ListItemAvatar, ListItemText, MenuItem } from '@mui/material' import { useId, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { useNavigate } from 'react-router-dom' import { AccountAvatar } from '../../components/Avatar/AccountAvatar.js' import type { BottomSheetBase } from '../../components/BottomSheet/types.js' import { ListItem } from '../../components/ListItem/ListItem.js' import { ListItemButton } from '../../components/ListItem/ListItemButton.js' import { Menu } from '../../components/Menu.js' import { useExplorer } from '../../hooks/useExplorer.js' import { useHeader } from '../../hooks/useHeader.js' import { useToAddressRequirements } from '../../hooks/useToAddressRequirements.js' import type { Bookmark } from '../../stores/bookmarks/types.js' import { useBookmarkActions } from '../../stores/bookmarks/useBookmarkActions.js' import { useBookmarks } from '../../stores/bookmarks/useBookmarks.js' import { useFieldActions } from '../../stores/form/useFieldActions.js' import { useSendToWalletActions } from '../../stores/settings/useSendToWalletStore.js' import { defaultChainIdsByType } from '../../utils/chainType.js' import { navigationRoutes } from '../../utils/navigationRoutes.js' import { shortenAddress } from '../../utils/wallet.js' import { BookmarkAddressSheet } from './BookmarkAddressSheet.js' import { EmptyListIndicator } from './EmptyListIndicator.js' import { ListContainer, OptionsMenuButton, SendToWalletPageContainer, } from './SendToWalletPage.style.js' export const RecentWalletsPage = () => { const { t } = useTranslation() const navigate = useNavigate() const [selectedRecent, setSelectedRecent] = useState() const bookmarkAddressSheetRef = useRef(null) const { recentWallets } = useBookmarks() const { requiredToChainType } = useToAddressRequirements() const { removeRecentWallet, addBookmark, setSelectedBookmark, addRecentWallet, } = useBookmarkActions() const { setFieldValue } = useFieldActions() const { setSendToWallet } = useSendToWalletActions() const moreMenuId = useId() const [moreMenuAnchorEl, setMenuAnchorEl] = useState() const open = Boolean(moreMenuAnchorEl) const { getAddressLink } = useExplorer() useHeader(t('header.recentWallets')) const handleRecentSelected = (recentWallet: Bookmark) => { addRecentWallet(recentWallet) setFieldValue('toAddress', recentWallet.address, { isTouched: true, isDirty: true, }) setSelectedBookmark(recentWallet) setSendToWallet(true) navigate('../../', { relative: 'path', replace: true, }) } const handleAddBookmark = (bookmark: Bookmark) => { addBookmark(bookmark) navigate(`../${navigationRoutes.bookmarks}`, { relative: 'path', replace: true, }) } const closeMenu = () => { setMenuAnchorEl(null) } const handleMenuOpen = (el: HTMLElement, recentWallet: Bookmark) => { setMenuAnchorEl(el) setSelectedRecent(recentWallet) } const handleCopyAddress = () => { if (selectedRecent) { navigator.clipboard.writeText(selectedRecent.address) } closeMenu() } const handleViewOnExplorer = () => { if (selectedRecent) { window.open( getAddressLink( selectedRecent.address, defaultChainIdsByType[selectedRecent.chainType] ), '_blank' ) } closeMenu() } const handleOpenBookmarkSheet = () => { if (selectedRecent) { setSelectedRecent(selectedRecent) bookmarkAddressSheetRef.current?.open() } closeMenu() } const handleRemoveRecentWallet = () => { if (selectedRecent) { removeRecentWallet(selectedRecent.address) } closeMenu() } return ( {recentWallets.map((recentWallet) => ( handleRecentSelected(recentWallet)} > handleMenuOpen(e.target as HTMLElement, recentWallet) } sx={{ opacity: requiredToChainType && requiredToChainType !== recentWallet.chainType ? 0.5 : 1, }} > ))} {!recentWallets.length && ( }> {t('sendToWallet.noRecentWallets')} )} {t('button.copyAddress')} {t('button.viewOnExplorer')} {t('button.bookmark')} {t('button.delete')} ) }