Connect to the Nostr relay before calling verify_credentials

This commit is contained in:
Alex Gleason 2024-10-22 16:52:25 -05:00
parent eb54495c10
commit 2b4886615d
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 8 additions and 8 deletions

View File

@ -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<NostrProviderProps> = ({ children }) => {
const [relay, setRelay] = useState<NRelay1>();
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],
);

View File

@ -47,6 +47,8 @@ const SoapboxLoad: React.FC<ISoapboxLoad> = ({ 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<ISoapboxLoad> = ({ 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<ISoapboxLoad> = ({ 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.