diff --git a/package.json b/package.json index a7ac29e08..4a2efa577 100644 --- a/package.json +++ b/package.json @@ -186,7 +186,6 @@ "vite-plugin-html": "^3.2.0", "vite-plugin-require": "^1.1.10", "vite-plugin-static-copy": "^1.0.0", - "websocket-ts": "^2.1.5", "wicg-inert": "^3.1.1", "zod": "^3.23.5" }, diff --git a/src/api/hooks/nostr/useSignerStream.ts b/src/api/hooks/nostr/useSignerStream.ts index 9c6899930..918d40ba3 100644 --- a/src/api/hooks/nostr/useSignerStream.ts +++ b/src/api/hooks/nostr/useSignerStream.ts @@ -1,6 +1,5 @@ import { NostrEvent, NostrConnectResponse, NSchema as n } from '@nostrify/nostrify'; -import { useEffect, useState } from 'react'; -import { WebsocketEvent } from 'websocket-ts'; +import { useEffect } from 'react'; import { useNostr } from 'soapbox/contexts/nostr-context'; import { nwcRequestSchema } from 'soapbox/schemas/nostr'; @@ -8,9 +7,6 @@ import { nwcRequestSchema } from 'soapbox/schemas/nostr'; function useSignerStream() { const { relay, pubkey, signer } = useNostr(); - const [opened, setOpened] = useState(false); - const [isConnected, setIsConnected] = useState(false); - async function sendConnect(response: NostrConnectResponse) { if (!relay || !pubkey || !signer) return; @@ -119,29 +115,6 @@ function useSignerStream() { } } - useEffect(() => { - if (relay?.socket.readyState === WebSocket.OPEN) { - setOpened(true); - } - - const openHandler = () => { - setOpened(true); - setIsConnected(true); - }; - - const closeHandler = () => { - setIsConnected(false); - }; - - relay?.socket.addEventListener(WebsocketEvent.open, openHandler); - relay?.socket.addEventListener(WebsocketEvent.close, closeHandler); - - return () => { - relay?.socket.removeEventListener(WebsocketEvent.open, openHandler); - relay?.socket.removeEventListener(WebsocketEvent.close, closeHandler); - }; - }, [relay]); - useEffect(() => { if (!relay || !pubkey) return; @@ -159,8 +132,6 @@ function useSignerStream() { }; }, [relay, pubkey, signer]); - - return { opened, isConnected }; } export { useSignerStream }; diff --git a/src/api/index.ts b/src/api/index.ts index 39d6a14d9..dda1fa508 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -103,7 +103,7 @@ export default (getState: () => RootState, authType: string = 'user'): AxiosInst const state = getState(); const accessToken = getToken(state, authType); const me = state.me; - const baseURL = me ? getAuthBaseURL(state, me) : localStorage.getItem('soapbox:external:baseurl') ?? ''; + const baseURL = me ? getAuthBaseURL(state, me) : ''; const relayUrl = state.getIn(['instance', 'nostr', 'relay']) as string | undefined; const pubkey = state.getIn(['instance', 'nostr', 'pubkey']) as string | undefined; diff --git a/src/contexts/nostr-context.tsx b/src/contexts/nostr-context.tsx index 79442d965..fc8129b2b 100644 --- a/src/contexts/nostr-context.tsx +++ b/src/contexts/nostr-context.tsx @@ -1,4 +1,4 @@ -import { NRelay1, NostrSigner } from '@nostrify/nostrify'; +import { NRelay, NRelay1, NostrSigner } from '@nostrify/nostrify'; import React, { createContext, useContext, useState, useEffect, useMemo } from 'react'; import { NKeys } from 'soapbox/features/nostr/keys'; @@ -6,7 +6,7 @@ import { useOwnAccount } from 'soapbox/hooks'; import { useInstance } from 'soapbox/hooks/useInstance'; interface NostrContextType { - relay?: NRelay1; + relay?: NRelay; pubkey?: string; signer?: NostrSigner; } diff --git a/src/features/ui/index.tsx b/src/features/ui/index.tsx index 552adf723..32a52a034 100644 --- a/src/features/ui/index.tsx +++ b/src/features/ui/index.tsx @@ -13,6 +13,7 @@ import { fetchScheduledStatuses } from 'soapbox/actions/scheduled-statuses'; import { fetchSuggestionsForTimeline } from 'soapbox/actions/suggestions'; import { expandHomeTimeline } from 'soapbox/actions/timelines'; import { useUserStream } from 'soapbox/api/hooks'; +import { useSignerStream } from 'soapbox/api/hooks/nostr/useSignerStream'; import SidebarNavigation from 'soapbox/components/sidebar-navigation'; import ThumbNavigation from 'soapbox/components/thumb-navigation'; import { Layout } from 'soapbox/components/ui'; @@ -461,6 +462,7 @@ const UI: React.FC = ({ children }) => { }, []); useUserStream(); + useSignerStream(); // The user has logged in useEffect(() => { diff --git a/src/init/soapbox-instance.tsx b/src/init/soapbox-instance.tsx deleted file mode 100644 index 12ed477e6..000000000 --- a/src/init/soapbox-instance.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React, { useEffect, useState } from 'react'; - -import { fetchInstance } from 'soapbox/actions/instance'; -import { useSignerStream } from 'soapbox/api/hooks/nostr/useSignerStream'; -import LoadingScreen from 'soapbox/components/loading-screen'; -import { useAppDispatch, useFeatures } from 'soapbox/hooks'; - -interface ISoapboxInstance { - children: React.ReactNode; -} - -const SoapboxInstance: React.FC = ({ children }) => { - const features = useFeatures(); - const dispatch = useAppDispatch(); - - const [isLoaded, setIsLoaded] = useState(false); - const { opened } = useSignerStream(); - - useEffect(() => { - dispatch(fetchInstance()).then(() => { - setIsLoaded(true); - }).catch(() => { - setIsLoaded(true); - }); - }, []); - - if (!isLoaded || (!opened && features.nostr)) { - return ; - } - - return <>{children}; -}; - -export default SoapboxInstance; \ No newline at end of file diff --git a/src/init/soapbox-load.tsx b/src/init/soapbox-load.tsx index 953872289..cc9b883f1 100644 --- a/src/init/soapbox-load.tsx +++ b/src/init/soapbox-load.tsx @@ -1,6 +1,7 @@ import React, { useState, useEffect } from 'react'; import { IntlProvider } from 'react-intl'; +import { fetchInstance } from 'soapbox/actions/instance'; import { fetchMe } from 'soapbox/actions/me'; import { loadSoapboxConfig } from 'soapbox/actions/soapbox'; import LoadingScreen from 'soapbox/components/loading-screen'; @@ -16,7 +17,11 @@ import MESSAGES from 'soapbox/messages'; const loadInitial = () => { // @ts-ignore return async(dispatch, getState) => { + // Await for authenticated fetch await dispatch(fetchMe()); + // Await for feature detection + await dispatch(fetchInstance()); + // Await for configuration await dispatch(loadSoapboxConfig()); }; }; diff --git a/src/init/soapbox.tsx b/src/init/soapbox.tsx index 7b1331af2..2b3cce228 100644 --- a/src/init/soapbox.tsx +++ b/src/init/soapbox.tsx @@ -12,7 +12,6 @@ import { preload } from '../actions/preload'; import { store } from '../store'; import SoapboxHead from './soapbox-head'; -import SoapboxInstance from './soapbox-instance'; import SoapboxLoad from './soapbox-load'; import SoapboxMount from './soapbox-mount'; @@ -32,13 +31,11 @@ const Soapbox: React.FC = () => { - - - - - - - + + + + +