fix: get amount from zap receipt if not present in zap request

This commit is contained in:
P. Reis 2024-06-17 14:50:46 -03:00
parent 2f49e94e4c
commit 7a29c349e8

View file

@ -21,6 +21,7 @@ import { addTag, deleteTag } from '@/utils/tags.ts';
import { asyncReplaceAll } from '@/utils/text.ts'; import { asyncReplaceAll } from '@/utils/text.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { getAmount } from '@/utils/bolt11.ts';
const createStatusSchema = z.object({ const createStatusSchema = z.object({
in_reply_to_id: n.id().nullish(), in_reply_to_id: n.id().nullish(),
@ -548,10 +549,17 @@ const zappedByController: AppController = async (c) => {
const amountSchema = z.coerce.number().int().nonnegative().catch(0); const amountSchema = z.coerce.number().int().nonnegative().catch(0);
const events: DittoEvent[] = (await store.query([{ kinds: [9735], '#e': [id], limit: 100 }])).map((event) => { const events: DittoEvent[] = (await store.query([{ kinds: [9735], '#e': [id], limit: 100 }])).map((event) => {
const zapRequest = event.tags.find(([name]) => name === 'description')?.[1]; const zapRequestString = event.tags.find(([name]) => name === 'description')?.[1];
if (!zapRequest) return; if (!zapRequestString) return;
try { try {
return JSON.parse(zapRequest); const zapRequest = JSON.parse(zapRequestString);
const amount = zapRequest?.tags.find(([name]: any) => name === 'amount')?.[1];
if (!amount) {
const amount = getAmount(event?.tags.find(([name]) => name === 'bolt11')?.[1]);
if (!amount) return;
zapRequest.tags.push(['amount', amount]);
}
return zapRequest;
} catch { } catch {
return; return;
} }