show firo sparl electrumx data cache size and implement clearing of that cache when all electrumx cache for firo is cleared

This commit is contained in:
julian 2024-05-31 11:59:43 -06:00
parent 16acbc366b
commit de949efbff
5 changed files with 154 additions and 1 deletions

View file

@ -29,6 +29,34 @@ List<String> _ffiHashTagsComputeWrapper(List<String> base64Tags) {
abstract class FiroCacheCoordinator {
static Future<void> init() => _FiroCache.init();
static Future<void> clearSharedCache() async {
return await _FiroCache._deleteAllCache();
}
static Future<String> getSparkCacheSize() async {
final dir = await StackFileSystem.applicationSQLiteDirectory();
final cacheFile = File("${dir.path}/${_FiroCache.sqliteDbFileName}");
final int bytes;
if (await cacheFile.exists()) {
bytes = await cacheFile.length();
} else {
bytes = 0;
}
if (bytes < 1024) {
return '$bytes B';
} else if (bytes < 1048576) {
final double kbSize = bytes / 1024;
return '${kbSize.toStringAsFixed(2)} KB';
} else if (bytes < 1073741824) {
final double mbSize = bytes / 1048576;
return '${mbSize.toStringAsFixed(2)} MB';
} else {
final double gbSize = bytes / 1073741824;
return '${gbSize.toStringAsFixed(2)} GB';
}
}
static Future<void> runFetchAndUpdateSparkUsedCoinTags(
ElectrumXClient client,
) async {
@ -164,6 +192,23 @@ abstract class _FiroCache {
);
}
static Future<void> _deleteAllCache() async {
final start = DateTime.now();
db.execute(
"""
DELETE FROM SparkSet;
DELETE FROM SparkCoin;
DELETE FROM SparkSetCoins;
DELETE FROM SparkUsedCoinTags;
VACUUM;
""",
);
_debugLog(
"_deleteAllCache() "
"duration = ${DateTime.now().difference(start)}",
);
}
static Future<void> _createDb(String file) async {
final db = sqlite3.open(
file,

View file

@ -16,6 +16,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tuple/tuple.dart';
import '../../../db/hive/db.dart';
import '../../../db/sqlite/firo_cache.dart';
import '../../../models/epicbox_config_model.dart';
import '../../../notifications/show_flush_bar.dart';
import '../../../providers/global/wallets_provider.dart';
@ -413,7 +414,8 @@ class _WalletSettingsViewState extends ConsumerState<WalletSettingsView> {
),
);
if (result == "OK" && mounted) {
if (result == "OK" &&
context.mounted) {
await showLoading(
whileFuture: Future.wait<void>(
[
@ -426,6 +428,9 @@ class _WalletSettingsViewState extends ConsumerState<WalletSettingsView> {
.clearSharedTransactionCache(
currency: coin,
),
if (coin is Firo)
FiroCacheCoordinator
.clearSharedCache(),
],
),
context: context,

View file

@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../db/sqlite/firo_cache.dart';
import '../../../../themes/stack_colors.dart';
import '../../../../utilities/text_styles.dart';
import '../../../../widgets/background.dart';
import '../../../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../../../widgets/detail_item.dart';
class SparkInfoView extends ConsumerWidget {
const SparkInfoView({
super.key,
});
static const String routeName = "/sparkInfo";
@override
Widget build(BuildContext context, WidgetRef ref) {
return Background(
child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () {
Navigator.of(context).pop();
},
),
title: Text(
"Spark Info",
style: STextStyles.navBarTitle(context),
),
),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
FutureBuilder(
future: FiroCacheCoordinator.getSparkCacheSize(),
builder: (_, snapshot) {
String detail = "Loading...";
if (snapshot.connectionState == ConnectionState.done) {
detail = snapshot.data ?? detail;
}
return DetailItem(
title: "Spark electrumx cache size",
detail: detail,
);
},
),
],
),
),
),
);
}
}

View file

@ -24,6 +24,7 @@ import '../../../pinpad_views/lock_screen_view.dart';
import 'delete_wallet_warning_view.dart';
import 'lelantus_settings_view.dart';
import 'rename_wallet_view.dart';
import 'spark_info.dart';
class WalletSettingsWalletSettingsView extends ConsumerWidget {
const WalletSettingsWalletSettingsView({
@ -216,6 +217,39 @@ class WalletSettingsWalletSettingsView extends ConsumerWidget {
),
),
),
const SizedBox(
height: 8,
),
RoundedWhiteContainer(
padding: const EdgeInsets.all(0),
child: RawMaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {
Navigator.of(context).pushNamed(
SparkInfoView.routeName,
);
},
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12.0,
vertical: 20,
),
child: Row(
children: [
Text(
"Spark info",
style: STextStyles.titleBold12(context),
),
],
),
),
),
),
],
),
),

View file

@ -131,6 +131,7 @@ import 'pages/settings_views/wallet_settings_view/wallet_settings_wallet_setting
import 'pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/delete_wallet_warning_view.dart';
import 'pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/lelantus_settings_view.dart';
import 'pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/rename_wallet_view.dart';
import 'pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/spark_info.dart';
import 'pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/wallet_settings_wallet_settings_view.dart';
import 'pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/xpub_view.dart';
import 'pages/special/firo_rescan_recovery_error_dialog.dart';
@ -1966,6 +1967,15 @@ class RouteGenerator {
}
return _routeError("${settings.name} invalid args: ${args.toString()}");
case SparkInfoView.routeName:
return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => const SparkInfoView(),
settings: RouteSettings(
name: settings.name,
),
);
// == Desktop specific routes ============================================
case CreatePasswordView.routeName:
if (args is bool) {