Handle deletion of active account

This commit is contained in:
Hanh 2022-03-28 13:55:48 +08:00
parent 3933ef021a
commit e104c5427d
3 changed files with 18 additions and 3 deletions

View File

@ -28,6 +28,12 @@ class AccountManagerState extends State<AccountManagerPage> {
showAboutOnce(this.context);
}
@override
void dispose() {
active.updateAccount();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

View File

@ -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<void> 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<void> updateAccount() async {
final a = accounts.get(coin, id);
if (a.id != active.id)
await setActiveAccount(a.coin, a.id);
}
@action
void toggleShowTAddr() {
showTAddr = !showTAddr;

View File

@ -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<HomePage> {
@override
Widget build(BuildContext context) => Observer(builder: (context) {
final _simpleMode = settings.simpleMode;
final _dataEpoch = active.dataEpoch;
final key = UniqueKey();
return HomeInnerPage(key: key);
});