Skip to content

Commit

Permalink
Updated label for import and create
Browse files Browse the repository at this point in the history
  • Loading branch information
i5hi committed Oct 20, 2023
1 parent 1596648 commit 5539af1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/create/bloc/create_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class CreateWalletCubit extends Cubit<CreateWalletState> {
emit(state.copyWith(passPhrase: text));
}

void walletLabelChanged(String text) {
emit(state.copyWith(walletLabel: text));
}
// void _showSavingErr(String err) {
// emit(
// state.copyWith(
Expand Down Expand Up @@ -86,6 +89,9 @@ class CreateWalletCubit extends Cubit<CreateWalletState> {
emit(state.copyWith(saving: false, errSaving: 'Error Creating Wallet'));
return;
}
final updatedWallet = (state.walletLabel != null && state.walletLabel != '')
? wallet!.copyWith(name: state.walletLabel)
: wallet;

final ssErr = await walletSensRepository.newSeed(seed: seed, secureStore: secureStorage);
if (ssErr != null) {
Expand Down Expand Up @@ -117,7 +123,7 @@ class CreateWalletCubit extends Cubit<CreateWalletState> {
}
}

final wsErr = await walletRepository.newWallet(wallet: wallet!, hiveStore: hiveStorage);
final wsErr = await walletRepository.newWallet(wallet: updatedWallet!, hiveStore: hiveStorage);
if (wsErr != null) {
emit(state.copyWith(saving: false, errSaving: 'Error Saving Wallet'));
}
Expand All @@ -127,7 +133,7 @@ class CreateWalletCubit extends Cubit<CreateWalletState> {
state.copyWith(
saving: false,
saved: true,
savedWallet: wallet,
savedWallet: updatedWallet,
),
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/create/bloc/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CreateWalletState with _$CreateWalletState {
@Default(false) bool saving,
@Default('') String errSaving,
@Default(false) bool saved,
String? walletLabel,
Wallet? savedWallet,
}) = _CreateWalletState;
const CreateWalletState._();
Expand Down
24 changes: 23 additions & 1 deletion lib/create/bloc/state.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mixin _$CreateWalletState {
bool get saving => throw _privateConstructorUsedError;
String get errSaving => throw _privateConstructorUsedError;
bool get saved => throw _privateConstructorUsedError;
String? get walletLabel => throw _privateConstructorUsedError;
Wallet? get savedWallet => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
Expand All @@ -54,6 +55,7 @@ abstract class $CreateWalletStateCopyWith<$Res> {
bool saving,
String errSaving,
bool saved,
String? walletLabel,
Wallet? savedWallet});

$WalletCopyWith<$Res>? get savedWallet;
Expand All @@ -79,6 +81,7 @@ class _$CreateWalletStateCopyWithImpl<$Res, $Val extends CreateWalletState>
Object? saving = null,
Object? errSaving = null,
Object? saved = null,
Object? walletLabel = freezed,
Object? savedWallet = freezed,
}) {
return _then(_value.copyWith(
Expand Down Expand Up @@ -110,6 +113,10 @@ class _$CreateWalletStateCopyWithImpl<$Res, $Val extends CreateWalletState>
? _value.saved
: saved // ignore: cast_nullable_to_non_nullable
as bool,
walletLabel: freezed == walletLabel
? _value.walletLabel
: walletLabel // ignore: cast_nullable_to_non_nullable
as String?,
savedWallet: freezed == savedWallet
? _value.savedWallet
: savedWallet // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -146,6 +153,7 @@ abstract class _$$CreateWalletStateImplCopyWith<$Res>
bool saving,
String errSaving,
bool saved,
String? walletLabel,
Wallet? savedWallet});

@override
Expand All @@ -170,6 +178,7 @@ class __$$CreateWalletStateImplCopyWithImpl<$Res>
Object? saving = null,
Object? errSaving = null,
Object? saved = null,
Object? walletLabel = freezed,
Object? savedWallet = freezed,
}) {
return _then(_$CreateWalletStateImpl(
Expand Down Expand Up @@ -201,6 +210,10 @@ class __$$CreateWalletStateImplCopyWithImpl<$Res>
? _value.saved
: saved // ignore: cast_nullable_to_non_nullable
as bool,
walletLabel: freezed == walletLabel
? _value.walletLabel
: walletLabel // ignore: cast_nullable_to_non_nullable
as String?,
savedWallet: freezed == savedWallet
? _value.savedWallet
: savedWallet // ignore: cast_nullable_to_non_nullable
Expand All @@ -220,6 +233,7 @@ class _$CreateWalletStateImpl extends _CreateWalletState {
this.saving = false,
this.errSaving = '',
this.saved = false,
this.walletLabel,
this.savedWallet})
: _mnemonic = mnemonic,
super._();
Expand Down Expand Up @@ -268,11 +282,13 @@ class _$CreateWalletStateImpl extends _CreateWalletState {
@JsonKey()
final bool saved;
@override
final String? walletLabel;
@override
final Wallet? savedWallet;

@override
String toString() {
return 'CreateWalletState(mnemonic: $mnemonic, passPhrase: $passPhrase, creatingNmemonic: $creatingNmemonic, errCreatingNmemonic: $errCreatingNmemonic, saving: $saving, errSaving: $errSaving, saved: $saved, savedWallet: $savedWallet)';
return 'CreateWalletState(mnemonic: $mnemonic, passPhrase: $passPhrase, creatingNmemonic: $creatingNmemonic, errCreatingNmemonic: $errCreatingNmemonic, saving: $saving, errSaving: $errSaving, saved: $saved, walletLabel: $walletLabel, savedWallet: $savedWallet)';
}

@override
Expand All @@ -291,6 +307,8 @@ class _$CreateWalletStateImpl extends _CreateWalletState {
(identical(other.errSaving, errSaving) ||
other.errSaving == errSaving) &&
(identical(other.saved, saved) || other.saved == saved) &&
(identical(other.walletLabel, walletLabel) ||
other.walletLabel == walletLabel) &&
(identical(other.savedWallet, savedWallet) ||
other.savedWallet == savedWallet));
}
Expand All @@ -305,6 +323,7 @@ class _$CreateWalletStateImpl extends _CreateWalletState {
saving,
errSaving,
saved,
walletLabel,
savedWallet);

@JsonKey(ignore: true)
Expand All @@ -324,6 +343,7 @@ abstract class _CreateWalletState extends CreateWalletState {
final bool saving,
final String errSaving,
final bool saved,
final String? walletLabel,
final Wallet? savedWallet}) = _$CreateWalletStateImpl;
const _CreateWalletState._() : super._();

Expand Down Expand Up @@ -352,6 +372,8 @@ abstract class _CreateWalletState extends CreateWalletState {
@override
bool get saved;
@override
String? get walletLabel;
@override
Wallet? get savedWallet;
@override
@JsonKey(ignore: true)
Expand Down
20 changes: 20 additions & 0 deletions lib/create/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class _Screen extends StatelessWidget {
const Words(),
const Gap(32),
const CreateWalletPassField(),
const Gap(32),
const _WalletLabel(),
const Gap(40),
const CreateWalletCreateButton(),
const Gap(80),
Expand Down Expand Up @@ -152,6 +154,24 @@ class CreateWalletPassField extends HookWidget {
}
}

class _WalletLabel extends StatelessWidget {
const _WalletLabel();

@override
Widget build(BuildContext context) {
final text = context.select((CreateWalletCubit cubit) => cubit.state.walletLabel ?? '');

return Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: BBTextInput.big(
value: text,
onChanged: (value) => context.read<CreateWalletCubit>().walletLabelChanged(value),
hint: 'Label your wallet',
),
);
}
}

class CreateWalletConfirmButton extends StatelessWidget {
const CreateWalletConfirmButton({super.key});

Expand Down
19 changes: 19 additions & 0 deletions lib/import/xpub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ImportXpubScreen extends StatelessWidget {
),
Gap(40),
ColdCardSection(),
_WalletLabel(),
_ImportButtons(),
Gap(80),
],
Expand Down Expand Up @@ -161,6 +162,24 @@ class _XpubTextFieldAreaState extends State<XpubTextFieldArea> {
}
}

class _WalletLabel extends StatelessWidget {
const _WalletLabel();

@override
Widget build(BuildContext context) {
final text = context.select((ImportWalletCubit cubit) => cubit.state.walletLabel ?? '');

return Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: BBTextInput.big(
value: text,
onChanged: (value) => context.read<ImportWalletCubit>().walletLabelChanged(value),
hint: 'Label your wallet',
),
);
}
}

class _ImportButtons extends StatelessWidget {
const _ImportButtons();

Expand Down

0 comments on commit 5539af1

Please sign in to comment.