From 74983756f4329146a7364f36f0d3c3a3dbac28b2 Mon Sep 17 00:00:00 2001 From: CharlVS <77973576+CharlVS@users.noreply.github.com> Date: Sat, 21 Mar 2026 14:29:26 +0100 Subject: [PATCH 1/2] fix(app): gate startup coin icon precaching --- lib/app_config/app_config.dart | 5 +++++ lib/bloc/app_bloc_root.dart | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/app_config/app_config.dart b/lib/app_config/app_config.dart index f4a192dfe1..c3e93177f0 100644 --- a/lib/app_config/app_config.dart +++ b/lib/app_config/app_config.dart @@ -1,6 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:web_dex/common/screen.dart'; const String mmRpcVersion = '2.0'; // issue https://github.com/flutter/flutter/issues/19462#issuecomment-478284020 @@ -36,6 +37,10 @@ const bool isBitrefillIntegrationEnabled = false; ///! trading purposes where it is not legally compliant. const bool kShowTradingWarning = false; +/// Controls whether startup coin icon precaching is enabled. +/// Defaults to web-only via the compile-time platform constant. +bool get kEnableCoinIconPrecache => kIsWeb && isMobile; + const Duration kPerformanceLogInterval = Duration(minutes: 1); /// Enable debug logging for electrum connections and RPC methods. diff --git a/lib/bloc/app_bloc_root.dart b/lib/bloc/app_bloc_root.dart index a8547cb77c..91cd9bdf07 100644 --- a/lib/bloc/app_bloc_root.dart +++ b/lib/bloc/app_bloc_root.dart @@ -359,6 +359,10 @@ class _MyAppViewState extends State<_MyAppView> { void didChangeDependencies() { super.didChangeDependencies(); + if (!kEnableCoinIconPrecache) { + return; + } + final sdk = RepositoryProvider.of(context); _precacheCoinIcons(sdk).ignore(); } From 3ae405423a66d5567c5d04b526a15b4384c7f94f Mon Sep 17 00:00:00 2001 From: CharlVS <77973576+CharlVS@users.noreply.github.com> Date: Sat, 21 Mar 2026 14:51:34 +0100 Subject: [PATCH 2/2] fix(app): dedupe startup coin icon precache --- lib/bloc/app_bloc_root.dart | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/bloc/app_bloc_root.dart b/lib/bloc/app_bloc_root.dart index 91cd9bdf07..ad59a044cc 100644 --- a/lib/bloc/app_bloc_root.dart +++ b/lib/bloc/app_bloc_root.dart @@ -396,19 +396,19 @@ class _MyAppViewState extends State<_MyAppView> { } } - Completer? _currentPrecacheOperation; - - Future _precacheCoinIcons(KomodoDefiSdk sdk) async { - if (_currentPrecacheOperation != null && - !_currentPrecacheOperation!.isCompleted) { - // completeError throws an uncaught exception, which causes the UI - // tests to fail when switching between light and dark theme - log('New request to precache icons started.'); - _currentPrecacheOperation!.complete(); + Future? _currentPrecacheOperation; + + Future _precacheCoinIcons(KomodoDefiSdk sdk) { + final currentPrecacheOperation = _currentPrecacheOperation; + if (currentPrecacheOperation != null) { + log('Coin icon precache already started, reusing existing operation.'); + return currentPrecacheOperation; } - _currentPrecacheOperation = Completer(); + return _currentPrecacheOperation = _runCoinIconPrecache(sdk); + } + Future _runCoinIconPrecache(KomodoDefiSdk sdk) async { try { final stopwatch = Stopwatch()..start(); final availableAssetIds = sdk.assets.available.keys.where( @@ -421,7 +421,6 @@ class _MyAppViewState extends State<_MyAppView> { // not mounted and return early with error. // ignore: use_build_context_synchronously // if (context.findRenderObject() == null) { - // _currentPrecacheOperation!.completeError('Build context is stale.'); // return; // } @@ -432,8 +431,6 @@ class _MyAppViewState extends State<_MyAppView> { ).onError((_, __) => debugPrint('Error precaching coin icon $assetId')); } - _currentPrecacheOperation!.complete(); - if (!mounted) return; context.read().logEvent( CoinsDataUpdatedEventData( @@ -444,7 +441,7 @@ class _MyAppViewState extends State<_MyAppView> { ); } catch (e) { log('Error precaching coin icons: $e'); - _currentPrecacheOperation!.completeError(e); + rethrow; } } }