From b950a7a0523387dfba6a88328982dda5c2e59c78 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 13 Feb 2024 17:01:07 -0600 Subject: [PATCH] Rework Nostr modal actions --- src/actions/nostr.ts | 13 +++++++------ .../nostr-extension-indicator.tsx | 12 +++++++----- .../nostr-signin-modal/steps/extension-step.tsx | 12 +++++------- .../nostr-signin-modal/steps/identity-step.tsx | 2 +- src/features/ui/components/navbar.tsx | 6 ++---- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/actions/nostr.ts b/src/actions/nostr.ts index 21044140b..ab7dfb8e0 100644 --- a/src/actions/nostr.ts +++ b/src/actions/nostr.ts @@ -1,22 +1,23 @@ import { nip19 } from 'nostr-tools'; -import { signer } from 'soapbox/features/nostr/sign'; import { type AppDispatch } from 'soapbox/store'; import { verifyCredentials } from './auth'; +import { closeModal } from './modals'; -/** Log in with a Nostr pubkey. */ -function nostrLogIn() { +/** Log in with a Nostr extension. */ +function nostrExtensionLogIn() { return async (dispatch: AppDispatch) => { - if (!signer) { + if (!window.nostr) { throw new Error('No Nostr signer available'); } - const pubkey = await signer.getPublicKey(); + const pubkey = await window.nostr.getPublicKey(); const npub = nip19.npubEncode(pubkey); + dispatch(closeModal('NOSTR_SIGNIN')); return dispatch(verifyCredentials(npub)); }; } -export { nostrLogIn }; \ No newline at end of file +export { nostrExtensionLogIn }; \ No newline at end of file diff --git a/src/features/ui/components/modals/nostr-signin-modal/nostr-extension-indicator.tsx b/src/features/ui/components/modals/nostr-signin-modal/nostr-extension-indicator.tsx index 735674a9a..4c5333b51 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/nostr-extension-indicator.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/nostr-extension-indicator.tsx @@ -1,14 +1,16 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import { nostrExtensionLogIn } from 'soapbox/actions/nostr'; import Stack from 'soapbox/components/ui/stack/stack'; import Text from 'soapbox/components/ui/text/text'; +import { useAppDispatch } from 'soapbox/hooks'; -interface INostrExtensionIndicator { - signinAction: () => void; -} +const NostrExtensionIndicator: React.FC = () => { + const dispatch = useAppDispatch(); + + const onClick = () => dispatch(nostrExtensionLogIn()); -const NostrExtensionIndicator: React.FC = ({ signinAction }) => { return ( @@ -17,7 +19,7 @@ const NostrExtensionIndicator: React.FC = ({ signinAct id='nostr_extension.found' defaultMessage='Sign in with browser extension.' values={{ - link: (node) => , + link: (node) => , }} /> ) : ( diff --git a/src/features/ui/components/modals/nostr-signin-modal/steps/extension-step.tsx b/src/features/ui/components/modals/nostr-signin-modal/steps/extension-step.tsx index 97077353c..58c079f3e 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/steps/extension-step.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/steps/extension-step.tsx @@ -1,22 +1,20 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import { nostrExtensionLogIn } from 'soapbox/actions/nostr'; import Button from 'soapbox/components/ui/button/button'; import Stack from 'soapbox/components/ui/stack/stack'; -import { signer } from 'soapbox/features/nostr/sign'; +import { useAppDispatch } from 'soapbox/hooks'; interface IExtensionStep { setStep: (step: number) => void; } const ExtensionStep: React.FC = ({ setStep }) => { - const onClick = () => { - signer!.getPublicKey(); - }; + const dispatch = useAppDispatch(); - const onClickAlt = () => { - setStep(1); - }; + const onClick = () => dispatch(nostrExtensionLogIn()); + const onClickAlt = () => setStep(1); return ( diff --git a/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx b/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx index be4fdd04b..ac7c409a9 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx @@ -17,7 +17,7 @@ interface IIdentityStep { const IdentityStep: React.FC = ({ username, setUsername, setStep }) => { return ( - setStep(0)} /> + { const onOpenSidebar = () => dispatch(openSidebar()); const handleNostrLogin = async () => { - setLoading(true); - await dispatch(nostrLogIn()).catch(console.error); - setLoading(false); + dispatch(openModal('NOSTR_SIGNIN')); }; const handleSubmit: React.FormEventHandler = (event) => {