mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-22 19:39:22 +00:00
fix desktop wallet name field
This commit is contained in:
parent
4559269784
commit
4593f7a0dc
2 changed files with 107 additions and 117 deletions
|
@ -59,7 +59,6 @@ class DesktopWalletView extends ConsumerStatefulWidget {
|
|||
|
||||
class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
||||
late final TextEditingController controller;
|
||||
late final String walletId;
|
||||
late final EventBus eventBus;
|
||||
|
||||
late final bool _shouldDisableAutoSyncOnLogOut;
|
||||
|
@ -74,8 +73,9 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
}
|
||||
|
||||
Future<void> _logout() async {
|
||||
final managerProvider =
|
||||
ref.read(walletsChangeNotifierProvider).getManagerProvider(walletId);
|
||||
final managerProvider = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManagerProvider(widget.walletId);
|
||||
if (_shouldDisableAutoSyncOnLogOut) {
|
||||
// disable auto sync if it was enabled only when loading wallet
|
||||
ref.read(managerProvider).shouldAutoSync = false;
|
||||
|
@ -95,7 +95,7 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
_cnLoadingService.loadAll(ref,
|
||||
coin: ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(walletId)
|
||||
.getManager(widget.walletId)
|
||||
.coin);
|
||||
} else {
|
||||
Logging.instance.log("User does not want to use external calls",
|
||||
|
@ -104,8 +104,9 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
}
|
||||
|
||||
void _onExchangePressed(BuildContext context) async {
|
||||
final managerProvider =
|
||||
ref.read(walletsChangeNotifierProvider).getManagerProvider(walletId);
|
||||
final managerProvider = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManagerProvider(widget.walletId);
|
||||
unawaited(_cnLoadingService.loadAll(ref));
|
||||
|
||||
final coin = ref.read(managerProvider).coin;
|
||||
|
@ -127,7 +128,6 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
} else {
|
||||
ref.read(currentExchangeNameStateProvider.state).state =
|
||||
ChangeNowExchange.exchangeName;
|
||||
final walletId = ref.read(managerProvider).walletId;
|
||||
ref.read(prefsChangeNotifierProvider).exchangeRateType =
|
||||
ExchangeRateType.estimated;
|
||||
|
||||
|
@ -160,7 +160,7 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
Navigator.of(context).pushNamed(
|
||||
WalletInitiatedExchangeView.routeName,
|
||||
arguments: Tuple3(
|
||||
walletId,
|
||||
widget.walletId,
|
||||
coin,
|
||||
_loadCNData,
|
||||
),
|
||||
|
@ -171,8 +171,9 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
}
|
||||
|
||||
Future<void> attemptAnonymize() async {
|
||||
final managerProvider =
|
||||
ref.read(walletsChangeNotifierProvider).getManagerProvider(walletId);
|
||||
final managerProvider = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManagerProvider(widget.walletId);
|
||||
|
||||
bool shouldPop = false;
|
||||
unawaited(
|
||||
|
@ -283,9 +284,9 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
@override
|
||||
void initState() {
|
||||
controller = TextEditingController();
|
||||
walletId = widget.walletId;
|
||||
final managerProvider =
|
||||
ref.read(walletsChangeNotifierProvider).getManagerProvider(walletId);
|
||||
final managerProvider = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManagerProvider(widget.walletId);
|
||||
|
||||
controller.text = ref.read(managerProvider).walletName;
|
||||
|
||||
|
@ -306,13 +307,19 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final manager = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManager(walletId)));
|
||||
.select((value) => value.getManager(widget.walletId)));
|
||||
final coin = manager.coin;
|
||||
final managerProvider = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManagerProvider(walletId)));
|
||||
.select((value) => value.getManagerProvider(widget.walletId)));
|
||||
|
||||
return DesktopScaffold(
|
||||
appBar: DesktopAppBar(
|
||||
|
@ -355,47 +362,8 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
minWidth: 48,
|
||||
),
|
||||
child: IntrinsicWidth(
|
||||
child: HoverTextField(
|
||||
controller: controller,
|
||||
style: STextStyles.desktopH3(context),
|
||||
readOnly: true,
|
||||
onDone: () async {
|
||||
final currentWalletName =
|
||||
ref.read(managerProvider).walletName;
|
||||
final newName = controller.text;
|
||||
if (newName != currentWalletName) {
|
||||
final success = await ref
|
||||
.read(walletsServiceChangeNotifierProvider)
|
||||
.renameWallet(
|
||||
from: currentWalletName,
|
||||
to: newName,
|
||||
shouldNotifyListeners: true,
|
||||
);
|
||||
if (success) {
|
||||
ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(walletId)
|
||||
.walletName = newName;
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.success,
|
||||
message: "Wallet renamed",
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
message:
|
||||
"Wallet named \"$newName\" already exists",
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
controller.text = currentWalletName;
|
||||
}
|
||||
}
|
||||
},
|
||||
child: DesktopWalletNameField(
|
||||
walletId: widget.walletId,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -403,20 +371,20 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
Row(
|
||||
children: [
|
||||
NetworkInfoButton(
|
||||
walletId: walletId,
|
||||
walletId: widget.walletId,
|
||||
eventBus: eventBus,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 2,
|
||||
),
|
||||
WalletKeysButton(
|
||||
walletId: walletId,
|
||||
walletId: widget.walletId,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 2,
|
||||
),
|
||||
DeleteWalletButton(
|
||||
walletId: walletId,
|
||||
walletId: widget.walletId,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 12,
|
||||
|
@ -446,7 +414,7 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
width: 10,
|
||||
),
|
||||
DesktopWalletSummary(
|
||||
walletId: walletId,
|
||||
walletId: widget.walletId,
|
||||
managerProvider: managerProvider,
|
||||
initialSyncStatus: ref.watch(managerProvider
|
||||
.select((value) => value.isRefreshing))
|
||||
|
@ -556,7 +524,7 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
SizedBox(
|
||||
width: 450,
|
||||
child: MyWallet(
|
||||
walletId: walletId,
|
||||
walletId: widget.walletId,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
|
@ -564,7 +532,7 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
),
|
||||
Expanded(
|
||||
child: RecentDesktopTransactions(
|
||||
walletId: walletId,
|
||||
walletId: widget.walletId,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -1,46 +1,31 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_service_provider.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
||||
class HoverTextField extends StatefulWidget {
|
||||
const HoverTextField({
|
||||
class DesktopWalletNameField extends ConsumerStatefulWidget {
|
||||
const DesktopWalletNameField({
|
||||
Key? key,
|
||||
this.controller,
|
||||
this.focusNode,
|
||||
this.readOnly = false,
|
||||
this.enabled,
|
||||
this.onTap,
|
||||
this.onChanged,
|
||||
this.onEditingComplete,
|
||||
this.style,
|
||||
this.onDone,
|
||||
required this.walletId,
|
||||
}) : super(key: key);
|
||||
|
||||
final TextEditingController? controller;
|
||||
final FocusNode? focusNode;
|
||||
final bool readOnly;
|
||||
final bool? enabled;
|
||||
final GestureTapCallback? onTap;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final VoidCallback? onEditingComplete;
|
||||
final TextStyle? style;
|
||||
final VoidCallback? onDone;
|
||||
final String walletId;
|
||||
|
||||
@override
|
||||
State<HoverTextField> createState() => _HoverTextFieldState();
|
||||
ConsumerState<DesktopWalletNameField> createState() => _HoverTextFieldState();
|
||||
}
|
||||
|
||||
class _HoverTextFieldState extends State<HoverTextField> {
|
||||
late final TextEditingController? controller;
|
||||
late final FocusNode? focusNode;
|
||||
late bool readOnly;
|
||||
late bool? enabled;
|
||||
late final GestureTapCallback? onTap;
|
||||
late final ValueChanged<String>? onChanged;
|
||||
late final VoidCallback? onEditingComplete;
|
||||
late final TextStyle? style;
|
||||
late final VoidCallback? onDone;
|
||||
class _HoverTextFieldState extends ConsumerState<DesktopWalletNameField> {
|
||||
late final TextEditingController controller;
|
||||
late final FocusNode focusNode;
|
||||
bool readOnly = true;
|
||||
|
||||
final InputBorder inputBorder = OutlineInputBorder(
|
||||
borderSide: const BorderSide(
|
||||
|
@ -50,33 +35,74 @@ class _HoverTextFieldState extends State<HoverTextField> {
|
|||
borderRadius: BorderRadius.circular(Constants.size.circularBorderRadius),
|
||||
);
|
||||
|
||||
Future<void> onDone() async {
|
||||
final currentWalletName = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(widget.walletId)
|
||||
.walletName;
|
||||
final newName = controller.text;
|
||||
if (newName != currentWalletName) {
|
||||
final success =
|
||||
await ref.read(walletsServiceChangeNotifierProvider).renameWallet(
|
||||
from: currentWalletName,
|
||||
to: newName,
|
||||
shouldNotifyListeners: true,
|
||||
);
|
||||
if (success) {
|
||||
ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(widget.walletId)
|
||||
.walletName = newName;
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.success,
|
||||
message: "Wallet renamed",
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
message: "Wallet named \"$newName\" already exists",
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
controller.text = currentWalletName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void listenerFunc() {
|
||||
if (!focusNode.hasPrimaryFocus && !readOnly) {
|
||||
setState(() {
|
||||
readOnly = true;
|
||||
});
|
||||
onDone.call();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
controller = widget.controller;
|
||||
focusNode = widget.focusNode ?? FocusNode();
|
||||
readOnly = widget.readOnly;
|
||||
enabled = widget.enabled;
|
||||
onChanged = widget.onChanged;
|
||||
style = widget.style;
|
||||
onTap = widget.onTap;
|
||||
onEditingComplete = widget.onEditingComplete;
|
||||
onDone = widget.onDone;
|
||||
controller = TextEditingController();
|
||||
focusNode = FocusNode();
|
||||
|
||||
focusNode!.addListener(() {
|
||||
if (!focusNode!.hasPrimaryFocus && !readOnly) {
|
||||
setState(() {
|
||||
readOnly = true;
|
||||
});
|
||||
onDone?.call();
|
||||
}
|
||||
focusNode.addListener(listenerFunc);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
controller.text = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(widget.walletId)
|
||||
.walletName;
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller?.dispose();
|
||||
focusNode?.dispose();
|
||||
controller.dispose();
|
||||
focusNode.removeListener(listenerFunc);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -88,22 +114,18 @@ class _HoverTextFieldState extends State<HoverTextField> {
|
|||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
readOnly: readOnly,
|
||||
enabled: enabled,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
readOnly = false;
|
||||
});
|
||||
onTap?.call();
|
||||
},
|
||||
onChanged: onChanged,
|
||||
onEditingComplete: () {
|
||||
setState(() {
|
||||
readOnly = true;
|
||||
});
|
||||
onEditingComplete?.call();
|
||||
onDone?.call();
|
||||
onDone.call();
|
||||
},
|
||||
style: style,
|
||||
style: STextStyles.desktopH3(context),
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
|
|
Loading…
Reference in a new issue