Skip to content

Commit

Permalink
Merge pull request #1454 from ardriveapp/PE-4897
Browse files Browse the repository at this point in the history
PE-4897: Can't log in after accessing onboarding with `get-started` link
  • Loading branch information
matibat authored Oct 31, 2023
2 parents 2f298c1 + fa6a3d0 commit e426da8
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 86 deletions.
6 changes: 3 additions & 3 deletions lib/authentication/login/blocs/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
} else if (event is AddWalletFromCompleter) {
await _handleAddWalletFromCompleterEvent(event, emit);
} else if (event is CreateNewWallet) {
await _handleCreateNewWalletEvent(event, emit);
_handleCreateNewWalletEvent(event, emit);
} else if (event is CompleteWalletGeneration) {
await _handleCompleteWalletGenerationEvent(event, emit);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
return;
}

if (event.gettinStarted) {
if (event.gettingStarted) {
_handleCreateNewWalletEvent(const CreateNewWallet(), emit);
} else {
emit(LoginInitial(_arConnectService.isExtensionPresent()));
Expand Down Expand Up @@ -404,7 +404,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
emit(LoginDownloadGeneratedWallet(event.mnemonic, wallet));
}

Future<void> _handleCreateNewWalletEvent(
void _handleCreateNewWalletEvent(
CreateNewWallet event,
Emitter<LoginState> emit,
) async {
Expand Down
4 changes: 2 additions & 2 deletions lib/authentication/login/blocs/login_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class AddWalletFromArConnect extends LoginEvent {
}

class CheckIfUserIsLoggedIn extends LoginEvent {
final bool gettinStarted;
final bool gettingStarted;

const CheckIfUserIsLoggedIn({
this.gettinStarted = false,
this.gettingStarted = false,
});

@override
Expand Down
200 changes: 119 additions & 81 deletions lib/authentication/login/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class LoginPage extends StatefulWidget {
}

class _LoginPageState extends State<LoginPage> {
bool didGettingStartedLoadedAlready = false;
bool get isGettingStartedLoading =>
widget.gettingStarted && !didGettingStartedLoadedAlready;

@override
void initState() {
super.initState();
Expand All @@ -65,30 +69,80 @@ class _LoginPageState extends State<LoginPage> {
userRepository: context.read<UserRepository>(),
)..add(
CheckIfUserIsLoggedIn(
gettinStarted: widget.gettingStarted,
gettingStarted: widget.gettingStarted,
),
);

return BlocProvider<LoginBloc>(
create: (context) => loginBloc,
child: BlocConsumer<LoginBloc, LoginState>(
listener: (context, state) {
if (state is LoginOnBoarding) {
listener: (context, loginState) {
if (loginState is! LoginLoading && loginState is! LoginInitial) {
setState(() {
didGettingStartedLoadedAlready = true;
});
}

if (loginState is LoginOnBoarding) {
preCacheOnBoardingAssets(context);
} else if (loginState is LoginFailure) {
// TODO: Verify if the error is `NoConnectionException` and show an appropriate message after validating with UI/UX

logger.e('Login Failure', loginState.error);

if (loginState.error is WalletMismatchException) {
showArDriveDialog(
context,
content: ArDriveIconModal(
title: appLocalizationsOf(context).loginFailed,
content: appLocalizationsOf(context)
.arConnectWalletDoestNotMatchArDriveWallet,
icon: ArDriveIcons.triangle(
size: 88,
color: ArDriveTheme.of(context)
.themeData
.colors
.themeErrorMuted,
),
),
);
return;
} else if (loginState.error is BiometricException) {
showBiometricExceptionDialogForException(
context, loginState.error as BiometricException, () {});
return;
}

showArDriveDialog(
context,
content: ArDriveIconModal(
title: appLocalizationsOf(context).loginFailed,
content: appLocalizationsOf(context).pleaseTryAgain,
icon: ArDriveIcons.triangle(
size: 88,
color:
ArDriveTheme.of(context).themeData.colors.themeErrorMuted,
),
),
);
} else if (loginState is LoginSuccess) {
logger.d('Login Success, unlocking default profile');

context.read<ProfileCubit>().unlockDefaultProfile(
loginState.user.password, loginState.user.profileType);
}
},
builder: (context, state) {
builder: (context, loginState) {
late Widget view;
if (state is LoginOnBoarding) {
view = OnBoardingView(wallet: state.walletFile);
} else if (state is LoginCreateNewWallet) {
view = CreateNewWalletView(mnemonic: state.mnemonic);
} else if (state is LoginLoading && widget.gettingStarted) {
view = const Center(
child: CircularProgressIndicator(),
);
if (loginState is LoginOnBoarding) {
view = OnBoardingView(wallet: loginState.walletFile);
} else if (loginState is LoginCreateNewWallet) {
view = CreateNewWalletView(mnemonic: loginState.mnemonic);
} else {
view = const LoginPageScaffold();
view = LoginPageScaffold(
loginState: loginState,
isGettingStartedLoading: isGettingStartedLoading,
);
}

return _FadeThroughTransitionSwitcher(
Expand All @@ -102,8 +156,13 @@ class _LoginPageState extends State<LoginPage> {
}

class LoginPageScaffold extends StatefulWidget {
final bool isGettingStartedLoading;
final LoginState loginState;

const LoginPageScaffold({
super.key,
this.isGettingStartedLoading = false,
required this.loginState,
});

@override
Expand All @@ -112,14 +171,18 @@ class LoginPageScaffold extends StatefulWidget {

class _LoginPageScaffoldState extends State<LoginPageScaffold> {
final globalKey = GlobalKey();

@override
void initState() {
super.initState();
}
bool getStartedLoadingHasRan = false;

@override
Widget build(BuildContext context) {
if (widget.isGettingStartedLoading) {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}

return ScreenTypeLayout.builder(
desktop: (context) => Material(
color: ArDriveTheme.of(context).themeData.backgroundColor,
Expand Down Expand Up @@ -150,7 +213,10 @@ class _LoginPageScaffoldState extends State<LoginPageScaffold> {
child: FractionallySizedBox(
widthFactor: 0.75,
child: Center(
child: _buildContent(context),
child: _buildContent(
context,
loginState: widget.loginState,
),
),
),
),
Expand All @@ -170,7 +236,10 @@ class _LoginPageScaffoldState extends State<LoginPageScaffold> {
Center(
child: Column(
children: [
_buildContent(context),
_buildContent(
context,
loginState: widget.loginState,
),
],
),
),
Expand Down Expand Up @@ -260,93 +329,62 @@ class _LoginPageScaffoldState extends State<LoginPageScaffold> {
);
}

Widget _buildContent(BuildContext context) {
Widget _buildContent(BuildContext context, {required LoginState loginState}) {
final enableSeedPhraseLogin =
context.read<ConfigService>().config.enableSeedPhraseLogin;
return BlocConsumer<LoginBloc, LoginState>(
return BlocBuilder<LoginBloc, LoginState>(
key: globalKey,
buildWhen: (previous, current) =>
current is! LoginFailure &&
current is! LoginSuccess &&
current is! LoginOnBoarding &&
current is! LoginCreateNewWallet,
listener: (context, state) {
if (state is LoginFailure) {
// TODO: Verify if the error is `NoConnectionException` and show an appropriate message after validating with UI/UX

logger.e('Login Failure', state.error);

if (state.error is WalletMismatchException) {
showArDriveDialog(
context,
content: ArDriveIconModal(
title: appLocalizationsOf(context).loginFailed,
content: appLocalizationsOf(context)
.arConnectWalletDoestNotMatchArDriveWallet,
icon: ArDriveIcons.triangle(
size: 88,
color:
ArDriveTheme.of(context).themeData.colors.themeErrorMuted,
),
),
);
return;
} else if (state.error is BiometricException) {
showBiometricExceptionDialogForException(
context, state.error as BiometricException, () {});
return;
}
buildWhen: (previous, current) {
final isFailure = current is LoginFailure;
final isSuccess = current is LoginSuccess;
final isOnBoarding = current is LoginOnBoarding;
final isCreateNewWallet = current is LoginCreateNewWallet;

logger.d(
'LoginBloc buildWhen'
' - isFailure: $isFailure'
' - isSuccess: $isSuccess'
' - isOnBoarding: $isOnBoarding'
' - isCreateNewWallet: $isCreateNewWallet',
);

showArDriveDialog(
context,
content: ArDriveIconModal(
title: appLocalizationsOf(context).loginFailed,
content: appLocalizationsOf(context).pleaseTryAgain,
icon: ArDriveIcons.triangle(
size: 88,
color:
ArDriveTheme.of(context).themeData.colors.themeErrorMuted,
),
),
);
} else if (state is LoginSuccess) {
context.read<ProfileCubit>().unlockDefaultProfile(
state.user.password, state.user.profileType);
}
return !(isFailure || isSuccess || isOnBoarding || isCreateNewWallet);
},
builder: (context, state) {
builder: (context, loginState) {
late Widget content;

if (state is PromptPassword) {
if (loginState is PromptPassword) {
content = PromptPasswordView(
wallet: state.walletFile,
wallet: loginState.walletFile,
);
} else if (state is CreatingNewPassword) {
} else if (loginState is CreatingNewPassword) {
content = CreatePasswordView(
wallet: state.walletFile,
wallet: loginState.walletFile,
);
} else if (state is LoginLoading) {
} else if (loginState is LoginLoading || loginState is LoginSuccess) {
content = const MaxDeviceSizesConstrainedBox(
child: _LoginCard(
content: Center(
child: CircularProgressIndicator(),
),
),
);
} else if (enableSeedPhraseLogin && state is LoginEnterSeedPhrase) {
} else if (enableSeedPhraseLogin &&
loginState is LoginEnterSeedPhrase) {
content = const EnterSeedPhraseView();
} else if (enableSeedPhraseLogin && state is LoginGenerateWallet) {
} else if (enableSeedPhraseLogin && loginState is LoginGenerateWallet) {
content = const GenerateWalletView();
} else if (enableSeedPhraseLogin &&
state is LoginDownloadGeneratedWallet) {
loginState is LoginDownloadGeneratedWallet) {
content = DownloadWalletView(
mnemonic: state.mnemonic,
wallet: state.walletFile,
mnemonic: loginState.mnemonic,
wallet: loginState.walletFile,
);
} else {
content = PromptWalletView(
key: const Key('promptWalletView'),
isArConnectAvailable: (state as LoginInitial).isArConnectAvailable,
isArConnectAvailable:
(loginState as LoginInitial).isArConnectAvailable,
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/pages/app_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
!gettingStarted &&
(!showingAnonymousRoute || state is ProfileLoggingOut)) {
signingIn = true;
gettingStarted = false;
notifyListeners();
}

Expand Down

0 comments on commit e426da8

Please sign in to comment.