diff --git a/lib/pages/accounts/rescan.dart b/lib/pages/accounts/rescan.dart index 351bcdaa..ee6a9c43 100644 --- a/lib/pages/accounts/rescan.dart +++ b/lib/pages/accounts/rescan.dart @@ -162,7 +162,7 @@ class _RewindState extends State { if (!confirmed) return; WarpApi.rewindTo(aa.coin, height); Future(() async { - syncStatus2.sync(true); + syncStatus2.sync(); }); GoRouter.of(context).pop(); } diff --git a/lib/pages/main/sync_status.dart b/lib/pages/main/sync_status.dart index bef6e132..c773e0ca 100644 --- a/lib/pages/main/sync_status.dart +++ b/lib/pages/main/sync_status.dart @@ -45,7 +45,7 @@ class SyncStatusState extends State { case 0: return '$syncedHeight / $latestHeight'; case 1: - final m = syncStatus2.isRescan ? s.rescan : s.catchup; + final m = syncStatus2.rescanning ? s.rescan : s.catchup; return '$m $percent %'; case 2: return remaining != null ? '$remaining...' : ''; @@ -104,7 +104,7 @@ class SyncStatusState extends State { } else { if (syncStatus2.paused) syncStatus2.setPause(false); - Future(() => syncStatus2.sync(false)); + Future(() => syncStatus2.sync()); } } } diff --git a/lib/pages/more/vote.dart b/lib/pages/more/vote.dart index 72df6f86..d0e957cb 100644 --- a/lib/pages/more/vote.dart +++ b/lib/pages/more/vote.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; +import 'package:gap/gap.dart'; import 'package:http/http.dart' as http; import 'package:go_router/go_router.dart'; import 'package:settings_ui/settings_ui.dart'; @@ -222,6 +223,7 @@ class VoteCandidateState extends State @override Widget build(BuildContext context) { + final t = Theme.of(context); final e = widget.vote.election; final candidates = e.candidates .asMap() @@ -240,12 +242,18 @@ class VoteCandidateState extends State child: Padding( padding: EdgeInsets.fromLTRB(8, 0, 8, 0), child: FormBuilder( - child: FormBuilderRadioGroup( - name: 'candidates', - initialValue: candidate, - orientation: OptionsOrientation.vertical, - options: candidates, - onChanged: (v) => setState(() => candidate = v!), + child: Column( + children: [ + Text(e.question, style: t.textTheme.headlineSmall), + Gap(16), + FormBuilderRadioGroup( + name: 'candidates', + initialValue: candidate, + orientation: OptionsOrientation.vertical, + options: candidates, + onChanged: (v) => setState(() => candidate = v!), + ), + ], ), ), ), diff --git a/lib/pages/splash.dart b/lib/pages/splash.dart index 2cd7a8c3..ddfc811f 100644 --- a/lib/pages/splash.dart +++ b/lib/pages/splash.dart @@ -269,7 +269,7 @@ void backgroundSyncDispatcher() { if (!appStore.initialized) return; Workmanager().executeTask((task, inputData) async { logger.i("Native called background task: $task"); - await syncStatus2.sync(false, auto: true); + await syncStatus2.sync(auto: true); return true; }); } diff --git a/lib/store2.dart b/lib/store2.dart index 0d0781b4..fdc54e37 100644 --- a/lib/store2.dart +++ b/lib/store2.dart @@ -51,9 +51,9 @@ Timer? syncTimer; Future startAutoSync() async { if (syncTimer == null) { await syncStatus2.update(); - await syncStatus2.sync(false, auto: true); + await syncStatus2.sync(auto: true); syncTimer = Timer.periodic(Duration(seconds: 15), (timer) { - syncStatus2.sync(false, auto: true); + syncStatus2.sync(auto: true); aa.updateDivisified(); }); } @@ -65,7 +65,6 @@ class SyncStatus2 = _SyncStatus2 with _$SyncStatus2; abstract class _SyncStatus2 with Store { int startSyncedHeight = 0; - bool isRescan = false; ETA eta = ETA(); @observable @@ -86,6 +85,8 @@ abstract class _SyncStatus2 with Store { @observable bool paused = false; + bool rescanning = false; + @observable int downloadedSize = 0; @@ -117,7 +118,7 @@ abstract class _SyncStatus2 with Store { @action void reset() { - isRescan = false; + rescanning = false; syncedHeight = WarpApi.getDbHeight(aa.coin).height; syncing = false; paused = false; @@ -139,8 +140,8 @@ abstract class _SyncStatus2 with Store { } @action - Future sync(bool rescan, {bool auto = false}) async { - logger.d('R/A/P/S $rescan $auto $paused $syncing'); + Future sync({bool auto = false}) async { + logger.d('A/P/S $auto $paused $syncing'); if (paused) return; if (syncing) return; try { @@ -148,13 +149,18 @@ abstract class _SyncStatus2 with Store { final lh = latestHeight; if (lh == null) return; // don't auto sync more than 1 month of data - if (!rescan && auto && lh - syncedHeight > 30 * 24 * 60 * 4 / 5) { + if (!rescanning && auto && lh - syncedHeight > 30 * 24 * 60 * 4 / 5) { paused = true; return; } - if (isSynced) return; + if (isSynced) { + rescanning = false; + return; + } + // user started/resumed a manual scan + if (!auto) + rescanning = true; syncing = true; - isRescan = rescan; _updateSyncedHeight(); startSyncedHeight = syncedHeight; eta.begin(latestHeight!); @@ -212,7 +218,7 @@ abstract class _SyncStatus2 with Store { WarpApi.rescanFrom(aa.coin, height); _updateSyncedHeight(); paused = false; - await sync(true); + await sync(); } @action