Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix: Added accounts numbering & separation
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Oct 18, 2023
1 parent 655b25f commit 187f634
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lib/features/common/account/account_cache_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@ class AccountCacheRepository extends GlobalCacheRepository {
List<Account> 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;
Expand All @@ -67,6 +77,7 @@ class AccountCacheRepository extends GlobalCacheRepository {
}
return e;
}).toList();

void resetAccounts() => accounts.value = [];

void setXsdConversionRate(double value) => xsdConversionRate.value = value;
Expand Down
6 changes: 3 additions & 3 deletions lib/features/common/account/account_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SettingsPresenter extends CompletePresenter<SettingsState> {
final index = _accountUserCase.findAccountsLastIndex();

final newAccount = await _authUseCase.addNewAccount(index);
_accountUserCase.addAccount(newAccount);
_accountUserCase.addAccount(newAccount, index: index);
loadCache();

notify(() => state.isLoading = false);
Expand Down

0 comments on commit 187f634

Please sign in to comment.