From 46ff2706d928d09713f09ac466ba5a02671df0fe Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Mon, 18 Mar 2024 14:18:15 -0700 Subject: [PATCH] make service api use proxy wrapper --- lib/di.dart | 1 + .../dashboard/dashboard_view_model.dart | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index 24c66b0bc..b990f60ab 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -392,6 +392,7 @@ Future setup({ keyService: getIt.get(), torViewModel: getIt.get(), sharedPreferences: getIt.get(), + proxyWrapper: getIt.get(), )); getIt.registerFactory( diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index 291087f86..03596eaa2 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:cake_wallet/buy/buy_provider.dart'; import 'package:cake_wallet/core/key_service.dart'; +import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; @@ -20,6 +21,7 @@ import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/store/yat/yat_store.dart'; import 'package:cake_wallet/utils/mobx.dart'; +import 'package:cake_wallet/utils/proxy_wrapper.dart'; import 'package:cake_wallet/view_model/dashboard/action_list_item.dart'; import 'package:cake_wallet/view_model/dashboard/anonpay_transaction_list_item.dart'; import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart'; @@ -68,6 +70,7 @@ abstract class DashboardViewModelBase with Store { required this.anonpayTransactionsStore, required this.keyService, required this.torViewModel, + required this.proxyWrapper, required this.sharedPreferences, }) : hasSellAction = false, hasBuyAction = false, @@ -299,6 +302,8 @@ abstract class DashboardViewModelBase with Store { TorViewModel torViewModel; + ProxyWrapper proxyWrapper; + AppStore appStore; SettingsStore settingsStore; @@ -523,21 +528,24 @@ abstract class DashboardViewModelBase with Store { Future getServicesStatus() async { try { - final res = await http.get(Uri.parse("https://service-api.cakewallet.com/v1/active-notices")); + final res = await proxyWrapper.get( + clearnetUri: Uri.parse("https://service-api.cakewallet.com/v1/active-notices"), + ); + final responseBody = await utf8.decodeStream(res); if (res.statusCode < 200 || res.statusCode >= 300) { - throw res.body; + throw responseBody; } final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); - final hash = await Cryptography.instance.sha256().hash(utf8.encode(res.body)); + final hash = await Cryptography.instance.sha256().hash(utf8.encode(responseBody)); final currentSha = bytesToHex(hash.bytes); final hasUpdates = oldSha != currentSha; return ServicesResponse.fromJson( - json.decode(res.body) as Map, + json.decode(responseBody) as Map, hasUpdates, currentSha, );