cake_wallet/cw_monero/lib/api/account_list.dart
Czarek Nakamoto 176150cc55 ...
2024-04-20 19:32:13 +02:00

61 lines
No EOL
1.8 KiB
Dart

import 'package:cw_monero/api/wallet.dart';
import 'package:monero/monero.dart' as monero;
monero.wallet? wptr = null;
monero.SubaddressAccount? subaddressAccount;
bool isUpdating = false;
void refreshAccounts() {
try {
isUpdating = true;
subaddressAccount = monero.Wallet_subaddressAccount(wptr!);
monero.SubaddressAccount_refresh(subaddressAccount!);
isUpdating = false;
} catch (e) {
isUpdating = false;
rethrow;
}
}
List<monero.SubaddressAccountRow> getAllAccount() {
// final size = monero.Wallet_numSubaddressAccounts(wptr!);
refreshAccounts();
int size = monero.SubaddressAccount_getAll_size(subaddressAccount!);
print("size: $size");
if (size == 0) {
monero.Wallet_addSubaddressAccount(wptr!);
return getAllAccount();
}
return List.generate(size, (index) {
return monero.SubaddressAccount_getAll_byIndex(subaddressAccount!, index: index);
});
}
void addAccountSync({required String label}) {
monero.Wallet_addSubaddressAccount(wptr!, label: label);
}
void setLabelForAccountSync({required int accountIndex, required String label}) {
// TODO(mrcyjanek): this may be wrong function?
monero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: 0, label: label);
}
void _addAccount(String label) => addAccountSync(label: label);
void _setLabelForAccount(Map<String, dynamic> args) {
final label = args['label'] as String;
final accountIndex = args['accountIndex'] as int;
setLabelForAccountSync(label: label, accountIndex: accountIndex);
}
Future<void> addAccount({required String label}) async {
_addAccount(label);
await store();
}
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
_setLabelForAccount({'accountIndex': accountIndex, 'label': label});
await store();
}