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

Commit

Permalink
feat: Added remove & add chain for local fixed list comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Oct 23, 2023
1 parent 728abb7 commit 83f11b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ChainConfigurationUseCase extends ReactiveUseCase {
}

void updateFixedNetworks() {
final fixedList = Network.fixedNetworks();
for (int i = 0; i < _repository.items.length; i++) {
final repoItem = _repository.items[i];

Expand All @@ -61,12 +62,26 @@ class ChainConfigurationUseCase extends ReactiveUseCase {

if (index != -1) {
// matches
final fixedItem = Network.fixedNetworks().elementAt(index);
final fixedItem = fixedList.elementAt(index);
if (!repoItem.compareWithOther(fixedItem)) {
_repository.updateItem(repoItem.copyWithOther(fixedItem), i);
}
} else {
// Fixed network does't contain repo Item It means It's deleted
_repository.removeItem(repoItem);
}
}

// Adding new networks If available
for (Network network in fixedList) {
final foundIndex =
_repository.items.indexWhere((e) => e.chainId == network.chainId);

if (foundIndex == -1) {
_repository.addItem(network);
}
}

update(networks, _repository.items);
}

Expand Down Expand Up @@ -114,6 +129,10 @@ class ChainConfigurationUseCase extends ReactiveUseCase {
update(selectedNetwork, selectedNetwork.value);
}

void updateSelectedNetwork(Network updatedSelectedNetwork) {
update(selectedNetwork, updatedSelectedNetwork);
}

/// only for details of custom network delete network page
void selectNetworkForDetails(Network network) {
update(selectedNetworkForDetails, network);
Expand Down

0 comments on commit 83f11b2

Please sign in to comment.