Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 27 additions & 9 deletions lib/feature/profile/widgets/rename_sheet/rename_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ 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';
// Cubit removed in favor of Elementary

/// 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<void> showRenameSheet(
BuildContext context,
PublicKey publicKey, {
bool renameSeed = false,
/// Snackbar will contains 'seed' if [isSeed] is true and 'key' if false.
ModalRoute<void> showRenameSheet({
required BuildContext context,
required PublicKey publicKey,
bool isSeed = false,
bool isCustodian = false,
}) {
return commonBottomSheetRoute(
titleTextStyle: context.themeStyleV2.textStyles.headingLarge,
title: LocaleKeys.enterNewName.tr(),
body: (_, __) => RenameSheet(
publicKey: publicKey,
renameSeed: renameSeed,
isSeed: isSeed,
isCustodian: isCustodian,
),
);
Expand All @@ -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,
),
);
Expand All @@ -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(
Expand Down
18 changes: 15 additions & 3 deletions lib/feature/profile/widgets/rename_sheet/rename_sheet_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 10 additions & 7 deletions lib/feature/profile/widgets/rename_sheet/rename_sheet_wm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ class RenameSheetWidgetModel extends CustomWidgetModelParametrized<RenameSheet,
RenameSheetModel, RenameSheetParams> {
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();
Expand All @@ -23,13 +27,12 @@ class RenameSheetWidgetModel extends CustomWidgetModelParametrized<RenameSheet,

model.rename(
publicKey: params.publicKey,
renameSeed: params.renameSeed,
isSeed: params.isSeed,
name: name,
isCustodian: params.isCustodian,
);
model.showMessage(
Message.successful(
message: params.renameSeed
message: params.isSeed
? LocaleKeys.valueRenamed.tr(
args: [LocaleKeys.seedPhrase.tr()],
)
Expand All @@ -48,11 +51,11 @@ class RenameSheetWidgetModel extends CustomWidgetModelParametrized<RenameSheet,
class RenameSheetParams {
const RenameSheetParams({
required this.publicKey,
required this.renameSeed,
required this.isSeed,
required this.isCustodian,
});

final PublicKey publicKey;
final bool renameSeed;
final bool isSeed;
final bool isCustodian;
}