fix(price): tolerate unpriced /realunit/price payloads without crashing#701
Closed
TaprootFreak wants to merge 1 commit into
Closed
fix(price): tolerate unpriced /realunit/price payloads without crashing#701TaprootFreak wants to merge 1 commit into
TaprootFreak wants to merge 1 commit into
Conversation
The live /v1/realunit/price endpoint returns only {"timestamp": ...}
while no price is published for the day, and the newest
/v1/realunit/price/history entry carries the same unpriced shape. The
inline parsing in DFXPriceService multiplied these missing fields
(null * 100), throwing an unhandled NoSuchMethodError from
DashboardBloc on every dashboard price refresh (reproducible on DEV
and PRD).
Root fix:
- Add RealUnitPriceDto with nullable chf/eur/timestamp so the wire
shape is parsed in one typed, null-safe place (no more inline JSON
parsing in the service).
- getPriceOfAsset returns BigInt.zero when the requested currency is
absent; the dashboard already renders the zero sentinel as "--.--".
- getPriceChart skips entries that are unpriced or carry no parseable
timestamp instead of crashing; partial/empty lists are already
handled by PriceChartCubit.
- getChfToEurRate falls back to 0.0 via the existing chf > 0 guard.
Tests pin every new branch (unpriced spot payload per currency,
skipped history entries, missing/invalid timestamps, DTO parsing);
scoped coverage stays at 100%. A new dashboard golden
(dashboard_price_no_chart) locks the "price present, history
unpriced" rendering.
Contributor
Author
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.
Problem
The live
/v1/realunit/priceendpoint returns only{"timestamp": ...}(nochf/eur) while no price is published for the day, and the newest/v1/realunit/price/historyentry carries the same unpriced shape.DFXPriceServicemultiplied the missing fields (null * 100), throwing an unhandledNoSuchMethodErrorfromDashboardBloc._onRefreshPriceEvent/_onRefreshPriceChartEventon every dashboard price refresh — reproducible against DEV and PRD today. The price renders asCHF --.--only because the bloc zone swallows the exception.Root fix
RealUnitPriceDto(nullablechf/eur/timestamp): the wire shape is parsed in one typed, null-safe place — removes the inline JSON parsing from the service (CONTRIBUTING DTO rule).getPriceOfAsset: requested currency absent →BigInt.zero; the dashboard already renders the zero sentinel as--.--(dashboard_price_widget.dart:82,DashboardStateinitial value).getPriceChart: skips entries that are unpriced or have no parseable timestamp;PriceChartCubitalready handles partial/empty lists.getChfToEurRate: null-safe via the existingchf > 0guard (→0.0).Behavior for fully-priced payloads is bit-identical (same
value * 100double arithmetic); non-200 still throws.Tests
getChfToEurRate.RealUnitPriceDtospec: full parse, int coercion, timestamp-only payload, absent/non-string/unparseable timestamp.dashboard_price_no_chartlocks the "price present, history unpriced → chart empty" dashboard rendering (deterministic: empty chart takes the zero-window path beforeDateTime.now()).flutter analyzeclean · full suite 2316 passed · golden suite 103 passed · scoped coverage stays 100% (floor met).Notes
DFXswiss/api: omit unpriced entries from/v1/realunit/price/historyor document the unpriced shape in Swagger.