tap the onion to connect/disconnect

This commit is contained in:
sneurlax 2023-09-12 15:01:02 -05:00
parent 50466ff509
commit f53bd53af4

View file

@ -17,6 +17,7 @@ import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
@ -41,40 +42,84 @@ class _TorSettingsViewState extends ConsumerState<TorSettingsView> {
Widget _buildTorIcon(TorConnectionStatus status) { Widget _buildTorIcon(TorConnectionStatus status) {
switch (status) { switch (status) {
case TorConnectionStatus.disconnected: case TorConnectionStatus.disconnected:
return Stack( return GestureDetector(
alignment: AlignmentDirectional.center, child: Stack(
children: [ alignment: AlignmentDirectional.center,
SvgPicture.asset( children: [
Assets.svg.tor, SvgPicture.asset(
color: Theme.of(context).extension<StackColors>()!.textSubtitle3, Assets.svg.tor,
width: 200, color:
height: 200, Theme.of(context).extension<StackColors>()!.textSubtitle3,
width: 200,
height: 200,
),
Text(
"CONNECT",
style: STextStyles.smallMed14(context).copyWith(
color:
Theme.of(context).extension<StackColors>()!.popupBG),
)
],
), ),
Text( onTap: () async {
"CONNECT", // Init the Tor service if it hasn't already been.
style: STextStyles.smallMed14(context).copyWith( ref.read(pTorService).init();
color: Theme.of(context).extension<StackColors>()!.popupBG),
) // Start the Tor service.
], try {
); await ref.read(pTorService).start();
// Toggle the useTor preference on success.
ref.read(prefsChangeNotifierProvider).useTor = true;
} catch (e, s) {
Logging.instance.log(
"Error starting tor: $e\n$s",
level: LogLevel.Error,
);
}
setState(() {
_networkStatus = TorConnectionStatus.connecting;
});
});
case TorConnectionStatus.connected: case TorConnectionStatus.connected:
return Stack( return GestureDetector(
alignment: AlignmentDirectional.center, child: Stack(
children: [ alignment: AlignmentDirectional.center,
SvgPicture.asset( children: [
Assets.svg.tor, SvgPicture.asset(
color: Assets.svg.tor,
Theme.of(context).extension<StackColors>()!.accentColorGreen, color: Theme.of(context)
width: 200, .extension<StackColors>()!
height: 200, .accentColorGreen,
width: 200,
height: 200,
),
Text(
"CONNECTED",
style: STextStyles.smallMed14(context).copyWith(
color:
Theme.of(context).extension<StackColors>()!.popupBG),
)
],
), ),
Text( onTap: () async {
"CONNECTED", // Init the Tor service if it hasn't already been.
style: STextStyles.smallMed14(context).copyWith( ref.read(pTorService).init();
color: Theme.of(context).extension<StackColors>()!.popupBG),
) // Start the Tor service.
], try {
); await ref.read(pTorService).start();
// Toggle the useTor preference on success.
ref.read(prefsChangeNotifierProvider).useTor = true;
} catch (e, s) {
Logging.instance.log(
"Error starting tor: $e\n$s",
level: LogLevel.Error,
);
}
});
case TorConnectionStatus.connecting: case TorConnectionStatus.connecting:
return Stack( return Stack(
alignment: AlignmentDirectional.center, alignment: AlignmentDirectional.center,