Browse Source

fix: 🐛

imwald
codytseng 11 months ago
parent
commit
2b9de01905
  1. 8
      src/providers/FeedProvider.tsx
  2. 7
      src/providers/NostrProvider/index.tsx

8
src/providers/FeedProvider.tsx

@ -34,7 +34,7 @@ export const useFeed = () => {
export function FeedProvider({ children }: { children: React.ReactNode }) { export function FeedProvider({ children }: { children: React.ReactNode }) {
const isFirstRenderRef = useRef(true) const isFirstRenderRef = useRef(true)
const { pubkey } = useNostr() const { pubkey, isInitialized } = useNostr()
const { relaySets, favoriteRelays } = useFavoriteRelays() const { relaySets, favoriteRelays } = useFavoriteRelays()
const [relayUrls, setRelayUrls] = useState<string[]>([]) const [relayUrls, setRelayUrls] = useState<string[]>([])
const [temporaryRelayUrls, setTemporaryRelayUrls] = useState<string[]>([]) const [temporaryRelayUrls, setTemporaryRelayUrls] = useState<string[]>([])
@ -66,6 +66,10 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
return return
} }
if (!isInitialized) {
return
}
let feedInfo: TFeedInfo = { let feedInfo: TFeedInfo = {
feedType: 'relay', feedType: 'relay',
id: favoriteRelays[0] ?? DEFAULT_FAVORITE_RELAYS[0] id: favoriteRelays[0] ?? DEFAULT_FAVORITE_RELAYS[0]
@ -92,7 +96,7 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
} }
init() init()
}, [pubkey]) }, [pubkey, isInitialized])
const switchFeed = async ( const switchFeed = async (
feedType: TFeedType, feedType: TFeedType,

7
src/providers/NostrProvider/index.tsx

@ -24,6 +24,7 @@ import { NsecSigner } from './nsec.signer'
import { NpubSigner } from './npub.signer' import { NpubSigner } from './npub.signer'
type TNostrContext = { type TNostrContext = {
isInitialized: boolean
pubkey: string | null pubkey: string | null
profile: TProfile | null profile: TProfile | null
profileEvent: Event | null profileEvent: Event | null
@ -83,6 +84,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
const [followListEvent, setFollowListEvent] = useState<Event | undefined>(undefined) const [followListEvent, setFollowListEvent] = useState<Event | undefined>(undefined)
const [muteListEvent, setMuteListEvent] = useState<Event | undefined>(undefined) const [muteListEvent, setMuteListEvent] = useState<Event | undefined>(undefined)
const [favoriteRelaysEvent, setFavoriteRelaysEvent] = useState<Event | null>(null) const [favoriteRelaysEvent, setFavoriteRelaysEvent] = useState<Event | null>(null)
const [isInitialized, setIsInitialized] = useState(false)
useEffect(() => { useEffect(() => {
const init = async () => { const init = async () => {
@ -96,7 +98,9 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
await loginWithAccountPointer(act) await loginWithAccountPointer(act)
} }
init() init().then(() => {
setIsInitialized(true)
})
const handleHashChange = () => { const handleHashChange = () => {
if (hasNostrLoginHash()) { if (hasNostrLoginHash()) {
@ -537,6 +541,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
return ( return (
<NostrContext.Provider <NostrContext.Provider
value={{ value={{
isInitialized,
pubkey: account?.pubkey ?? null, pubkey: account?.pubkey ?? null,
profile, profile,
profileEvent, profileEvent,

Loading…
Cancel
Save