NostrSigninModal: hold accountId instead of username in the state
This commit is contained in:
parent
872be9ead1
commit
9ddcb1634e
4 changed files with 13 additions and 12 deletions
|
@ -22,7 +22,7 @@ function useAccountLookup(acct: string | undefined, opts: UseAccountLookupOpts =
|
|||
|
||||
const { entity: account, isUnauthorized, ...result } = useEntityLookup<Account>(
|
||||
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 },
|
||||
);
|
||||
|
|
|
@ -16,7 +16,7 @@ interface INostrSigninModal {
|
|||
const NostrSigninModal: React.FC<INostrSigninModal> = ({ onClose }) => {
|
||||
const [step, setStep] = useState(0);
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [accountId, setAccountId] = useState<string | undefined>();
|
||||
|
||||
const handleClose = () => {
|
||||
onClose('NOSTR_SIGNIN');
|
||||
|
@ -27,11 +27,11 @@ const NostrSigninModal: React.FC<INostrSigninModal> = ({ onClose }) => {
|
|||
case 0:
|
||||
return <ExtensionStep setStep={setStep} />;
|
||||
case 1:
|
||||
return <IdentityStep username={username} setUsername={setUsername} setStep={setStep} />;
|
||||
return <IdentityStep setAccountId={setAccountId} setStep={setStep} />;
|
||||
case 2:
|
||||
return <KeyStep setStep={setStep} />;
|
||||
case 3:
|
||||
return <AccountStep username={username} />;
|
||||
return <AccountStep accountId={accountId!} />;
|
||||
case 4:
|
||||
return <RegisterStep />;
|
||||
}
|
||||
|
|
|
@ -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<IAccountStep> = ({ username }) => {
|
||||
const { account } = useAccountLookup(username);
|
||||
const AccountStep: React.FC<IAccountStep> = ({ accountId }) => {
|
||||
const { account } = useAccount(accountId);
|
||||
const instance = useInstance();
|
||||
|
||||
const isBech32 = useMemo(
|
||||
|
|
|
@ -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<IIdentityStep> = ({ username, setUsername, setStep }) => {
|
||||
const IdentityStep: React.FC<IIdentityStep> = ({ setAccountId, setStep }) => {
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [notFound, setNotFound] = useState(false);
|
||||
const [username, setUsername] = useState('');
|
||||
|
||||
const handleChangeUsername: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||
setNotFound(false);
|
||||
|
@ -33,7 +33,8 @@ const IdentityStep: React.FC<IIdentityStep> = ({ username, setUsername, setStep
|
|||
setLoading(true);
|
||||
|
||||
await dispatch(accountLookup(username))
|
||||
.then(() => {
|
||||
.then((account) => {
|
||||
setAccountId(account.id);
|
||||
setStep(3);
|
||||
setNotFound(false);
|
||||
setLoading(false);
|
||||
|
|
Loading…
Reference in a new issue