Feat: Multi unit support#174
Conversation
🦋 Changeset detectedLatest commit: 597eea4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
0f23030 to
597eea4
Compare
|
@codex kindly trigger auto review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 597eea40f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| methodData: MintMethodData = {}, | ||
| ): Promise<PendingMintOperation> { | ||
| const initOperation = await this.init(mintUrl, { amount, unit }, method, methodData); | ||
| const parsed = parseUnitAmount(amount, { explicitUnit: unit }); |
There was a problem hiding this comment.
Parse amount without implicit sat override
prepareNewQuote now accepts UnitAmountLike, but it always passes explicitUnit: unit to parseUnitAmount while unit defaults to 'sat'. This makes object-form inputs like { amount: 10, unit: 'usd' } fail with a unit-mismatch unless callers redundantly pass the same unit as the third argument, which breaks the intended object-form API for custom units. The parser should only enforce explicitUnit when the caller actually provided a unit override.
Useful? React with 👍 / 👎.
Description
This pull request adds first-class support for custom Cashu units across Coco while preserving existing bare-amount
satbehavior. It makes amount and unit travel together through public APIs, operations, proof storage, balance queries, quote handling, payment requests, React hooks, persistence adapters, migrations, docs, and tests.This pull request resolves #159.
Problem
Coco previously assumed
satin many internal and public flows. That made custom-unit Cashu usage unsafe because mint/send/receive/melt flows could silently fall back to sats, balances could be interpreted without unit scope, persisted proofs and operations lacked complete unit metadata, and adapter migrations did not consistently round-trip custom units.Summary
packages/core/amounts.ts, including defaultsatbehavior, lowercase normalization, object-form amount input, and unit assertions.WalletServiceunit-scoped, with mint+unit wallet caching and active keyset resolution by unit.TokenServiceto infer unit from proof keysets when token metadata is absent, reject token/keyset unit mismatches, and fallback tosatfor legacy/unresolvable unitless tokens.MeltQuoteServiceand made quote creation/payment unit-aware..changeset/many-units-restore.mdfor public API and migration behavior.Verification
bun run --filter='@cashu/coco-core' test:unitbun run --filter='@cashu/coco-core' typecheckbun run --filter='@cashu/coco-react' typecheckbun run --filter='@cashu/coco-react' test -- src/lib/hooks/operationHooks.test.tsx src/lib/hooks/useBalances.test.tsx src/lib/providers/root.test.tsxbun run --filter='@cashu/coco-adapter-tests' buildChangeset
.changeset/many-units-restore.md