2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_monero/api/wallet.dart';
|
2024-04-10 12:27:10 +00:00
|
|
|
import 'package:monero/monero.dart' as monero;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-04-10 12:27:10 +00:00
|
|
|
monero.wallet? wptr = null;
|
|
|
|
monero.SubaddressAccount? account;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
bool isUpdating = false;
|
|
|
|
|
|
|
|
void refreshAccounts() {
|
|
|
|
try {
|
|
|
|
isUpdating = true;
|
2024-04-10 12:27:10 +00:00
|
|
|
account = monero.Wallet_subaddressAccount(wptr!);
|
|
|
|
monero.SubaddressAccount_refresh(account!);
|
2021-12-24 12:52:08 +00:00
|
|
|
isUpdating = false;
|
|
|
|
} catch (e) {
|
|
|
|
isUpdating = false;
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-10 12:27:10 +00:00
|
|
|
List<monero.SubaddressAccountRow> getAllAccount() {
|
|
|
|
// final size = monero.Wallet_numSubaddressAccounts(wptr!);
|
|
|
|
final size = monero.SubaddressAccount_getAll_size(wptr!);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-04-10 12:27:10 +00:00
|
|
|
return List.generate(size, (index) {
|
|
|
|
return monero.SubaddressAccount_getAll_byIndex(wptr!, index: index);
|
|
|
|
});
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
void addAccountSync({required String label}) {
|
2024-04-10 12:27:10 +00:00
|
|
|
monero.Wallet_addSubaddressAccount(wptr!, label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
void setLabelForAccountSync({required int accountIndex, required String label}) {
|
2024-04-10 12:27:10 +00:00
|
|
|
// TODO(mrcyjanek): this may be wrong function?
|
|
|
|
monero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: 0, label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<void> addAccount({required String label}) async {
|
2024-04-10 12:27:10 +00:00
|
|
|
_addAccount(label);
|
2021-12-24 12:52:08 +00:00
|
|
|
await store();
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
2024-04-10 12:27:10 +00:00
|
|
|
_setLabelForAccount({'accountIndex': accountIndex, 'label': label});
|
2021-12-24 12:52:08 +00:00
|
|
|
await store();
|
|
|
|
}
|