diff --git a/src/actions/nostr.ts b/src/actions/nostr.ts index d82fa49f4..6908f06b6 100644 --- a/src/actions/nostr.ts +++ b/src/actions/nostr.ts @@ -23,4 +23,4 @@ function nostrExtensionLogIn() { }; } -export { nostrExtensionLogIn }; \ No newline at end of file +export { logInNostr, nostrExtensionLogIn }; \ No newline at end of file diff --git a/src/features/ui/components/modals/nostr-login-modal/steps/key-add-step.tsx b/src/features/ui/components/modals/nostr-login-modal/steps/key-add-step.tsx index 15b20dcb0..9153d4966 100644 --- a/src/features/ui/components/modals/nostr-login-modal/steps/key-add-step.tsx +++ b/src/features/ui/components/modals/nostr-login-modal/steps/key-add-step.tsx @@ -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 = ({ onClose }) => { const [nsec, setNsec] = useState(''); const [error, setError] = useState(); + const dispatch = useAppDispatch(); + const handleChange = (e: React.ChangeEvent) => { 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 = ({ onClose }) => { /> -