stack_wallet/lib/utilities/test_epic_box_connection.dart

27 lines
708 B
Dart
Raw Normal View History

2022-08-26 08:11:35 +00:00
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:stackwallet/utilities/logger.dart';
Future<bool> testEpicBoxNodeConnection(Uri uri) async {
try {
final client = http.Client();
final response = await client.get(
uri,
headers: {'Content-Type': 'application/json'},
).timeout(const Duration(milliseconds: 1200),
onTimeout: () async => http.Response('Error', 408));
final json = jsonDecode(response.body);
if (response.statusCode == 200 && json["node_version"] != null) {
return true;
} else {
return false;
}
} catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
return false;
}
}