fix: rebuild NUT-18 PR payload on mint switch - #533
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sendData.tokensBase64and short-circuited on it. After a failed POST, switching mint viaChooseMintleft the cache untouched, so the next pay attempt re-sent a payload embedding the previous mint's URL. WatchingactiveMintUrland invalidating the cached PR token/history reference on switch forcespreparePaymentRequestTokensto rebuild from the newly-selected mint.ChooseMintwhen the selected mint isn't in the PR'smallow-list. The check is wrapped in apaymentRequestMintConstrainthelper so once NUT-18: Payment request consolidation (and extra fees for non-preferred mints) nuts#381 is merged andmbecomes mandatory-or-preferred, a"preferred"kind can be added without reshaping callers.updateActiveProofs: filter the live in-memoryproofsref (kept in sync by the existingliveQuery) instead of re-querying Dexie. The update now happens in the same tick asactiveMintUrl/activeUnit, soactiveBalancere-evaluates immediately and the brief "insufficient balance" flicker on mint switch goes away. Both call sites are safe — one fire-and-forget, oneawait-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.errorsblock); others fall through to en-US.Test plan
npm run test:ci— 35 tests pass (3 new insendTokensStore.test.tscovering the invalidation helper)tsc --noEmitclean on all modified filesmlist — open the Pay sheet, switch to a disallowed mint (button disables, banner shows), switch back to the allowed mint (button re-enables), pay successfully