From b79df2f3f8bc43d9925d8b3900057aeae37b977e Mon Sep 17 00:00:00 2001 From: fosse Date: Thu, 21 Dec 2023 11:42:52 -0500 Subject: [PATCH] revert apimode changes --- lib/anonpay/anonpay_api.dart | 23 +++------------- lib/core/fiat_conversion_service.dart | 10 +++---- lib/di.dart | 3 ++- .../provider/trocador_exchange_provider.dart | 6 ++--- lib/reactions/fiat_rate_update.dart | 9 ++++--- .../on_current_fiat_api_mode_change.dart | 18 ++++++------- lib/reactions/on_current_fiat_change.dart | 18 ++++++------- lib/reactions/on_current_wallet_change.dart | 27 +++++-------------- .../dashboard/home_settings_view_model.dart | 7 +++-- .../exchange/exchange_view_model.dart | 4 +-- 10 files changed, 48 insertions(+), 77 deletions(-) diff --git a/lib/anonpay/anonpay_api.dart b/lib/anonpay/anonpay_api.dart index e0729fec9..e46499407 100644 --- a/lib/anonpay/anonpay_api.dart +++ b/lib/anonpay/anonpay_api.dart @@ -4,8 +4,6 @@ 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'; @@ -15,10 +13,10 @@ import 'package:cake_wallet/.secrets.g.dart' as secrets; class AnonPayApi { const AnonPayApi({ - this.apiMode = ExchangeApiMode.enabled, + this.useTorOnly = false, required this.wallet, }); - final ExchangeApiMode apiMode; + final bool useTorOnly; final WalletBase wallet; static const anonpayRef = secrets.anonPayReferralCode; @@ -135,23 +133,10 @@ class AnonPayApi { }) async { double fiatRate = 0.0; if (fiatCurrency != null) { - late FiatApiMode fiatApiMode; - switch (apiMode) { - case ExchangeApiMode.torOnly: - fiatApiMode = FiatApiMode.torOnly; - break; - case ExchangeApiMode.disabled: - fiatApiMode = FiatApiMode.disabled; - break; - case ExchangeApiMode.enabled: - default: - fiatApiMode = FiatApiMode.enabled; - break; - } fiatRate = await FiatConversionService.fetchPrice( crypto: cryptoCurrency, fiat: fiatCurrency, - apiMode: fiatApiMode, + torOnly: useTorOnly, ); } @@ -215,7 +200,7 @@ class AnonPayApi { Future _getAuthority() async { try { - if (apiMode == ExchangeApiMode.torOnly) { + if (useTorOnly) { return onionApiAuthority; } final uri = Uri.https(onionApiAuthority, '/anonpay'); diff --git a/lib/core/fiat_conversion_service.dart b/lib/core/fiat_conversion_service.dart index b20376eb1..3e3673802 100644 --- a/lib/core/fiat_conversion_service.dart +++ b/lib/core/fiat_conversion_service.dart @@ -16,7 +16,7 @@ const _fiatApiPath = '/v2/rates'; Future _fetchPrice(Map args) async { final crypto = args['crypto'] as String; final fiat = args['fiat'] as String; - final torOnly = args['apiMode'] as String == FiatApiMode.torOnly.toString(); + final torOnly = args['torOnly'] as bool; final mainThreadProxyPort = args['port'] as int; final Map queryParams = { @@ -84,11 +84,11 @@ Future _fetchPrice(Map args) async { } Future _fetchPriceAsync( - CryptoCurrency crypto, FiatCurrency fiat, FiatApiMode apiMode) async => + CryptoCurrency crypto, FiatCurrency fiat, bool torOnly) async => compute(_fetchPrice, { 'fiat': fiat.toString(), 'crypto': crypto.toString(), - 'apiMode': apiMode.toString(), + 'torOnly': torOnly.toString(), 'port': ProxyWrapper.port, 'torEnabled': ProxyWrapper.enabled, }); @@ -97,7 +97,7 @@ class FiatConversionService { static Future fetchPrice({ required CryptoCurrency crypto, required FiatCurrency fiat, - required FiatApiMode apiMode, + required bool torOnly, }) async => - await _fetchPriceAsync(crypto, fiat, apiMode); + await _fetchPriceAsync(crypto, fiat, torOnly); } diff --git a/lib/di.dart b/lib/di.dart index 6cdef4d8a..1b29a7d32 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1128,7 +1128,8 @@ Future setup({ getIt.registerFactory(() => IoniaAccountCardsPage(getIt.get())); getIt.registerFactory(() => AnonPayApi( - apiMode: getIt.get().exchangeStatus, wallet: getIt.get().wallet!)); + useTorOnly: getIt.get().exchangeStatus == ExchangeApiMode.torOnly, + wallet: getIt.get().wallet!)); getIt.registerFactory(() => DesktopWalletSelectionDropDown(getIt.get(), getIt.get())); diff --git a/lib/exchange/provider/trocador_exchange_provider.dart b/lib/exchange/provider/trocador_exchange_provider.dart index 0468d4836..1ec434bb2 100644 --- a/lib/exchange/provider/trocador_exchange_provider.dart +++ b/lib/exchange/provider/trocador_exchange_provider.dart @@ -13,11 +13,11 @@ import 'package:cw_core/crypto_currency.dart'; import 'package:http/http.dart'; class TrocadorExchangeProvider extends ExchangeProvider { - TrocadorExchangeProvider({this.apiMode = FiatApiMode.enabled, this.providerStates = const {}}) + TrocadorExchangeProvider({this.useTorOnly = false, this.providerStates = const {}}) : _lastUsedRateId = '', _provider = [], super(pairList: supportedPairs(_notSupported)); - FiatApiMode apiMode; + bool useTorOnly; final Map providerStates; static const List availableProviders = [ @@ -309,7 +309,7 @@ class TrocadorExchangeProvider extends ExchangeProvider { Future _getUri(String path, Map queryParams) async { final uri = Uri.http(onionApiAuthority, path, queryParams); - if (apiMode == FiatApiMode.torOnly) return uri; + if (useTorOnly) return uri; try { await get(uri); diff --git a/lib/reactions/fiat_rate_update.dart b/lib/reactions/fiat_rate_update.dart index 551541119..828516978 100644 --- a/lib/reactions/fiat_rate_update.dart +++ b/lib/reactions/fiat_rate_update.dart @@ -30,9 +30,10 @@ Future startFiatRateUpdate( } else { fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice( - crypto: appStore.wallet!.currency, - fiat: settingsStore.fiatCurrency, - apiMode: settingsStore.fiatApiMode); + crypto: appStore.wallet!.currency, + fiat: settingsStore.fiatCurrency, + torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly, + ); } Iterable? currencies; @@ -52,7 +53,7 @@ Future startFiatRateUpdate( fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice( crypto: currency, fiat: settingsStore.fiatCurrency, - apiMode: settingsStore.fiatApiMode, + torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly, ); }.call(); } diff --git a/lib/reactions/on_current_fiat_api_mode_change.dart b/lib/reactions/on_current_fiat_api_mode_change.dart index 34519b653..5bcaeef4c 100644 --- a/lib/reactions/on_current_fiat_api_mode_change.dart +++ b/lib/reactions/on_current_fiat_api_mode_change.dart @@ -7,19 +7,19 @@ import 'package:cake_wallet/store/app_store.dart'; ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer; -void startCurrentFiatApiModeChangeReaction( - AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { +void startCurrentFiatApiModeChangeReaction(AppStore appStore, + SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { _onCurrentFiatCurrencyChangeDisposer?.reaction.dispose(); - _onCurrentFiatCurrencyChangeDisposer = - reaction((_) => settingsStore.fiatApiMode, (FiatApiMode fiatApiMode) async { + _onCurrentFiatCurrencyChangeDisposer = reaction( + (_) => settingsStore.fiatApiMode, (FiatApiMode fiatApiMode) async { if (appStore.wallet == null || fiatApiMode == FiatApiMode.disabled) { return; } - fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice( - crypto: appStore.wallet!.currency, - fiat: settingsStore.fiatCurrency, - apiMode: fiatApiMode, - ); + fiatConversionStore.prices[appStore.wallet!.currency] = + await FiatConversionService.fetchPrice( + crypto: appStore.wallet!.currency, + fiat: settingsStore.fiatCurrency, + torOnly: fiatApiMode == FiatApiMode.torOnly); }); } diff --git a/lib/reactions/on_current_fiat_change.dart b/lib/reactions/on_current_fiat_change.dart index c7c2bd2b6..873984940 100644 --- a/lib/reactions/on_current_fiat_change.dart +++ b/lib/reactions/on_current_fiat_change.dart @@ -8,20 +8,20 @@ import 'package:cake_wallet/entities/fiat_currency.dart'; ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer; -void startCurrentFiatChangeReaction( - AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { +void startCurrentFiatChangeReaction(AppStore appStore, + SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { _onCurrentFiatCurrencyChangeDisposer?.reaction.dispose(); - _onCurrentFiatCurrencyChangeDisposer = - reaction((_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async { + _onCurrentFiatCurrencyChangeDisposer = reaction( + (_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async { if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) { return; } final cryptoCurrency = appStore.wallet!.currency; - fiatConversionStore.prices[cryptoCurrency] = await FiatConversionService.fetchPrice( - crypto: cryptoCurrency, - fiat: fiatCurrency, - apiMode: settingsStore.fiatApiMode, - ); + fiatConversionStore.prices[cryptoCurrency] = + await FiatConversionService.fetchPrice( + crypto: cryptoCurrency, + fiat: fiatCurrency, + torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly); }); } diff --git a/lib/reactions/on_current_wallet_change.dart b/lib/reactions/on_current_wallet_change.dart index fbe0af5c3..e7be4d05a 100644 --- a/lib/reactions/on_current_wallet_change.dart +++ b/lib/reactions/on_current_wallet_change.dart @@ -23,19 +23,16 @@ import 'package:cw_core/wallet_type.dart'; ReactionDisposer? _onCurrentWalletChangeReaction; ReactionDisposer? _onCurrentWalletChangeFiatRateUpdateReaction; //ReactionDisposer _onCurrentWalletAddressChangeReaction; - void startCurrentWalletChangeReaction( AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { _onCurrentWalletChangeReaction?.reaction.dispose(); _onCurrentWalletChangeFiatRateUpdateReaction?.reaction.dispose(); //_onCurrentWalletAddressChangeReaction?.reaction?dispose(); - //_onCurrentWalletAddressChangeReaction = reaction((_) => appStore.wallet.walletAddresses.address, //(String address) async { //if (address == appStore.wallet.walletInfo.yatLastUsedAddress) { // return; //} - //try { // final yatStore = getIt.get(); // await updateEmojiIdAddress( @@ -50,7 +47,6 @@ void startCurrentWalletChangeReaction( // print(e.toString()); //} //}); - _onCurrentWalletChangeReaction = reaction((_) => appStore.wallet, (WalletBase, TransactionInfo>? wallet) async { @@ -58,33 +54,26 @@ void startCurrentWalletChangeReaction( if (wallet == null) { return; } - final node = settingsStore.getCurrentNode(wallet.type); - startWalletSyncStatusChangeReaction(wallet, fiatConversionStore); startCheckConnectionReaction(wallet, settingsStore); await getIt.get().setString(PreferencesKey.currentWalletName, wallet.name); await getIt .get() .setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type)); - if (wallet.type == WalletType.monero) { _setAutoGenerateSubaddressStatus(wallet, settingsStore); } - await wallet.connectToNode(node: node); if (wallet.type == WalletType.nano || wallet.type == WalletType.banano) { final powNode = settingsStore.getCurrentPowNode(wallet.type); await wallet.connectToPowNode(node: powNode); } - if (wallet.type == WalletType.haven) { await updateHavenRate(fiatConversionStore); } - if (wallet.walletInfo.address.isEmpty) { wallet.walletInfo.address = wallet.walletAddresses.address; - if (wallet.walletInfo.isInBox) { await wallet.walletInfo.save(); } @@ -93,7 +82,6 @@ void startCurrentWalletChangeReaction( print(e.toString()); } }); - _onCurrentWalletChangeFiatRateUpdateReaction = reaction((_) => appStore.wallet, (WalletBase, TransactionInfo>? wallet) async { @@ -104,10 +92,9 @@ void startCurrentWalletChangeReaction( fiatConversionStore.prices[wallet.currency] = 0; fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice( - crypto: wallet.currency, - fiat: settingsStore.fiatCurrency, - apiMode: settingsStore.fiatApiMode, - ); + crypto: wallet.currency, + fiat: settingsStore.fiatCurrency, + torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly); Iterable? currencies; if (wallet.type == WalletType.ethereum) { @@ -118,15 +105,13 @@ void startCurrentWalletChangeReaction( currencies = polygon!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled); } - if (currencies != null) { for (final currency in currencies) { () async { fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice( - crypto: currency, - fiat: settingsStore.fiatCurrency, - apiMode: settingsStore.fiatApiMode, - ); + crypto: currency, + fiat: settingsStore.fiatCurrency, + torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly); }.call(); } } diff --git a/lib/view_model/dashboard/home_settings_view_model.dart b/lib/view_model/dashboard/home_settings_view_model.dart index 37d5d6539..fc2c27a7c 100644 --- a/lib/view_model/dashboard/home_settings_view_model.dart +++ b/lib/view_model/dashboard/home_settings_view_model.dart @@ -86,10 +86,9 @@ abstract class HomeSettingsViewModelBase with Store { try { _balanceViewModel.fiatConvertationStore.prices[token] = await FiatConversionService.fetchPrice( - crypto: token, - fiat: _settingsStore.fiatCurrency, - apiMode: _settingsStore.fiatApiMode, - ); + crypto: token, + fiat: _settingsStore.fiatCurrency, + torOnly: _settingsStore.fiatApiMode == FiatApiMode.torOnly); } catch (_) {} } diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 5e061e5dc..57d47fed6 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -145,8 +145,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with ChangeNowExchangeProvider(settingsStore: _settingsStore), SideShiftExchangeProvider(), SimpleSwapExchangeProvider(), - TrocadorExchangeProvider(apiMode: _settingsStore.fiatApiMode, - providerStates: _settingsStore.trocadorProviderStates), + TrocadorExchangeProvider( + useTorOnly: _useTorOnly, providerStates: _settingsStore.trocadorProviderStates), if (FeatureFlag.isExolixEnabled) ExolixExchangeProvider(), ];