Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/app_config/app_config.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
27 changes: 14 additions & 13 deletions lib/bloc/app_bloc_root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ class _MyAppViewState extends State<_MyAppView> {
void didChangeDependencies() {
super.didChangeDependencies();

if (!kEnableCoinIconPrecache) {
return;
}

final sdk = RepositoryProvider.of<KomodoDefiSdk>(context);
_precacheCoinIcons(sdk).ignore();
}
Expand Down Expand Up @@ -392,19 +396,19 @@ class _MyAppViewState extends State<_MyAppView> {
}
}

Completer<void>? _currentPrecacheOperation;
Future<void>? _currentPrecacheOperation;

Future<void> _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<void> _precacheCoinIcons(KomodoDefiSdk sdk) {
final currentPrecacheOperation = _currentPrecacheOperation;
if (currentPrecacheOperation != null) {
log('Coin icon precache already started, reusing existing operation.');
return currentPrecacheOperation;
}

_currentPrecacheOperation = Completer<void>();
return _currentPrecacheOperation = _runCoinIconPrecache(sdk);
}

Future<void> _runCoinIconPrecache(KomodoDefiSdk sdk) async {
try {
final stopwatch = Stopwatch()..start();
final availableAssetIds = sdk.assets.available.keys.where(
Expand All @@ -417,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;
// }

Expand All @@ -428,8 +431,6 @@ class _MyAppViewState extends State<_MyAppView> {
).onError((_, __) => debugPrint('Error precaching coin icon $assetId'));
}

_currentPrecacheOperation!.complete();

if (!mounted) return;
context.read<AnalyticsBloc>().logEvent(
CoinsDataUpdatedEventData(
Expand All @@ -440,7 +441,7 @@ class _MyAppViewState extends State<_MyAppView> {
);
} catch (e) {
log('Error precaching coin icons: $e');
_currentPrecacheOperation!.completeError(e);
rethrow;
}
}
}
Loading