mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 20:09:24 +00:00
review fixes
This commit is contained in:
parent
e2413be087
commit
3ae3753e22
16 changed files with 54 additions and 92 deletions
|
@ -4,19 +4,19 @@ 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/di.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/exchange/limits.dart';
|
||||
import 'package:cake_wallet/utils/proxy_wrapper.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
|
||||
class AnonPayApi {
|
||||
const AnonPayApi({
|
||||
this.useTorOnly = false,
|
||||
required this.wallet,
|
||||
});
|
||||
final bool useTorOnly;
|
||||
final WalletBase wallet;
|
||||
|
||||
static const anonpayRef = secrets.anonPayReferralCode;
|
||||
|
@ -29,9 +29,9 @@ class AnonPayApi {
|
|||
static const apiKey = secrets.trocadorApiKey;
|
||||
|
||||
Future<AnonpayStatusResponse> paymentStatus(String id) async {
|
||||
final authority = await _getAuthority();
|
||||
final response = await get(Uri.https(authority, "$anonPayStatus/$id"));
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final response = await proxyGet("$anonPayStatus/$id", {});
|
||||
final responseBody = await utf8.decodeStream(response);
|
||||
final responseJSON = json.decode(responseBody) as Map<String, dynamic>;
|
||||
final status = responseJSON['Status'] as String;
|
||||
final fiatAmount = responseJSON['Fiat_Amount'] as double?;
|
||||
final fiatEquiv = responseJSON['Fiat_Equiv'] as String?;
|
||||
|
@ -69,11 +69,10 @@ class AnonPayApi {
|
|||
if (request.fiatEquivalent != null) {
|
||||
body['fiat_equiv'] = request.fiatEquivalent;
|
||||
}
|
||||
final authority = await _getAuthority();
|
||||
|
||||
final response = await get(Uri.https(authority, anonPayPath, body));
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final response = await proxyGet(anonPayPath, body);
|
||||
final responseBody = await utf8.decodeStream(response);
|
||||
final responseJSON = json.decode(responseBody) as Map<String, dynamic>;
|
||||
final id = responseJSON['ID'] as String;
|
||||
final url = responseJSON['url'] as String;
|
||||
final urlOnion = responseJSON['url_onion'] as String;
|
||||
|
@ -136,8 +135,6 @@ class AnonPayApi {
|
|||
fiatRate = await FiatConversionService.fetchPrice(
|
||||
crypto: cryptoCurrency,
|
||||
fiat: fiatCurrency,
|
||||
torOnly: useTorOnly,
|
||||
onionOnly: false,// TODO: CW-519
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -147,16 +144,14 @@ class AnonPayApi {
|
|||
'name': cryptoCurrency.name,
|
||||
};
|
||||
|
||||
final String apiAuthority = await _getAuthority();
|
||||
final uri = Uri.https(apiAuthority, coinPath, params);
|
||||
|
||||
final response = await get(uri);
|
||||
final response = await proxyGet(coinPath, params);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as List<dynamic>;
|
||||
final responseBody = await utf8.decodeStream(response);
|
||||
final responseJSON = json.decode(responseBody) as List<dynamic>;
|
||||
|
||||
if (responseJSON.isEmpty) {
|
||||
throw Exception('No data');
|
||||
|
@ -199,16 +194,14 @@ class AnonPayApi {
|
|||
}
|
||||
}
|
||||
|
||||
Future<String> _getAuthority() async {
|
||||
try {
|
||||
if (useTorOnly) {
|
||||
return onionApiAuthority;
|
||||
}
|
||||
final uri = Uri.https(onionApiAuthority, '/anonpay');
|
||||
await get(uri);
|
||||
return onionApiAuthority;
|
||||
} catch (e) {
|
||||
return clearNetAuthority;
|
||||
}
|
||||
Future<HttpClientResponse> proxyGet(String path, Map<String, dynamic> queryParams) async {
|
||||
ProxyWrapper proxy = await getIt.get<ProxyWrapper>();
|
||||
Uri onionUri = Uri.http(onionApiAuthority, path, queryParams);
|
||||
Uri clearnetUri = Uri.https(clearNetAuthority, path, queryParams);
|
||||
return await proxy.get(
|
||||
onionUri: onionUri,
|
||||
clearnetUri: clearnetUri,
|
||||
torOnly: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ 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['torOnly'] as bool;
|
||||
final mainThreadProxyPort = args['port'] as int;
|
||||
|
||||
final Map<String, String> queryParams = {
|
||||
|
@ -43,7 +42,7 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
|||
onionUri: onionUri,
|
||||
clearnetUri: clearnetUri,
|
||||
portOverride: mainThreadProxyPort,
|
||||
torOnly: torOnly,
|
||||
torOnly: false,
|
||||
);
|
||||
responseBody = await utf8.decodeStream(httpResponse);
|
||||
statusCode = httpResponse.statusCode;
|
||||
|
@ -70,30 +69,17 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
|||
}
|
||||
|
||||
Future<double> _fetchPriceAsync(
|
||||
CryptoCurrency crypto, FiatCurrency fiat, bool torOnly, bool onionOnly) async =>
|
||||
// compute(_fetchPrice, {
|
||||
// 'fiat': fiat.toString(),
|
||||
// 'crypto': crypto.toString(),
|
||||
// 'torOnly': torOnly,
|
||||
// 'onionOnly': onionOnly,
|
||||
// 'port': ProxyWrapper.port,
|
||||
// 'torEnabled': ProxyWrapper.enabled,
|
||||
// });
|
||||
_fetchPrice({
|
||||
CryptoCurrency crypto, FiatCurrency fiat) async =>
|
||||
compute(_fetchPrice, {
|
||||
'fiat': fiat.toString(),
|
||||
'crypto': crypto.toString(),
|
||||
'torOnly': torOnly,
|
||||
'onionOnly': onionOnly,
|
||||
'port': ProxyWrapper.port,
|
||||
'torEnabled': ProxyWrapper.enabled,
|
||||
});
|
||||
|
||||
class FiatConversionService {
|
||||
static Future<double> fetchPrice({
|
||||
required CryptoCurrency crypto,
|
||||
required FiatCurrency fiat,
|
||||
required bool torOnly,
|
||||
required bool onionOnly,
|
||||
}) async =>
|
||||
await _fetchPriceAsync(crypto, fiat, torOnly, onionOnly);
|
||||
await _fetchPriceAsync(crypto, fiat);
|
||||
}
|
||||
|
|
|
@ -14,14 +14,12 @@ class WalletLoadingService {
|
|||
this.sharedPreferences,
|
||||
this.keyService,
|
||||
this.walletServiceFactory,
|
||||
this.settingsStore,
|
||||
this.torViewModel,
|
||||
);
|
||||
|
||||
final SharedPreferences sharedPreferences;
|
||||
final KeyService keyService;
|
||||
final WalletService Function(WalletType type) walletServiceFactory;
|
||||
final SettingsStore settingsStore;
|
||||
final TorViewModel torViewModel;
|
||||
|
||||
Future<void> renameWallet(WalletType type, String name, String newName) async {
|
||||
|
|
|
@ -352,7 +352,6 @@ Future<void> setup({
|
|||
getIt.get<SharedPreferences>(),
|
||||
getIt.get<KeyService>(),
|
||||
(WalletType type) => getIt.get<WalletService>(param1: type),
|
||||
getIt.get<SettingsStore>(),
|
||||
getIt.get<TorViewModel>(),
|
||||
));
|
||||
|
||||
|
@ -1144,9 +1143,7 @@ Future<void> setup({
|
|||
|
||||
getIt.registerFactory(() => IoniaAccountCardsPage(getIt.get<IoniaAccountViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => AnonPayApi(
|
||||
useTorOnly: getIt.get<SettingsStore>().exchangeStatus == ExchangeApiMode.torOnly,
|
||||
wallet: getIt.get<AppStore>().wallet!));
|
||||
getIt.registerFactory(() => AnonPayApi(wallet: getIt.get<AppStore>().wallet!));
|
||||
|
||||
getIt.registerFactory(() =>
|
||||
DesktopWalletSelectionDropDown(getIt.get<WalletListViewModel>(), getIt.get<AuthService>()));
|
||||
|
|
|
@ -185,6 +185,9 @@ Future<void> defaultSettingsMigration(
|
|||
case 25:
|
||||
await rewriteSecureStoragePin(secureStorage: secureStorage);
|
||||
break;
|
||||
case 26:
|
||||
await migrateTorPreferences(sharedPreferences: sharedPreferences);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -378,6 +381,18 @@ Node getMoneroDefaultNode({required Box<Node> nodes}) {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> migrateTorPreferences({required SharedPreferences sharedPreferences}) async {
|
||||
|
||||
if (sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey) == 1) {
|
||||
await sharedPreferences.setInt(PreferencesKey.currentFiatApiModeKey, 0);
|
||||
}
|
||||
|
||||
if (sharedPreferences.getInt(PreferencesKey.exchangeStatusKey) == 1) {
|
||||
await sharedPreferences.setInt(PreferencesKey.currentFiatApiModeKey, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Future<void> rewriteSecureStoragePin({required FlutterSecureStorage secureStorage}) async {
|
||||
// the bug only affects ios/mac:
|
||||
if (!Platform.isIOS && !Platform.isMacOS) {
|
||||
|
|
|
@ -4,18 +4,15 @@ import 'package:cw_core/enumerable_item.dart';
|
|||
class ExchangeApiMode extends EnumerableItem<int> with Serializable<int> {
|
||||
const ExchangeApiMode({required String title, required int raw}) : super(title: title, raw: raw);
|
||||
|
||||
static const all = [ExchangeApiMode.enabled, ExchangeApiMode.torOnly, ExchangeApiMode.disabled];
|
||||
static const all = [ExchangeApiMode.enabled, ExchangeApiMode.disabled];
|
||||
|
||||
static const enabled = ExchangeApiMode(raw: 0, title: 'Enabled');
|
||||
static const torOnly = ExchangeApiMode(raw: 1, title: 'Tor only');
|
||||
static const disabled = ExchangeApiMode(raw: 2, title: 'Disabled');
|
||||
static const disabled = ExchangeApiMode(raw: 1, title: 'Disabled');
|
||||
|
||||
static ExchangeApiMode deserialize({required int raw}) {
|
||||
switch (raw) {
|
||||
case 0:
|
||||
return enabled;
|
||||
case 1:
|
||||
return torOnly;
|
||||
case 2:
|
||||
return disabled;
|
||||
default:
|
||||
|
@ -28,8 +25,6 @@ class ExchangeApiMode extends EnumerableItem<int> with Serializable<int> {
|
|||
switch (this) {
|
||||
case ExchangeApiMode.enabled:
|
||||
return S.current.enabled;
|
||||
case ExchangeApiMode.torOnly:
|
||||
return S.current.tor_only;
|
||||
case ExchangeApiMode.disabled:
|
||||
return S.current.disabled;
|
||||
default:
|
||||
|
|
|
@ -4,19 +4,16 @@ import 'package:cw_core/enumerable_item.dart';
|
|||
class FiatApiMode extends EnumerableItem<int> with Serializable<int> {
|
||||
const FiatApiMode({required String title, required int raw}) : super(title: title, raw: raw);
|
||||
|
||||
static const all = [FiatApiMode.enabled, FiatApiMode.torOnly, FiatApiMode.disabled];
|
||||
static const all = [FiatApiMode.enabled, FiatApiMode.disabled];
|
||||
|
||||
static const enabled = FiatApiMode(raw: 0, title: 'Enabled');
|
||||
static const torOnly = FiatApiMode(raw: 1, title: 'Tor only');
|
||||
static const disabled = FiatApiMode(raw: 2, title: 'Disabled');
|
||||
static const disabled = FiatApiMode(raw: 1, title: 'Disabled');
|
||||
|
||||
static FiatApiMode deserialize({required int raw}) {
|
||||
switch (raw) {
|
||||
case 0:
|
||||
return enabled;
|
||||
case 1:
|
||||
return torOnly;
|
||||
case 2:
|
||||
return disabled;
|
||||
default:
|
||||
throw Exception('Unexpected token: $raw for FiatApiMode deserialize');
|
||||
|
@ -28,8 +25,6 @@ class FiatApiMode extends EnumerableItem<int> with Serializable<int> {
|
|||
switch (this) {
|
||||
case FiatApiMode.enabled:
|
||||
return S.current.enabled;
|
||||
case FiatApiMode.torOnly:
|
||||
return S.current.tor_only;
|
||||
case FiatApiMode.disabled:
|
||||
return S.current.disabled;
|
||||
default:
|
||||
|
|
|
@ -14,12 +14,11 @@ import 'package:cake_wallet/utils/proxy_wrapper.dart';
|
|||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
class TrocadorExchangeProvider extends ExchangeProvider {
|
||||
TrocadorExchangeProvider({this.useTorOnly = false, this.providerStates = const {}})
|
||||
TrocadorExchangeProvider({this.providerStates = const {}})
|
||||
: _lastUsedRateId = '',
|
||||
_provider = [],
|
||||
super(pairList: supportedPairs(_notSupported));
|
||||
|
||||
bool useTorOnly;
|
||||
final Map<String, bool> providerStates;
|
||||
|
||||
static const List<String> availableProviders = [
|
||||
|
@ -308,11 +307,11 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
Future<HttpClientResponse> proxyGet(String path, Map<String, String> queryParams) async {
|
||||
ProxyWrapper proxy = await getIt.get<ProxyWrapper>();
|
||||
Uri onionUri = Uri.http(onionApiAuthority, path, queryParams);
|
||||
Uri clearnetUri = Uri.http(onionApiAuthority, path, queryParams);
|
||||
Uri clearnetUri = Uri.http(clearNetAuthority, path, queryParams);
|
||||
return await proxy.get(
|
||||
onionUri: onionUri,
|
||||
clearnetUri: clearnetUri,
|
||||
torOnly: useTorOnly,
|
||||
torOnly: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ Future<void> initializeAppConfigs() async {
|
|||
transactionDescriptions: transactionDescriptions,
|
||||
secureStorage: secureStorage,
|
||||
anonpayInvoiceInfo: anonpayInvoiceInfo,
|
||||
initialMigrationVersion: 25);
|
||||
initialMigrationVersion: 26);
|
||||
}
|
||||
|
||||
Future<void> initialSetup(
|
||||
|
|
|
@ -33,8 +33,6 @@ Future<void> startFiatRateUpdate(
|
|||
await FiatConversionService.fetchPrice(
|
||||
crypto: appStore.wallet!.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.torConnectionMode == TorConnectionMode.onionOnly,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -55,8 +53,6 @@ Future<void> startFiatRateUpdate(
|
|||
fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.torConnectionMode == TorConnectionMode.onionOnly,
|
||||
);
|
||||
}.call();
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ void startCurrentFiatApiModeChangeReaction(
|
|||
fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: appStore.wallet!.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.torConnectionMode == TorConnectionMode.onionOnly,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ void startCurrentFiatChangeReaction(
|
|||
fiatConversionStore.prices[cryptoCurrency] = await FiatConversionService.fetchPrice(
|
||||
crypto: cryptoCurrency,
|
||||
fiat: fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.torConnectionMode == TorConnectionMode.onionOnly,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -95,8 +95,6 @@ void startCurrentWalletChangeReaction(
|
|||
fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: wallet.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.torConnectionMode == TorConnectionMode.onionOnly,
|
||||
);
|
||||
|
||||
Iterable<Erc20Token>? currencies;
|
||||
|
@ -114,8 +112,6 @@ void startCurrentWalletChangeReaction(
|
|||
fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.torConnectionMode == TorConnectionMode.onionOnly,
|
||||
);
|
||||
}.call();
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ class ConnectionSyncPage extends BasePage {
|
|||
),
|
||||
const StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
|
||||
],
|
||||
if (FeatureFlag.isInAppTorEnabled) ...[
|
||||
if (FeatureFlag.isInAppTorEnabled && !DeviceInfo.instance.isMobile) ...[
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
child: Column(children: [
|
||||
|
|
|
@ -89,8 +89,6 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
await FiatConversionService.fetchPrice(
|
||||
crypto: token,
|
||||
fiat: _settingsStore.fiatCurrency,
|
||||
torOnly: _settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: _settingsStore.torConnectionMode == TorConnectionMode.onionOnly,
|
||||
);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ import 'package:cake_wallet/store/settings_store.dart';
|
|||
import 'package:cake_wallet/store/templates/exchange_template_store.dart';
|
||||
import 'package:cake_wallet/utils/feature_flag.dart';
|
||||
import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
|
||||
import 'package:cake_wallet/view_model/settings/tor_view_model.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/sync_status.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
|
@ -67,7 +69,6 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
depositAddress = '',
|
||||
isDepositAddressEnabled = false,
|
||||
isReceiveAmountEditable = false,
|
||||
_useTorOnly = false,
|
||||
receiveCurrencies = <CryptoCurrency>[],
|
||||
depositCurrencies = <CryptoCurrency>[],
|
||||
limits = Limits(min: 0, max: 0),
|
||||
|
@ -78,7 +79,6 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
providerList = [],
|
||||
selectedProviders = ObservableList<ExchangeProvider>(),
|
||||
super(appStore: appStore) {
|
||||
_useTorOnly = _settingsStore.exchangeStatus == ExchangeApiMode.torOnly;
|
||||
_setProviders();
|
||||
const excludeDepositCurrencies = [CryptoCurrency.btt];
|
||||
const excludeReceiveCurrencies = [
|
||||
|
@ -135,7 +135,6 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
});
|
||||
}
|
||||
|
||||
bool _useTorOnly;
|
||||
final Box<Trade> trades;
|
||||
final ExchangeTemplateStore _exchangeTemplateStore;
|
||||
final TradesStore tradesStore;
|
||||
|
@ -145,8 +144,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
ChangeNowExchangeProvider(settingsStore: _settingsStore),
|
||||
SideShiftExchangeProvider(),
|
||||
SimpleSwapExchangeProvider(),
|
||||
TrocadorExchangeProvider(
|
||||
useTorOnly: _useTorOnly, providerStates: _settingsStore.trocadorProviderStates),
|
||||
TrocadorExchangeProvider(providerStates: _settingsStore.trocadorProviderStates),
|
||||
if (FeatureFlag.isExolixEnabled) ExolixExchangeProvider(),
|
||||
];
|
||||
|
||||
|
@ -721,7 +719,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
}
|
||||
|
||||
void _setProviders() {
|
||||
if (_settingsStore.exchangeStatus == ExchangeApiMode.torOnly)
|
||||
if (_settingsStore.torConnectionMode == TorConnectionMode.onionOnly)
|
||||
providerList = _allProviders.where((provider) => provider.supportsOnionAddress).toList();
|
||||
else
|
||||
providerList = _allProviders;
|
||||
|
|
Loading…
Reference in a new issue