Skip to content

fix: rebuild NUT-18 PR payload on mint switch - #533

Merged
callebtc merged 2 commits into
cashubtc:mainfrom
robwoodgate:fix/nut18-pr-mint-switch
Jun 10, 2026
Merged

fix: rebuild NUT-18 PR payload on mint switch#533
callebtc merged 2 commits into
cashubtc:mainfrom
robwoodgate:fix/nut18-pr-mint-switch

Conversation

@robwoodgate

@robwoodgate robwoodgate commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Mint-switch cache bug (the main fix): the Pay-PaymentRequest sheet cached sendData.tokensBase64 and short-circuited on it. After a failed POST, switching mint via ChooseMint left the cache untouched, so the next pay attempt re-sent a payload embedding the previous mint's URL. Watching activeMintUrl and invalidating the cached PR token/history reference on switch forces preparePaymentRequestTokens to rebuild from the newly-selected mint.
  • Pre-flight gate: disable the pay button and show a banner under ChooseMint when the selected mint isn't in the PR's m allow-list. The check is wrapped in a paymentRequestMintConstraint helper so once NUT-18: Payment request consolidation (and extra fees for non-preferred mints) nuts#381 is merged and m becomes mandatory-or-preferred, a "preferred" kind can be added without reshaping callers.
  • Synchronous updateActiveProofs: filter the live in-memory proofs ref (kept in sync by the existing liveQuery) instead of re-querying Dexie. The update now happens in the same tick as activeMintUrl/activeUnit, so activeBalance re-evaluates immediately and the brief "insufficient balance" flicker on mint switch goes away. Both call sites are safe — one fire-and-forget, one await-in-async-watcher that doesn't care if the function resolves synchronously.

i18n added for the new banner string in en-US, cs-CZ, pt-BR (the locales that already have a SendTokenDialog.errors block); others fall through to en-US.

Test plan

  • npm run test:ci — 35 tests pass (3 new in sendTokensStore.test.ts covering the invalidation helper)
  • tsc --noEmit clean on all modified files
  • Manual: NUT-18 PR with a strict m list — open the Pay sheet, switch to a disallowed mint (button disables, banner shows), switch back to the allowed mint (button re-enables), pay successfully
  • Manual: mint switch no longer flashes "insufficient balance" before the new mint's balance loads

The Pay-PaymentRequest sheet cached `tokensBase64` and returned it
across mint changes, so a failed POST followed by a mint switch
re-sent a payload embedding the previous mint's URL. Watch
`activeMintUrl` and clear the cached token/history reference on
switch so the next attempt rebuilds from the newly-selected mint.

Also disable the pay button and surface a banner when the selected
mint isn't in the request's `m` allow-list. The constraint check is
wrapped in a small helper that can grow a `preferred` variant once
nuts#381 lands without reshaping callers.

Finally, filter activeProofs from the live in-memory `proofs` ref
instead of re-querying Dexie. This makes the update synchronous, so
`activeBalance` re-evaluates in the same tick as `activeMintUrl` and
the brief "insufficient balance" flicker on mint switch goes away.
@callebtc
callebtc merged commit 3576efd into cashubtc:main Jun 10, 2026
7 checks passed
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.

2 participants