make service api use proxy wrapper

This commit is contained in:
Matthew Fosse 2024-03-18 14:18:15 -07:00
parent 08eb54b3b3
commit 46ff2706d9
2 changed files with 13 additions and 4 deletions

View file

@ -392,6 +392,7 @@ Future<void> setup({
keyService: getIt.get<KeyService>(), keyService: getIt.get<KeyService>(),
torViewModel: getIt.get<TorViewModel>(), torViewModel: getIt.get<TorViewModel>(),
sharedPreferences: getIt.get<SharedPreferences>(), sharedPreferences: getIt.get<SharedPreferences>(),
proxyWrapper: getIt.get<ProxyWrapper>(),
)); ));
getIt.registerFactory<AuthService>( getIt.registerFactory<AuthService>(

View file

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:cake_wallet/buy/buy_provider.dart'; import 'package:cake_wallet/buy/buy_provider.dart';
import 'package:cake_wallet/core/key_service.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/auto_generate_subaddress_status.dart';
import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/preferences_key.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/settings_store.dart';
import 'package:cake_wallet/store/yat/yat_store.dart'; import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:cake_wallet/utils/mobx.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/action_list_item.dart';
import 'package:cake_wallet/view_model/dashboard/anonpay_transaction_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'; 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.anonpayTransactionsStore,
required this.keyService, required this.keyService,
required this.torViewModel, required this.torViewModel,
required this.proxyWrapper,
required this.sharedPreferences, required this.sharedPreferences,
}) : hasSellAction = false, }) : hasSellAction = false,
hasBuyAction = false, hasBuyAction = false,
@ -299,6 +302,8 @@ abstract class DashboardViewModelBase with Store {
TorViewModel torViewModel; TorViewModel torViewModel;
ProxyWrapper proxyWrapper;
AppStore appStore; AppStore appStore;
SettingsStore settingsStore; SettingsStore settingsStore;
@ -523,21 +528,24 @@ 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")); 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) { if (res.statusCode < 200 || res.statusCode >= 300) {
throw res.body; throw responseBody;
} }
final oldSha = sharedPreferences.getString(PreferencesKey.serviceStatusShaKey); 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 currentSha = bytesToHex(hash.bytes);
final hasUpdates = oldSha != currentSha; final hasUpdates = oldSha != currentSha;
return ServicesResponse.fromJson( return ServicesResponse.fromJson(
json.decode(res.body) as Map<String, dynamic>, json.decode(responseBody) as Map<String, dynamic>,
hasUpdates, hasUpdates,
currentSha, currentSha,
); );