From 1feeaf7b1e92b3cca6d568c92576967684c4bdca Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 14 Aug 2024 22:05:17 -0500 Subject: [PATCH] Put zap splits behind a feature flag, disabled by default --- src/config.ts | 4 ++++ src/controllers/api/statuses.ts | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/config.ts b/src/config.ts index dabb3bb7..0cb71509 100644 --- a/src/config.ts +++ b/src/config.ts @@ -262,6 +262,10 @@ class Conf { static get policy(): string { return Deno.env.get('DITTO_POLICY') || new URL('../data/policy.ts', import.meta.url).pathname; } + /** Whether zap splits should be enabled. */ + static get zapSplitsEnabled(): boolean { + return optionalBooleanSchema.parse(Deno.env.get('ZAP_SPLITS_ENABLED')) ?? false; + } } const optionalBooleanSchema = z diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 23ad2c76..0b910369 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -169,17 +169,19 @@ const createStatusController: AppController = async (c) => { const author = await getAuthor(await c.get('signer')?.getPublicKey()!); - const meta = n.json().pipe(n.metadata()).catch({}).parse(author?.content); - const lnurl = getLnurl(meta); - const dittoZapSplit = await getZapSplits(store, Conf.pubkey); - if (lnurl && dittoZapSplit) { - let totalSplit = 0; - for (const pubkey in dittoZapSplit) { - totalSplit += dittoZapSplit[pubkey].weight; - tags.push(['zap', pubkey, Conf.relay, dittoZapSplit[pubkey].weight.toString()]); - } - if (totalSplit) { - tags.push(['zap', author?.pubkey as string, Conf.relay, Math.max(0, 100 - totalSplit).toString()]); + if (Conf.zapSplitsEnabled) { + const meta = n.json().pipe(n.metadata()).catch({}).parse(author?.content); + const lnurl = getLnurl(meta); + const dittoZapSplit = await getZapSplits(store, Conf.pubkey); + if (lnurl && dittoZapSplit) { + let totalSplit = 0; + for (const pubkey in dittoZapSplit) { + totalSplit += dittoZapSplit[pubkey].weight; + tags.push(['zap', pubkey, Conf.relay, dittoZapSplit[pubkey].weight.toString()]); + } + if (totalSplit) { + tags.push(['zap', author?.pubkey as string, Conf.relay, Math.max(0, 100 - totalSplit).toString()]); + } } }