diff --git a/cw_monero/lib/api/account_list.dart b/cw_monero/lib/api/account_list.dart index 28b00c925..3ceef5815 100644 --- a/cw_monero/lib/api/account_list.dart +++ b/cw_monero/lib/api/account_list.dart @@ -1,4 +1,7 @@ +import 'dart:async'; + import 'package:cw_monero/api/wallet.dart'; +import 'package:cw_monero/monero_account_list.dart'; import 'package:monero/monero.dart' as monero; monero.wallet? wptr = null; @@ -15,7 +18,6 @@ monero.WalletListener? getWlptr() { return _wlptr!; } - monero.SubaddressAccount? subaddressAccount; bool isUpdating = false; @@ -51,8 +53,9 @@ void addAccountSync({required String 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); + monero.SubaddressAccount_setLabel(subaddressAccount!, accountIndex: accountIndex, label: label); + MoneroAccountListBase.cachedAccounts[wptr!.address] = []; + refreshAccounts(); } void _addAccount(String label) => addAccountSync(label: label); @@ -66,10 +69,10 @@ void _setLabelForAccount(Map args) { Future addAccount({required String label}) async { _addAccount(label); - await store(); + unawaited(store()); } Future setLabelForAccount({required int accountIndex, required String label}) async { _setLabelForAccount({'accountIndex': accountIndex, 'label': label}); - await store(); + unawaited(store()); } \ No newline at end of file diff --git a/cw_monero/lib/monero_account_list.dart b/cw_monero/lib/monero_account_list.dart index 82a0efd32..c9a48a939 100644 --- a/cw_monero/lib/monero_account_list.dart +++ b/cw_monero/lib/monero_account_list.dart @@ -45,18 +45,18 @@ abstract class MoneroAccountListBase with Store { } } - Map> _cachedAccounts = {}; + static Map> cachedAccounts = {}; List getAll() { final allAccounts = account_list.getAllAccount(); final currentCount = allAccounts.length; - _cachedAccounts[account_list.wptr!.address] ??= []; + cachedAccounts[account_list.wptr!.address] ??= []; - if (_cachedAccounts[account_list.wptr!.address]!.length == currentCount) { - return _cachedAccounts[account_list.wptr!.address]!; + if (cachedAccounts[account_list.wptr!.address]!.length == currentCount) { + return cachedAccounts[account_list.wptr!.address]!; } - _cachedAccounts[account_list.wptr!.address] = allAccounts.map((accountRow) { + cachedAccounts[account_list.wptr!.address] = allAccounts.map((accountRow) { final balance = monero.SubaddressAccountRow_getUnlockedBalance(accountRow); return Account( @@ -66,7 +66,7 @@ abstract class MoneroAccountListBase with Store { ); }).toList(); - return _cachedAccounts[account_list.wptr!.address]!; + return cachedAccounts[account_list.wptr!.address]!; } Future addAccount({required String label}) async { diff --git a/cw_wownero/lib/api/account_list.dart b/cw_wownero/lib/api/account_list.dart index a73e4dcd2..5bd18d51e 100644 --- a/cw_wownero/lib/api/account_list.dart +++ b/cw_wownero/lib/api/account_list.dart @@ -48,8 +48,7 @@ void addAccountSync({required String label}) { } void setLabelForAccountSync({required int accountIndex, required String label}) { - // TODO(mrcyjanek): this may be wrong function? - wownero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: 0, label: label); + wownero.SubaddressAccount_setLabel(subaddressAccount!, accountIndex: accountIndex, label: label); } void _addAccount(String label) => addAccountSync(label: label);