Merge branch 'arti' into wallets_refactor

This commit is contained in:
julian 2023-09-18 07:39:08 -06:00
commit a0a653b088
44 changed files with 787 additions and 605 deletions

5
.gitmodules vendored
View file

@ -6,7 +6,4 @@
url = https://github.com/cypherstack/flutter_libmonero.git
[submodule "crypto_plugins/flutter_liblelantus"]
path = crypto_plugins/flutter_liblelantus
url = https://github.com/cypherstack/flutter_liblelantus.git
[submodule "crypto_plugins/tor"]
path = crypto_plugins/tor
url = https://github.com/cypherstack/tor.git
url = https://github.com/cypherstack/flutter_liblelantus.git

View file

@ -34,7 +34,9 @@ if (keystorePropertiesFile.exists()) {
android {
compileSdkVersion 33
ndkVersion = "21.1.6352462"
// ndkVersion = "21.1.6352462"
// ndkVersion = "25.2.9519653"
ndkVersion = "23.1.7779620"
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
@ -49,7 +51,9 @@ android {
applicationId "com.cypherstack.stackwallet"
minSdkVersion 23
targetSdkVersion 33
ndkVersion = "21.1.6352462"
// ndkVersion = "21.1.6352462"
// ndkVersion = "25.2.9519653"
ndkVersion = "23.1.7779620"
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit f677dec0b34d3f9fe8fce2bc8ff5c508c3f3bb9a
Subproject commit 2de3fa0459ac29361d65a86883e1d0648e6a4b1a

@ -1 +1 @@
Subproject commit 9cd241b5ea142e21c01dd7639b42603281c43287
Subproject commit 1f8fde935bbb23585477b0cb884bee9be6d12a87

@ -1 +1 @@
Subproject commit e48952185556a10f182184fd572bcb04365f5831
Subproject commit 8a46a5d0984cf7fbc1ce5d77cbb74dc6933da59c

@ -1 +0,0 @@
Subproject commit a819223b23e9fa1d76bde82ed9109651e96f2ad3

View file

@ -187,8 +187,8 @@ class ElectrumX {
void _checkRpcClient() {
// If we're supposed to use Tor...
if (_prefs.useTor) {
// But Tor isn't enabled...
if (!_torService.enabled) {
// But Tor isn't running...
if (_torService.status != TorConnectionStatus.connected) {
// And the killswitch isn't set...
if (!_prefs.torKillSwitch) {
// Then we'll just proceed and connect to ElectrumX through clearnet at the bottom of this function.
@ -203,7 +203,7 @@ class ElectrumX {
}
} else {
// Get the proxy info from the TorService.
final proxyInfo = _torService.proxyInfo;
final proxyInfo = _torService.getProxyInfo();
if (currentFailoverIndex == -1) {
_rpcClient ??= JsonRPC(

View file

@ -173,7 +173,9 @@ void main() async {
// Some refactoring will need to be done here to make sure we don't make any
// network calls before starting up tor
if (Prefs.instance.useTor) {
TorService.sharedInstance.init();
TorService.sharedInstance.init(
torDataDirPath: (await StackFileSystem.applicationTorDirectory()).path,
);
await TorService.sharedInstance.start();
}

View file

@ -12,10 +12,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
import 'package:stackwallet/pages/buy_view/buy_form.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart';
import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:stackwallet/widgets/tor_subscription.dart';
class BuyView extends ConsumerStatefulWidget {
const BuyView({
@ -36,18 +38,16 @@ class BuyView extends ConsumerStatefulWidget {
class _BuyViewState extends ConsumerState<BuyView> {
Coin? coin;
EthContract? tokenContract;
late bool torEnabled = false;
late bool torEnabled;
@override
void initState() {
coin = widget.coin;
tokenContract = widget.tokenContract;
WidgetsBinding.instance.addPostFrameCallback((_) async {
setState(() {
torEnabled = ref.read(prefsChangeNotifierProvider).useTor;
});
});
torEnabled =
ref.read(pTorService).status != TorConnectionStatus.disconnected;
super.initState();
}
@ -56,35 +56,42 @@ class _BuyViewState extends ConsumerState<BuyView> {
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");
return Stack(
children: [
SafeArea(
child: Padding(
padding: const EdgeInsets.only(
left: 16,
right: 16,
top: 16,
),
child: BuyForm(
coin: coin,
tokenContract: tokenContract,
return TorSubscription(
onTorStatusChanged: (status) {
setState(() {
torEnabled = status != TorConnectionStatus.disconnected;
});
},
child: Stack(
children: [
SafeArea(
child: Padding(
padding: const EdgeInsets.only(
left: 16,
right: 16,
top: 16,
),
child: BuyForm(
coin: coin,
tokenContract: tokenContract,
),
),
),
),
if (torEnabled)
Container(
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.7),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: const StackDialog(
title: "Tor is enabled",
message: "Purchasing not available while Tor is enabled",
if (torEnabled)
Container(
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.7),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: const StackDialog(
title: "Tor is enabled",
message: "Purchasing not available while Tor is enabled",
),
),
),
],
],
),
);
}
}

View file

@ -12,6 +12,7 @@ import 'package:stackwallet/models/isar/ordinal.dart';
import 'package:stackwallet/networking/http.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/providers/db/main_db_provider.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/themes/stack_colors.dart';
@ -20,7 +21,6 @@ import 'package:stackwallet/utilities/amount/amount_formatter.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/prefs.dart';
import 'package:stackwallet/utilities/show_loading.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/background.dart';
@ -219,7 +219,7 @@ class _DetailsItemWCopy extends StatelessWidget {
}
}
class _OrdinalImageGroup extends StatelessWidget {
class _OrdinalImageGroup extends ConsumerWidget {
const _OrdinalImageGroup({
Key? key,
required this.walletId,
@ -231,13 +231,14 @@ class _OrdinalImageGroup extends StatelessWidget {
static const _spacing = 12.0;
Future<String> _savePngToFile() async {
Future<String> _savePngToFile(WidgetRef ref) async {
HTTP client = HTTP();
final response = await client.get(
url: Uri.parse(ordinal.content),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: ref.read(prefsChangeNotifierProvider).useTor
? ref.read(pTorService).getProxyInfo()
: null,
);
if (response.code != 200) {
@ -268,7 +269,7 @@ class _OrdinalImageGroup extends StatelessWidget {
}
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
@ -318,7 +319,7 @@ class _OrdinalImageGroup extends StatelessWidget {
onPressed: () async {
bool didError = false;
final filePath = await showLoading<String>(
whileFuture: _savePngToFile(),
whileFuture: _savePngToFile(ref),
context: context,
isDesktop: true,
message: "Saving ordinal image",

View file

@ -50,8 +50,9 @@ Future<bool> doesCommitExist(
final commitQuery = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final response = jsonDecode(commitQuery.body.toString());
@ -89,8 +90,9 @@ Future<bool> isHeadCommit(
final commitQuery = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final response = jsonDecode(commitQuery.body.toString());

View file

@ -13,6 +13,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:lottie/lottie.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart';
import 'package:stackwallet/services/tor_service.dart';
@ -20,6 +21,7 @@ import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/stack_file_system.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
@ -31,7 +33,9 @@ import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:stackwallet/widgets/tor_subscription.dart';
class TorSettingsView extends ConsumerStatefulWidget {
const TorSettingsView({Key? key}) : super(key: key);
const TorSettingsView({
Key? key,
}) : super(key: key);
static const String routeName = "/torSettings";
@ -71,7 +75,7 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
useSafeArea: false,
barrierDismissible: true,
builder: (context) {
return const StackDialog(
return StackDialog(
title: "What is Tor?",
message:
"Short for \"The Onion Router\", is an open-source software that enables internet communication"
@ -79,6 +83,7 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
" to obscure the origin and destination of data.",
rightButton: SecondaryButton(
label: "Close",
onPressed: Navigator.of(context).pop,
),
);
},
@ -98,7 +103,7 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
children: [
Padding(
padding: EdgeInsets.all(10.0),
child: TorIcon(),
child: TorAnimatedButton(),
),
],
),
@ -140,7 +145,7 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
useSafeArea: false,
barrierDismissible: true,
builder: (context) {
return const StackDialog(
return StackDialog(
title: "What is Tor killswitch?",
message:
"A security feature that protects your information from accidental exposure by"
@ -148,6 +153,8 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
" connection is disrupted or compromised.",
rightButton: SecondaryButton(
label: "Close",
onPressed:
Navigator.of(context).pop,
),
);
},
@ -194,48 +201,19 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
}
}
class TorIcon extends ConsumerStatefulWidget {
const TorIcon({super.key});
class TorAnimatedButton extends ConsumerStatefulWidget {
const TorAnimatedButton({super.key});
@override
ConsumerState<TorIcon> createState() => _TorIconState();
ConsumerState<TorAnimatedButton> createState() => _TorAnimatedButtonState();
}
class _TorIconState extends ConsumerState<TorIcon> {
class _TorAnimatedButtonState extends ConsumerState<TorAnimatedButton>
with SingleTickerProviderStateMixin {
late final AnimationController controller1;
late TorConnectionStatus _status;
Color _color(
TorConnectionStatus status,
StackColors colors,
) {
switch (status) {
case TorConnectionStatus.disconnected:
return colors.textSubtitle3;
case TorConnectionStatus.connected:
return colors.accentColorGreen;
case TorConnectionStatus.connecting:
return colors.accentColorYellow;
}
}
String _label(
TorConnectionStatus status,
StackColors colors,
) {
switch (status) {
case TorConnectionStatus.disconnected:
return "CONNECT";
case TorConnectionStatus.connected:
return "STOP";
case TorConnectionStatus.connecting:
return "CONNECTING";
}
}
bool _tapLock = false;
Future<void> onTap() async {
@ -268,22 +246,106 @@ class _TorIconState extends ConsumerState<TorIcon> {
}
}
Future<void> _playConnecting() async {
await _play(
from: "connecting-start",
to: "connecting-end",
repeat: true,
);
}
Future<void> _playConnectingDone() async {
await _play(
from: "connecting-end",
to: "connected-start",
repeat: false,
);
}
Future<void> _playConnected() async {
await _play(
from: "connected-start",
to: "connected-end",
repeat: true,
);
}
Future<void> _playDisconnect() async {
await _play(
from: "disconnection-start",
to: "disconnection-end",
repeat: false,
);
controller1.reset();
}
Future<void> _play({
required String from,
required String to,
required bool repeat,
}) async {
final composition = await _completer.future;
final start = composition.getMarker(from)!.start;
final end = composition.getMarker(to)!.start;
controller1.value = start;
if (repeat) {
await controller1.repeat(
min: start,
max: end,
period: composition.duration * (end - start),
);
} else {
await controller1.animateTo(
end,
duration: composition.duration * (end - start),
);
}
}
late Completer<LottieComposition> _completer;
@override
void initState() {
_status = ref.read(pTorService).enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
controller1 = AnimationController(vsync: this);
_status = ref.read(pTorService).status;
_completer = Completer();
super.initState();
}
@override
void dispose() {
controller1.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: modify size (waiting for updated onion lottie animation file)
final width = MediaQuery.of(context).size.width / 1.5;
return TorSubscription(
onTorStatusChanged: (status) {
setState(() {
_status = status;
});
onTorStatusChanged: (status) async {
_status = status;
switch (_status) {
case TorConnectionStatus.disconnected:
await _playDisconnect();
break;
case TorConnectionStatus.connected:
await _playConnectingDone();
await _playConnected();
break;
case TorConnectionStatus.connecting:
await _playConnecting();
break;
}
},
child: ConditionalParent(
condition: _status != TorConnectionStatus.connecting,
@ -291,32 +353,29 @@ class _TorIconState extends ConsumerState<TorIcon> {
onTap: onTap,
child: child,
),
child: SizedBox(
width: 220,
height: 220,
child: Stack(
alignment: AlignmentDirectional.center,
children: [
SvgPicture.asset(
Assets.svg.tor,
color: _color(
_status,
Theme.of(context).extension<StackColors>()!,
),
width: 200,
height: 200,
child: Column(
children: [
SizedBox(
width: width,
child: Lottie.asset(
Assets.lottie.onionTor,
controller: controller1,
width: width,
// height: width,
onLoaded: (composition) {
_completer.complete(composition);
controller1.duration = composition.duration;
if (_status == TorConnectionStatus.connected) {
_playConnected();
} else if (_status == TorConnectionStatus.connecting) {
_playConnecting();
}
},
),
Text(
_label(
_status,
Theme.of(context).extension<StackColors>()!,
),
style: STextStyles.smallMed14(context).copyWith(
color: Theme.of(context).extension<StackColors>()!.popupBG,
),
),
],
),
),
const UpperCaseTorText(),
],
),
),
);
@ -399,9 +458,7 @@ class _TorButtonState extends ConsumerState<TorButton> {
@override
void initState() {
_status = ref.read(pTorService).enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
_status = ref.read(pTorService).status;
super.initState();
}
@ -447,6 +504,78 @@ class _TorButtonState extends ConsumerState<TorButton> {
}
}
class UpperCaseTorText extends ConsumerStatefulWidget {
const UpperCaseTorText({super.key});
@override
ConsumerState<UpperCaseTorText> createState() => _UpperCaseTorTextState();
}
class _UpperCaseTorTextState extends ConsumerState<UpperCaseTorText> {
late TorConnectionStatus _status;
Color _color(
TorConnectionStatus status,
StackColors colors,
) {
switch (status) {
case TorConnectionStatus.disconnected:
return colors.textSubtitle3;
case TorConnectionStatus.connected:
return colors.accentColorGreen;
case TorConnectionStatus.connecting:
return colors.accentColorYellow;
}
}
String _label(
TorConnectionStatus status,
) {
switch (status) {
case TorConnectionStatus.disconnected:
return "CONNECT";
case TorConnectionStatus.connected:
return "STOP";
case TorConnectionStatus.connecting:
return "CONNECTING";
}
}
@override
void initState() {
_status = ref.read(pTorService).status;
super.initState();
}
@override
Widget build(BuildContext context) {
return TorSubscription(
onTorStatusChanged: (status) {
setState(() {
_status = status;
});
},
child: Text(
_label(
_status,
),
style: STextStyles.pageTitleH2(
context,
).copyWith(
color: _color(
_status,
Theme.of(context).extension<StackColors>()!,
),
),
));
}
}
/// Connect to the Tor network.
///
/// This method is called when the user taps the "Connect" button.
@ -455,11 +584,11 @@ class _TorButtonState extends ConsumerState<TorButton> {
///
/// Returns a Future that completes when the Tor service has started.
Future<void> _connectTor(WidgetRef ref, BuildContext context) async {
// Init the Tor service if it hasn't already been.
ref.read(pTorService).init();
// Start the Tor service.
try {
// Init the Tor service if it hasn't already been.
final torDir = await StackFileSystem.applicationTorDirectory();
ref.read(pTorService).init(torDataDirPath: torDir.path);
// Start the Tor service.
await ref.read(pTorService).start();
// Toggle the useTor preference on success.
@ -485,7 +614,7 @@ Future<void> _connectTor(WidgetRef ref, BuildContext context) async {
Future<void> _disconnectTor(WidgetRef ref, BuildContext context) async {
// Stop the Tor service.
try {
await ref.read(pTorService).stop();
await ref.read(pTorService).disable();
// Toggle the useTor preference on success.
ref.read(prefsChangeNotifierProvider).useTor = false;

View file

@ -36,6 +36,7 @@ import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/stack_file_system.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/animated_text.dart';
@ -48,6 +49,7 @@ import 'package:stackwallet/widgets/progress_bar.dart';
import 'package:stackwallet/widgets/rounded_container.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:stackwallet/widgets/tor_subscription.dart';
import 'package:tuple/tuple.dart';
import 'package:wakelock/wakelock.dart';
@ -98,10 +100,6 @@ class _WalletNetworkSettingsViewState
/// The current status of the Tor connection.
late TorConnectionStatus _torConnectionStatus;
/// The subscription to the TorConnectionStatusChangedEvent.
late final StreamSubscription<TorConnectionStatusChangedEvent>
_torConnectionStatusSubscription;
Future<void> _attemptRescan() async {
if (!Platform.isLinux) await Wakelock.enable();
@ -280,22 +278,7 @@ class _WalletNetworkSettingsViewState
// );
// Initialize the TorConnectionStatus.
_torConnectionStatus = ref.read(pTorService).enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
// Subscribe to the TorConnectionStatusChangedEvent.
_torConnectionStatusSubscription =
eventBus.on<TorConnectionStatusChangedEvent>().listen(
(event) async {
// Rebuild the widget.
setState(() {
_torConnectionStatus = event.newStatus;
});
// TODO implement spinner or animations and control from here
},
);
_torConnectionStatus = ref.read(pTorService).status;
super.initState();
}
@ -306,7 +289,6 @@ class _WalletNetworkSettingsViewState
_syncStatusSubscription.cancel();
_refreshSubscription.cancel();
_blocksRemainingSubscription?.cancel();
_torConnectionStatusSubscription.cancel();
super.dispose();
}
@ -793,7 +775,7 @@ class _WalletNetworkSettingsViewState
onTap: () async {
// Stop the Tor service.
try {
await ref.read(pTorService).stop();
await ref.read(pTorService).disable();
// Toggle the useTor preference on success.
ref.read(prefsChangeNotifierProvider).useTor = false;
@ -813,11 +795,12 @@ class _WalletNetworkSettingsViewState
prefsChangeNotifierProvider.select((value) => value.useTor)))
GestureDetector(
onTap: () async {
// Init the Tor service if it hasn't already been.
ref.read(pTorService).init();
// Start the Tor service.
try {
// Init the Tor service if it hasn't already been.
final torDir =
await StackFileSystem.applicationTorDirectory();
ref.read(pTorService).init(torDataDirPath: torDir.path);
// Start the Tor service.
await ref.read(pTorService).start();
// Toggle the useTor preference on success.
@ -827,6 +810,7 @@ class _WalletNetworkSettingsViewState
"Error starting tor: $e\n$s",
level: LogLevel.Error,
);
// TODO: show dialog with error message
}
},
child: Text(
@ -896,35 +880,46 @@ class _WalletNetworkSettingsViewState
SizedBox(
width: _boxPadding,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Tor status",
style: STextStyles.desktopTextExtraExtraSmall(context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
),
if (_torConnectionStatus == TorConnectionStatus.connected)
TorSubscription(
onTorStatusChanged: (status) {
setState(() {
_torConnectionStatus = status;
});
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Connected",
style: STextStyles.desktopTextExtraExtraSmall(context),
"Tor status",
style: STextStyles.desktopTextExtraExtraSmall(context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
),
if (_torConnectionStatus == TorConnectionStatus.connecting)
Text(
"Connecting...",
style: STextStyles.desktopTextExtraExtraSmall(context),
),
if (_torConnectionStatus ==
TorConnectionStatus.disconnected)
Text(
"Disconnected",
style: STextStyles.desktopTextExtraExtraSmall(context),
),
],
if (_torConnectionStatus == TorConnectionStatus.connected)
Text(
"Connected",
style:
STextStyles.desktopTextExtraExtraSmall(context),
),
if (_torConnectionStatus ==
TorConnectionStatus.connecting)
Text(
"Connecting...",
style:
STextStyles.desktopTextExtraExtraSmall(context),
),
if (_torConnectionStatus ==
TorConnectionStatus.disconnected)
Text(
"Disconnected",
style:
STextStyles.desktopTextExtraExtraSmall(context),
),
],
),
),
],
),

View file

@ -11,13 +11,15 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages/buy_view/buy_form.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart';
import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/tor_subscription.dart';
class DesktopBuyView extends ConsumerStatefulWidget {
const DesktopBuyView({Key? key}) : super(key: key);
@ -29,117 +31,121 @@ class DesktopBuyView extends ConsumerStatefulWidget {
}
class _DesktopBuyViewState extends ConsumerState<DesktopBuyView> {
late bool torEnabled = false;
late bool torEnabled;
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
setState(() {
torEnabled = ref.read(prefsChangeNotifierProvider).useTor;
});
});
torEnabled =
ref.read(pTorService).status != TorConnectionStatus.disconnected;
super.initState();
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
DesktopScaffold(
appBar: DesktopAppBar(
isCompactHeight: true,
leading: Padding(
padding: const EdgeInsets.only(
left: 24,
return TorSubscription(
onTorStatusChanged: (status) {
setState(() {
torEnabled = status != TorConnectionStatus.disconnected;
});
},
child: Stack(
children: [
DesktopScaffold(
appBar: DesktopAppBar(
isCompactHeight: true,
leading: Padding(
padding: const EdgeInsets.only(
left: 24,
),
child: Text(
"Buy crypto",
style: STextStyles.desktopH3(context),
),
),
child: Text(
"Buy crypto",
style: STextStyles.desktopH3(context),
),
body: const Padding(
padding: EdgeInsets.only(
left: 24,
right: 24,
bottom: 24,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 16,
),
RoundedWhiteContainer(
padding: EdgeInsets.all(24),
child: BuyForm(),
),
],
),
),
SizedBox(
width: 16,
),
// Expanded(
// child: Row(
// children: const [
// Expanded(
// child: DesktopTradeHistory(),
// ),
// ],
// ),
// ),
],
),
),
),
body: Padding(
padding: const EdgeInsets.only(
left: 24,
right: 24,
bottom: 24,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
if (torEnabled)
Container(
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.7),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: DesktopDialog(
maxHeight: 200,
maxWidth: 350,
child: Padding(
padding: const EdgeInsets.all(
15.0,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
SizedBox(
height: 16,
// crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.pageTitleH1(context),
),
RoundedWhiteContainer(
padding: EdgeInsets.all(24),
child: BuyForm(),
const SizedBox(
height: 30,
),
Text(
"Purchasing not available while Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.desktopTextMedium(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.infoItemLabel,
),
),
],
),
),
const SizedBox(
width: 16,
),
// Expanded(
// child: Row(
// children: const [
// Expanded(
// child: DesktopTradeHistory(),
// ),
// ],
// ),
// ),
],
),
),
),
if (torEnabled)
Container(
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.7),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: DesktopDialog(
maxHeight: 200,
maxWidth: 350,
child: Padding(
padding: const EdgeInsets.all(
15.0,
),
child: Column(
// crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.pageTitleH1(context),
),
const SizedBox(
height: 30,
),
Text(
"Purchasing not available while Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.desktopTextMedium(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.infoItemLabel,
),
),
],
),
),
),
),
],
],
),
);
}
}

View file

@ -56,8 +56,9 @@ class _DesktopOrdinalDetailsViewState
final response = await client.get(
url: Uri.parse(widget.ordinal.content),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code != 200) {

View file

@ -22,6 +22,7 @@ import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/stack_file_system.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart';
@ -59,11 +60,11 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
width: 200,
buttonHeight: ButtonHeight.m,
onPressed: () async {
// Init the Tor service if it hasn't already been.
ref.read(pTorService).init();
// Start the Tor service.
try {
// Init the Tor service if it hasn't already been.
final torDir = await StackFileSystem.applicationTorDirectory();
ref.read(pTorService).init(torDataDirPath: torDir.path);
// Start the Tor service.
await ref.read(pTorService).start();
// Toggle the useTor preference on success.
@ -73,6 +74,7 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
"Error starting tor: $e\n$s",
level: LogLevel.Error,
);
// TODO: show dialog with error message
}
},
);
@ -93,7 +95,7 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
onPressed: () async {
// Stop the Tor service.
try {
await ref.read(pTorService).stop();
await ref.read(pTorService).disable();
// Toggle the useTor preference on success.
ref.read(prefsChangeNotifierProvider).useTor = false;
@ -114,9 +116,7 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
eventBus = GlobalEventBus.instance;
// Set the initial Tor connection status.
_torConnectionStatus = ref.read(pTorService).enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
_torConnectionStatus = ref.read(pTorService).status;
// Subscribe to the TorConnectionStatusChangedEvent.
_torConnectionStatusSubscription =
@ -219,8 +219,21 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.end,
MainAxisAlignment
.spaceBetween,
children: [
Padding(
padding:
const EdgeInsets.only(
left: 32,
),
child: Text(
"What is Tor?",
style:
STextStyles.desktopH2(
context),
),
),
DesktopDialogCloseButton(
onPressedOverride: () =>
Navigator.of(context)
@ -229,34 +242,24 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
],
),
Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Text(
"What is Tor?",
style:
STextStyles.desktopH2(
context),
),
const SizedBox(
height: 20,
),
Text(
"Short for \"The Onion Router\", is an open-source software that enables internet communication"
" to remain anonymous by routing internet traffic through a series of layered nodes,"
" to obscure the origin and destination of data.",
style: STextStyles
.desktopTextMedium(
context)
.copyWith(
color: Theme.of(context)
.extension<
StackColors>()!
.textDark3,
),
),
],
padding: const EdgeInsets.only(
top: 12,
left: 32,
bottom: 32,
right: 32,
),
child: Text(
"Short for \"The Onion Router\", is an open-source software that enables internet communication"
" to remain anonymous by routing internet traffic through a series of layered nodes,"
" to obscure the origin and destination of data.",
style: STextStyles
.desktopTextMedium(
context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark3,
),
),
),
],
@ -289,21 +292,25 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
children: [
Row(
children: [
RichText(
textAlign: TextAlign.start,
text: TextSpan(
children: [
TextSpan(
text: "Tor killswitch",
style: STextStyles.desktopTextExtraExtraSmall(
context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark),
),
TextSpan(
text: "\nWhat is Tor killswitch?",
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Tor killswitch",
style: STextStyles.desktopTextExtraExtraSmall(
context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark),
),
const SizedBox(
height: 8,
),
RichText(
textAlign: TextAlign.start,
text: TextSpan(
text: "What is Tor killswitch?",
style: STextStyles.richLink(context).copyWith(
fontSize: 14,
),
@ -321,8 +328,20 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.end,
MainAxisAlignment
.spaceBetween,
children: [
Padding(
padding:
const EdgeInsets.only(
left: 32,
),
child: Text(
"What is Tor killswitch?",
style: STextStyles
.desktopH2(context),
),
),
DesktopDialogCloseButton(
onPressedOverride: () =>
Navigator.of(context)
@ -332,35 +351,25 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
),
Padding(
padding:
const EdgeInsets.all(20),
child: Column(
mainAxisSize:
MainAxisSize.max,
children: [
Text(
"What is Tor killswitch?",
style: STextStyles
.desktopH2(context),
),
const SizedBox(
height: 20,
),
Text(
"A security feature that protects your information from accidental exposure by"
" disconnecting your device from the Tor network if the"
" connection is disrupted or compromised.",
style: STextStyles
.desktopTextMedium(
context)
.copyWith(
color: Theme.of(
context)
.extension<
StackColors>()!
.textDark3,
),
),
],
const EdgeInsets.only(
top: 12,
left: 32,
bottom: 32,
right: 32,
),
child: Text(
"A security feature that protects your information from accidental exposure by"
" disconnecting your device from the Tor network if the"
" connection is disrupted or compromised.",
style: STextStyles
.desktopTextMedium(
context)
.copyWith(
color: Theme.of(context)
.extension<
StackColors>()!
.textDark3,
),
),
),
],
@ -370,8 +379,8 @@ class _TorSettingsState extends ConsumerState<TorSettings> {
);
},
),
],
),
),
],
),
],
),

View file

@ -59,7 +59,7 @@ class SimplexAPI {
url: url,
headers: headers,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
Prefs.instance.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
if (res.code != 200) {
throw Exception(
@ -125,7 +125,7 @@ class SimplexAPI {
url: url,
headers: headers,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
Prefs.instance.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
if (res.code != 200) {
throw Exception(
@ -206,7 +206,7 @@ class SimplexAPI {
url: url,
headers: headers,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
Prefs.instance.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
if (res.code != 200) {
throw Exception('getQuote exception: statusCode= ${res.code}');
@ -313,7 +313,7 @@ class SimplexAPI {
url: url,
headers: headers,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
Prefs.instance.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
if (res.code != 200) {
throw Exception('newOrder exception: statusCode= ${res.code}');

View file

@ -160,7 +160,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
},
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
)
.then((client) {
if (client.code == 200) {
@ -195,7 +195,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: balanceBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final balanceData = jsonDecode(balanceResponse.body);
@ -215,7 +215,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: infoBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final String frontier =
@ -270,7 +270,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: processBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final Map<String, dynamic> decoded =
@ -344,7 +344,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: body,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final data = jsonDecode(response.body);
_balance = Balance(
@ -388,7 +388,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: infoBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final infoData = jsonDecode(infoResponse.body);
@ -408,7 +408,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: balanceBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final balanceData = jsonDecode(balanceResponse.body);
@ -483,7 +483,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: processBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final Map<String, dynamic> decoded =
@ -504,7 +504,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
"count": "-1",
}),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final receivableData = await jsonDecode(receivableResponse.body);
@ -536,7 +536,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
"count": "-1",
}),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final data = await jsonDecode(response.body);
final transactions =
@ -858,7 +858,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
},
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
return response.code == 200;
@ -952,7 +952,7 @@ class BananoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: infoBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final infoData = jsonDecode(infoResponse.body);

View file

@ -169,7 +169,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
},
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
)
.then((Response response) {
if (response.code == 200) {
@ -204,7 +204,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: balanceBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final balanceData = jsonDecode(balanceResponse.body);
@ -224,7 +224,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: infoBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final String frontier =
@ -279,7 +279,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: processBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final Map<String, dynamic> decoded =
@ -349,7 +349,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: body,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final data = jsonDecode(response.body);
_balance = Balance(
@ -393,7 +393,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: infoBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final infoData = jsonDecode(infoResponse.body);
@ -413,7 +413,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: balanceBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final balanceData = jsonDecode(balanceResponse.body);
@ -488,7 +488,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: processBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final Map<String, dynamic> decoded =
@ -509,7 +509,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
"count": "-1",
}),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final receivableData = await jsonDecode(receivableResponse.body);
@ -541,7 +541,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
"count": "-1",
}),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final data = await jsonDecode(response.body);
final transactions =
@ -869,7 +869,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
},
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
return response.code == 200;
@ -963,7 +963,7 @@ class NanoWallet extends CoinServiceAPI with WalletCache, WalletDB {
headers: headers,
body: infoBody,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
final infoData = jsonDecode(infoResponse.body);

View file

@ -245,7 +245,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
var response = jsonDecode((await client.get(
url: Uri.parse(api),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
))
.body)[0];
double totalFees = response[4] as double;
@ -270,7 +270,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
var response = jsonDecode((await client.get(
url: Uri.parse(api),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
))
.body);
double totalFees = response[0][4] as double;
@ -509,9 +509,8 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
var response = jsonDecode(await client
.get(
url: Uri.parse(balanceCall),
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.proxyInfo
: null,
proxyInfo:
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
)
.then((value) => value.body));
Amount balanceInAmount = Amount(
@ -538,9 +537,8 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
var response = jsonDecode(await client
.get(
url: Uri.parse(transactionsCall),
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.proxyInfo
: null,
proxyInfo:
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
)
.then((value) => value.body));
List<Tuple2<Transaction, Address>> txs = [];
@ -619,9 +617,8 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
var jsonParsedResponse = jsonDecode(await client
.get(
url: Uri.parse(api),
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.proxyInfo
: null,
proxyInfo:
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
)
.then((value) => value.body));
final int intHeight = int.parse(jsonParsedResponse["level"].toString());
@ -707,7 +704,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
url: Uri.parse(
"${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/header/shell"),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
_prefs.useTor ? TorService.sharedInstance.getProxyInfo() : null,
);
return true;
} catch (e) {

View file

@ -61,8 +61,9 @@ abstract class EthereumAPI {
url: Uri.parse(
"$stackBaseServer/export?addrs=$address&firstBlock=$firstBlock",
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -184,8 +185,9 @@ abstract class EthereumAPI {
url: Uri.parse(
"$stackBaseServer/transactions?transactions=${txns.map((e) => e.hash).join(" ")}&raw=true",
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -244,8 +246,9 @@ abstract class EthereumAPI {
url: Uri.parse(
"$stackBaseServer/transactions?transactions=${txids.join(" ")}",
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -303,8 +306,9 @@ abstract class EthereumAPI {
url: Uri.parse(
"$stackBaseServer/export?addrs=$address&emitter=$tokenContractAddress&logs=true",
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -437,8 +441,9 @@ abstract class EthereumAPI {
);
final response = await client.get(
url: uri,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -488,8 +493,9 @@ abstract class EthereumAPI {
);
final response = await client.get(
url: uri,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -535,8 +541,9 @@ abstract class EthereumAPI {
url: Uri.parse(
"$stackBaseServer/gas-prices",
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -606,8 +613,9 @@ abstract class EthereumAPI {
url: Uri.parse(
"$stackBaseServer/tokens?addrs=$contractAddress&parts=all",
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -675,8 +683,9 @@ abstract class EthereumAPI {
url: Uri.parse(
"$stackBaseServer/abis?addrs=$contractAddress&verbose=true",
),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
@ -717,8 +726,9 @@ abstract class EthereumAPI {
final response = await client.get(
url: Uri.parse(
"$stackBaseServer/state?addrs=$contractAddress&parts=proxy"),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
final json = jsonDecode(response.body);

View file

@ -60,8 +60,9 @@ class ChangeNowAPI {
final response = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
String? data;
try {
@ -90,8 +91,9 @@ class ChangeNowAPI {
// 'Content-Type': 'application/json',
'x-changenow-api-key': apiKey,
},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final data = response.body;
@ -114,8 +116,9 @@ class ChangeNowAPI {
url: uri,
headers: {'Content-Type': 'application/json'},
body: jsonEncode(body),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
String? data;

View file

@ -49,8 +49,9 @@ class MajesticBankAPI {
try {
final response = await client.get(
url: uri,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
code = response.code;

View file

@ -47,8 +47,9 @@ class SimpleSwapAPI {
try {
final response = await client.get(
url: uri,
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
code = response.code;
@ -74,8 +75,9 @@ class SimpleSwapAPI {
url: uri,
headers: {'Content-Type': 'application/json'},
body: jsonEncode(body),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {

View file

@ -52,8 +52,9 @@ abstract class TrocadorAPI {
final response = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
code = response.code;

View file

@ -22,8 +22,9 @@ class LitescribeAPI {
Future<LitescribeResponse> _getResponse(String endpoint) async {
final response = await client.get(
url: Uri.parse('$baseUrl$endpoint'),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {
return LitescribeResponse(data: _validateJson(response.body));

View file

@ -25,8 +25,9 @@ class MonKeyService {
final response = await client.get(
url: Uri.parse(url),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
if (response.code == 200) {

View file

@ -31,8 +31,9 @@ class NanoAPI {
"representative": "true",
"account": account,
}),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final map = jsonDecode(response.body);
@ -124,8 +125,9 @@ class NanoAPI {
"subtype": "change",
"block": block,
}),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
return jsonDecode(response.body);

View file

@ -107,8 +107,9 @@ class PriceAPI {
final coinGeckoResponse = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final coinGeckoData = jsonDecode(coinGeckoResponse.body) as List<dynamic>;
@ -154,8 +155,9 @@ class PriceAPI {
final response = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final json = jsonDecode(response.body) as List<dynamic>;
@ -195,8 +197,9 @@ class PriceAPI {
final coinGeckoResponse = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final coinGeckoData = jsonDecode(coinGeckoResponse.body) as Map;

View file

@ -10,33 +10,45 @@ final pTorService = Provider((_) => TorService.sharedInstance);
class TorService {
Tor? _tor;
String? _torDataDirPath;
/// Flag to indicate that a Tor circuit is thought to have been established.
bool _enabled = false;
/// Getter for the enabled flag.
bool get enabled => _enabled;
TorService._();
/// Current status. Same as that fired on the event bus
TorConnectionStatus get status => _status;
TorConnectionStatus _status = TorConnectionStatus.disconnected;
/// Singleton instance of the TorService.
///
/// Use this to access the TorService and its properties.
static final sharedInstance = TorService._();
// private constructor for singleton
TorService._();
/// Getter for the proxyInfo.
///
/// Returns null if disabled on the stack wallet level.
({
InternetAddress host,
int port,
}) get proxyInfo => (
}) getProxyInfo() {
if (status == TorConnectionStatus.connected) {
return (
host: InternetAddress.loopbackIPv4,
port: _tor!.port,
);
} else {
throw Exception("Tor proxy info fetched while not connected!");
}
}
/// Initialize the tor ffi lib instance if it hasn't already been set. Nothing
/// changes if _tor is already been set.
void init({Tor? mockableOverride}) {
void init({
required String torDataDirPath,
Tor? mockableOverride,
}) {
_tor ??= mockableOverride ?? Tor.instance;
_torDataDirPath ??= torDataDirPath;
}
/// Start the Tor service.
@ -47,46 +59,25 @@ class TorService {
///
/// Returns a Future that completes when the Tor service has started.
Future<void> start() async {
if (_tor == null) {
if (_tor == null || _torDataDirPath == null) {
throw Exception("TorService.init has not been called!");
}
if (_enabled) {
// already started so just return
// could throw an exception here or something so the caller
// is explicitly made aware of this
// TODO restart tor after that's been added to the tor-ffi crate
// (probably better to have a restart function separately)
// Fire a TorConnectionStatusChangedEvent on the event bus.
GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent(
TorConnectionStatus.connected,
"Tor connection status changed: connect ($_enabled)",
),
);
return;
}
// Start the Tor service.
try {
GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent(
TorConnectionStatus.connecting,
"Tor connection status changed: connecting",
),
_updateStatusAndFireEvent(
status: TorConnectionStatus.connecting,
message: "TorService.start call in progress",
);
await _tor!.start();
await _tor!.start(torDataDirPath: _torDataDirPath!);
// no exception or error so we can (probably?) assume tor
// has started successfully
_enabled = true;
// Fire a TorConnectionStatusChangedEvent on the event bus.
GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent(
TorConnectionStatus.connected,
"Tor connection status changed: connect ($_enabled)",
),
_updateStatusAndFireEvent(
status: TorConnectionStatus.connected,
message: "TorService.start call success",
);
} catch (e, s) {
Logging.instance.log(
@ -96,47 +87,41 @@ class TorService {
// _enabled should already be false
// Fire a TorConnectionStatusChangedEvent on the event bus.
GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent(
TorConnectionStatus.disconnected,
"Tor connection status changed: $_enabled (failed)",
),
_updateStatusAndFireEvent(
status: TorConnectionStatus.disconnected,
message: "TorService.start call failed",
);
rethrow;
}
}
Future<void> stop() async {
/// disable tor
Future<void> disable() async {
if (_tor == null) {
throw Exception("TorService.init has not been called!");
}
if (!_enabled) {
// already stopped so just return
// could throw an exception here or something so the caller
// is explicitly made aware of this
// TODO make sure to kill
// no need to update status and fire event if status won't change
if (_status == TorConnectionStatus.disconnected) {
return;
}
// Stop the Tor service.
try {
_tor!.disable();
// no exception or error so we can (probably?) assume tor
// has started successfully
_enabled = false;
GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent(
TorConnectionStatus.disconnected,
"Tor connection status changed: $_enabled (disabled)",
),
);
} catch (e, s) {
Logging.instance.log(
"TorService.stop failed: $e\n$s",
level: LogLevel.Warning,
);
rethrow;
}
_updateStatusAndFireEvent(
status: TorConnectionStatus.disconnected,
message: "TorService.disable call success",
);
}
void _updateStatusAndFireEvent({
required TorConnectionStatus status,
required String message,
}) {
_status = status;
GlobalEventBus.instance.fire(
TorConnectionStatusChangedEvent(
_status,
message,
),
);
}
}

View file

@ -213,8 +213,9 @@ class ThemeService {
try {
final response = await client.get(
url: Uri.parse("$baseServerUrl/themes"),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final jsonList = jsonDecode(response.body) as List;
@ -240,8 +241,9 @@ class ThemeService {
try {
final response = await client.get(
url: Uri.parse("$baseServerUrl/theme/${themeMetaData.id}"),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
final bytes = Uint8List.fromList(response.bodyBytes);

View file

@ -258,4 +258,5 @@ class _ANIMATIONS {
String get iconSend => "assets/lottie/icon_send.json";
String get loaderAndCheckmark => "assets/lottie/loader_and_checkmark.json";
String get arrowRotate => "assets/lottie/arrow_rotate.json";
String get onionTor => "assets/lottie/onion_animation.json";
}

View file

@ -52,8 +52,9 @@ class PaynymIsApi {
url: uri,
headers: headers,
body: jsonEncode(body),
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);
debugPrint("Paynym request uri: $uri");

View file

@ -24,7 +24,7 @@ Future<bool> _testEpicBoxNodeConnection(Uri uri) async {
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.proxyInfo
? TorService.sharedInstance.getProxyInfo()
: null,
)
.timeout(const Duration(milliseconds: 2000),

View file

@ -13,8 +13,9 @@ Future<bool> testStellarNodeConnection(String host, int port) async {
.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo:
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
)
.timeout(const Duration(milliseconds: 2000),
onTimeout: () async => http.Response(utf8.encode('Error'), 408));

View file

@ -81,9 +81,7 @@ class _DesktopTorStatusButtonState extends ConsumerState<DesktopTorStatusButton>
eventBus = GlobalEventBus.instance;
// Initialize the TorConnectionStatus.
_torConnectionStatus = ref.read(pTorService).enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
_torConnectionStatus = ref.read(pTorService).status;
// Subscribe to the TorConnectionStatusChangedEvent.
_torConnectionStatusSubscription =
@ -93,25 +91,6 @@ class _DesktopTorStatusButtonState extends ConsumerState<DesktopTorStatusButton>
setState(() {
_torConnectionStatus = event.newStatus;
});
// TODO implement spinner or animations and control from here
// switch (event.newStatus) {
// case TorConnectionStatus.disconnected:
// // if (_spinController.hasLoadedAnimation) {
// // _spinController.stop?.call();
// // }
// break;
// case TorConnectionStatus.connecting:
// // if (_spinController.hasLoadedAnimation) {
// // _spinController.repeat?.call();
// // }
// break;
// case TorConnectionStatus.connected:
// // if (_spinController.hasLoadedAnimation) {
// // _spinController.stop?.call();
// // }
// break;
// }
},
);

View file

@ -37,9 +37,7 @@ class _SmallTorIconState extends ConsumerState<SmallTorIcon> {
@override
void initState() {
_status = ref.read(pTorService).enabled
? TorConnectionStatus.connected
: TorConnectionStatus.disconnected;
_status = ref.read(pTorService).status;
super.initState();
}

View file

@ -1655,9 +1655,11 @@ packages:
tor_ffi_plugin:
dependency: "direct main"
description:
path: "crypto_plugins/tor"
relative: true
source: path
path: "."
ref: "8a26a160bdc4dcac2ba5a0350a151a345d1dead9"
resolved-ref: "8a26a160bdc4dcac2ba5a0350a151a345d1dead9"
url: "https://github.com/cypherstack/tor.git"
source: git
version: "0.0.1"
tuple:
dependency: "direct main"

View file

@ -58,7 +58,9 @@ dependencies:
ref: 081ca1863c2feba00c35bb5b297902f12f499941
tor_ffi_plugin:
path: ./crypto_plugins/tor
git:
url: https://github.com/cypherstack/tor.git
ref: 8a26a160bdc4dcac2ba5a0350a151a345d1dead9
# Utility plugins
http: ^0.13.0
@ -377,6 +379,7 @@ flutter:
- assets/lottie/icon_send.json
- assets/lottie/loader_and_checkmark.json
- assets/lottie/arrow_rotate.json
- assets/lottie/onion_animation.json
# default themes_testing
- assets/default_themes/

View file

@ -5,6 +5,7 @@ import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/electrumx_rpc/rpc.dart';
import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart';
import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/utilities/prefs.dart';
@ -1528,7 +1529,8 @@ void main() {
.thenAnswer((_) => false); // Or true, shouldn't matter.
when(mockPrefs.wifiOnly).thenAnswer((_) => false);
final mockTorService = MockTorService();
when(mockTorService.enabled).thenAnswer((_) => false);
when(mockTorService.status)
.thenAnswer((_) => TorConnectionStatus.disconnected);
final client = ElectrumX(
host: "some server",
@ -1551,7 +1553,7 @@ void main() {
verify(mockPrefs.useTor).called(1);
verifyNever(mockPrefs.torKillSwitch);
verifyNoMoreInteractions(mockPrefs);
verifyNever(mockTorService.enabled);
verifyNever(mockTorService.status);
verifyNoMoreInteractions(mockTorService);
});
@ -1575,8 +1577,9 @@ void main() {
when(mockPrefs.wifiOnly).thenAnswer((_) => false);
final mockTorService = MockTorService();
when(mockTorService.enabled).thenAnswer((_) => false);
when(mockTorService.proxyInfo).thenAnswer((_) => (
when(mockTorService.status)
.thenAnswer((_) => TorConnectionStatus.disconnected);
when(mockTorService.getProxyInfo()).thenAnswer((_) => (
host: InternetAddress('1.2.3.4'),
port: -1
)); // Port is set to -1 until Tor is enabled.
@ -1601,8 +1604,8 @@ void main() {
verify(mockPrefs.useTor).called(1);
verify(mockPrefs.torKillSwitch).called(1);
verifyNoMoreInteractions(mockPrefs);
verify(mockTorService.enabled).called(1);
verifyNever(mockTorService.proxyInfo);
verify(mockTorService.status).called(1);
verifyNever(mockTorService.getProxyInfo());
verifyNoMoreInteractions(mockTorService);
});
@ -1628,8 +1631,9 @@ void main() {
when(mockPrefs.wifiOnly).thenAnswer((_) => false);
final mockTorService = MockTorService();
when(mockTorService.enabled).thenAnswer((_) => true);
when(mockTorService.proxyInfo)
when(mockTorService.status)
.thenAnswer((_) => TorConnectionStatus.connected);
when(mockTorService.getProxyInfo())
.thenAnswer((_) => (host: InternetAddress('1.2.3.4'), port: 42));
final client = ElectrumX(
@ -1653,8 +1657,8 @@ void main() {
verify(mockPrefs.useTor).called(1);
verifyNever(mockPrefs.torKillSwitch);
verifyNoMoreInteractions(mockPrefs);
verify(mockTorService.enabled).called(1);
verify(mockTorService.proxyInfo).called(1);
verify(mockTorService.status).called(1);
verify(mockTorService.getProxyInfo()).called(1);
verifyNoMoreInteractions(mockTorService);
});
@ -1685,7 +1689,8 @@ void main() {
when(mockPrefs.torKillSwitch).thenAnswer((_) => true);
when(mockPrefs.wifiOnly).thenAnswer((_) => false);
final mockTorService = MockTorService();
when(mockTorService.enabled).thenAnswer((_) => false);
when(mockTorService.status)
.thenAnswer((_) => TorConnectionStatus.disconnected);
final client = ElectrumX(
host: "some server",
@ -1712,7 +1717,7 @@ void main() {
verify(mockPrefs.useTor).called(1);
verify(mockPrefs.torKillSwitch).called(1);
verifyNoMoreInteractions(mockPrefs);
verify(mockTorService.enabled).called(1);
verify(mockTorService.status).called(1);
verifyNoMoreInteractions(mockTorService);
});
@ -1740,7 +1745,8 @@ void main() {
when(mockPrefs.torKillSwitch).thenAnswer((_) => false);
when(mockPrefs.wifiOnly).thenAnswer((_) => false);
final mockTorService = MockTorService();
when(mockTorService.enabled).thenAnswer((_) => false);
when(mockTorService.status)
.thenAnswer((_) => TorConnectionStatus.disconnected);
final client = ElectrumX(
host: "some server",
@ -1763,7 +1769,7 @@ void main() {
verify(mockPrefs.useTor).called(1);
verify(mockPrefs.torKillSwitch).called(1);
verifyNoMoreInteractions(mockPrefs);
verify(mockTorService.enabled).called(1);
verify(mockTorService.status).called(1);
verifyNoMoreInteractions(mockTorService);
});
});

View file

@ -9,13 +9,15 @@ import 'dart:ui' as _i10;
import 'package:mockito/mockito.dart' as _i1;
import 'package:stackwallet/electrumx_rpc/rpc.dart' as _i2;
import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart'
as _i12;
import 'package:stackwallet/services/tor_service.dart' as _i11;
import 'package:stackwallet/utilities/amount/amount_unit.dart' as _i8;
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart' as _i7;
import 'package:stackwallet/utilities/enums/coin_enum.dart' as _i9;
import 'package:stackwallet/utilities/enums/sync_type_enum.dart' as _i6;
import 'package:stackwallet/utilities/prefs.dart' as _i5;
import 'package:tor_ffi_plugin/tor_ffi_plugin.dart' as _i12;
import 'package:tor_ffi_plugin/tor_ffi_plugin.dart' as _i13;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@ -659,27 +661,40 @@ class MockTorService extends _i1.Mock implements _i11.TorService {
}
@override
bool get enabled => (super.noSuchMethod(
Invocation.getter(#enabled),
returnValue: false,
) as bool);
_i12.TorConnectionStatus get status => (super.noSuchMethod(
Invocation.getter(#status),
returnValue: _i12.TorConnectionStatus.disconnected,
) as _i12.TorConnectionStatus);
@override
({_i3.InternetAddress host, int port}) get proxyInfo => (super.noSuchMethod(
Invocation.getter(#proxyInfo),
({_i3.InternetAddress host, int port}) getProxyInfo() => (super.noSuchMethod(
Invocation.method(
#getProxyInfo,
[],
),
returnValue: (
host: _FakeInternetAddress_2(
this,
Invocation.getter(#proxyInfo),
Invocation.method(
#getProxyInfo,
[],
),
),
port: 0
),
) as ({_i3.InternetAddress host, int port}));
@override
void init({_i12.Tor? mockableOverride}) => super.noSuchMethod(
void init({
required String? torDataDirPath,
_i13.Tor? mockableOverride,
}) =>
super.noSuchMethod(
Invocation.method(
#init,
[],
{#mockableOverride: mockableOverride},
{
#torDataDirPath: torDataDirPath,
#mockableOverride: mockableOverride,
},
),
returnValueForMissingStub: null,
);
@ -693,9 +708,9 @@ class MockTorService extends _i1.Mock implements _i11.TorService {
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);
@override
_i4.Future<void> stop() => (super.noSuchMethod(
_i4.Future<void> disable() => (super.noSuchMethod(
Invocation.method(
#stop,
#disable,
[],
),
returnValue: _i4.Future<void>.value(),

View file

@ -12,6 +12,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart' as _i5;
import 'package:mockito/mockito.dart' as _i1;
import 'package:stackwallet/models/node_model.dart' as _i18;
import 'package:stackwallet/services/coins/manager.dart' as _i6;
import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart'
as _i20;
import 'package:stackwallet/services/node_service.dart' as _i3;
import 'package:stackwallet/services/tor_service.dart' as _i19;
import 'package:stackwallet/services/wallets.dart' as _i9;
@ -23,7 +25,7 @@ import 'package:stackwallet/utilities/enums/sync_type_enum.dart' as _i15;
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'
as _i7;
import 'package:stackwallet/utilities/prefs.dart' as _i13;
import 'package:tor_ffi_plugin/tor_ffi_plugin.dart' as _i20;
import 'package:tor_ffi_plugin/tor_ffi_plugin.dart' as _i21;
import 'package:tuple/tuple.dart' as _i11;
// ignore_for_file: type=lint
@ -1025,27 +1027,40 @@ class MockTorService extends _i1.Mock implements _i19.TorService {
}
@override
bool get enabled => (super.noSuchMethod(
Invocation.getter(#enabled),
returnValue: false,
) as bool);
_i20.TorConnectionStatus get status => (super.noSuchMethod(
Invocation.getter(#status),
returnValue: _i20.TorConnectionStatus.disconnected,
) as _i20.TorConnectionStatus);
@override
({_i8.InternetAddress host, int port}) get proxyInfo => (super.noSuchMethod(
Invocation.getter(#proxyInfo),
({_i8.InternetAddress host, int port}) getProxyInfo() => (super.noSuchMethod(
Invocation.method(
#getProxyInfo,
[],
),
returnValue: (
host: _FakeInternetAddress_5(
this,
Invocation.getter(#proxyInfo),
Invocation.method(
#getProxyInfo,
[],
),
),
port: 0
),
) as ({_i8.InternetAddress host, int port}));
@override
void init({_i20.Tor? mockableOverride}) => super.noSuchMethod(
void init({
required String? torDataDirPath,
_i21.Tor? mockableOverride,
}) =>
super.noSuchMethod(
Invocation.method(
#init,
[],
{#mockableOverride: mockableOverride},
{
#torDataDirPath: torDataDirPath,
#mockableOverride: mockableOverride,
},
),
returnValueForMissingStub: null,
);
@ -1059,9 +1074,9 @@ class MockTorService extends _i1.Mock implements _i19.TorService {
returnValueForMissingStub: _i12.Future<void>.value(),
) as _i12.Future<void>);
@override
_i12.Future<void> stop() => (super.noSuchMethod(
_i12.Future<void> disable() => (super.noSuchMethod(
Invocation.method(
#stop,
#disable,
[],
),
returnValue: _i12.Future<void>.value(),