This commit is contained in:
Matthew Fosse 2023-12-11 08:56:10 -08:00
parent 54463b2ca3
commit 3108c759e0
5 changed files with 13 additions and 10 deletions

View file

@ -4,6 +4,8 @@ import 'package:cake_wallet/anonpay/anonpay_invoice_info.dart';
import 'package:cake_wallet/anonpay/anonpay_request.dart';
import 'package:cake_wallet/anonpay/anonpay_status_response.dart';
import 'package:cake_wallet/core/fiat_conversion_service.dart';
import 'package:cake_wallet/entities/exchange_api_mode.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/exchange/limits.dart';
import 'package:cw_core/wallet_base.dart';
@ -13,10 +15,10 @@ import 'package:cake_wallet/.secrets.g.dart' as secrets;
class AnonPayApi {
const AnonPayApi({
this.useTorOnly = false,
this.apiMode = ExchangeApiMode.enabled,
required this.wallet,
});
final bool useTorOnly;
final ExchangeApiMode apiMode;
final WalletBase wallet;
static const anonpayRef = secrets.anonPayReferralCode;
@ -136,7 +138,7 @@ class AnonPayApi {
fiatRate = await FiatConversionService.fetchPrice(
crypto: cryptoCurrency,
fiat: fiatCurrency,
torOnly: useTorOnly,
apiMode: apiMode,
);
}
@ -200,7 +202,7 @@ class AnonPayApi {
Future<String> _getAuthority() async {
try {
if (useTorOnly) {
if (apiMode == ExchangeApiMode.torOnly) {
return onionApiAuthority;
}
final uri = Uri.https(onionApiAuthority, '/anonpay');

View file

@ -1125,7 +1125,7 @@ Future<void> setup({
getIt.registerFactory(() => IoniaAccountCardsPage(getIt.get<IoniaAccountViewModel>()));
getIt.registerFactory(() => AnonPayApi(
useTorOnly: getIt.get<SettingsStore>().exchangeStatus == ExchangeApiMode.torOnly,
apiMode: getIt.get<SettingsStore>().exchangeStatus,
wallet: getIt.get<AppStore>().wallet!));
getIt.registerFactory(() =>

View file

@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/limits.dart';
import 'package:cake_wallet/exchange/provider/exchange_provider.dart';
@ -12,11 +13,11 @@ import 'package:cw_core/crypto_currency.dart';
import 'package:http/http.dart';
class TrocadorExchangeProvider extends ExchangeProvider {
TrocadorExchangeProvider({this.useTorOnly = false, this.providerStates = const {}})
TrocadorExchangeProvider({this.apiMode = FiatApiMode.enabled, this.providerStates = const {}})
: _lastUsedRateId = '', _provider = [],
super(pairList: supportedPairs(_notSupported));
bool useTorOnly;
FiatApiMode apiMode;
final Map<String, bool> providerStates;
static const List<String> availableProviders = [
@ -304,7 +305,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
Future<Uri> _getUri(String path, Map<String, String> queryParams) async {
final uri = Uri.http(onionApiAuthority, path, queryParams);
if (useTorOnly) return uri;
if (apiMode == FiatApiMode.torOnly) return uri;
try {
await get(uri);

View file

@ -32,7 +32,7 @@ Future<void> startFiatRateUpdate(
await FiatConversionService.fetchPrice(
crypto: appStore.wallet!.currency,
fiat: settingsStore.fiatCurrency,
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
apiMode: settingsStore.fiatApiMode == FiatApiMode.torOnly);
}
Iterable<Erc20Token>? currencies;

View file

@ -147,7 +147,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
ChangeNowExchangeProvider(settingsStore: _settingsStore),
SideShiftExchangeProvider(),
SimpleSwapExchangeProvider(),
TrocadorExchangeProvider(useTorOnly: _useTorOnly,
TrocadorExchangeProvider(apiMode: _settingsStore.fiatApiMode,
providerStates: _settingsStore.trocadorProviderStates),
if (FeatureFlag.isExolixEnabled) ExolixExchangeProvider(),
];