mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix: get amount from zap receipt if not present in zap request
This commit is contained in:
parent
2f49e94e4c
commit
7a29c349e8
1 changed files with 11 additions and 3 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue