mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
fix sending nip4
This commit is contained in:
1 parent
d3866ae0af
commit
f37d86b8d3
1 file changed
+18
-43
+18
-43
@@ -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,
|
||||||
{
|
content: encryptedContent,
|
||||||
kind: 4,
|
tags,
|
||||||
content: encryptedContent,
|
|
||||||
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),
|
kind: 1059,
|
||||||
onError: (error) => reject(error),
|
content: myGiftWrapContent,
|
||||||
}
|
tags: [['p', user.pubkey]],
|
||||||
);
|
}),
|
||||||
});
|
]);
|
||||||
|
|
||||||
const myGiftWrapPromise = new Promise<NostrEvent>((resolve, reject) => {
|
|
||||||
createEvent(
|
|
||||||
{
|
|
||||||
kind: 1059,
|
|
||||||
content: myGiftWrapContent,
|
|
||||||
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;
|
||||||
|
|||||||
Reference in new issue
Block a user