refactor(zap split): rename amount to weight

This commit is contained in:
P. Reis 2024-08-05 14:33:47 -03:00
parent 25bbeceb8d
commit 0a3ed4e160
3 changed files with 7 additions and 7 deletions

View file

@ -159,7 +159,7 @@ export const nameRequestsController: AppController = async (c) => {
const zapSplitSchema = z.record( const zapSplitSchema = z.record(
n.id(), n.id(),
z.object({ z.object({
amount: z.number().int().min(1).max(100), weight: z.number().int().min(1).max(100),
message: z.string().max(500), message: z.string().max(500),
}), }),
); );
@ -189,7 +189,7 @@ export const updateZapSplitsController: AppController = async (c) => {
{ kinds: [30078], authors: [Conf.pubkey], '#d': ['pub.ditto.zapSplits'], limit: 1 }, { kinds: [30078], authors: [Conf.pubkey], '#d': ['pub.ditto.zapSplits'], limit: 1 },
(tags) => (tags) =>
pubkeys.reduce((accumulator, pubkey) => { pubkeys.reduce((accumulator, pubkey) => {
return addTag(accumulator, ['p', pubkey, data[pubkey].amount.toString(), data[pubkey].message]); return addTag(accumulator, ['p', pubkey, data[pubkey].weight.toString(), data[pubkey].message]);
}, tags), }, tags),
c, c,
); );
@ -244,7 +244,7 @@ export const getZapSplitsController: AppController = async (c) => {
return { return {
account, account,
amount: zap_split[pubkey].amount, weight: zap_split[pubkey].weight,
message: zap_split[pubkey].message, message: zap_split[pubkey].message,
}; };
})); }));

View file

@ -183,8 +183,8 @@ const createStatusController: AppController = async (c) => {
if (lnurl && zap_split) { if (lnurl && zap_split) {
let totalSplit = 0; let totalSplit = 0;
for (const pubkey in zap_split) { for (const pubkey in zap_split) {
totalSplit += zap_split[pubkey].amount; totalSplit += zap_split[pubkey].weight;
tags.push(['zap', pubkey, Conf.relay, zap_split[pubkey].amount.toString()]); tags.push(['zap', pubkey, Conf.relay, zap_split[pubkey].weight.toString()]);
} }
if (totalSplit) { if (totalSplit) {
tags.push(['zap', author?.pubkey as string, Conf.relay, Math.max(0, 100 - totalSplit).toString()]); tags.push(['zap', author?.pubkey as string, Conf.relay, Math.max(0, 100 - totalSplit).toString()]);

View file

@ -10,7 +10,7 @@ type ExtraMessage = string;
type splitPercentages = number; type splitPercentages = number;
export type DittoZapSplits = { export type DittoZapSplits = {
[key: Pubkey]: { amount: splitPercentages; message: ExtraMessage }; [key: Pubkey]: { weight: splitPercentages; message: ExtraMessage };
}; };
/** Gets zap splits from NIP-78 in DittoZapSplits format. */ /** Gets zap splits from NIP-78 in DittoZapSplits format. */
@ -30,7 +30,7 @@ export async function getZapSplits(store: NStore, pubkey: string): Promise<Ditto
tag[0] === 'p' && n.id().safeParse(tag[1]).success && tag[0] === 'p' && n.id().safeParse(tag[1]).success &&
percentageSchema.safeParse(tag[2]).success percentageSchema.safeParse(tag[2]).success
) { ) {
zapSplits[tag[1]] = { amount: Number(tag[2]), message: tag[3] }; zapSplits[tag[1]] = { weight: Number(tag[2]), message: tag[3] };
} }
} }