dev
dart 66 lines 1.75 KB
Raw
1 import 'dart:async';
2
3 import 'package:cw_core/utils/print_verbose.dart';
4 import 'package:cw_monero/api/wallet.dart';
5 import 'package:cw_monero/monero_account_list.dart';
6 import 'package:monero/src/wallet2.dart';
7 import 'package:monero/src/monero.dart';
8
9 Wallet2Wallet? currentWallet = null;
10 bool get isViewOnly => int.tryParse(currentWallet!.secretSpendKey()) == 0;
11
12 int _wlptrForW = 0;
13 Wallet2WalletListener? _wlptr = null;
14
15 Wallet2WalletListener? getWlptr() {
16 if (currentWallet == null) return null;
17 if (_wlptrForW == currentWallet!.ffiAddress()) {
18 return _wlptr;
19 } else {
20 _wlptrForW = currentWallet!.ffiAddress();
21 _wlptr = currentWallet!.getWalletListener();
22 return _wlptr;
23 }
24 }
25
26 Wallet2SubaddressAccount? subaddressAccount;
27
28 bool isUpdating = false;
29
30 void refreshAccounts() {
31 try {
32 isUpdating = true;
33 subaddressAccount = currentWallet?.subaddressAccount();
34 subaddressAccount?.refresh();
35 isUpdating = false;
36 } catch (e) {
37 isUpdating = false;
38 rethrow;
39 }
40 }
41
42 List<Wallet2SubaddressAccountRow> getAllAccount() {
43 // final size = monero.Wallet_numSubaddressAccounts(wptr!);
44 refreshAccounts();
45 int size = subaddressAccount!.getAll_size();
46 if (size == 0) {
47 currentWallet!.addSubaddressAccount();
48 currentWallet!.status();
49 return [];
50 }
51 return List.generate(size, (index) {
52 return subaddressAccount!.getAll_byIndex(index);
53 });
54 }
55
56 void addAccount({required String label}) {
57 currentWallet!.addSubaddressAccount(label: label);
58 unawaited(store());
59 }
60
61 void setLabelForAccount({required int accountIndex, required String label}) {
62 subaddressAccount!.setLabel(accountIndex: accountIndex, label: label);
63 MoneroAccountListBase.cachedAccounts[currentWallet!.ffiAddress()] = [];
64 refreshAccounts();
65 unawaited(store());
66 }