From 0dc53895c60f8e8317fc7dd4b29d1c93a49258ba Mon Sep 17 00:00:00 2001 From: tuxsudo Date: Sat, 25 May 2024 10:57:30 -0400 Subject: [PATCH] Fix connection leak when service bulletin is disabled (#1465) * Fix connection leak when service bulletin disabled * Update dashboard_view_model.dart --------- Co-authored-by: Omar Hatem --- .../dashboard/dashboard_view_model.dart | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index bd8ae6dda..f438c5724 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -535,24 +535,29 @@ abstract class DashboardViewModelBase with Store { Future getServicesStatus() async { try { - final res = await http.get(Uri.parse("https://service-api.cakewallet.com/v1/active-notices")); + if (isEnabledBulletinAction) { + final res = await http.get(Uri.parse("https://service-api.cakewallet.com/v1/active-notices")); - if (res.statusCode < 200 || res.statusCode >= 300) { - throw res.body; + if (res.statusCode < 200 || res.statusCode >= 300) { + throw res.body; + } + + final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); + + final hash = await Cryptography.instance.sha256().hash(utf8.encode(res.body)); + final currentSha = bytesToHex(hash.bytes); + + final hasUpdates = oldSha != currentSha; + + return ServicesResponse.fromJson( + json.decode(res.body) as Map, + hasUpdates, + currentSha, + ); } - - final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); - - final hash = await Cryptography.instance.sha256().hash(utf8.encode(res.body)); - final currentSha = bytesToHex(hash.bytes); - - final hasUpdates = oldSha != currentSha; - - return ServicesResponse.fromJson( - json.decode(res.body) as Map, - hasUpdates, - currentSha, - ); + else { + return ServicesResponse([], false, ''); + } } catch (_) { return ServicesResponse([], false, ''); }