🐛 add env to useDb and apply prettier
tinyedge/deploy Deployed by TinyEdge

This commit is contained in:
2026-08-07 13:28:26 +02:00
parent 67727f96ab
commit cbe1b42f6e
54 changed files with 5492 additions and 2406 deletions
+12 -9
View File
@@ -1,21 +1,24 @@
import type { ParticipantId } from '../types'
import type { ParticipantId } from '../types';
/**
* Splits amountCents equally among participantIds. Any remainder cents (from
* integer division) go one-each to the first participants in the given
* order, so the shares always sum exactly back to amountCents.
*/
export function computeSplit(amountCents: number, participantIds: ParticipantId[]): Record<ParticipantId, number> {
export function computeSplit(
amountCents: number,
participantIds: ParticipantId[],
): Record<ParticipantId, number> {
if (participantIds.length === 0) {
throw new Error('computeSplit requires at least one participant')
throw new Error('computeSplit requires at least one participant');
}
const base = Math.floor(amountCents / participantIds.length)
const remainder = amountCents - base * participantIds.length
const base = Math.floor(amountCents / participantIds.length);
const remainder = amountCents - base * participantIds.length;
const shares: Record<ParticipantId, number> = {}
const shares: Record<ParticipantId, number> = {};
participantIds.forEach((id, index) => {
shares[id] = base + (index < remainder ? 1 : 0)
})
return shares
shares[id] = base + (index < remainder ? 1 : 0);
});
return shares;
}