Skip to content

team-split.util.ts's validateSplitPercentages and escrow.service.ts's assertValidSplits independently reimplement near-identical split-percentage validation #167

Description

@chonilius

src/teams/team-split.util.ts's validateSplitPercentages() and src/escrow/escrow.service.ts's private assertValidSplits() both exist to answer the same question — "does this list of recipient percentages sum to 100, with no non-positive entries" — for the two places this codebase collects percentage-based splits (CreateTeamDto.members and SplitReleaseDto.recipients). They're implemented completely independently rather than sharing one utility:

  • Both reject an empty list.
  • Both sum percentages and reject if Math.abs(total - 100) > 0.01.
  • Both reject non-positive individual percentages.
  • validateSplitPercentages additionally rejects percentage > 100 per-entry; assertValidSplits doesn't bother, because SplitRecipientDto.percentage already has @Max(100) — but TeamMemberSplitDto.percentage doesn't have an equivalent @Max() (already tracked separately), so the one place this duplication isn't purely cosmetic is exactly the one place the two implementations diverge in strictness.

Consolidating into one shared validator (in src/common/, alongside money.validator.ts/stellar-address.validator.ts) would remove the duplication and make the two DTOs' validation strictness consistent by construction rather than by two authors remembering to keep them in sync.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programarchitectureArchitecture/design issuebugSomething isn't workinghelp wantedExtra attention is neededvery hardVery difficult task, expert-level effort required

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions