From 83f11b2925ff9c6421d1a13cab63478c8284dbc9 Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 23 Oct 2023 10:04:26 +0330 Subject: [PATCH] feat: Added remove & add chain for local fixed list comparison --- .../domain/chain_configuration_use_case.dart | 21 ++++++++++++++++++- packages/shared | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart index e497bbd2..891f4fa5 100644 --- a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart +++ b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart @@ -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]; @@ -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); } @@ -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); diff --git a/packages/shared b/packages/shared index ec30acf4..a3e46009 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit ec30acf43d8e5369f6aae0cf642d8f4198fa4e2a +Subproject commit a3e460096a0242eff5fd7fa5c51d88a2ea6705d5