Skip to content

fix: first channel toast uses cache channel count#509

Merged
piotr-iohk merged 1 commit intomasterfrom
fix/channel-ready-toast-count
Mar 26, 2026
Merged

fix: first channel toast uses cache channel count#509
piotr-iohk merged 1 commit intomasterfrom
fix/channel-ready-toast-count

Conversation

@piotr-iohk
Copy link
Copy Markdown
Collaborator

@piotr-iohk piotr-iohk commented Mar 25, 2026

Description

This PR fixes a race condition where the "Spending balance ready" toast (SpendingBalanceReadyToast) would not appear after the user's first Lightning channel becomes ready.

Bug: When a .channelReady event fires, the channelCache dictionary is already updated with the new channel, but lightningService.channels (backed by cachedChannels) may still be empty because it hasn't been refreshed yet. The old code only checked channels?.count == 1, so if channels was still empty (count 0), the toast was suppressed — even though this was genuinely the first channel.

Fix: Introduce FirstChannelToastPolicy that checks max(channelCacheCount, publishedChannelsCount) == 1, so the toast shows if either data source reports exactly one channel. Both counts are read in a single MainActor.run block to ensure a consistent snapshot.

Unit tests cover the key scenarios: cache ahead of published (the bug), both in sync, multiple channels, and zero channels.

Linked Issues/Tasks

N/A

Screenshot / Video

N/A

Comment thread Bitkit/ViewModels/AppViewModel.swift Outdated
@piotr-iohk piotr-iohk force-pushed the fix/channel-ready-toast-count branch from 0993667 to 1b970b1 Compare March 25, 2026 13:41
@claude
Copy link
Copy Markdown

claude bot commented Mar 25, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@piotr-iohk piotr-iohk self-assigned this Mar 25, 2026
@piotr-iohk piotr-iohk merged commit 0e3b3a8 into master Mar 26, 2026
16 of 20 checks passed
@piotr-iohk piotr-iohk deleted the fix/channel-ready-toast-count branch March 26, 2026 08:29
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