@@ -315,21 +315,26 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
315
315
final networks = _chainConfigurationUseCase.networks.value;
316
316
final foundChainIdIndex =
317
317
networks.indexWhere ((element) => element.chainId == chainId);
318
+ // user can add a network again meaning It will override the old network
319
+ final alreadyExists = foundChainIdIndex != - 1 ;
320
+ final alreadyEnabled =
321
+ alreadyExists ? networks[foundChainIdIndex].enabled : false ;
322
+
323
+ // Add network
324
+ final newNetwork = Network .fromAddEthereumChain (networkDetails, chainId);
325
+
326
+ final res = await showAddNetworkDialog (
327
+ context! ,
328
+ network: newNetwork,
329
+ approveFunction: (network) => alreadyExists
330
+ ? updateNetwork (network, foundChainIdIndex)
331
+ : addNewNetwork (network),
332
+ );
318
333
319
- // TODO:
320
- if (foundChainIdIndex == - 1 ) {
321
- // Add network
322
- final newNetwork = Network .fromAddEthereumChain (networkDetails, chainId);
323
-
324
- final res = await showAddNetworkDialog (
325
- context! ,
326
- network: newNetwork,
327
- approveFunction: addNewNetwork,
328
- );
329
-
330
- if (! (res ?? false )) {
331
- cancelRequest (id);
332
- } else {
334
+ if (! (res ?? false )) {
335
+ cancelRequest (id);
336
+ } else {
337
+ if (! alreadyEnabled) {
333
338
final res = await showSwitchNetworkDialog (context! ,
334
339
fromNetwork: state.network! .label ?? state.network! .web3RpcHttpUrl,
335
340
toNetwork: newNetwork.label ?? newNetwork.web3RpcHttpUrl,
@@ -340,13 +345,14 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
340
345
cancelRequest (id);
341
346
}
342
347
}
343
- } else {
344
- // TODO:
345
- addError (translate ('Network already exists!' ));
346
- cancelRequest (id);
347
348
}
348
349
}
349
350
351
+ Network ? updateNetwork (Network network, int index) {
352
+ _chainConfigurationUseCase.updateItem (network, index);
353
+ return network;
354
+ }
355
+
350
356
Network ? addNewNetwork (Network newNetwork) {
351
357
_chainConfigurationUseCase.addItem (newNetwork);
352
358
return newNetwork;
0 commit comments