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