Skip to content

Lot Merge: extract mergeOpenLots pure module + tests + modal rewire #3

@heyitsStylez

Description

@heyitsStylez

Parent

#1

What to build

Extract Lot Merge logic out of the merge modal into a new pure module exposing mergeOpenLots(trades, asset) → trades'. The function encapsulates: synthesising the merged Lot's costBasis (size-weighted) and size, picking the earliest lot-opener as the kept Trade, removing the other lot-openers, and clearing lotNum on the asset's CALL Trades so they reattach to the surviving Lot. Audit-trail behaviour is unchanged — no synthetic MERGE Trade type.

The merge modal becomes view + confirmation only. It computes the preview using mergeOpenLots against the current Trades (or equivalent inspection helpers) and, on confirm, applies the same function via the project's current Trade write convention (save() + render()). A later slice will migrate the modal to the commitTrades seam.

Tests cover Lot Merge invariants using the test harness introduced in #2.

Acceptance criteria

  • New pure module exports mergeOpenLots(trades, asset) → trades'
  • Module has a dual-export footer so it loads in both the browser concatenation and Node tests
  • Module ordering in src/js/ places it after the Lot Engine
  • Merge modal preview uses mergeOpenLots (or its derived totals) — no inline merge arithmetic in the modal
  • Merge modal confirm calls mergeOpenLots and persists the result via the current Trade write convention
  • Tests cover: merging two open Lots produces one Lot with size-weighted costBasis and summed lotPremiums; CALL lotNum references on the asset are cleared; non-target assets are untouched; merging fewer than two open Lots is a no-op
  • node --test test/ passes
  • python3 build.py --check passes
  • Merging two Lots in the UI produces the same merged Lot as today (no behavioural regression)

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions