Skip to content

compat: Value & Amount constructs public for Redux#232

Merged
matthewjablack merged 1 commit into
masterfrom
compat/redux-immer
Oct 8, 2025
Merged

compat: Value & Amount constructs public for Redux#232
matthewjablack merged 1 commit into
masterfrom
compat/redux-immer

Conversation

@matthewjablack
Copy link
Copy Markdown
Contributor

Problem

The Value and Amount classes had protected/private members that prevented them from working with Redux Toolkit's Immer-based state management:

  • protected _picoSats: bigint - Immer proxies couldn't access this property
  • protected constructor() - Immer couldn't create new instances during state updates
  • TypeScript errors: Property '_picoSats' is missing in type 'WritableDraft<Value>'

Solution

Made the necessary properties and constructors public to enable Immer proxy compatibility:

  • protected _picoSatspublic _picoSats
  • protected constructor()public constructor() (Value)
  • private constructor()public constructor() (Amount)

Impact

  • No breaking changes - all existing APIs work exactly the same
  • Enables Redux usage - can now use Value/Amount objects directly in Redux state
  • Maintains encapsulation - _ prefix still signals internal use
  • All tests pass - 76/76 tests passing with 97.56% coverage

Usage

// Before: Had to use workarounds in Redux
const state = current(draftState); // Required for Value objects

// After: Can use directly in Redux
state.loan.initialBitcoinCollateral = Value.fromBitcoin(2.5); // Works!

The factory methods (fromBitcoin, fromSats, etc.) remain the recommended way to create instances, but direct construction is now possible for framework compatibility.

- change protected _picoSats to public _picoSats in Value class
- change protected constructor to public constructor in Value class
- change private constructor to public constructor in Amount class
- enables Immer proxy compatibility for Redux state management
- maintains all existing functionality and API surface
- allows direct usage in React/Redux applications without type casting
@matthewjablack matthewjablack merged commit 085680d into master Oct 8, 2025
2 checks passed
@matthewjablack matthewjablack deleted the compat/redux-immer branch October 8, 2025 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant