From 0a6d7f84dab0d7bb76891e4bcff76bcaec00b568 Mon Sep 17 00:00:00 2001 From: Egor Komarov Date: Fri, 3 Oct 2025 12:31:50 +0200 Subject: [PATCH] feat(EWM-570): seed/key rename input --- .../view/account_detail_view.dart | 6 +++- .../seed_settings/seed_settings_wm.dart | 8 ++++- .../widgets/key_settings_sheet.dart | 2 +- .../widgets/rename_sheet/rename_sheet.dart | 36 ++++++++++++++----- .../rename_sheet/rename_sheet_model.dart | 18 ++++++++-- .../widgets/rename_sheet/rename_sheet_wm.dart | 17 +++++---- 6 files changed, 65 insertions(+), 22 deletions(-) diff --git a/lib/feature/profile/account_detail/view/account_detail_view.dart b/lib/feature/profile/account_detail/view/account_detail_view.dart index c750075a7..8f5bbaad7 100644 --- a/lib/feature/profile/account_detail/view/account_detail_view.dart +++ b/lib/feature/profile/account_detail/view/account_detail_view.dart @@ -153,7 +153,11 @@ class AccountDetailView extends StatelessWidget { buttonType: EverButtonType.ghost, color: colors.textSecondary, onPressed: () => Navigator.of(context).push( - showRenameSheet(context, custodian.publicKey, isCustodian: true), + showRenameSheet( + context: context, + publicKey: custodian.publicKey, + isCustodian: true, + ), ), ), ); diff --git a/lib/feature/profile/manage_seeds_accounts/widgets/seed_settings/seed_settings_wm.dart b/lib/feature/profile/manage_seeds_accounts/widgets/seed_settings/seed_settings_wm.dart index 2f428c1e1..02c0c788a 100644 --- a/lib/feature/profile/manage_seeds_accounts/widgets/seed_settings/seed_settings_wm.dart +++ b/lib/feature/profile/manage_seeds_accounts/widgets/seed_settings/seed_settings_wm.dart @@ -35,7 +35,13 @@ class SeedSettingsWidgetModel extends CustomWidgetModelParametrized< void onRename() { Navigator.of(context) ..pop() - ..push(showRenameSheet(context, publicKeyState.value, renameSeed: true)); + ..push( + showRenameSheet( + context: context, + publicKey: publicKeyState.value, + isSeed: true, + ), + ); } void onExport() { diff --git a/lib/feature/profile/seed_detail/widgets/key_settings_sheet.dart b/lib/feature/profile/seed_detail/widgets/key_settings_sheet.dart index 47d82d414..db0ebe204 100644 --- a/lib/feature/profile/seed_detail/widgets/key_settings_sheet.dart +++ b/lib/feature/profile/seed_detail/widgets/key_settings_sheet.dart @@ -66,7 +66,7 @@ class KeySettingsSheet extends StatelessWidget { CommonListTile( onPressed: () => Navigator.of(context) ..pop() - ..push(showRenameSheet(context, publicKey)), + ..push(showRenameSheet(context: context, publicKey: publicKey)), titleText: LocaleKeys.renameWord.tr(), trailing: CommonIconWidget.svg( svg: Assets.images.edit.path, diff --git a/lib/feature/profile/widgets/rename_sheet/rename_sheet.dart b/lib/feature/profile/widgets/rename_sheet/rename_sheet.dart index 6b96850f3..bf7999091 100644 --- a/lib/feature/profile/widgets/rename_sheet/rename_sheet.dart +++ b/lib/feature/profile/widgets/rename_sheet/rename_sheet.dart @@ -3,6 +3,7 @@ import 'package:app/feature/profile/widgets/rename_sheet/rename_sheet_wm.dart'; import 'package:app/generated/generated.dart'; import 'package:app/utils/constants.dart'; import 'package:flutter/material.dart'; +import 'package:lucide_icons_flutter/lucide_icons.dart'; import 'package:nekoton_repository/nekoton_repository.dart' hide Message; import 'package:ui_components_lib/ui_components_lib.dart'; import 'package:ui_components_lib/v2/widgets/widgets.dart'; @@ -10,13 +11,13 @@ import 'package:ui_components_lib/v2/widgets/widgets.dart'; /// Helper method to show the [RenameSheet] widget as a bottom sheet. /// -/// To rename seed phrase, put [renameSeed] true, else key will be renamed. +/// To rename seed phrase, put [isSeed] true, else key will be renamed. /// -/// Snackbar will contains 'seed' if [renameSeed] is true and 'key' if false. -ModalRoute showRenameSheet( - BuildContext context, - PublicKey publicKey, { - bool renameSeed = false, +/// Snackbar will contains 'seed' if [isSeed] is true and 'key' if false. +ModalRoute showRenameSheet({ + required BuildContext context, + required PublicKey publicKey, + bool isSeed = false, bool isCustodian = false, }) { return commonBottomSheetRoute( @@ -24,7 +25,7 @@ ModalRoute showRenameSheet( title: LocaleKeys.enterNewName.tr(), body: (_, __) => RenameSheet( publicKey: publicKey, - renameSeed: renameSeed, + isSeed: isSeed, isCustodian: isCustodian, ), ); @@ -36,13 +37,13 @@ class RenameSheet extends InjectedElementaryParametrizedWidget< RenameSheetWidgetModel, RenameSheetParams> { RenameSheet({ required PublicKey publicKey, - required bool renameSeed, + required bool isSeed, required bool isCustodian, super.key, }) : super( wmFactoryParam: RenameSheetParams( publicKey: publicKey, - renameSeed: renameSeed, + isSeed: isSeed, isCustodian: isCustodian, ), ); @@ -54,9 +55,26 @@ class RenameSheet extends InjectedElementaryParametrizedWidget< spacing: DimensSize.d24, children: [ PrimaryTextField( + isAutofocus: true, maxLength: maxLengthForMainEntities, textEditingController: wm.nameController, hintText: LocaleKeys.nameWord.tr(), + suffixes: [ + ValueListenableBuilder( + valueListenable: wm.nameController, + builder: (_, value, __) => value.text.isNotEmpty + ? Padding( + padding: const EdgeInsets.only(right: DimensSizeV2.d8), + child: PrimaryButton( + icon: LucideIcons.x, + buttonShape: ButtonShape.square, + buttonSize: ButtonSize.small, + onPressed: wm.nameController.clear, + ), + ) + : const SizedBox.shrink(), + ), + ], onSubmit: wm.rename, ), PrimaryButton( diff --git a/lib/feature/profile/widgets/rename_sheet/rename_sheet_model.dart b/lib/feature/profile/widgets/rename_sheet/rename_sheet_model.dart index f98cabcca..3a86d00b2 100644 --- a/lib/feature/profile/widgets/rename_sheet/rename_sheet_model.dart +++ b/lib/feature/profile/widgets/rename_sheet/rename_sheet_model.dart @@ -15,13 +15,25 @@ class RenameSheetModel extends ElementaryModel { final NekotonRepository _nekotonRepository; final MessengerService _messengerService; + String getName({ + required PublicKey publicKey, + required bool isSeed, + }) { + if (isSeed) { + final seed = _nekotonRepository.seedList.findSeed(publicKey); + return seed?.name ?? ''; + } else { + final key = _nekotonRepository.seedList.findSeedKey(publicKey); + return key?.name ?? ''; + } + } + void rename({ required PublicKey publicKey, - required bool renameSeed, + required bool isSeed, required String name, - required bool isCustodian, }) { - if (renameSeed) { + if (isSeed) { final seed = _nekotonRepository.seedList.findSeed(publicKey); seed?.rename(name: name); } else { diff --git a/lib/feature/profile/widgets/rename_sheet/rename_sheet_wm.dart b/lib/feature/profile/widgets/rename_sheet/rename_sheet_wm.dart index de66b54d6..bcbd800bc 100644 --- a/lib/feature/profile/widgets/rename_sheet/rename_sheet_wm.dart +++ b/lib/feature/profile/widgets/rename_sheet/rename_sheet_wm.dart @@ -12,8 +12,12 @@ class RenameSheetWidgetModel extends CustomWidgetModelParametrized { RenameSheetWidgetModel(super.model); - late final TextEditingController nameController = - createTextEditingController(); + late final nameController = createTextEditingController( + model.getName( + publicKey: wmParams.value.publicKey, + isSeed: wmParams.value.isSeed, + ), + ); void rename([String? _]) { final name = nameController.text.trim(); @@ -23,13 +27,12 @@ class RenameSheetWidgetModel extends CustomWidgetModelParametrized