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>
This commit is contained in:
tuxsudo 2024-05-25 10:57:30 -04:00 committed by GitHub
parent 7d0720b21d
commit 0dc53895c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -535,24 +535,29 @@ abstract class DashboardViewModelBase with Store {
Future<ServicesResponse> getServicesStatus() async { Future<ServicesResponse> getServicesStatus() async {
try { 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) { if (res.statusCode < 200 || res.statusCode >= 300) {
throw res.body; 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<String, dynamic>,
hasUpdates,
currentSha,
);
} }
else {
final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); return ServicesResponse([], false, '');
}
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<String, dynamic>,
hasUpdates,
currentSha,
);
} catch (_) { } catch (_) {
return ServicesResponse([], false, ''); return ServicesResponse([], false, '');
} }