Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dap erased after typo #270

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions lib/features/dap/dap_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';

class DapForm extends HookConsumerWidget {
final String buttonTitle;
final ValueNotifier<String?> dapText;
final ValueNotifier<AsyncValue<Dap>?> dap;
final Future<void> Function(Dap, List<MoneyAddress>) onSubmit;

DapForm({
required this.buttonTitle,
required this.dapText,
required this.dap,
required this.onSubmit,
super.key,
Expand All @@ -26,9 +28,19 @@ class DapForm extends HookConsumerWidget {
final errorText = useState<String?>(null);
final focusNode = useFocusNode();

final textController = useTextEditingController();
final textController = useTextEditingController(text: dapText.value);
final errorMessage = Loc.of(context).invalidDap;

useEffect(
() {
if (dapText.value != null && dapText.value!.isNotEmpty) {
focusNode.requestFocus();
}
return null;
},
[],
);

return Form(
key: _formKey,
child: Column(
Expand All @@ -46,11 +58,13 @@ class DapForm extends HookConsumerWidget {
controller: textController,
onTap: () => errorText.value = null,
onTapOutside: (_) {
_parseDap(
textController.text,
errorMessage,
errorText,
);
if (textController.text.isNotEmpty) {
_parseDap(
textController.text,
errorMessage,
errorText,
);
}

focusNode.unfocus();
},
Expand Down Expand Up @@ -82,6 +96,8 @@ class DapForm extends HookConsumerWidget {
errorText,
);

dapText.value = textController.text;

if (errorText.value == null) {
await _resolveDap(parsedDap);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/features/send/send_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SendPage extends HookConsumerWidget {
final featureFlags = ref.watch(featureFlagsProvider);

final dap = useState<AsyncValue<Dap>?>(null);
final dapText = useState<String?>(null);

return Scaffold(
appBar: _buildAppBar(context, featureFlags),
Expand All @@ -47,6 +48,7 @@ class SendPage extends HookConsumerWidget {
Expanded(
child: DapForm(
buttonTitle: Loc.of(context).next,
dapText: dapText,
dap: dap,
onSubmit: (recipientDap, moneyAddresses) async {
await Navigator.of(context).push(
Expand Down
Loading