1- import 'package:bb_mobile/core/swaps/domain/usecases/get_auto_swap_settings_usecase.dart' ;
21import 'package:bb_mobile/core/utils/result.dart' ;
3- import 'package:bb_mobile/core/wallet/domain/usecases/get_wallets_usecase.dart' ;
42import 'package:bb_mobile/features/announcements/domain/announcements_failure.dart' ;
53import 'package:bb_mobile/features/announcements/domain/entities/announcement.dart' ;
64import 'package:bb_mobile/features/announcements/domain/entities/announcement_catalog.dart' ;
75import 'package:bb_mobile/features/announcements/domain/repositories/announcement_dismissal_repository.dart' ;
86
97/// Orchestrates which announcements are currently visible on the home carousel.
108///
11- /// Thin orchestration only: it gathers the trigger signals (autoswap settings
12- /// and the Liquid balance they apply to), asks each catalog entry whether its
13- /// trigger fires, drops anything the user has dismissed (respecting the
14- /// per-announcement dismiss policy), and returns the survivors ordered by
15- /// ascending priority. All decision *rules* live on the entities / catalog;
16- /// this use-case only wires signals to them.
9+ /// Thin orchestration only: it asks each catalog entry whether its trigger
10+ /// fires for the current [AnnouncementSignals] , drops anything the user has
11+ /// dismissed (respecting the per-announcement dismiss policy), and returns
12+ /// the survivors ordered by ascending priority. All decision *rules* live on
13+ /// the entities / catalog; this use-case only wires signals to them. (The
14+ /// catalog is currently empty — see its doc comment — so this returns an
15+ /// empty list until a future announcement is added.)
1716class GetVisibleAnnouncementsUsecase {
18- final GetWalletsUsecase _getWalletsUsecase;
19- final GetAutoSwapSettingsUsecase _getAutoSwapSettingsUsecase;
2017 final AnnouncementDismissalRepository _dismissalRepository;
2118
22- GetVisibleAnnouncementsUsecase ({
23- required this ._getWalletsUsecase,
24- required this ._getAutoSwapSettingsUsecase,
25- required this ._dismissalRepository,
26- });
19+ GetVisibleAnnouncementsUsecase ({required this ._dismissalRepository});
2720
2821 Future <Result <List <Announcement >, AnnouncementsFailure >> execute () async {
2922 try {
30- // The three sources are independent, so gather them concurrently.
31- final (liquidBalanceSat, autoSwap, dismissals) = await (
32- _defaultLiquidBalanceSat (),
33- _getAutoSwapSettingsUsecase.execute (),
34- _dismissalRepository.getDismissals (),
35- ).wait;
36-
37- // Autoswap sweeps the default Liquid wallet, so its balance is what
38- // the trigger threshold applies to. The threshold rule itself lives on
39- // the AutoSwap entity (passedRequiredBalance also checks `enabled`).
40- final signals = AnnouncementSignals (
41- isAutoswapTriggerable:
42- ! autoSwap.showWarning &&
43- autoSwap.passedRequiredBalance (liquidBalanceSat.toInt ()),
44- );
23+ final dismissals = await _dismissalRepository.getDismissals ();
4524
25+ const signals = AnnouncementSignals ();
4626 final dismissedAtById = {for (final d in dismissals) d.id: d.dismissedAt};
4727 final now = DateTime .now ().toUtc ();
4828
@@ -62,29 +42,7 @@ class GetVisibleAnnouncementsUsecase {
6242 visible.sort ((a, b) => a.priority.compareTo (b.priority));
6343 return Ok (visible);
6444 } catch (e) {
65- // Sources span wallets/autoswap/storage, so this is a genuine
66- // catch-all rather than a storage-only failure.
6745 return Err (AnnouncementUnexpectedFailure (e.toString ()));
6846 }
6947 }
70-
71- /// Balance of the default Liquid wallet(s) of the current environment, or
72- /// zero when there is none.
73- ///
74- /// [GetWalletsUsecase] throws [NoWalletsFoundException] on an empty result,
75- /// which would turn a perfectly ordinary state ("this environment has no
76- /// default liquid wallet yet") into an `Err` , i.e. an error snackbar on the
77- /// home screen, re-fired on every wallet sync. No wallet means no balance,
78- /// which is a signal value, not a failure.
79- Future <BigInt > _defaultLiquidBalanceSat () async {
80- try {
81- final wallets = await _getWalletsUsecase.execute (
82- onlyLiquid: true ,
83- onlyDefaults: true ,
84- );
85- return wallets.fold <BigInt >(BigInt .zero, (sum, w) => sum + w.balanceSat);
86- } on NoWalletsFoundException {
87- return BigInt .zero;
88- }
89- }
9048}
0 commit comments