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>(
|
const { entity: account, isUnauthorized, ...result } = useEntityLookup<Account>(
|
||||||
Entities.ACCOUNTS,
|
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}`),
|
() => api.get(`/api/v1/accounts/lookup?acct=${acct}`),
|
||||||
{ schema: accountSchema, enabled: !!acct },
|
{ schema: accountSchema, enabled: !!acct },
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,7 +16,7 @@ interface INostrSigninModal {
|
||||||
const NostrSigninModal: React.FC<INostrSigninModal> = ({ onClose }) => {
|
const NostrSigninModal: React.FC<INostrSigninModal> = ({ onClose }) => {
|
||||||
const [step, setStep] = useState(0);
|
const [step, setStep] = useState(0);
|
||||||
|
|
||||||
const [username, setUsername] = useState('');
|
const [accountId, setAccountId] = useState<string | undefined>();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
onClose('NOSTR_SIGNIN');
|
onClose('NOSTR_SIGNIN');
|
||||||
|
@ -27,11 +27,11 @@ const NostrSigninModal: React.FC<INostrSigninModal> = ({ onClose }) => {
|
||||||
case 0:
|
case 0:
|
||||||
return <ExtensionStep setStep={setStep} />;
|
return <ExtensionStep setStep={setStep} />;
|
||||||
case 1:
|
case 1:
|
||||||
return <IdentityStep username={username} setUsername={setUsername} setStep={setStep} />;
|
return <IdentityStep setAccountId={setAccountId} setStep={setStep} />;
|
||||||
case 2:
|
case 2:
|
||||||
return <KeyStep setStep={setStep} />;
|
return <KeyStep setStep={setStep} />;
|
||||||
case 3:
|
case 3:
|
||||||
return <AccountStep username={username} />;
|
return <AccountStep accountId={accountId!} />;
|
||||||
case 4:
|
case 4:
|
||||||
return <RegisterStep />;
|
return <RegisterStep />;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
import { NSchema as n } from 'nspec';
|
import { NSchema as n } from 'nspec';
|
||||||
import React, { useMemo } from 'react';
|
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 { Avatar, Text, Stack, Emoji, Button, Tooltip } from 'soapbox/components/ui';
|
||||||
import { useInstance } from 'soapbox/hooks';
|
import { useInstance } from 'soapbox/hooks';
|
||||||
|
|
||||||
interface IAccountStep {
|
interface IAccountStep {
|
||||||
username: string;
|
accountId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AccountStep: React.FC<IAccountStep> = ({ username }) => {
|
const AccountStep: React.FC<IAccountStep> = ({ accountId }) => {
|
||||||
const { account } = useAccountLookup(username);
|
const { account } = useAccount(accountId);
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
|
|
||||||
const isBech32 = useMemo(
|
const isBech32 = useMemo(
|
||||||
|
|
|
@ -13,16 +13,16 @@ import EmojiGraphic from '../components/emoji-graphic';
|
||||||
import NostrExtensionIndicator from '../components/nostr-extension-indicator';
|
import NostrExtensionIndicator from '../components/nostr-extension-indicator';
|
||||||
|
|
||||||
interface IIdentityStep {
|
interface IIdentityStep {
|
||||||
username: string;
|
setAccountId(accountId: string): void;
|
||||||
setUsername(username: string): void;
|
|
||||||
setStep(step: number): void;
|
setStep(step: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const IdentityStep: React.FC<IIdentityStep> = ({ username, setUsername, setStep }) => {
|
const IdentityStep: React.FC<IIdentityStep> = ({ setAccountId, setStep }) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [notFound, setNotFound] = useState(false);
|
const [notFound, setNotFound] = useState(false);
|
||||||
|
const [username, setUsername] = useState('');
|
||||||
|
|
||||||
const handleChangeUsername: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
const handleChangeUsername: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
setNotFound(false);
|
setNotFound(false);
|
||||||
|
@ -33,7 +33,8 @@ const IdentityStep: React.FC<IIdentityStep> = ({ username, setUsername, setStep
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
await dispatch(accountLookup(username))
|
await dispatch(accountLookup(username))
|
||||||
.then(() => {
|
.then((account) => {
|
||||||
|
setAccountId(account.id);
|
||||||
setStep(3);
|
setStep(3);
|
||||||
setNotFound(false);
|
setNotFound(false);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
Loading…
Reference in a new issue