Skip to content
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
2 changes: 1 addition & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"walletCreationNameLengthError": "Name length should be between 1 and 40",
"walletCreationFormatPasswordError": "Password must contain at least 12 characters, with at least one lower-case, one upper-case and one special symbol.",
"walletCreationConfirmPasswordError": "Your passwords do not match. Please try again.",
"invalidPasswordError": "Invalid password",
"incorrectPassword": "Incorrect password",
"importSeedEnterSeedPhraseHint": "Enter seed",
"passphraseCheckingTitle": "Let's double check your seed phrase",
"passphraseCheckingDescription": "Your seed phrase is important - that's why it is important to make sure it is saved correctly. We'll ask you to confirm the position of three words in your seed phrase to make sure it has been saved, so you'll be able to easily restore your wallet wherever and whenever you want.",
Expand Down
53 changes: 37 additions & 16 deletions lib/bloc/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,31 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> {
);
final KdfUser? currentUser = await _kdfSdk.auth.currentUser;
if (currentUser == null) {
return emit(AuthBlocState.error('Failed to login'));
return emit(AuthBlocState.error(AuthException.notSignedIn()));
}

_log.info('logged in from a wallet');
emit(AuthBlocState.loggedIn(currentUser));
_listenToAuthStateChanges();
} catch (e, s) {
final error = 'Failed to login wallet ${event.wallet.name}';
_log.shout(error, e, s);
emit(AuthBlocState.error(error));
if (e is AuthException) {
// Preserve the original error type for specific errors like incorrect password
_log.shout(
'Auth error during login for wallet ${event.wallet.name}',
e,
s,
);
emit(AuthBlocState.error(e));
} else {
// For non-auth exceptions, use a generic error type
final errorMsg = 'Failed to login wallet ${event.wallet.name}';
_log.shout(errorMsg, e, s);
emit(
AuthBlocState.error(
AuthException(errorMsg, type: AuthExceptionType.generalAuthError),
),
);
}
await _authChangesSubscription?.cancel();
}
}
Expand Down Expand Up @@ -143,9 +158,13 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> {
emit(AuthBlocState.loggedIn(currentUser));
_listenToAuthStateChanges();
} catch (e, s) {
final error = 'Failed to register wallet ${event.wallet.name}';
_log.shout(error, e, s);
emit(AuthBlocState.error(error));
final errorMsg = 'Failed to register wallet ${event.wallet.name}';
_log.shout(errorMsg, e, s);
emit(
AuthBlocState.error(
AuthException(errorMsg, type: AuthExceptionType.generalAuthError),
),
);
await _authChangesSubscription?.cancel();
}
}
Expand Down Expand Up @@ -192,20 +211,22 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> {

_listenToAuthStateChanges();
} catch (e, s) {
final error = 'Failed to restore existing wallet ${event.wallet.name}';
_log.shout(error, e, s);
emit(AuthBlocState.error(error));
final errorMsg = 'Failed to restore existing wallet ${event.wallet.name}';
_log.shout(errorMsg, e, s);
emit(
AuthBlocState.error(
AuthException(errorMsg, type: AuthExceptionType.generalAuthError),
),
);
await _authChangesSubscription?.cancel();
}
}

Future<bool> _didSignInExistingWallet(
Wallet wallet,
String password,
) async {
Future<bool> _didSignInExistingWallet(Wallet wallet, String password) async {
final existingWallets = await _kdfSdk.auth.getUsers();
final walletExists = existingWallets
.any((KdfUser user) => user.walletId.name == wallet.name);
final walletExists = existingWallets.any(
(KdfUser user) => user.walletId.name == wallet.name,
);
if (walletExists) {
add(AuthSignInRequested(wallet: wallet, password: password));
_log.warning('Wallet ${wallet.name} already exist, attempting sign-in');
Expand Down
10 changes: 5 additions & 5 deletions lib/bloc/auth_bloc/auth_bloc_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AuthBlocState extends Equatable {
required this.mode,
this.currentUser,
this.status = AuthStatus.initial,
this.errorMessage,
this.authError,
});

factory AuthBlocState.initial() =>
Expand All @@ -16,10 +16,10 @@ class AuthBlocState extends Equatable {
mode: AuthorizeMode.noLogin,
status: AuthStatus.loading,
);
factory AuthBlocState.error(String errorMessage) => AuthBlocState(
factory AuthBlocState.error(AuthException authError) => AuthBlocState(
mode: AuthorizeMode.noLogin,
status: AuthStatus.failure,
errorMessage: errorMessage,
authError: authError,
);
factory AuthBlocState.loggedIn(KdfUser user) => AuthBlocState(
mode: AuthorizeMode.logIn,
Expand All @@ -30,12 +30,12 @@ class AuthBlocState extends Equatable {
final KdfUser? currentUser;
final AuthorizeMode mode;
final AuthStatus status;
final String? errorMessage;
final AuthException? authError;

bool get isSignedIn => currentUser != null;
bool get isLoading => status == AuthStatus.loading;
bool get isError => status == AuthStatus.failure;

@override
List<Object?> get props => [mode, currentUser, status, errorMessage];
List<Object?> get props => [mode, currentUser, status, authError];
}
13 changes: 5 additions & 8 deletions lib/bloc/security_settings/security_settings_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class SecuritySettingsBloc
on<ShowSeedCopiedEvent>(_onSeedCopied);
}


void _onReset(
ResetEvent event,
Emitter<SecuritySettingsState> emit,
Expand Down Expand Up @@ -51,13 +50,11 @@ class SecuritySettingsBloc
PasswordUpdateEvent event,
Emitter<SecuritySettingsState> emit,
) {
// TODO!: re-enable once password change is implemented
// final newState = state.copyWith(
// step: SecuritySettingsStep.passwordUpdate,
// showSeedWords: false,
// );
// emit(newState);
emit(state);
final newState = state.copyWith(
step: SecuritySettingsStep.passwordUpdate,
showSeedWords: false,
);
emit(newState);
}

void _onSeedConfirm(
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/security_settings/security_settings_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum SecuritySettingsStep {
seedSuccess,

/// The screen for updating the password.
// passwordUpdate,
passwordUpdate,
}

class SecuritySettingsState extends Equatable {
Expand Down
Loading
Loading