Skip to content

Commit

Permalink
fix nostr extension detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jiftechnify committed Oct 4, 2023
1 parent 1eac64a commit 3e4f3d6
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/states/nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -194,17 +194,10 @@ export const pubkeysOrderByLastStatusUpdateTimeAtom = atom((get) => {

const nostrExtensionAtom = atom<NostrExtension | undefined>(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) => {
Expand Down

0 comments on commit 3e4f3d6

Please sign in to comment.