mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 20:39:35 +00:00
revert apimode changes
This commit is contained in:
parent
1b7718bb10
commit
b79df2f3f8
10 changed files with 48 additions and 77 deletions
|
@ -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<String> _getAuthority() async {
|
||||
try {
|
||||
if (apiMode == ExchangeApiMode.torOnly) {
|
||||
if (useTorOnly) {
|
||||
return onionApiAuthority;
|
||||
}
|
||||
final uri = Uri.https(onionApiAuthority, '/anonpay');
|
||||
|
|
|
@ -16,7 +16,7 @@ const _fiatApiPath = '/v2/rates';
|
|||
Future<double> _fetchPrice(Map<String, dynamic> 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<String, String> queryParams = {
|
||||
|
@ -84,11 +84,11 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
|||
}
|
||||
|
||||
Future<double> _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<double> fetchPrice({
|
||||
required CryptoCurrency crypto,
|
||||
required FiatCurrency fiat,
|
||||
required FiatApiMode apiMode,
|
||||
required bool torOnly,
|
||||
}) async =>
|
||||
await _fetchPriceAsync(crypto, fiat, apiMode);
|
||||
await _fetchPriceAsync(crypto, fiat, torOnly);
|
||||
}
|
||||
|
|
|
@ -1128,7 +1128,8 @@ Future<void> setup({
|
|||
getIt.registerFactory(() => IoniaAccountCardsPage(getIt.get<IoniaAccountViewModel>()));
|
||||
|
||||
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(() =>
|
||||
DesktopWalletSelectionDropDown(getIt.get<WalletListViewModel>(), getIt.get<AuthService>()));
|
||||
|
|
|
@ -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<String, bool> providerStates;
|
||||
|
||||
static const List<String> availableProviders = [
|
||||
|
@ -309,7 +309,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
Future<Uri> _getUri(String path, Map<String, String> queryParams) async {
|
||||
final uri = Uri.http(onionApiAuthority, path, queryParams);
|
||||
|
||||
if (apiMode == FiatApiMode.torOnly) return uri;
|
||||
if (useTorOnly) return uri;
|
||||
|
||||
try {
|
||||
await get(uri);
|
||||
|
|
|
@ -32,7 +32,8 @@ Future<void> startFiatRateUpdate(
|
|||
await FiatConversionService.fetchPrice(
|
||||
crypto: appStore.wallet!.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
apiMode: settingsStore.fiatApiMode);
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
);
|
||||
}
|
||||
|
||||
Iterable<Erc20Token>? currencies;
|
||||
|
@ -52,7 +53,7 @@ Future<void> startFiatRateUpdate(
|
|||
fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
apiMode: settingsStore.fiatApiMode,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
);
|
||||
}.call();
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
fiatConversionStore.prices[appStore.wallet!.currency] =
|
||||
await FiatConversionService.fetchPrice(
|
||||
crypto: appStore.wallet!.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
apiMode: fiatApiMode,
|
||||
);
|
||||
torOnly: fiatApiMode == FiatApiMode.torOnly);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
fiatConversionStore.prices[cryptoCurrency] =
|
||||
await FiatConversionService.fetchPrice(
|
||||
crypto: cryptoCurrency,
|
||||
fiat: fiatCurrency,
|
||||
apiMode: settingsStore.fiatApiMode,
|
||||
);
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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<YatStore>();
|
||||
// await updateEmojiIdAddress(
|
||||
|
@ -50,7 +47,6 @@ void startCurrentWalletChangeReaction(
|
|||
// print(e.toString());
|
||||
//}
|
||||
//});
|
||||
|
||||
_onCurrentWalletChangeReaction = reaction((_) => appStore.wallet,
|
||||
(WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, 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<SharedPreferences>().setString(PreferencesKey.currentWalletName, wallet.name);
|
||||
await getIt
|
||||
.get<SharedPreferences>()
|
||||
.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<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>?
|
||||
wallet) async {
|
||||
|
@ -106,8 +94,7 @@ void startCurrentWalletChangeReaction(
|
|||
fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: wallet.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
apiMode: settingsStore.fiatApiMode,
|
||||
);
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
|
||||
Iterable<Erc20Token>? 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,
|
||||
);
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
}.call();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,8 +88,7 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
await FiatConversionService.fetchPrice(
|
||||
crypto: token,
|
||||
fiat: _settingsStore.fiatCurrency,
|
||||
apiMode: _settingsStore.fiatApiMode,
|
||||
);
|
||||
torOnly: _settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in a new issue