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 <omarh.ismail1@gmail.com>
tuxsudo committed
May 25, 2024 at 10:57 UTC
0dc53895c60f8e8317fc7dd4b29d1c93a49258ba
1 file changed
+18
-13
lib/view_model/dashboard/dashboard_view_model.dart
+18
-13
@@ -535,24 +535,29 @@ abstract class DashboardViewModelBase with Store {
535
536
Future<ServicesResponse> getServicesStatus() async {
537
try {
538
- final res = await http.get(Uri.parse("https://service-api.cakewallet.com/v1/active-notices"));
538
+ if (isEnabledBulletinAction) {
539
+ final res = await http.get(Uri.parse("https://service-api.cakewallet.com/v1/active-notices"));
540
540
- if (res.statusCode < 200 || res.statusCode >= 300) {
541
- throw res.body;
542
- }
541
+ if (res.statusCode < 200 || res.statusCode >= 300) {
542
+ throw res.body;
543
+ }
544
544
- final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey);
545
+ final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey);
546
546
- final hash = await Cryptography.instance.sha256().hash(utf8.encode(res.body));
547
- final currentSha = bytesToHex(hash.bytes);
547
+ final hash = await Cryptography.instance.sha256().hash(utf8.encode(res.body));
548
+ final currentSha = bytesToHex(hash.bytes);
549
549
- final hasUpdates = oldSha != currentSha;
550
+ final hasUpdates = oldSha != currentSha;
551
551
- return ServicesResponse.fromJson(
552
- json.decode(res.body) as Map<String, dynamic>,
553
- hasUpdates,
554
- currentSha,
555
- );
552
+ return ServicesResponse.fromJson(
553
+ json.decode(res.body) as Map<String, dynamic>,
554
+ hasUpdates,
555
+ currentSha,
556
+ );
557
+ }
558
+ else {
559
+ return ServicesResponse([], false, '');
560
+ }
561
} catch (_) {
562
return ServicesResponse([], false, '');
563
}