Merge branch 'nostr-load' into 'main'
Connect to the Nostr relay before calling verify_credentials See merge request soapbox-pub/soapbox!3178
This commit is contained in:
commit
b032b47359
|
@ -2,7 +2,7 @@ import { NRelay, NRelay1, NostrSigner } from '@nostrify/nostrify';
|
||||||
import React, { createContext, useContext, useState, useEffect, useMemo } from 'react';
|
import React, { createContext, useContext, useState, useEffect, useMemo } from 'react';
|
||||||
|
|
||||||
import { NKeys } from 'soapbox/features/nostr/keys';
|
import { NKeys } from 'soapbox/features/nostr/keys';
|
||||||
import { useAppSelector, useOwnAccount } from 'soapbox/hooks';
|
import { useAppSelector } from 'soapbox/hooks';
|
||||||
import { useInstance } from 'soapbox/hooks/useInstance';
|
import { useInstance } from 'soapbox/hooks/useInstance';
|
||||||
|
|
||||||
interface NostrContextType {
|
interface NostrContextType {
|
||||||
|
@ -25,13 +25,11 @@ export const NostrProvider: React.FC<NostrProviderProps> = ({ children }) => {
|
||||||
const [relay, setRelay] = useState<NRelay1>();
|
const [relay, setRelay] = useState<NRelay1>();
|
||||||
const [isRelayOpen, setIsRelayOpen] = useState(false);
|
const [isRelayOpen, setIsRelayOpen] = useState(false);
|
||||||
|
|
||||||
const { account } = useOwnAccount();
|
|
||||||
|
|
||||||
const url = instance.nostr?.relay;
|
const url = instance.nostr?.relay;
|
||||||
const accountPubkey = useAppSelector((state) => state.meta.pubkey ?? account?.nostr.pubkey);
|
const accountPubkey = useAppSelector(({ meta, auth }) => meta.pubkey ?? auth.users.get(auth.me!)?.id);
|
||||||
|
|
||||||
const signer = useMemo(
|
const signer = useMemo(
|
||||||
() => (accountPubkey ? NKeys.get(accountPubkey) : undefined) ?? window.nostr,
|
() => accountPubkey ? NKeys.get(accountPubkey) ?? window.nostr : undefined,
|
||||||
[accountPubkey, window.nostr],
|
[accountPubkey, window.nostr],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,8 @@ const SoapboxLoad: React.FC<ISoapboxLoad> = ({ children }) => {
|
||||||
const { hasNostr, isRelayOpen, signer } = useNostr();
|
const { hasNostr, isRelayOpen, signer } = useNostr();
|
||||||
const { isSubscribed } = useSignerStream();
|
const { isSubscribed } = useSignerStream();
|
||||||
|
|
||||||
|
const nostrLoading = Boolean(hasNostr && signer && (!isRelayOpen || !isSubscribed));
|
||||||
|
|
||||||
/** Whether to display a loading indicator. */
|
/** Whether to display a loading indicator. */
|
||||||
const showLoading = [
|
const showLoading = [
|
||||||
me === null,
|
me === null,
|
||||||
|
@ -55,7 +57,7 @@ const SoapboxLoad: React.FC<ISoapboxLoad> = ({ children }) => {
|
||||||
localeLoading,
|
localeLoading,
|
||||||
instance.isLoading,
|
instance.isLoading,
|
||||||
swUpdating,
|
swUpdating,
|
||||||
hasNostr && me && signer && (!isRelayOpen || !isSubscribed),
|
nostrLoading,
|
||||||
].some(Boolean);
|
].some(Boolean);
|
||||||
|
|
||||||
// Load the user's locale
|
// Load the user's locale
|
||||||
|
@ -68,14 +70,14 @@ const SoapboxLoad: React.FC<ISoapboxLoad> = ({ children }) => {
|
||||||
|
|
||||||
// Load initial data from the API
|
// Load initial data from the API
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!instance.isLoading) {
|
if (!instance.isLoading && !nostrLoading) {
|
||||||
dispatch(loadInitial()).then(() => {
|
dispatch(loadInitial()).then(() => {
|
||||||
setIsLoaded(true);
|
setIsLoaded(true);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
setIsLoaded(true);
|
setIsLoaded(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [instance.isLoading]);
|
}, [instance.isLoading, nostrLoading]);
|
||||||
|
|
||||||
// intl is part of loading.
|
// intl is part of loading.
|
||||||
// It's important nothing in here depends on intl.
|
// It's important nothing in here depends on intl.
|
||||||
|
|
Loading…
Reference in New Issue