From 880b09e016d3c507a91883454b9c3aaf77239b9c Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Thu, 13 Jun 2024 15:51:13 -0300 Subject: [PATCH] refactor: parse zap request with NSchema --- src/utils/stats.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/stats.ts b/src/utils/stats.ts index e6001d1..ccba0a5 100644 --- a/src/utils/stats.ts +++ b/src/utils/stats.ts @@ -1,4 +1,4 @@ -import { NostrEvent, NStore } from '@nostrify/nostrify'; +import { NostrEvent, NSchema as n, NStore } from '@nostrify/nostrify'; import { Kysely, UpdateObject } from 'kysely'; import { SetRequired } from 'type-fest'; import { z } from 'zod'; @@ -144,7 +144,7 @@ async function handleEvent9735(kysely: Kysely, event: NostrEvent): const amountSchema = z.coerce.number().int().nonnegative().catch(0); let amount = 0; try { - const zapRequest = JSON.parse(event.tags.find(([name]) => name === 'description')?.[1]!) as NostrEvent; + const zapRequest = n.json().pipe(n.event()).parse(event.tags.find(([name]) => name === 'description')?.[1]); amount = amountSchema.parse(zapRequest.tags.find(([name]) => name === 'amount')?.[1]); if (amount <= 0) return; } catch {