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