diff --git a/lib/pages/settings_views/global_settings_view/manage_nodes_views/node_details_view.dart b/lib/pages/settings_views/global_settings_view/manage_nodes_views/node_details_view.dart index 49a2127f8..e4c298453 100644 --- a/lib/pages/settings_views/global_settings_view/manage_nodes_views/node_details_view.dart +++ b/lib/pages/settings_views/global_settings_view/manage_nodes_views/node_details_view.dart @@ -14,6 +14,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/test_epic_box_connection.dart'; +import 'package:stackwallet/utilities/test_eth_node_connection.dart'; import 'package:stackwallet/utilities/test_monero_node_connection.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -150,6 +151,14 @@ class _NodeDetailsViewState extends ConsumerState { } break; + + case Coin.ethereum: + try { + testPassed = await testEthNodeConnection(node!.host); + } catch (_) { + testPassed = false; + } + break; } if (testPassed) { diff --git a/lib/utilities/test_eth_node_connection.dart b/lib/utilities/test_eth_node_connection.dart new file mode 100644 index 000000000..f90ae1353 --- /dev/null +++ b/lib/utilities/test_eth_node_connection.dart @@ -0,0 +1,12 @@ +import 'package:http/http.dart'; +import 'package:web3dart/web3dart.dart' as web3; + +Future testEthNodeConnection(String host) async { + web3.Web3Client client = web3.Web3Client(host, Client()); + try { + await client.getBlockNumber(); + return true; + } catch (_) { + return false; + } +} diff --git a/lib/widgets/node_card.dart b/lib/widgets/node_card.dart index 7717e0dbb..8c145ac18 100644 --- a/lib/widgets/node_card.dart +++ b/lib/widgets/node_card.dart @@ -17,6 +17,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/sync_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/test_epic_box_connection.dart'; +import 'package:stackwallet/utilities/test_eth_node_connection.dart'; import 'package:stackwallet/utilities/test_monero_node_connection.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -172,6 +173,14 @@ class _NodeCardState extends ConsumerState { } break; + + case Coin.ethereum: + try { + testPassed = await testEthNodeConnection(node.host); + } catch (_) { + testPassed = false; + } + break; } if (testPassed) { diff --git a/lib/widgets/node_options_sheet.dart b/lib/widgets/node_options_sheet.dart index 6eb4b0626..919b2e0ce 100644 --- a/lib/widgets/node_options_sheet.dart +++ b/lib/widgets/node_options_sheet.dart @@ -17,6 +17,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/sync_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/test_epic_box_connection.dart'; +import 'package:stackwallet/utilities/test_eth_node_connection.dart'; import 'package:stackwallet/utilities/test_monero_node_connection.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; @@ -155,6 +156,14 @@ class NodeOptionsSheet extends ConsumerWidget { } break; + + case Coin.ethereum: + try { + testPassed = await testEthNodeConnection(node.host); + } catch (_) { + testPassed = false; + } + break; } if (testPassed) {