diff --git a/src/features/account/components/header.tsx b/src/features/account/components/header.tsx index 392ecd834..837b5c976 100644 --- a/src/features/account/components/header.tsx +++ b/src/features/account/components/header.tsx @@ -1,6 +1,7 @@ import { useMutation } from '@tanstack/react-query'; import { AxiosError } from 'axios'; import { List as ImmutableList } from 'immutable'; +import { nip19 } from 'nostr-tools'; import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { useHistory } from 'react-router-dom'; @@ -45,6 +46,7 @@ const messages = defineMessages({ mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' }, report: { id: 'account.report', defaultMessage: 'Report @{name}' }, copy: { id: 'account.copy', defaultMessage: 'Copy link to profile' }, + npub: { id: 'account.npub', defaultMessage: 'Copy user npub' }, share: { id: 'account.share', defaultMessage: 'Share @{name}\'s profile' }, media: { id: 'account.media', defaultMessage: 'Media' }, blockDomain: { id: 'account.block_domain', defaultMessage: 'Hide everything from {domain}' }, @@ -276,6 +278,10 @@ const Header: React.FC = ({ account }) => { copy(account.url); }; + const handleCopyNpub: React.EventHandler = (e) => { + copy(nip19.npubEncode(account.nostr.pubkey!)); + }; + const makeMenu = () => { const menu: Menu = []; @@ -316,6 +322,14 @@ const Header: React.FC = ({ account }) => { icon: require('@tabler/icons/outline/clipboard-copy.svg'), }); + if (account.nostr.pubkey) { + menu.push({ + text: intl.formatMessage(messages.npub), + action: handleCopyNpub, + icon: require('@tabler/icons/outline/clipboard-copy.svg'), + }); + } + if (!ownAccount) return menu; if (features.searchFromAccount) { diff --git a/src/locales/en.json b/src/locales/en.json index 64d7aa2f9..2a5cad6ce 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -38,6 +38,7 @@ "account.mute": "Mute @{name}", "account.muted": "Muted", "account.never_active": "Never", + "account.npub": "Copy user npub", "account.patron": "Patron", "account.posts": "Posts", "account.posts_with_replies": "Posts & replies",