Make NostrLogin modal flow work
This commit is contained in:
parent
10a12905ff
commit
1417d46af5
2 changed files with 11 additions and 5 deletions
|
@ -23,4 +23,4 @@ function nostrExtensionLogIn() {
|
|||
};
|
||||
}
|
||||
|
||||
export { nostrExtensionLogIn };
|
||||
export { logInNostr, nostrExtensionLogIn };
|
|
@ -2,9 +2,11 @@ import { nip19 } from 'nostr-tools';
|
|||
import React, { useState } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
import { logInNostr } from 'soapbox/actions/nostr';
|
||||
import EmojiGraphic from 'soapbox/components/emoji-graphic';
|
||||
import { Button, Stack, Modal, Input, FormGroup, Form } from 'soapbox/components/ui';
|
||||
import { NKeys } from 'soapbox/features/nostr/keys';
|
||||
import { useAppDispatch } from 'soapbox/hooks';
|
||||
|
||||
import NostrExtensionIndicator from '../components/nostr-extension-indicator';
|
||||
|
||||
|
@ -16,18 +18,22 @@ const KeyAddStep: React.FC<IKeyAddStep> = ({ onClose }) => {
|
|||
const [nsec, setNsec] = useState('');
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setNsec(e.target.value);
|
||||
setError(undefined);
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const result = nip19.decode(nsec);
|
||||
if (result.type === 'nsec') {
|
||||
const seckey = result.data;
|
||||
NKeys.add(seckey);
|
||||
// TODO: log in, close modal
|
||||
const signer = NKeys.add(seckey);
|
||||
const pubkey = await signer.getPublicKey();
|
||||
dispatch(logInNostr(pubkey));
|
||||
onClose();
|
||||
}
|
||||
} catch (e) {
|
||||
setError('Invalid nsec');
|
||||
|
@ -52,7 +58,7 @@ const KeyAddStep: React.FC<IKeyAddStep> = ({ onClose }) => {
|
|||
/>
|
||||
</FormGroup>
|
||||
|
||||
<Button theme='accent' size='lg' type='submit'>
|
||||
<Button theme='accent' size='lg' type='submit' disabled={!nsec}>
|
||||
Add Key
|
||||
</Button>
|
||||
</Stack>
|
||||
|
|
Loading…
Reference in a new issue