button style consistency on desktop network info

This commit is contained in:
julian 2023-09-20 13:39:18 -06:00
parent eff2d7d539
commit 90a913540c
2 changed files with 36 additions and 64 deletions

View file

@ -225,11 +225,11 @@ class _TorAnimatedButtonState extends ConsumerState<TorAnimatedButton>
// Connect or disconnect when the user taps the status. // Connect or disconnect when the user taps the status.
switch (_status) { switch (_status) {
case TorConnectionStatus.disconnected: case TorConnectionStatus.disconnected:
await _connectTor(ref, context); await connectTor(ref, context);
break; break;
case TorConnectionStatus.connected: case TorConnectionStatus.connected:
await _disconnectTor(ref, context); await disconnectTor(ref, context);
break; break;
@ -435,11 +435,11 @@ class _TorButtonState extends ConsumerState<TorButton> {
// Connect or disconnect when the user taps the status. // Connect or disconnect when the user taps the status.
switch (_status) { switch (_status) {
case TorConnectionStatus.disconnected: case TorConnectionStatus.disconnected:
await _connectTor(ref, context); await connectTor(ref, context);
break; break;
case TorConnectionStatus.connected: case TorConnectionStatus.connected:
await _disconnectTor(ref, context); await disconnectTor(ref, context);
break; break;
@ -583,7 +583,7 @@ class _UpperCaseTorTextState extends ConsumerState<UpperCaseTorText> {
/// Throws an exception if the Tor service fails to start. /// Throws an exception if the Tor service fails to start.
/// ///
/// Returns a Future that completes when the Tor service has started. /// Returns a Future that completes when the Tor service has started.
Future<void> _connectTor(WidgetRef ref, BuildContext context) async { Future<void> connectTor(WidgetRef ref, BuildContext context) async {
try { try {
// Init the Tor service if it hasn't already been. // Init the Tor service if it hasn't already been.
final torDir = await StackFileSystem.applicationTorDirectory(); final torDir = await StackFileSystem.applicationTorDirectory();
@ -600,8 +600,6 @@ Future<void> _connectTor(WidgetRef ref, BuildContext context) async {
); );
// TODO: show dialog with error message // TODO: show dialog with error message
} }
return;
} }
/// Disconnect from the Tor network. /// Disconnect from the Tor network.
@ -611,7 +609,7 @@ Future<void> _connectTor(WidgetRef ref, BuildContext context) async {
/// Throws an exception if the Tor service fails to stop. /// Throws an exception if the Tor service fails to stop.
/// ///
/// Returns a Future that completes when the Tor service has stopped. /// Returns a Future that completes when the Tor service has stopped.
Future<void> _disconnectTor(WidgetRef ref, BuildContext context) async { Future<void> disconnectTor(WidgetRef ref, BuildContext context) async {
// Stop the Tor service. // Stop the Tor service.
try { try {
await ref.read(pTorService).disable(); await ref.read(pTorService).disable();

View file

@ -16,6 +16,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart'; import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/tor_settings/tor_settings_view.dart';
import 'package:stackwallet/pages/settings_views/sub_widgets/nodes_list.dart'; import 'package:stackwallet/pages/settings_views/sub_widgets/nodes_list.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/confirm_full_rescan.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/confirm_full_rescan.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/rescanning_dialog.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_network_settings_view/sub_widgets/rescanning_dialog.dart';
@ -35,8 +36,6 @@ 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/enums/coin_enum.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/text_styles.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/animated_text.dart'; import 'package:stackwallet/widgets/animated_text.dart';
@ -100,6 +99,26 @@ class _WalletNetworkSettingsViewState
/// The current status of the Tor connection. /// The current status of the Tor connection.
late TorConnectionStatus _torConnectionStatus; late TorConnectionStatus _torConnectionStatus;
bool _buttonLockTor = false;
Future<void> onTorTapped() async {
if (_buttonLockTor) {
return;
}
_buttonLockTor = true;
try {
if (ref.read(prefsChangeNotifierProvider).useTor) {
await disconnectTor(ref, context);
} else {
await connectTor(ref, context);
}
} catch (_) {
// Nothing. Just using finally to ensure button lock is reset in case
// some unexpected error happens
} finally {
_buttonLockTor = false;
}
}
Future<void> _attemptRescan() async { Future<void> _attemptRescan() async {
if (!Platform.isLinux) await Wakelock.enable(); if (!Platform.isLinux) await Wakelock.enable();
@ -477,17 +496,14 @@ class _WalletNetworkSettingsViewState
? STextStyles.desktopTextExtraExtraSmall(context) ? STextStyles.desktopTextExtraExtraSmall(context)
: STextStyles.smallMed12(context), : STextStyles.smallMed12(context),
), ),
GestureDetector( CustomTextButton(
text: "Resync",
onTap: () { onTap: () {
ref ref
.read(walletsChangeNotifierProvider) .read(walletsChangeNotifierProvider)
.getManager(widget.walletId) .getManager(widget.walletId)
.refresh(); .refresh();
}, },
child: Text(
"Resync",
style: STextStyles.link2(context),
),
), ),
], ],
), ),
@ -769,55 +785,13 @@ class _WalletNetworkSettingsViewState
? STextStyles.desktopTextExtraExtraSmall(context) ? STextStyles.desktopTextExtraExtraSmall(context)
: STextStyles.smallMed12(context), : STextStyles.smallMed12(context),
), ),
if (ref.watch( CustomTextButton(
prefsChangeNotifierProvider.select((value) => value.useTor))) text: ref.watch(prefsChangeNotifierProvider
GestureDetector( .select((value) => value.useTor))
onTap: () async { ? "Disconnect"
// Stop the Tor service. : "Connect",
try { onTap: onTorTapped,
await ref.read(pTorService).disable(); ),
// Toggle the useTor preference on success.
ref.read(prefsChangeNotifierProvider).useTor = false;
} catch (e, s) {
Logging.instance.log(
"Error stopping tor: $e\n$s",
level: LogLevel.Error,
);
}
},
child: Text(
"Disconnect",
style: STextStyles.link2(context),
),
),
if (!ref.watch(
prefsChangeNotifierProvider.select((value) => value.useTor)))
GestureDetector(
onTap: () async {
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.
ref.read(prefsChangeNotifierProvider).useTor = true;
} catch (e, s) {
Logging.instance.log(
"Error starting tor: $e\n$s",
level: LogLevel.Error,
);
// TODO: show dialog with error message
}
},
child: Text(
"Connect",
style: STextStyles.link2(context),
),
),
], ],
), ),
SizedBox( SizedBox(