From c02f23c322c1dafd0ecc34d226a59f6b2d9622fc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 27 Mar 2024 09:52:07 -0500 Subject: [PATCH] EditIdentity: pull identifiers from Nostr --- src/features/edit-identity/index.tsx | 84 ++++++++++++++++++---------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/src/features/edit-identity/index.tsx b/src/features/edit-identity/index.tsx index 8263e0ca9..8cd48db22 100644 --- a/src/features/edit-identity/index.tsx +++ b/src/features/edit-identity/index.tsx @@ -1,9 +1,11 @@ -import React from 'react'; +import React, { useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { patchMe } from 'soapbox/actions/me'; import List, { ListItem } from 'soapbox/components/list'; import { Button, Column, Emoji, HStack, Icon, Input, Tooltip } from 'soapbox/components/ui'; +import { useNostr } from 'soapbox/contexts/nostr-context'; +import { useNostrReq } from 'soapbox/features/nostr/hooks/useNostrReq'; import { useAppDispatch, useInstance, useOwnAccount } from 'soapbox/hooks'; import toast from 'soapbox/toast'; @@ -18,17 +20,22 @@ const messages = defineMessages({ error: { id: 'edit_profile.error', defaultMessage: 'Profile update failed' }, }); -const identifiers = [ - 'alex@alexgleason.me', - 'lunk@alexgleason.me', - 'yolo@alexgleason.me', -]; - /** EditIdentity component. */ const EditIdentity: React.FC = () => { const intl = useIntl(); + const instance = useInstance(); const dispatch = useAppDispatch(); const { account } = useOwnAccount(); + const { relay, signer } = useNostr(); + + const admin = instance.nostr?.pubkey; + const [username, setUsername] = useState(''); + + const { events: labels } = useNostrReq( + admin + ? [{ kinds: [1985], authors: [admin], '#L': ['nip05'] }] + : [], + ); if (!account) return null; @@ -42,30 +49,51 @@ const EditIdentity: React.FC = () => { } }; + const submit = async () => { + if (!admin || !signer || !relay) return; + + const event = await signer.signEvent({ + kind: 5950, + content: '', + tags: [ + ['i', `${username}@${instance.domain}`, 'text'], + ['p', admin], + ], + created_at: Math.floor(Date.now() / 1000), + }); + + await relay.event(event); + }; + return ( - {identifiers.map((identifier) => ( - - {identifier} - {(account.source?.nostr?.nip05 === identifier && account.acct !== identifier) && ( - -
- -
-
- )} - - } - isSelected={account.source?.nostr?.nip05 === identifier} - onSelect={() => updateNip05(identifier)} - /> - ))} - }> - + {labels.map((label) => { + const identifier = label.tags.find(([name]) => name === 'l')?.[1]; + if (!identifier) return null; + + return ( + + {identifier} + {(account.source?.nostr?.nip05 === identifier && account.acct !== identifier) && ( + +
+ +
+
+ )} + + } + isSelected={account.source?.nostr?.nip05 === identifier} + onSelect={() => updateNip05(identifier)} + /> + ); + })} + setUsername(e.target.value)} />}> +