fix sending nip4

This commit is contained in:
sam committed 2025-10-18 20:53:53 +07:00
1 parent d3866ae0af
commit f37d86b8d3
1 file changed
+9 -34
+9 -34
View File
@@ -74,7 +74,7 @@ function createImetaTags(attachments: FileAttachment[] = []): string[][] {
export function useSendDM(): UseSendDMReturn { export function useSendDM(): UseSendDMReturn {
const { user } = useCurrentUser(); const { user } = useCurrentUser();
const { mutate: createEvent } = useNostrPublish(); const { mutateAsync: createEvent } = useNostrPublish();
const { toast } = useToast(); const { toast } = useToast();
// Send NIP-04 Message // Send NIP-04 Message
@@ -101,18 +101,10 @@ export function useSendDM(): UseSendDMReturn {
]; ];
// Create and publish the event // Create and publish the event
return new Promise((resolve, reject) => { return await createEvent({
createEvent(
{
kind: 4, kind: 4,
content: encryptedContent, content: encryptedContent,
tags, tags,
},
{
onSuccess: (event) => resolve(event),
onError: (error) => reject(error),
}
);
}); });
}, },
onError: (error) => { onError: (error) => {
@@ -182,36 +174,19 @@ export function useSendDM(): UseSendDMReturn {
const recipientGiftWrapContent = await user.signer.nip44.encrypt(recipientPubkey, JSON.stringify(recipientSeal)); const recipientGiftWrapContent = await user.signer.nip44.encrypt(recipientPubkey, JSON.stringify(recipientSeal));
const myGiftWrapContent = await user.signer.nip44.encrypt(user.pubkey, JSON.stringify(senderSeal)); const myGiftWrapContent = await user.signer.nip44.encrypt(user.pubkey, JSON.stringify(senderSeal));
const recipientGiftWrapPromise = new Promise<NostrEvent>((resolve, reject) => { // Publish both gift wraps in parallel
createEvent( const [recipientGiftWrap] = await Promise.all([
{ createEvent({
kind: 1059, kind: 1059,
content: recipientGiftWrapContent, content: recipientGiftWrapContent,
tags: [['p', recipientPubkey]], tags: [['p', recipientPubkey]],
}, }),
{ createEvent({
onSuccess: (event) => resolve(event),
onError: (error) => reject(error),
}
);
});
const myGiftWrapPromise = new Promise<NostrEvent>((resolve, reject) => {
createEvent(
{
kind: 1059, kind: 1059,
content: myGiftWrapContent, content: myGiftWrapContent,
tags: [['p', user.pubkey]], tags: [['p', user.pubkey]],
}, }),
{ ]);
onSuccess: (event) => resolve(event),
onError: (error) => reject(error),
}
);
});
// Wait for both gift wraps to be published
const [recipientGiftWrap] = await Promise.all([recipientGiftWrapPromise, myGiftWrapPromise]);
// Return the recipient's gift wrap as the "result" // Return the recipient's gift wrap as the "result"
return recipientGiftWrap; return recipientGiftWrap;