refactor(price): answer the price fetch on one typed outcome channel - #1298
Open
zancas wants to merge 1 commit into
Open
refactor(price): answer the price fetch on one typed outcome channel#1298zancas wants to merge 1 commit into
zancas wants to merge 1 commit into
Conversation
getZecPrice returned a number carrying both the price and the failure, with zero, minus one and minus two standing for three different outcomes, beside a prose string. callFfi already hands it a discriminated FfiResult whose code is a ZingolibError variant name, and the sentinels threw that typing away. The function now returns a ZecPriceOutcome: a zecPrice arm holding the quote, or an ErrorKeyed arm holding a catalog key and the diagnostic detail. This is what ADR 0002 and ADR 0003 ask of every module boundary, and this file's own header already claimed it. Three defects fall out with the sentinels. NaN is falsy, so the guard above the isNaN arm always won and that arm was unreachable, which reported a malformed number as no price yet. The payload's error field is dead, because zec_price returns only current_price and signals every failure by rejecting. The store retried every non-positive answer, so a deliberate mixnet-off refusal under ADR 0011 cost two failing calls rather than one clear answer. A quote is now required to be a positive finite number, so an absent, null or non-positive value fails as a malformed payload instead of passing as a price. One behaviour changes. A failed refresh now always leaves the last good price on screen. Previously two of the three failure arms did that and the third overwrote the price with zero, so the same fetch failing two ways produced opposite displays. The snackbar copy is untouched. The two translation keys keep their present wording, which reads identically for both failures. That is a user-facing concern and belongs in its own change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
What this changes
getZecPricereturned one number that carried both the price and the failure.Zero, minus one and minus two each named a different outcome. A prose string
travelled beside the number.
callFfialready gives this function a discriminatedFfiResult. Itscodeis a
ZingolibErrorvariant name. The sentinels discarded that typing.The function now returns a
ZecPriceOutcome. One arm iszecPriceand holdsthe quote. The other arm is
ErrorKeyedand holds a catalog key with thediagnostic detail. ADR 0002 and ADR 0003 ask this of every module boundary.
The file's own header already claimed it.
What the sentinels were hiding
Three defects go away with them.
NaNis falsy. The guard above theisNaNarm therefore always won, andthat arm was unreachable. A malformed number reported as "no price yet".
errorfield is dead.zec_pricereturns onlycurrent_price. It signals every failure by rejecting.under ADR 0011 therefore cost two failing calls, not one clear answer.
A quote must now be a positive finite number. An absent, null or non-positive
value fails as a malformed payload. It cannot pass as a price.
Behaviour change
A failed refresh now always leaves the last good price on screen. Two of the
three old failure arms did that. The third overwrote the price with zero. The
same fetch failing two ways therefore produced opposite displays.
Scope
This is a mobile backend change. The snackbar copy is untouched, and the two
translation keys keep their present wording. Those two strings read almost
identically, so a reader cannot tell the two failures apart. That is a
user-facing concern and belongs in its own change.
Verification
npm run typecheckpasses.npx eslintreports nothing on the four changed files.npx prettier --checkpasses.walletUtilsunit suite passes with 24 tests. Its price cases nowassert the error key rather than a sentinel, and they cover a null price and
a non-positive price, which the old shape could not express.
PriceFetchersnapshot passes unchanged.🤖 Generated with Claude Code