diff --git a/lib/features/common/account/account_cache_repository.dart b/lib/features/common/account/account_cache_repository.dart index 7f9267fb..08f9ec6b 100644 --- a/lib/features/common/account/account_cache_repository.dart +++ b/lib/features/common/account/account_cache_repository.dart @@ -54,9 +54,19 @@ class AccountCacheRepository extends GlobalCacheRepository { List get accountItems => accounts.value; Account get accountItem => account.value!; - void addAccount(Account item) => accounts.value = [...accounts.value, item]; + void addAccount(Account item, {int? index}) { + if (index == null) { + accounts.value = [...accounts.value, item]; + } else { + final newList = accounts.value; + newList.insert(index, item); + accounts.value = newList; + } + } + void removeAccount(Account item) => accounts.value = accounts.value.where((e) => e.address != item.address).toList(); + void updateAccount(Account item) => accounts.value = accounts.value.map((e) { if (item.address == account.value!.address) { account.value = item; @@ -67,6 +77,7 @@ class AccountCacheRepository extends GlobalCacheRepository { } return e; }).toList(); + void resetAccounts() => accounts.value = []; void setXsdConversionRate(double value) => xsdConversionRate.value = value; diff --git a/lib/features/common/account/account_use_case.dart b/lib/features/common/account/account_use_case.dart index 3b6dae30..d9696f8d 100644 --- a/lib/features/common/account/account_use_case.dart +++ b/lib/features/common/account/account_use_case.dart @@ -32,8 +32,8 @@ class AccountUseCase extends ReactiveUseCase { update(account, item); } - void addAccount(Account item) async { - _accountCacheRepository.addAccount(item); + void addAccount(Account item, {int? index}) async { + _accountCacheRepository.addAccount(item, index: index); final items = _accountCacheRepository.accountItems; update(account, item); update(accounts, items); @@ -47,7 +47,7 @@ class AccountUseCase extends ReactiveUseCase { final items = _accountCacheRepository.accountItems; update(accounts, items); } - + bool isAccountSelected(Account item) { return (item.address == account.value!.address); } diff --git a/lib/features/settings/presentation/settings_page_presenter.dart b/lib/features/settings/presentation/settings_page_presenter.dart index 2c96bf35..61789a22 100644 --- a/lib/features/settings/presentation/settings_page_presenter.dart +++ b/lib/features/settings/presentation/settings_page_presenter.dart @@ -57,7 +57,7 @@ class SettingsPresenter extends CompletePresenter { final index = _accountUserCase.findAccountsLastIndex(); final newAccount = await _authUseCase.addNewAccount(index); - _accountUserCase.addAccount(newAccount); + _accountUserCase.addAccount(newAccount, index: index); loadCache(); notify(() => state.isLoading = false);