Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(deriv_auth): renamed localization getter in ContextExtension #414

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
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import 'package:flutter/material.dart';
/// Extension methods for [BuildContext].
extension ContextExtension on BuildContext {
/// Gets [DerivAuthUILocalization].
DerivAuthLocalization get localization => DerivAuthLocalization.of(this);
DerivAuthLocalization get derivAuthLocalization =>
DerivAuthLocalization.of(this);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ String getCountryConsentMessage(
}

final Map<String, String> consentMessages = <String, String>{
'br': context.localization.labelCountryConsentBrazil,
'br': context.derivAuthLocalization.labelCountryConsentBrazil,
// Add more countries and consent messages here.
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DerivUnavailableCountryLayout extends StatelessWidget {
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
elevation: ThemeProvider.zeroMargin,
title: Text(context.localization.labelNotAvailable),
title: Text(context.derivAuthLocalization.labelNotAvailable),
),
body: Container(
padding:
Expand All @@ -50,22 +50,23 @@ class DerivUnavailableCountryLayout extends StatelessWidget {
children: <Widget>[
const SizedBox(height: ThemeProvider.margin16),
Text(
context.localization.warnNotAvailableCountriesTitle(appName),
context.derivAuthLocalization
.warnNotAvailableCountriesTitle(appName),
style: TextStyles.title,
textAlign: TextAlign.center,
),
const SizedBox(height: ThemeProvider.margin08),
RichText(
text: TextSpan(
text: context.localization.warnNotAvailableCountries,
text: context.derivAuthLocalization.warnNotAvailableCountries,
style: context.theme.textStyle(
textStyle: TextStyles.body1,
color: context.theme.colors.general,
),
children: <InlineSpan>[
buildTextSpanHyperlink(
context: context,
label: context.localization.labelLiveChat,
label: context.derivAuthLocalization.labelLiveChat,
onTap: onLiveChatPressed,
style: context.theme.textStyle(
textStyle: TextStyles.body1Bold,
Expand Down
48 changes: 24 additions & 24 deletions packages/deriv_auth/lib/core/states/auth_error_state_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,107 +20,107 @@ base class AuthErrorStateHandler {
void invalid2faCode(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informInvalid2FACode,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informInvalid2FACode,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On account is not activated.
void onAccountUnavailable(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informDeactivatedAccount,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informDeactivatedAccount,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On expired account.
void onExpiredAccount(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informExpiredAccount,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informExpiredAccount,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On failed authorization.
void onFailedAuthorization(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informFailedAuthorization,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informFailedAuthorization,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// User is trying to authenticate from an unsupported residence.
void onInavlidResidence(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informInvalidResidence,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informInvalidResidence,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On invalid credentials.
void onInvalidCredentials(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informInvalidCredentials,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informInvalidCredentials,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// User has set up 2FA and needs to enter 2FA.
void onMissingOtp(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informMissingOtp,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informMissingOtp,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On self closed account.
void onSelfClosed(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informSelfClosed,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informSelfClosed,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On unexpected error.
void onUnexpectedError(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informUnexpectedError,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informUnexpectedError,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// Account is not supported in the country.
void onUnsupportedCountry(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informUnsupportedCountry,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informUnsupportedCountry,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On connection error.
void onConnectionError(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informConnectionError,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informConnectionError,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}

/// On switch account error.
void onSwitchAccountError(DerivAuthErrorState state) {
showErrorDialog(
context: context,
errorMessage: context.localization.informSwitchAccountError,
actionLabel: context.localization.actionTryAgain,
errorMessage: context.derivAuthLocalization.informSwitchAccountError,
actionLabel: context.derivAuthLocalization.actionTryAgain,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class _DerivGetStartedLayoutState extends State<DerivGetStartedLayout> {
onPressed: widget.onSignupTapped,
child: Center(
child: Text(
context.localization.actionGetAFreeAccount,
context.derivAuthLocalization.actionGetAFreeAccount,
style: context.theme.textStyle(
textStyle: TextStyles.body2,
color: context.theme.colors.prominent,
Expand All @@ -163,7 +163,7 @@ class _DerivGetStartedLayoutState extends State<DerivGetStartedLayout> {
onPressed: widget.onLoginTapped,
child: Center(
child: Text(
context.localization.actionLogin,
context.derivAuthLocalization.actionLogin,
style: context.theme.textStyle(
textStyle: TextStyles.body2,
color: context.theme.colors.prominent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class _Deriv2FALayoutState extends State<Deriv2FALayout> {
appBar: AppBar(
elevation: ThemeProvider.zeroMargin,
title: Text(
context.localization.labelLogIn,
context.derivAuthLocalization.labelLogIn,
style: TextStyles.title,
),
),
Expand All @@ -53,13 +53,13 @@ class _Deriv2FALayoutState extends State<Deriv2FALayout> {
children: <Widget>[
SvgPicture.asset(Assets.twoFactorAuthIcon),
Text(
context.localization.labelTwoFactorAuth,
context.derivAuthLocalization.labelTwoFactorAuth,
style: context.theme.textStyle(textStyle: TextStyles.title),
textAlign: TextAlign.center,
),
const SizedBox(height: ThemeProvider.margin08),
Text(
context.localization.informEnterTwoFactorAuthCode,
context.derivAuthLocalization.informEnterTwoFactorAuthCode,
style: context.theme.textStyle(
textStyle: TextStyles.body1,
color: context.theme.colors.general,
Expand All @@ -69,8 +69,8 @@ class _Deriv2FALayoutState extends State<Deriv2FALayout> {
const SizedBox(height: ThemeProvider.margin24),
BaseTextField(
controller: _otpController,
labelText:
context.localization.labelTwoFactorAuthenticationCode,
labelText: context
.derivAuthLocalization.labelTwoFactorAuthenticationCode,
labelColor: context.theme.colors.disabled,
focusNode: _otpFocusNode,
enabled: !_isLoading(),
Expand Down Expand Up @@ -100,7 +100,7 @@ class _Deriv2FALayoutState extends State<Deriv2FALayout> {
width: ThemeProvider.iconSize16,
)
: Text(
context.localization.actionProceed,
context.derivAuthLocalization.actionProceed,
style: TextStyles.body2.copyWith(
color: context.theme.colors.prominent,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
appBar: AppBar(
elevation: ThemeProvider.zeroMargin,
title: Text(
context.localization.labelLogIn,
context.derivAuthLocalization.labelLogIn,
style: TextStyles.title,
),
backgroundColor: context.theme.colors.secondary,
Expand Down Expand Up @@ -126,7 +126,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
_buildLoginButton(),
const SizedBox(height: ThemeProvider.margin24),
DerivSocialAuthDivider(
label: context.localization.informLoginOptions,
label: context.derivAuthLocalization.informLoginOptions,
isVisible: widget.isSocialAuthEnabled,
),
if (widget.isSocialAuthEnabled)
Expand Down Expand Up @@ -173,7 +173,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
semanticLabel: SemanticsLabels.loginEmailFieldSemantic,
controller: _emailController,
focusNode: _emailFocusNode,
labelText: context.localization.labelEmail,
labelText: context.derivAuthLocalization.labelEmail,
borderColor: context.theme.colors.hover,
focusedBorderColor: context.theme.colors.blue,
keyboardType: TextInputType.emailAddress,
Expand All @@ -188,7 +188,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
semanticLabel: SemanticsLabels.loginPasswordFieldSemantic,
controller: _passwordController,
focusNode: _passwordFocusNode,
labelText: context.localization.labelPassword,
labelText: context.derivAuthLocalization.labelPassword,
obscureText: !_isPasswordVisible,
enabled: isEnabled,
suffixIcon: IconButton(
Expand All @@ -214,7 +214,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
child: InkWell(
onTap: widget.onResetPassTapped,
child: Text(
context.localization.actionForgotPassword,
context.derivAuthLocalization.actionForgotPassword,
style: context.theme.textStyle(
textStyle: TextStyles.body2,
color: context.theme.colors.coral,
Expand Down Expand Up @@ -247,7 +247,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
width: ThemeProvider.iconSize16,
)
: Text(
context.localization.actionLogin,
context.derivAuthLocalization.actionLogin,
style: context.theme.textStyle(
textStyle: TextStyles.body2,
color: context.theme.colors.prominent.withOpacity(
Expand All @@ -264,7 +264,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
context.localization.labelDontHaveAnAccountYet,
context.derivAuthLocalization.labelDontHaveAnAccountYet,
style: context.theme.textStyle(
textStyle: TextStyles.body1,
color: context.theme.colors.general,
Expand All @@ -275,7 +275,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
child: Padding(
padding: const EdgeInsets.all(ThemeProvider.margin04),
child: Text(
context.localization.actionCreateANewAccount,
context.derivAuthLocalization.actionCreateANewAccount,
style: context.theme.textStyle(
textStyle: TextStyles.body2,
color: context.theme.colors.coral,
Expand Down Expand Up @@ -312,15 +312,15 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
return null;
}

return context.localization.informInvalidEmailFormat;
return context.derivAuthLocalization.informInvalidEmailFormat;
}

String? _passwordValidator(String? input) {
if (input?.isValidLoginPasswordLength ?? false) {
return null;
}

return context.localization.warnPasswordLength;
return context.derivAuthLocalization.warnPasswordLength;
}

Future<void> _onLoginTapped() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _DerivChooseNewPassLayoutState extends State<DerivChooseNewPassLayout> {
appBar: AppBar(
elevation: ThemeProvider.zeroMargin,
title: Text(
context.localization.labelResetPassword,
context.derivAuthLocalization.labelResetPassword,
style: TextStyles.title,
),
),
Expand Down Expand Up @@ -103,14 +103,14 @@ class _DerivChooseNewPassLayoutState extends State<DerivChooseNewPassLayout> {
),
const SizedBox(height: ThemeProvider.margin48),
Text(
context.localization.labelChooseNewPass,
context.derivAuthLocalization.labelChooseNewPass,
style: TextStyles.title,
),
const SizedBox(height: ThemeProvider.margin24),
BaseTextField(
controller: _passController,
focusNode: _passFocusNode,
labelText: context.localization.labelCreatePass,
labelText: context.derivAuthLocalization.labelCreatePass,
obscureText: !_isPasswordVisible,
suffixIcon: IconButton(
icon: Icon(
Expand Down Expand Up @@ -155,7 +155,7 @@ class _DerivChooseNewPassLayoutState extends State<DerivChooseNewPassLayout> {
width: ThemeProvider.iconSize16,
)
: Text(
context.localization.actionResetPass,
context.derivAuthLocalization.actionResetPass,
style: context.theme.textStyle(
textStyle: TextStyles.body2,
color: context.theme.colors.prominent.withOpacity(
Expand Down Expand Up @@ -186,7 +186,7 @@ class _DerivChooseNewPassLayoutState extends State<DerivChooseNewPassLayout> {
return null;
}

return context.localization.informInvalidPasswordFormat;
return context.derivAuthLocalization.informInvalidPasswordFormat;
}

bool isFormValid() => _passwordValidator(_passController.text) == null;
Expand Down
Loading