You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cake_wallet/cw_wownero/lib/wownero_account_list.dart

79 lines
1.7 KiB

import 'package:mobx/mobx.dart';
import 'package:cw_core/account.dart';
import 'package:cw_wownero/api/account_list.dart' as account_list;
part 'wownero_account_list.g.dart';
class WowneroAccountList = WowneroAccountListBase with _$WowneroAccountList;
abstract class WowneroAccountListBase with Store {
WowneroAccountListBase()
: accounts = ObservableList<Account>(),
_isRefreshing = false,
_isUpdating = false {
refresh();
print(account_list.accountSizeNative());
}
@observable
ObservableList<Account> accounts;
bool _isRefreshing;
bool _isUpdating;
void update() async {
if (_isUpdating) {
return;
}
try {
_isUpdating = true;
refresh();
final accounts = getAll();
if (accounts.isNotEmpty) {
this.accounts.clear();
this.accounts.addAll(accounts);
}
_isUpdating = false;
} catch (e) {
_isUpdating = false;
rethrow;
}
}
List<Account> getAll() => account_list
.getAllAccount()
.map((accountRow) => Account(
id: accountRow.getId(),
label: accountRow.getLabel()))
.toList();
Future addAccount({String label}) async {
await account_list.addAccount(label: label);
update();
}
Future setLabelAccount({int accountIndex, String label}) async {
await account_list.setLabelForAccount(
accountIndex: accountIndex, label: label);
update();
}
void refresh() {
if (_isRefreshing) {
return;
}
try {
_isRefreshing = true;
account_list.refreshAccounts();
_isRefreshing = false;
} catch (e) {
_isRefreshing = false;
print(e);
rethrow;
}
}
}