Skip to content

Commit

Permalink
Updates in signup flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ernest-deriv committed Jul 16, 2024
1 parent 646dd80 commit 15cc37c
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import 'package:deriv_auth/core/extensions/context_extension.dart';
import 'package:deriv_auth/core/helpers/assets.dart';
import 'package:deriv_auth/core/helpers/country_selection_helper.dart';
import 'package:deriv_auth/features/signup/cubit/deriv_country_selection_cubit.dart';
import 'package:deriv_auth/features/signup/cubit/signup_cubit.dart';
import 'package:deriv_auth/features/signup/models/deriv_residence_model.dart';
import 'package:deriv_auth/features/signup/presentation/layouts/deriv_set_password_layout.dart';
import 'package:deriv_auth/features/signup/presentation/widgets/country_selection_list_widget.dart';
import 'package:deriv_auth/features/single_entry/core/auth_data.dart';
import 'package:deriv_theme/deriv_theme.dart';
import 'package:deriv_ui/deriv_ui.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -49,16 +52,31 @@ class _DerivCountrySelectionLayoutState

late TextEditingController _textController;

late final DerivCountrySelectionCubit _countrySelectionCubit;

DerivCountrySelectionCubit? _countrySelectionCubit;
@override
void initState() {
super.initState();

_countrySelectionCubit = DerivCountrySelectionCubit(widget.residences)
..fetchResidenceCountries();

_textController = TextEditingController();

_countrySelectionCubit = DerivCountrySelectionCubit(widget.residences);
_initializeResidences();
}

Future<void> _initializeResidences() async {
try {
final List<DerivResidenceModel> residencesList = await widget.residences;

setState(
() {
_countrySelectionCubit = DerivCountrySelectionCubit(
Future<List<DerivResidenceModel>>.value(residencesList),
)..fetchResidenceCountries();
},
);
} on Exception catch (error) {
print('Error fetching residences: $error');
}
}

@override
Expand Down Expand Up @@ -154,7 +172,24 @@ class _DerivCountrySelectionLayoutState
isConsentRequired: state.selectedCountryRequiresConsent,
agreedToTerms: state.agreedToTerms,
),
onPressed: widget.onNextPressed,
onPressed: AuthData().data.signupPageModel.handleFlowFromPackage
? () {
Navigator.pushReplacement<BuildContext,
Route<DerivSetPasswordLayout>>(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => DerivSetPasswordLayout(
onDerivSignupState: (BuildContext BuildContext,
DerivSignupState DerivSignupState) {},
onPreviousPressed: () {},
residence: state.selectedCountry?.code,
verificationCode: widget.verificationCode,
affiliateToken: widget.affiliateToken,
),
),
);
}
: widget.onNextPressed,
child: Center(
child: Text(
context.derivAuthLocalization.actionNext,
Expand All @@ -179,7 +214,7 @@ class _DerivCountrySelectionLayoutState
countries: countries,
onChanged: (int index) => setState(
() {
_countrySelectionCubit.changeSelectedCountry(
_countrySelectionCubit!.changeSelectedCountry(
selectedCountry: countries[index],
);
},
Expand Down Expand Up @@ -207,7 +242,7 @@ class _DerivCountrySelectionLayoutState
contentsVerticalAlignment: CrossAxisAlignment.start,
value: state.agreedToTerms,
onValueChanged: ({bool? isChecked}) =>
_countrySelectionCubit.updateCountryConsentStatus(
_countrySelectionCubit!.updateCountryConsentStatus(
agreedToTerms: isChecked,
),
message: countryConsentMessage ??
Expand Down Expand Up @@ -275,7 +310,7 @@ class _DerivCountrySelectionLayoutState
void dispose() {
_focusNode.dispose();

_countrySelectionCubit.close();
_countrySelectionCubit!.close();

super.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:deriv_auth/core/helpers/assets.dart';
import 'package:deriv_auth/core/states/auth_state_listener.dart';
import 'package:deriv_auth/deriv_auth.dart';
import 'package:deriv_auth/features/signup/presentation/widgets/password_policy_checker_widget.dart';
import 'package:deriv_auth/features/single_entry/core/auth_data.dart';
import 'package:deriv_theme/deriv_theme.dart';
import 'package:deriv_ui/deriv_ui.dart';
import 'package:flutter/material.dart';
Expand All @@ -19,6 +20,7 @@ class DerivSetPasswordLayout extends StatefulWidget {
this.authErrorStateHandler,
this.utmModel,
this.onAuthError,
this.affiliateToken,
Key? key,
}) : super(key: key);

Expand All @@ -43,6 +45,9 @@ class DerivSetPasswordLayout extends StatefulWidget {
/// Callback to be called when previous button is tapped.
final VoidCallback onPreviousPressed;

/// Affiliate token.
final String? affiliateToken;

@override
State<DerivSetPasswordLayout> createState() => _DerivSetPasswordLayoutState();
}
Expand Down Expand Up @@ -125,17 +130,42 @@ class _DerivSetPasswordLayoutState extends State<DerivSetPasswordLayout> {
children: <Widget>[
Expanded(child: _buildPreviousButton()),
const SizedBox(width: ThemeProvider.margin08),
Expanded(
child: BlocConsumer<DerivSignupCubit, DerivSignupState>(
listener: widget.onDerivSignupState,
builder: (BuildContext context, DerivSignupState state) =>
_buildStartTradingButton(state),
BlocConsumer<DerivAuthCubit, DerivAuthState>(
listener: _onAuthState,
builder: (BuildContext context, DerivAuthState state) => Expanded(
child: BlocConsumer<DerivSignupCubit, DerivSignupState>(
listener:
AuthData().data.signupPageModel.handleFlowFromPackage
? (BuildContext context, DerivSignupState state) =>
_onSignupState(state)
: widget.onDerivSignupState,
builder: (BuildContext context, DerivSignupState state) =>
_buildStartTradingButton(state),
),
),
),
],
),
);

void _onAuthState(BuildContext context, DerivAuthState state) {
if (state is DerivAuthLoggedInState) {
AuthData().data.loginPageModel.onLoggedIn.call(context, state);
}
}

Future<void> _onSignupState(DerivSignupState state) async {
if (state is DerivSignupErrorState) {
//TODO Handle state
} else if (state is DerivSignupDoneState) {
//TODO Handle state

await context.read<DerivAuthCubit>().tokenLogin(
state.account?.token ?? 'invalid_token',
);
}
}

Widget _buildPasswordInput() => BaseTextField(
focusNode: _passwordFocusNode,
controller: _passwordTextController,
Expand Down Expand Up @@ -178,7 +208,23 @@ class _DerivSetPasswordLayoutState extends State<DerivSetPasswordLayout> {
);

Widget _buildPreviousButton() => SecondaryButton(
onPressed: widget.onPreviousPressed,
onPressed: AuthData().data.signupPageModel.handleFlowFromPackage
? () {
Navigator.pushReplacement<BuildContext,
Route<DerivCountrySelectionLayout>>(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) =>
DerivCountrySelectionLayout(
affiliateToken: widget.affiliateToken,
onNextPressed: () {},
verificationCode: widget.verificationCode!,
residences: AuthData().data.signupPageModel.residences,
),
),
);
}
: widget.onPreviousPressed,
child: Center(
child: Text(
context.derivAuthLocalization.actionPrevious,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:deriv_auth/core/extensions/context_extension.dart';
import 'package:deriv_auth/core/helpers/assets.dart';
import 'package:deriv_auth/features/signup/models/deriv_residence_model.dart';
import 'package:deriv_auth/features/signup/presentation/layouts/deriv_country_selection_layout.dart';
import 'package:deriv_auth/features/single_entry/core/auth_data.dart';
import 'package:deriv_theme/deriv_theme.dart';
import 'package:deriv_ui/deriv_ui.dart';
import 'package:flutter/material.dart';
Expand All @@ -12,6 +15,7 @@ class DerivVerificationDoneLayout extends StatelessWidget {
required this.verificationCode,
required this.onContinuePressed,
this.affiliateToken,
this.residences,
Key? key,
}) : super(key: key);

Expand All @@ -24,6 +28,9 @@ class DerivVerificationDoneLayout extends StatelessWidget {
/// Callback to be called when continue button is tapped.
final VoidCallback onContinuePressed;

/// List of residences to be shown.
final Future<List<DerivResidenceModel>>? residences;

@override
Widget build(BuildContext context) => Scaffold(
backgroundColor: context.theme.colors.primary,
Expand Down Expand Up @@ -77,7 +84,28 @@ class DerivVerificationDoneLayout extends StatelessWidget {
);

Widget _buildContinueButton(BuildContext context) => PrimaryButton(
onPressed: onContinuePressed,
onPressed: AuthData().data.signupPageModel.handleFlowFromPackage
? () async {
final List<DerivResidenceModel> residencesList =
await residences!;

// Navigate to the new page once the residences are loaded
await Navigator.pushReplacement<BuildContext,
Route<DerivCountrySelectionLayout>>(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) =>
DerivCountrySelectionLayout(
affiliateToken: affiliateToken,
verificationCode: verificationCode,
onNextPressed: () {},
residences: Future<List<DerivResidenceModel>>.value(
residencesList),
),
),
);
}
: onContinuePressed,
child: Center(
child: Text(
context.derivAuthLocalization.actionContinue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class SignupPageModel {
required this.socialAuthStateHandler,
required this.redirectURL,
required this.onWebViewError,
required this.handleFlowFromPackage,
required this.residences,
this.onSignupPressed,
this.onSocialAuthButtonPressed,
this.affiliateToken,
Expand Down Expand Up @@ -52,4 +54,10 @@ class SignupPageModel {
/// Callback to be called when social auth button is tapped.
/// Give access to [SocialAuthDto] for 2FA.
final SocialAuthCallback? onSocialAuthButtonPressed;

/// Handle flow from package
final bool handleFlowFromPackage;

/// List of residences to be shown.
final Future<List<DerivResidenceModel>> residences;
}

0 comments on commit 15cc37c

Please sign in to comment.