revert apimode changes

This commit is contained in:
fosse 2023-12-21 11:42:52 -05:00
parent 1b7718bb10
commit b79df2f3f8
10 changed files with 48 additions and 77 deletions

View file

@ -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_request.dart';
import 'package:cake_wallet/anonpay/anonpay_status_response.dart'; import 'package:cake_wallet/anonpay/anonpay_status_response.dart';
import 'package:cake_wallet/core/fiat_conversion_service.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/entities/fiat_currency.dart';
import 'package:cake_wallet/exchange/limits.dart'; import 'package:cake_wallet/exchange/limits.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
@ -15,10 +13,10 @@ import 'package:cake_wallet/.secrets.g.dart' as secrets;
class AnonPayApi { class AnonPayApi {
const AnonPayApi({ const AnonPayApi({
this.apiMode = ExchangeApiMode.enabled, this.useTorOnly = false,
required this.wallet, required this.wallet,
}); });
final ExchangeApiMode apiMode; final bool useTorOnly;
final WalletBase wallet; final WalletBase wallet;
static const anonpayRef = secrets.anonPayReferralCode; static const anonpayRef = secrets.anonPayReferralCode;
@ -135,23 +133,10 @@ class AnonPayApi {
}) async { }) async {
double fiatRate = 0.0; double fiatRate = 0.0;
if (fiatCurrency != null) { 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( fiatRate = await FiatConversionService.fetchPrice(
crypto: cryptoCurrency, crypto: cryptoCurrency,
fiat: fiatCurrency, fiat: fiatCurrency,
apiMode: fiatApiMode, torOnly: useTorOnly,
); );
} }
@ -215,7 +200,7 @@ class AnonPayApi {
Future<String> _getAuthority() async { Future<String> _getAuthority() async {
try { try {
if (apiMode == ExchangeApiMode.torOnly) { if (useTorOnly) {
return onionApiAuthority; return onionApiAuthority;
} }
final uri = Uri.https(onionApiAuthority, '/anonpay'); final uri = Uri.https(onionApiAuthority, '/anonpay');

View file

@ -16,7 +16,7 @@ const _fiatApiPath = '/v2/rates';
Future<double> _fetchPrice(Map<String, dynamic> args) async { Future<double> _fetchPrice(Map<String, dynamic> args) async {
final crypto = args['crypto'] as String; final crypto = args['crypto'] as String;
final fiat = args['fiat'] 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 mainThreadProxyPort = args['port'] as int;
final Map<String, String> queryParams = { final Map<String, String> queryParams = {
@ -84,11 +84,11 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
} }
Future<double> _fetchPriceAsync( Future<double> _fetchPriceAsync(
CryptoCurrency crypto, FiatCurrency fiat, FiatApiMode apiMode) async => CryptoCurrency crypto, FiatCurrency fiat, bool torOnly) async =>
compute(_fetchPrice, { compute(_fetchPrice, {
'fiat': fiat.toString(), 'fiat': fiat.toString(),
'crypto': crypto.toString(), 'crypto': crypto.toString(),
'apiMode': apiMode.toString(), 'torOnly': torOnly.toString(),
'port': ProxyWrapper.port, 'port': ProxyWrapper.port,
'torEnabled': ProxyWrapper.enabled, 'torEnabled': ProxyWrapper.enabled,
}); });
@ -97,7 +97,7 @@ class FiatConversionService {
static Future<double> fetchPrice({ static Future<double> fetchPrice({
required CryptoCurrency crypto, required CryptoCurrency crypto,
required FiatCurrency fiat, required FiatCurrency fiat,
required FiatApiMode apiMode, required bool torOnly,
}) async => }) async =>
await _fetchPriceAsync(crypto, fiat, apiMode); await _fetchPriceAsync(crypto, fiat, torOnly);
} }

View file

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

View file

@ -13,11 +13,11 @@ import 'package:cw_core/crypto_currency.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
class TrocadorExchangeProvider extends ExchangeProvider { class TrocadorExchangeProvider extends ExchangeProvider {
TrocadorExchangeProvider({this.apiMode = FiatApiMode.enabled, this.providerStates = const {}}) TrocadorExchangeProvider({this.useTorOnly = false, this.providerStates = const {}})
: _lastUsedRateId = '', _provider = [], : _lastUsedRateId = '', _provider = [],
super(pairList: supportedPairs(_notSupported)); super(pairList: supportedPairs(_notSupported));
FiatApiMode apiMode; bool useTorOnly;
final Map<String, bool> providerStates; final Map<String, bool> providerStates;
static const List<String> availableProviders = [ static const List<String> availableProviders = [
@ -309,7 +309,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
Future<Uri> _getUri(String path, Map<String, String> queryParams) async { Future<Uri> _getUri(String path, Map<String, String> queryParams) async {
final uri = Uri.http(onionApiAuthority, path, queryParams); final uri = Uri.http(onionApiAuthority, path, queryParams);
if (apiMode == FiatApiMode.torOnly) return uri; if (useTorOnly) return uri;
try { try {
await get(uri); await get(uri);

View file

@ -30,9 +30,10 @@ Future<void> startFiatRateUpdate(
} else { } else {
fiatConversionStore.prices[appStore.wallet!.currency] = fiatConversionStore.prices[appStore.wallet!.currency] =
await FiatConversionService.fetchPrice( await FiatConversionService.fetchPrice(
crypto: appStore.wallet!.currency, crypto: appStore.wallet!.currency,
fiat: settingsStore.fiatCurrency, fiat: settingsStore.fiatCurrency,
apiMode: settingsStore.fiatApiMode); torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
);
} }
Iterable<Erc20Token>? currencies; Iterable<Erc20Token>? currencies;
@ -52,7 +53,7 @@ Future<void> startFiatRateUpdate(
fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice( fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice(
crypto: currency, crypto: currency,
fiat: settingsStore.fiatCurrency, fiat: settingsStore.fiatCurrency,
apiMode: settingsStore.fiatApiMode, torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
); );
}.call(); }.call();
} }

View file

@ -7,19 +7,19 @@ import 'package:cake_wallet/store/app_store.dart';
ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer; ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer;
void startCurrentFiatApiModeChangeReaction( void startCurrentFiatApiModeChangeReaction(AppStore appStore,
AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose(); _onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
_onCurrentFiatCurrencyChangeDisposer = _onCurrentFiatCurrencyChangeDisposer = reaction(
reaction((_) => settingsStore.fiatApiMode, (FiatApiMode fiatApiMode) async { (_) => settingsStore.fiatApiMode, (FiatApiMode fiatApiMode) async {
if (appStore.wallet == null || fiatApiMode == FiatApiMode.disabled) { if (appStore.wallet == null || fiatApiMode == FiatApiMode.disabled) {
return; return;
} }
fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice( fiatConversionStore.prices[appStore.wallet!.currency] =
crypto: appStore.wallet!.currency, await FiatConversionService.fetchPrice(
fiat: settingsStore.fiatCurrency, crypto: appStore.wallet!.currency,
apiMode: fiatApiMode, fiat: settingsStore.fiatCurrency,
); torOnly: fiatApiMode == FiatApiMode.torOnly);
}); });
} }

View file

@ -8,20 +8,20 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer; ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer;
void startCurrentFiatChangeReaction( void startCurrentFiatChangeReaction(AppStore appStore,
AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose(); _onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
_onCurrentFiatCurrencyChangeDisposer = _onCurrentFiatCurrencyChangeDisposer = reaction(
reaction((_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async { (_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async {
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) { if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) {
return; return;
} }
final cryptoCurrency = appStore.wallet!.currency; final cryptoCurrency = appStore.wallet!.currency;
fiatConversionStore.prices[cryptoCurrency] = await FiatConversionService.fetchPrice( fiatConversionStore.prices[cryptoCurrency] =
crypto: cryptoCurrency, await FiatConversionService.fetchPrice(
fiat: fiatCurrency, crypto: cryptoCurrency,
apiMode: settingsStore.fiatApiMode, fiat: fiatCurrency,
); torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
}); });
} }

View file

@ -23,19 +23,16 @@ import 'package:cw_core/wallet_type.dart';
ReactionDisposer? _onCurrentWalletChangeReaction; ReactionDisposer? _onCurrentWalletChangeReaction;
ReactionDisposer? _onCurrentWalletChangeFiatRateUpdateReaction; ReactionDisposer? _onCurrentWalletChangeFiatRateUpdateReaction;
//ReactionDisposer _onCurrentWalletAddressChangeReaction; //ReactionDisposer _onCurrentWalletAddressChangeReaction;
void startCurrentWalletChangeReaction( void startCurrentWalletChangeReaction(
AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
_onCurrentWalletChangeReaction?.reaction.dispose(); _onCurrentWalletChangeReaction?.reaction.dispose();
_onCurrentWalletChangeFiatRateUpdateReaction?.reaction.dispose(); _onCurrentWalletChangeFiatRateUpdateReaction?.reaction.dispose();
//_onCurrentWalletAddressChangeReaction?.reaction?dispose(); //_onCurrentWalletAddressChangeReaction?.reaction?dispose();
//_onCurrentWalletAddressChangeReaction = reaction((_) => appStore.wallet.walletAddresses.address, //_onCurrentWalletAddressChangeReaction = reaction((_) => appStore.wallet.walletAddresses.address,
//(String address) async { //(String address) async {
//if (address == appStore.wallet.walletInfo.yatLastUsedAddress) { //if (address == appStore.wallet.walletInfo.yatLastUsedAddress) {
// return; // return;
//} //}
//try { //try {
// final yatStore = getIt.get<YatStore>(); // final yatStore = getIt.get<YatStore>();
// await updateEmojiIdAddress( // await updateEmojiIdAddress(
@ -50,7 +47,6 @@ void startCurrentWalletChangeReaction(
// print(e.toString()); // print(e.toString());
//} //}
//}); //});
_onCurrentWalletChangeReaction = reaction((_) => appStore.wallet, _onCurrentWalletChangeReaction = reaction((_) => appStore.wallet,
(WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>? (WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>?
wallet) async { wallet) async {
@ -58,33 +54,26 @@ void startCurrentWalletChangeReaction(
if (wallet == null) { if (wallet == null) {
return; return;
} }
final node = settingsStore.getCurrentNode(wallet.type); final node = settingsStore.getCurrentNode(wallet.type);
startWalletSyncStatusChangeReaction(wallet, fiatConversionStore); startWalletSyncStatusChangeReaction(wallet, fiatConversionStore);
startCheckConnectionReaction(wallet, settingsStore); startCheckConnectionReaction(wallet, settingsStore);
await getIt.get<SharedPreferences>().setString(PreferencesKey.currentWalletName, wallet.name); await getIt.get<SharedPreferences>().setString(PreferencesKey.currentWalletName, wallet.name);
await getIt await getIt
.get<SharedPreferences>() .get<SharedPreferences>()
.setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type)); .setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type));
if (wallet.type == WalletType.monero) { if (wallet.type == WalletType.monero) {
_setAutoGenerateSubaddressStatus(wallet, settingsStore); _setAutoGenerateSubaddressStatus(wallet, settingsStore);
} }
await wallet.connectToNode(node: node); await wallet.connectToNode(node: node);
if (wallet.type == WalletType.nano || wallet.type == WalletType.banano) { if (wallet.type == WalletType.nano || wallet.type == WalletType.banano) {
final powNode = settingsStore.getCurrentPowNode(wallet.type); final powNode = settingsStore.getCurrentPowNode(wallet.type);
await wallet.connectToPowNode(node: powNode); await wallet.connectToPowNode(node: powNode);
} }
if (wallet.type == WalletType.haven) { if (wallet.type == WalletType.haven) {
await updateHavenRate(fiatConversionStore); await updateHavenRate(fiatConversionStore);
} }
if (wallet.walletInfo.address.isEmpty) { if (wallet.walletInfo.address.isEmpty) {
wallet.walletInfo.address = wallet.walletAddresses.address; wallet.walletInfo.address = wallet.walletAddresses.address;
if (wallet.walletInfo.isInBox) { if (wallet.walletInfo.isInBox) {
await wallet.walletInfo.save(); await wallet.walletInfo.save();
} }
@ -93,7 +82,6 @@ void startCurrentWalletChangeReaction(
print(e.toString()); print(e.toString());
} }
}); });
_onCurrentWalletChangeFiatRateUpdateReaction = reaction((_) => appStore.wallet, _onCurrentWalletChangeFiatRateUpdateReaction = reaction((_) => appStore.wallet,
(WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>? (WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>?
wallet) async { wallet) async {
@ -104,10 +92,9 @@ void startCurrentWalletChangeReaction(
fiatConversionStore.prices[wallet.currency] = 0; fiatConversionStore.prices[wallet.currency] = 0;
fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice( fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice(
crypto: wallet.currency, crypto: wallet.currency,
fiat: settingsStore.fiatCurrency, fiat: settingsStore.fiatCurrency,
apiMode: settingsStore.fiatApiMode, torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
);
Iterable<Erc20Token>? currencies; Iterable<Erc20Token>? currencies;
if (wallet.type == WalletType.ethereum) { if (wallet.type == WalletType.ethereum) {
@ -118,15 +105,13 @@ void startCurrentWalletChangeReaction(
currencies = currencies =
polygon!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled); polygon!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled);
} }
if (currencies != null) { if (currencies != null) {
for (final currency in currencies) { for (final currency in currencies) {
() async { () async {
fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice( fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice(
crypto: currency, crypto: currency,
fiat: settingsStore.fiatCurrency, fiat: settingsStore.fiatCurrency,
apiMode: settingsStore.fiatApiMode, torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
);
}.call(); }.call();
} }
} }

View file

@ -86,10 +86,9 @@ abstract class HomeSettingsViewModelBase with Store {
try { try {
_balanceViewModel.fiatConvertationStore.prices[token] = _balanceViewModel.fiatConvertationStore.prices[token] =
await FiatConversionService.fetchPrice( await FiatConversionService.fetchPrice(
crypto: token, crypto: token,
fiat: _settingsStore.fiatCurrency, fiat: _settingsStore.fiatCurrency,
apiMode: _settingsStore.fiatApiMode, torOnly: _settingsStore.fiatApiMode == FiatApiMode.torOnly);
);
} catch (_) {} } catch (_) {}
} }

View file

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