diff --git a/src/contexts/nostr-context.tsx b/src/contexts/nostr-context.tsx index 6dcca2241..4352a7316 100644 --- a/src/contexts/nostr-context.tsx +++ b/src/contexts/nostr-context.tsx @@ -2,7 +2,7 @@ import { NRelay, NRelay1, NostrSigner } from '@nostrify/nostrify'; import React, { createContext, useContext, useState, useEffect, useMemo } from 'react'; import { NKeys } from 'soapbox/features/nostr/keys'; -import { useAppSelector, useOwnAccount } from 'soapbox/hooks'; +import { useAppSelector } from 'soapbox/hooks'; import { useInstance } from 'soapbox/hooks/useInstance'; interface NostrContextType { @@ -25,13 +25,11 @@ export const NostrProvider: React.FC = ({ children }) => { const [relay, setRelay] = useState(); const [isRelayOpen, setIsRelayOpen] = useState(false); - const { account } = useOwnAccount(); - const url = instance.nostr?.relay; - const accountPubkey = useAppSelector((state) => state.meta.pubkey ?? account?.nostr.pubkey); + const accountPubkey = useAppSelector((state) => state.meta.pubkey ?? state.me); const signer = useMemo( - () => (accountPubkey ? NKeys.get(accountPubkey) : undefined) ?? window.nostr, + () => accountPubkey ? NKeys.get(accountPubkey) ?? window.nostr : undefined, [accountPubkey, window.nostr], ); diff --git a/src/init/soapbox-load.tsx b/src/init/soapbox-load.tsx index 7f3c90685..28808726e 100644 --- a/src/init/soapbox-load.tsx +++ b/src/init/soapbox-load.tsx @@ -47,6 +47,8 @@ const SoapboxLoad: React.FC = ({ children }) => { const { hasNostr, isRelayOpen, signer } = useNostr(); const { isSubscribed } = useSignerStream(); + const nostrLoading = Boolean(hasNostr && signer && (!isRelayOpen || !isSubscribed)); + /** Whether to display a loading indicator. */ const showLoading = [ me === null, @@ -55,7 +57,7 @@ const SoapboxLoad: React.FC = ({ children }) => { localeLoading, instance.isLoading, swUpdating, - hasNostr && me && signer && (!isRelayOpen || !isSubscribed), + nostrLoading, ].some(Boolean); // Load the user's locale @@ -68,14 +70,14 @@ const SoapboxLoad: React.FC = ({ children }) => { // Load initial data from the API useEffect(() => { - if (!instance.isLoading) { + if (!instance.isLoading && !nostrLoading) { dispatch(loadInitial()).then(() => { setIsLoaded(true); }).catch(() => { setIsLoaded(true); }); } - }, [instance.isLoading]); + }, [instance.isLoading, nostrLoading]); // intl is part of loading. // It's important nothing in here depends on intl.