diff --git a/src/states/nostr.ts b/src/states/nostr.ts index d1d64c6..e6bdfc0 100644 --- a/src/states/nostr.ts +++ b/src/states/nostr.ts @@ -22,7 +22,7 @@ import { RESET, atomFamily, atomWithReset, atomWithStorage, loadable, selectAtom import { useCallback, useEffect, useState } from "react"; import { rxNostrAdapter } from "@nostr-fetch/adapter-rx-nostr"; -import "nip07-awaiter"; +import { waitNostr } from "nip07-awaiter"; import { NostrEvent, NostrFetcher } from "nostr-fetch"; import { getPublicKey } from "nostr-tools"; import { createRxForwardReq, createRxNostr, getSignedEvent, uniq, verify } from "rx-nostr"; @@ -194,17 +194,10 @@ export const pubkeysOrderByLastStatusUpdateTimeAtom = atom((get) => { const nostrExtensionAtom = atom(window.nostr); nostrExtensionAtom.onMount = (set) => { - const updateNostrExt = (ev: CustomEvent<{ nostr: NostrExtension }>) => { - set(ev.detail.nostr); - }; - - window.addEventListener("nostrloaded", updateNostrExt); - window.addEventListener("nostrupdated", updateNostrExt); - - return () => { - window.removeEventListener("nostrloaded", updateNostrExt); - window.removeEventListener("nostrupdated", updateNostrExt); + const setNostrExt = async () => { + set(await waitNostr(1500)); }; + setNostrExt().catch((e) => console.error("failed to detect Nostr extension:", e)); }; export const isNostrExtAvailableAtom = atom((get) => {