diff --git a/web/avatars/edit-user-avatar-menu.react.js b/web/avatars/edit-user-avatar-menu.react.js --- a/web/avatars/edit-user-avatar-menu.react.js +++ b/web/avatars/edit-user-avatar-menu.react.js @@ -6,12 +6,16 @@ import { EditUserAvatarContext } from 'lib/components/edit-user-avatar-provider.react.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import SWMansionIcon from 'lib/components/SWMansionIcon.react.js'; +import { useENSAvatar } from 'lib/hooks/ens-cache.js'; +import { getETHAddressForUserInfo } from 'lib/shared/account-utils.js'; import css from './edit-user-avatar-menu.css'; import EmojiAvatarSelectionModal from './emoji-avatar-selection-modal.react.js'; +import CommIcon from '../CommIcon.react.js'; import MenuItem from '../components/menu-item.react.js'; import Menu from '../components/menu.react.js'; import { allowedMimeTypeString } from '../media/file-utils.js'; +import { useSelector } from '../redux/redux-utils.js'; const editIcon = (
@@ -20,6 +24,13 @@ ); function EditUserAvatarMenu(): React.Node { + const currentUserInfo = useSelector(state => state.currentUserInfo); + const ethAddress: ?string = React.useMemo( + () => getETHAddressForUserInfo(currentUserInfo), + [currentUserInfo], + ); + const ensAvatarURI: ?string = useENSAvatar(ethAddress); + const editUserAvatarContext = React.useContext(EditUserAvatarContext); invariant(editUserAvatarContext, 'editUserAvatarContext should be set'); @@ -72,6 +83,28 @@ [onImageMenuItemClicked], ); + const setENSUserAvatar = React.useCallback( + () => baseSetUserAvatar({ type: 'ens' }), + [baseSetUserAvatar], + ); + + const ethereumIcon = React.useMemo( + () => , + [], + ); + + const ensMenuItem = React.useMemo( + () => ( + + ), + [ethereumIcon, setENSUserAvatar], + ); + const removeMenuItem = React.useMemo( () => ( [emojiMenuItem, imageMenuItem, removeMenuItem], - [emojiMenuItem, imageMenuItem, removeMenuItem], - ); + const menuItems = React.useMemo(() => { + const items = [emojiMenuItem, imageMenuItem]; + if (ensAvatarURI) { + items.push(ensMenuItem); + } + if (currentUserInfo?.avatar) { + items.push(removeMenuItem); + } + return items; + }, [ + currentUserInfo?.avatar, + emojiMenuItem, + ensAvatarURI, + ensMenuItem, + imageMenuItem, + removeMenuItem, + ]); return (
diff --git a/web/components/menu.css b/web/components/menu.css --- a/web/components/menu.css +++ b/web/components/menu.css @@ -67,6 +67,7 @@ div.menuActionIcon { display: flex; justify-content: center; + align-items: center; margin-right: 8px; height: 24px; width: 24px;