mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 10:45:08 +00:00
onionOnly updates
This commit is contained in:
parent
c8dcf49503
commit
e6fa2a58db
11 changed files with 132 additions and 114 deletions
|
@ -137,6 +137,7 @@ class AnonPayApi {
|
|||
crypto: cryptoCurrency,
|
||||
fiat: fiatCurrency,
|
||||
torOnly: useTorOnly,
|
||||
onionOnly: false,// TODO: CW-519
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ 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 onionOnly = args['onionOnly'] as bool;
|
||||
final mainThreadProxyPort = args['port'] as int;
|
||||
|
||||
final Map<String, String> queryParams = {
|
||||
|
@ -42,25 +43,31 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
|||
|
||||
// we might have tor enabled (no way of knowing), so we try to use it first
|
||||
try {
|
||||
// connect through onion url first:
|
||||
try {
|
||||
final request = await client.getUrl(onionUri);
|
||||
httpResponse = await request.close();
|
||||
responseBody = await utf8.decodeStream(httpResponse);
|
||||
} catch (e) {
|
||||
// if the onion url fails, and not set to tor only, try the clearnet url, (still using tor!):
|
||||
if (!torOnly) {
|
||||
// if the onion url fails, try the clearnet url, (still using tor!):
|
||||
// only do this if we are not onionOnly, otherwise we will fail
|
||||
if (!onionOnly) {
|
||||
final request = await client.getUrl(clearnetUri);
|
||||
httpResponse = await request.close();
|
||||
responseBody = await utf8.decodeStream(httpResponse);
|
||||
} else {
|
||||
// we failed to connect through onionOnly
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
statusCode = httpResponse.statusCode;
|
||||
} catch (e) {
|
||||
// connections all failed / tor is not enabled, so we use the clearnet url directly as normal:
|
||||
if (torOnly) {
|
||||
// we failed to connect through tor
|
||||
// we failed to connect through torOnly
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// connections all failed / tor is not enabled, so we use the clearnet url directly as normal:
|
||||
final response = await get(clearnetUri);
|
||||
responseBody = response.body;
|
||||
statusCode = response.statusCode;
|
||||
|
@ -83,12 +90,12 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future<double> _fetchPriceAsync(
|
||||
CryptoCurrency crypto, FiatCurrency fiat, bool torOnly) 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,
|
||||
});
|
||||
|
@ -98,6 +105,7 @@ class FiatConversionService {
|
|||
required CryptoCurrency crypto,
|
||||
required FiatCurrency fiat,
|
||||
required bool torOnly,
|
||||
required bool onionOnly,
|
||||
}) async =>
|
||||
await _fetchPriceAsync(crypto, fiat, torOnly);
|
||||
await _fetchPriceAsync(crypto, fiat, torOnly, onionOnly);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:cake_wallet/polygon/polygon.dart';
|
|||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
|
||||
import 'package:cw_core/erc20_token.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
@ -33,6 +34,7 @@ Future<void> startFiatRateUpdate(
|
|||
crypto: appStore.wallet!.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.currentTorConnection == TorConnectionType.onionOnly,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -54,6 +56,7 @@ Future<void> startFiatRateUpdate(
|
|||
crypto: currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.currentTorConnection == TorConnectionType.onionOnly,
|
||||
);
|
||||
}.call();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
|
@ -7,19 +8,20 @@ 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,
|
||||
torOnly: fiatApiMode == FiatApiMode.torOnly);
|
||||
torOnly: fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.currentTorConnection == TorConnectionType.onionOnly,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
|
@ -8,20 +9,21 @@ 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,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.currentTorConnection == TorConnectionType.onionOnly,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
|||
import 'package:cake_wallet/entities/update_haven_rate.dart';
|
||||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||
import 'package:cake_wallet/polygon/polygon.dart';
|
||||
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
|
||||
import 'package:cw_core/erc20_token.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
import 'package:cw_core/balance.dart';
|
||||
|
@ -94,7 +95,9 @@ void startCurrentWalletChangeReaction(
|
|||
fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: wallet.currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.currentTorConnection == TorConnectionType.onionOnly,
|
||||
);
|
||||
|
||||
Iterable<Erc20Token>? currencies;
|
||||
if (wallet.type == WalletType.ethereum) {
|
||||
|
@ -111,7 +114,9 @@ void startCurrentWalletChangeReaction(
|
|||
fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: currency,
|
||||
fiat: settingsStore.fiatCurrency,
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: settingsStore.currentTorConnection == TorConnectionType.onionOnly,
|
||||
);
|
||||
}.call();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class NodeForm extends StatelessWidget {
|
|||
_portController = TextEditingController(text: editingNode?.uri.port.toString()),
|
||||
_loginController = TextEditingController(text: editingNode?.login),
|
||||
_passwordController = TextEditingController(text: editingNode?.password),
|
||||
_socksAddressController = TextEditingController(text: editingNode?.socksProxyAddress){
|
||||
_socksAddressController = TextEditingController(text: editingNode?.socksProxyAddress) {
|
||||
if (editingNode != null) {
|
||||
nodeViewModel
|
||||
..setAddress((editingNode!.uri.host.toString()))
|
||||
|
@ -60,7 +60,8 @@ class NodeForm extends StatelessWidget {
|
|||
_portController.addListener(() => nodeViewModel.port = _portController.text);
|
||||
_loginController.addListener(() => nodeViewModel.login = _loginController.text);
|
||||
_passwordController.addListener(() => nodeViewModel.password = _passwordController.text);
|
||||
_socksAddressController.addListener(() => nodeViewModel.socksProxyAddress = _socksAddressController.text);
|
||||
_socksAddressController
|
||||
.addListener(() => nodeViewModel.socksProxyAddress = _socksAddressController.text);
|
||||
}
|
||||
|
||||
final NodeCreateOrEditViewModel nodeViewModel;
|
||||
|
@ -103,6 +104,26 @@ class NodeForm extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
SizedBox(height: 10.0),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Observer(
|
||||
builder: (_) => StandardCheckbox(
|
||||
value: nodeViewModel.useSSL,
|
||||
gradientBackground: true,
|
||||
borderColor: Theme.of(context).dividerColor,
|
||||
iconColor: Colors.white,
|
||||
onChanged: (value) => nodeViewModel.useSSL = value,
|
||||
caption: S.of(context).use_ssl,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10.0),
|
||||
if (nodeViewModel.hasAuthCredentials) ...[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
|
@ -123,25 +144,6 @@ class NodeForm extends StatelessWidget {
|
|||
))
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Observer(
|
||||
builder: (_) => StandardCheckbox(
|
||||
value: nodeViewModel.useSSL,
|
||||
gradientBackground: true,
|
||||
borderColor: Theme.of(context).dividerColor,
|
||||
iconColor: Colors.white,
|
||||
onChanged: (value) => nodeViewModel.useSSL = value,
|
||||
caption: S.of(context).use_ssl,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Row(
|
||||
|
|
|
@ -3,9 +3,10 @@ import 'package:flutter/material.dart';
|
|||
import 'package:cake_wallet/palette.dart';
|
||||
|
||||
class NodeIndicator extends StatelessWidget {
|
||||
NodeIndicator({this.isLive = false});
|
||||
NodeIndicator({this.isLive = false, this.showText = false});
|
||||
|
||||
final bool isLive;
|
||||
final bool showText;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -17,12 +18,14 @@ class NodeIndicator extends StatelessWidget {
|
|||
decoration:
|
||||
BoxDecoration(shape: BoxShape.circle, color: isLive ? Palette.green : Palette.red),
|
||||
),
|
||||
if (showText) ...[
|
||||
const SizedBox(width: 8.0),
|
||||
Text(
|
||||
isLive ? S.current.connected : S.current.disconnected,
|
||||
style: TextStyle(fontSize: 14.0),
|
||||
)
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ class ConnectionSyncPage extends BasePage {
|
|||
),
|
||||
);
|
||||
}),
|
||||
TorListRow(
|
||||
TorStatus(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(25), bottomRight: Radius.circular(25)),
|
||||
color: const Color.fromARGB(255, 236, 244, 255),
|
||||
|
|
|
@ -1,34 +1,23 @@
|
|||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/src/screens/nodes/widgets/node_indicator.dart';
|
||||
import 'package:cake_wallet/src/widgets/standard_list.dart';
|
||||
import 'package:cake_wallet/themes/extensions/receive_page_theme.dart';
|
||||
import 'package:cw_core/node.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/themes/extensions/filter_theme.dart';
|
||||
import 'package:tor/tor.dart';
|
||||
|
||||
class TorListRow extends StandardListRow {
|
||||
TorListRow(
|
||||
class TorStatus extends StandardListRow {
|
||||
TorStatus(
|
||||
{required String title,
|
||||
required void Function(BuildContext context) onTap,
|
||||
required bool isSelected,
|
||||
BoxDecoration? decoration})
|
||||
: super(title: title, onTap: onTap, isSelected: isSelected, decoration: decoration);
|
||||
|
||||
|
||||
@override
|
||||
Widget buildTrailing(BuildContext context) {
|
||||
// return FutureBuilder(
|
||||
// future: node.requestNode(),
|
||||
// builder: (context, snapshot) {
|
||||
// switch (snapshot.connectionState) {
|
||||
// case ConnectionState.done:
|
||||
// return NodeIndicator(isLive: (snapshot.data as bool?) ?? false);
|
||||
// default:
|
||||
// return NodeIndicator(isLive: false);
|
||||
// }
|
||||
// });
|
||||
return NodeIndicator(isLive: Tor.instance.started);
|
||||
return NodeIndicator(
|
||||
isLive: Tor.instance.started && Tor.instance.enabled,
|
||||
showText: true,
|
||||
);
|
||||
}
|
||||
|
||||
// @override
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:cake_wallet/ethereum/ethereum.dart';
|
|||
import 'package:cake_wallet/polygon/polygon.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/erc20_token.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
@ -88,7 +89,9 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
await FiatConversionService.fetchPrice(
|
||||
crypto: token,
|
||||
fiat: _settingsStore.fiatCurrency,
|
||||
torOnly: _settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
||||
torOnly: _settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
onionOnly: _settingsStore.currentTorConnection == TorConnectionType.onionOnly,
|
||||
);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue