Skip to content

Commit

Permalink
Merge pull request #36 from jiftechnify/improve-nip07-detection
Browse files Browse the repository at this point in the history
fix nostr extension detection
  • Loading branch information
jiftechnify authored Oct 4, 2023
2 parents 36d90b2 + 3e4f3d6 commit 878dfdb
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 878dfdb

Please sign in to comment.