Skip to content

fix(tokens): animate market cap period changes and reset the period on each open - #1584

Merged
bmc08gt merged 2 commits into
code/cashfrom
fix/market-cap-chart-period
Sep 28, 2026
Merged

bmc08gt merged 2 commits into
code/cashfrom
fix/market-cap-chart-period

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Four market cap chart bugs in the currency-info overlay:

  • Switching periods no longer animated. The overlay passes animateChartOpen = false to skip the draw-in, and that set Vico's animationSpec to null. animationSpec also drives the transition between datasets. The flag now controls initialAnimationSpec (first draw only), and animationSpec stays at tween(300).
  • The period didn't reset between opens. The overlay reuses one TokenInfoViewModel across opens, so selectedPeriod persisted. OnMintProvided gained resetChartPeriod, which the overlay sets on each open.
  • A mint with the same market cap as the previous one didn't load its chart. The history load hangs off two distinctUntilChanged calls keyed on the market cap alone, so the reused VM skipped it until Retry or a period change. Both now key on the mint too.
  • The line changed color before the new data drew. The trend was derived from the incoming data during composition, while Vico builds the model off the main thread and starts the morph when runTransaction returns. Switching ALL to 1W on the emulator showed the old all-time line in red for about 450 ms. The trend is now set after runTransaction returns, and the line, area and marker colors fade over the same 300 ms as the curve. They're read at draw time, so the chart isn't rebuilt per frame; Vico's AreaFill.single and its indicator cache take fixed colors, so this adds VerticalGradientAreaFill and ColorProviderComponent. A recording of the same switch shows the old line staying green until the morph starts, then fading through to red with it.

Notes on the second fix:

  • The pushed TokenInfoScreen leaves resetChartPeriod off. It re-dispatches OnMintProvided from LaunchedEffect(Unit) when a screen pushed over it pops (e.g. Swap), and a reset there would throw away the period the user picked.
  • historicalMarketCapData is keyed by period only, so opening a different mint now clears it rather than briefly showing the previous mint's chart.
  • The period-selection flow dropped distinctUntilChanged. Once the state resets to All, it would swallow re-picking the period from the previous open. The tab row ignores taps on the already-selected period instead, so there's no reload on a redundant tap.

New reducer tests in TokenInfoViewModelStateTest cover the reset, the default of keeping the period, and keeping versus clearing chart data by mint. TokenInfoViewModelChartLoadTest opens two mints with the same market cap on one VM and checks both load history; it failed on the second mint before the fix.

…n each open

The currency-info overlay passes animateChartOpen = false to skip the
chart's draw-in, but that nulled Vico's animationSpec, which also drives
the animation between datasets. Period switches stopped animating. Keep
animationSpec and put the flag on initialAnimationSpec, which only
covers the first draw.

The overlay reuses one TokenInfoViewModel across opens, so the selected
period carried over from the last open. OnMintProvided now takes
resetChartPeriod, which the overlay sets. The pushed TokenInfoScreen
leaves it off because it re-dispatches OnMintProvided when a screen
pushed over it pops, and resetting there would drop the user's pick.
Chart data is keyed by period only, so a different mint now clears it.

The period-selection flow no longer uses distinctUntilChanged: after a
reset it would swallow re-picking the previous open's period. The tab
row ignores taps on the selected period instead.
@bmc08gt bmc08gt self-assigned this Sep 28, 2026
@github-actions github-actions Bot added area: tokens Token accounts, balances, token info type: fix Bug fix labels Sep 28, 2026
The chart's history load fires when the market cap arrives, behind two
distinctUntilChanged calls keyed on the market cap alone. The overlay
reuses one TokenInfoViewModel across opens, so opening a mint whose
market cap equals the previous mint's skipped the load and the chart
stayed empty until Retry or a period change. Key both de-dupes on the
mint as well.
@bmc08gt
bmc08gt merged commit add00e2 into code/cash Sep 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tokens Token accounts, balances, token info type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant