From 9ddcb1634e79a256f4baef95f0377390a9e32c73 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 18 Feb 2024 13:00:37 -0600 Subject: [PATCH] NostrSigninModal: hold accountId instead of username in the state --- src/api/hooks/accounts/useAccountLookup.ts | 2 +- .../modals/nostr-signin-modal/nostr-signin-modal.tsx | 6 +++--- .../modals/nostr-signin-modal/steps/account-step.tsx | 8 ++++---- .../modals/nostr-signin-modal/steps/identity-step.tsx | 9 +++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/api/hooks/accounts/useAccountLookup.ts b/src/api/hooks/accounts/useAccountLookup.ts index 0e88435b6..7aed05f98 100644 --- a/src/api/hooks/accounts/useAccountLookup.ts +++ b/src/api/hooks/accounts/useAccountLookup.ts @@ -22,7 +22,7 @@ function useAccountLookup(acct: string | undefined, opts: UseAccountLookupOpts = const { entity: account, isUnauthorized, ...result } = useEntityLookup( Entities.ACCOUNTS, - (account) => account.acct.toLowerCase() === acct?.toLowerCase() || account.nostr.npub === acct, + (account) => account.acct.toLowerCase() === acct?.toLowerCase(), () => api.get(`/api/v1/accounts/lookup?acct=${acct}`), { schema: accountSchema, enabled: !!acct }, ); diff --git a/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx b/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx index 479ea53e5..da8ada336 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx @@ -16,7 +16,7 @@ interface INostrSigninModal { const NostrSigninModal: React.FC = ({ onClose }) => { const [step, setStep] = useState(0); - const [username, setUsername] = useState(''); + const [accountId, setAccountId] = useState(); const handleClose = () => { onClose('NOSTR_SIGNIN'); @@ -27,11 +27,11 @@ const NostrSigninModal: React.FC = ({ onClose }) => { case 0: return ; case 1: - return ; + return ; case 2: return ; case 3: - return ; + return ; case 4: return ; } diff --git a/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx b/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx index 2527bd779..8df2447fa 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx @@ -1,16 +1,16 @@ import { NSchema as n } from 'nspec'; import React, { useMemo } from 'react'; -import { useAccountLookup } from 'soapbox/api/hooks'; +import { useAccount } from 'soapbox/api/hooks'; import { Avatar, Text, Stack, Emoji, Button, Tooltip } from 'soapbox/components/ui'; import { useInstance } from 'soapbox/hooks'; interface IAccountStep { - username: string; + accountId: string; } -const AccountStep: React.FC = ({ username }) => { - const { account } = useAccountLookup(username); +const AccountStep: React.FC = ({ accountId }) => { + const { account } = useAccount(accountId); const instance = useInstance(); const isBech32 = useMemo( diff --git a/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx b/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx index 5d20c0b1c..7b043eac5 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx @@ -13,16 +13,16 @@ import EmojiGraphic from '../components/emoji-graphic'; import NostrExtensionIndicator from '../components/nostr-extension-indicator'; interface IIdentityStep { - username: string; - setUsername(username: string): void; + setAccountId(accountId: string): void; setStep(step: number): void; } -const IdentityStep: React.FC = ({ username, setUsername, setStep }) => { +const IdentityStep: React.FC = ({ setAccountId, setStep }) => { const dispatch = useAppDispatch(); const [loading, setLoading] = useState(false); const [notFound, setNotFound] = useState(false); + const [username, setUsername] = useState(''); const handleChangeUsername: React.ChangeEventHandler = (e) => { setNotFound(false); @@ -33,7 +33,8 @@ const IdentityStep: React.FC = ({ username, setUsername, setStep setLoading(true); await dispatch(accountLookup(username)) - .then(() => { + .then((account) => { + setAccountId(account.id); setStep(3); setNotFound(false); setLoading(false);