Make NostrLogin modal flow work

environments/review-ditto-auth-csh1vn/deployments/4454
Alex Gleason 2024-03-17 15:29:58 -05:00
rodzic 10a12905ff
commit 1417d46af5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 11 dodań i 5 usunięć

Wyświetl plik

@ -23,4 +23,4 @@ function nostrExtensionLogIn() {
};
}
export { nostrExtensionLogIn };
export { logInNostr, nostrExtensionLogIn };

Wyświetl plik

@ -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>