wip: zap
This commit is contained in:
@@ -4,16 +4,18 @@ import { useNDK } from '@libs/ndk/provider';
|
||||
import { createNote, getNoteByID } from '@libs/storage';
|
||||
|
||||
import { parser } from '@utils/parser';
|
||||
import { LumeEvent } from '@utils/types';
|
||||
|
||||
export function useEvent(id: string, fallback?: string) {
|
||||
const { ndk } = useNDK();
|
||||
const { status, data, error, isFetching } = useQuery(['note', id], async () => {
|
||||
const result = await getNoteByID(id);
|
||||
if (result) {
|
||||
return result;
|
||||
return result as LumeEvent;
|
||||
} else {
|
||||
if (fallback) {
|
||||
const embed = JSON.parse(fallback);
|
||||
const embed: LumeEvent = JSON.parse(fallback);
|
||||
embed['event_id'] = embed.id;
|
||||
await createNote(
|
||||
embed.id,
|
||||
embed.pubkey,
|
||||
@@ -40,7 +42,7 @@ export function useEvent(id: string, fallback?: string) {
|
||||
// @ts-ignore
|
||||
event['content'] = parser(event);
|
||||
}
|
||||
return event;
|
||||
return event as LumeEvent;
|
||||
} else {
|
||||
throw new Error('Event not found');
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NDKEvent, NDKKind, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk';
|
||||
import { NDKEvent, NDKKind, NDKPrivateKeySigner, NostrEvent } from '@nostr-dev-kit/ndk';
|
||||
import destr from 'destr';
|
||||
|
||||
import { useNDK } from '@libs/ndk/provider';
|
||||
|
||||
@@ -38,5 +39,17 @@ export function usePublish() {
|
||||
return event;
|
||||
};
|
||||
|
||||
return publish;
|
||||
const createZap = async (event: NostrEvent, amount: number) => {
|
||||
if (!privkey) throw new Error('Private key not found');
|
||||
if (typeof event.tags === 'string') event.tags = destr(event.tags);
|
||||
|
||||
const signer = new NDKPrivateKeySigner(privkey);
|
||||
ndk.signer = signer;
|
||||
|
||||
const ndkEvent = new NDKEvent(ndk, event);
|
||||
const res = await ndkEvent.zap(amount, 'test zap from lume');
|
||||
return res;
|
||||
};
|
||||
|
||||
return { publish, createZap };
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import { nip02ToArray } from '@utils/transform';
|
||||
|
||||
export function useSocial() {
|
||||
const queryClient = useQueryClient();
|
||||
const publish = usePublish();
|
||||
|
||||
const { publish } = usePublish();
|
||||
const { fetcher, relayUrls } = useNDK();
|
||||
const { account } = useAccount();
|
||||
const { status, data: userFollows } = useQuery(
|
||||
|
||||
Reference in New Issue
Block a user