From e104c5427d7db218ee8e8a4b644892ac49f1a8a2 Mon Sep 17 00:00:00 2001 From: Hanh Date: Mon, 28 Mar 2022 13:55:48 +0800 Subject: [PATCH] Handle deletion of active account --- lib/account_manager.dart | 6 ++++++ lib/accounts.dart | 13 ++++++++++--- lib/home.dart | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/account_manager.dart b/lib/account_manager.dart index 92c41f4..ce6acfb 100644 --- a/lib/account_manager.dart +++ b/lib/account_manager.dart @@ -28,6 +28,12 @@ class AccountManagerState extends State { showAboutOnce(this.context); } + @override + void dispose() { + active.updateAccount(); + super.dispose(); + } + @override Widget build(BuildContext context) { final theme = Theme.of(context); diff --git a/lib/accounts.dart b/lib/accounts.dart index 6e4b095..672432d 100644 --- a/lib/accounts.dart +++ b/lib/accounts.dart @@ -110,10 +110,9 @@ abstract class _AccountManager2 with Store { class ActiveAccount = _ActiveAccount with _$ActiveAccount; abstract class _ActiveAccount with Store { - @observable - int dataEpoch = 0; + @observable int dataEpoch = 0; - int coin = 0; + @observable int coin = 0; int id = 0; Account account = emptyAccount; @@ -158,6 +157,7 @@ abstract class _ActiveAccount with Store { @action Future setActiveAccount(int _coin, int _id) async { + print("setActiveAccount $_coin $_id"); coin = _coin; id = _id; accounts.saveActive(coin, id); @@ -189,6 +189,13 @@ abstract class _ActiveAccount with Store { await priceStore.updateChart(); } + @action + Future updateAccount() async { + final a = accounts.get(coin, id); + if (a.id != active.id) + await setActiveAccount(a.coin, a.id); + } + @action void toggleShowTAddr() { showTAddr = !showTAddr; diff --git a/lib/home.dart b/lib/home.dart index ea12795..a8fd0eb 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -9,6 +9,7 @@ import 'package:warp_api/warp_api.dart'; import 'about.dart'; import 'account.dart'; import 'account_manager.dart'; +import 'accounts.dart'; import 'budget.dart'; import 'contact.dart'; import 'history.dart'; @@ -65,6 +66,7 @@ class HomeState extends State { @override Widget build(BuildContext context) => Observer(builder: (context) { final _simpleMode = settings.simpleMode; + final _dataEpoch = active.dataEpoch; final key = UniqueKey(); return HomeInnerPage(key: key); });