|
|
@ -1,5 +1,5 @@
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
|
|
|
|
|
|
|
|
|
|
|
import { accountLookup } from 'soapbox/actions/accounts';
|
|
|
|
import { accountLookup } from 'soapbox/actions/accounts';
|
|
|
|
import { Button, Form, FormGroup, HStack, Input, Stack, Modal } from 'soapbox/components/ui';
|
|
|
|
import { Button, Form, FormGroup, HStack, Input, Stack, Modal } from 'soapbox/components/ui';
|
|
|
@ -15,40 +15,44 @@ interface IIdentityStep {
|
|
|
|
onClose(): void;
|
|
|
|
onClose(): void;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
|
|
|
|
notFound: { id: 'nostr_signin.identity.not_found', defaultMessage: 'Account not found' },
|
|
|
|
|
|
|
|
nsec: { id: 'nostr_signin.identity.nsec', defaultMessage: 'Enter your public key' },
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const IdentityStep: React.FC<IIdentityStep> = ({ setAccountId, setStep, onClose }) => {
|
|
|
|
const IdentityStep: React.FC<IIdentityStep> = ({ setAccountId, setStep, onClose }) => {
|
|
|
|
|
|
|
|
const intl = useIntl();
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [error, setError] = useState<string>();
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [notFound, setNotFound] = useState(false);
|
|
|
|
|
|
|
|
const [username, setUsername] = useState('');
|
|
|
|
const [username, setUsername] = useState('');
|
|
|
|
|
|
|
|
|
|
|
|
const handleChangeUsername: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
|
|
|
const handleChangeUsername: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
|
|
|
setNotFound(false);
|
|
|
|
setError(undefined);
|
|
|
|
setUsername(e.target.value);
|
|
|
|
setUsername(e.target.value);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
setLoading(true);
|
|
|
|
setLoading(true);
|
|
|
|
|
|
|
|
|
|
|
|
await dispatch(accountLookup(username))
|
|
|
|
if (username.startsWith('nsec1')) {
|
|
|
|
.then((account) => {
|
|
|
|
setError(intl.formatMessage(messages.nsec));
|
|
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const account = await dispatch(accountLookup(username));
|
|
|
|
setAccountId(account.id);
|
|
|
|
setAccountId(account.id);
|
|
|
|
setStep('account');
|
|
|
|
setStep('account');
|
|
|
|
setNotFound(false);
|
|
|
|
} catch (e: any) {
|
|
|
|
setLoading(false);
|
|
|
|
if (e.response?.status === 404) {
|
|
|
|
})
|
|
|
|
setError(intl.formatMessage(messages.notFound));
|
|
|
|
.catch((error) => {
|
|
|
|
|
|
|
|
if (error.response?.status === 404) {
|
|
|
|
|
|
|
|
setNotFound(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setLoading(false);
|
|
|
|
setLoading(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const errors: string[] = [];
|
|
|
|
|
|
|
|
if (notFound) {
|
|
|
|
|
|
|
|
errors.push('Account not found');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Modal title={<FormattedMessage id='nostr_signin.identity.title' defaultMessage='Who are you?' />} onClose={onClose}>
|
|
|
|
<Modal title={<FormattedMessage id='nostr_signin.identity.title' defaultMessage='Who are you?' />} onClose={onClose}>
|
|
|
@ -60,7 +64,7 @@ const IdentityStep: React.FC<IIdentityStep> = ({ setAccountId, setStep, onClose
|
|
|
|
|
|
|
|
|
|
|
|
<EmojiGraphic emoji='🕵️' />
|
|
|
|
<EmojiGraphic emoji='🕵️' />
|
|
|
|
|
|
|
|
|
|
|
|
<FormGroup labelText='Username' errors={errors}>
|
|
|
|
<FormGroup labelText='Username' errors={error ? [error] : []}>
|
|
|
|
<Input
|
|
|
|
<Input
|
|
|
|
icon={require('@tabler/icons/at.svg')}
|
|
|
|
icon={require('@tabler/icons/at.svg')}
|
|
|
|
placeholder='Username or npub'
|
|
|
|
placeholder='Username or npub'
|
|
|
@ -76,7 +80,7 @@ const IdentityStep: React.FC<IIdentityStep> = ({ setAccountId, setStep, onClose
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
theme='accent'
|
|
|
|
theme='accent'
|
|
|
|
type='submit' disabled={!username || loading || notFound}
|
|
|
|
type='submit' disabled={!username || loading || !!error}
|
|
|
|
onClick={handleSubmit}
|
|
|
|
onClick={handleSubmit}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
Next
|
|
|
|
Next
|
|
|
|