Skip to content

Commit

Permalink
refactor: move localization to constants
Browse files Browse the repository at this point in the history
- localization no longer depends on the current context as we use the global context
- remove util/localization.dart file to consolidate into constants file.
  • Loading branch information
parodyBit committed Oct 25, 2023
1 parent 798c665 commit f6f5bfb
Show file tree
Hide file tree
Showing 51 changed files with 285 additions and 389 deletions.
12 changes: 12 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:my_wit_wallet/screens/create_wallet/bloc/create_wallet_bloc.dart';
import 'package:my_wit_wallet/util/storage/database/wallet.dart';
import 'package:my_wit_wallet/globals.dart' as globals;

typedef String LocalizationCallback(String value);

AppLocalizations localization =
AppLocalizations.of(globals.navigatorKey.currentContext!)!;

Map<WalletType, String> walletTypeToLabel(BuildContext context) => {
WalletType.hd: AppLocalizations.of(context)!.walletTypeHDLabel,
WalletType.single: AppLocalizations.of(context)!.walletTypeNodeLabel,
};

/// Explorer Settings
const bool USE_EXPLORER_DEV = false;
Expand Down Expand Up @@ -65,6 +76,7 @@ Map<ImportOrigin, CreateWalletType> importOriginToXprvType = {
ImportOrigin.fromSheikah: CreateWalletType.encryptedXprv,
ImportOrigin.fromNode: CreateWalletType.xprv
};

Map<CreateWalletType, WalletType> xprvTypeToWalletType = {
CreateWalletType.encryptedXprv: WalletType.hd,
CreateWalletType.xprv: WalletType.single
Expand Down
21 changes: 10 additions & 11 deletions lib/screens/create_wallet/build_wallet_card.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:async';
import 'dart:math';

import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:my_wit_wallet/bloc/crypto/crypto_bloc.dart';
import 'package:my_wit_wallet/constants.dart';
import 'package:my_wit_wallet/screens/create_wallet/bloc/api_create_wallet.dart';
import 'package:my_wit_wallet/screens/create_wallet/bloc/create_wallet_bloc.dart';
import 'package:my_wit_wallet/screens/create_wallet/nav_action.dart';
Expand Down Expand Up @@ -47,7 +47,6 @@ class BuildWalletCardState extends State<BuildWalletCard>
int currentAddressCount = 0;
int currentTransactionCount = 0;
static const headerAniInterval = Interval(.1, .3, curve: Curves.easeOut);
AppLocalizations get _localization => AppLocalizations.of(context)!;

void prevAction() {
CreateWalletType type =
Expand All @@ -64,14 +63,14 @@ class BuildWalletCardState extends State<BuildWalletCard>

NavAction prev() {
return NavAction(
label: _localization.backLabel,
label: localization.backLabel,
action: prevAction,
);
}

NavAction next() {
return NavAction(
label: _localization.continueLabel,
label: localization.continueLabel,
action: nextAction,
);
}
Expand Down Expand Up @@ -130,7 +129,7 @@ class BuildWalletCardState extends State<BuildWalletCard>
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(_localization.buildWalletHeader,
Text(localization.buildWalletHeader,
style: theme.textTheme.titleLarge),
],
),
Expand All @@ -141,7 +140,7 @@ class BuildWalletCardState extends State<BuildWalletCard>
Expanded(
flex: 1,
child: Text(
_localization.buildWallet01,
localization.buildWallet01,
style: theme.textTheme.bodyLarge,
))
]),
Expand Down Expand Up @@ -190,7 +189,7 @@ class BuildWalletCardState extends State<BuildWalletCard>
final theme = Theme.of(context);
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackbar(
theme, _localization.connectionIssue, theme.colorScheme.error));
theme, localization.connectionIssue, theme.colorScheme.error));
Timer(Duration(seconds: 4), () {
ScaffoldMessenger.of(context).clearSnackBars();
Navigator.pushReplacementNamed(context, InitScreen.route);
Expand Down Expand Up @@ -254,7 +253,7 @@ class BuildWalletCardState extends State<BuildWalletCard>
children: [
Row(
children: [
Text(_localization.buildWalletBalance,
Text(localization.buildWalletBalance,
style: theme.textTheme.bodyLarge),
SizedBox(
height: 8,
Expand Down Expand Up @@ -283,7 +282,7 @@ class BuildWalletCardState extends State<BuildWalletCard>
),
Row(
children: [
Text(_localization.transactionsFound,
Text(localization.transactionsFound,
style: theme.textTheme.bodyLarge!),
AutoSizeText(
'$currentTransactionCount',
Expand All @@ -296,7 +295,7 @@ class BuildWalletCardState extends State<BuildWalletCard>
Row(
children: [
AutoSizeText(
_localization.exploredAddresses,
localization.exploredAddresses,
maxLines: 2,
minFontSize: 16,
),
Expand All @@ -315,7 +314,7 @@ class BuildWalletCardState extends State<BuildWalletCard>
Row(
children: [
Text(
_localization.exploringAddress,
localization.exploringAddress,
style: theme.textTheme.bodyLarge!,
),
Expanded(
Expand Down
11 changes: 5 additions & 6 deletions lib/screens/create_wallet/confirm_mnemonic_card.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:witnet/crypto.dart';
import 'package:my_wit_wallet/constants.dart';
import 'package:my_wit_wallet/screens/create_wallet/bloc/api_create_wallet.dart';
import 'package:my_wit_wallet/screens/create_wallet/bloc/create_wallet_bloc.dart';
import 'package:my_wit_wallet/shared/locator.dart';
Expand All @@ -27,7 +27,6 @@ class ConfirmMnemonicCardState extends State<ConfirmMnemonicCard>
String mnemonic = '';
final TextEditingController textController = TextEditingController();
int numLines = 0;
AppLocalizations get _localization => AppLocalizations.of(context)!;

void prevAction() {
CreateWalletType type =
Expand All @@ -44,14 +43,14 @@ class ConfirmMnemonicCardState extends State<ConfirmMnemonicCard>

NavAction prev() {
return NavAction(
label: _localization.backLabel,
label: localization.backLabel,
action: prevAction,
);
}

NavAction next() {
return NavAction(
label: _localization.continueLabel,
label: localization.continueLabel,
action: nextAction,
);
}
Expand All @@ -78,14 +77,14 @@ class ConfirmMnemonicCardState extends State<ConfirmMnemonicCard>
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_localization.confirmMnemonicHeader,
localization.confirmMnemonicHeader,
style: theme.textTheme.titleLarge,
),
SizedBox(
height: 16,
),
Text(
_localization.confirmMnemonic01,
localization.confirmMnemonic01,
style: theme.textTheme.bodyLarge,
),
SizedBox(
Expand Down
16 changes: 7 additions & 9 deletions lib/screens/create_wallet/create_import_wallet.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:my_wit_wallet/constants.dart';
import 'package:my_wit_wallet/screens/login/bloc/login_bloc.dart';
import 'package:my_wit_wallet/shared/locator.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -36,8 +36,6 @@ class Action {
}

class CreateImportWalletState extends State<CreateImportWallet> {
AppLocalizations get _localization => AppLocalizations.of(context)!;

Widget build(BuildContext context) {
final theme = Theme.of(context);
return Column(
Expand Down Expand Up @@ -79,21 +77,21 @@ class CreateImportWalletState extends State<CreateImportWallet> {

Action prev() {
return Action(
label: _localization.backLabel,
label: localization.backLabel,
action: prevAction,
);
}

Action nextCreateAction() {
return Action(
label: _localization.createNewWalletLabel,
label: localization.createNewWalletLabel,
action: createWallet,
);
}

Action nextImportAction() {
return Action(
label: _localization.importWalletLabel,
label: localization.importWalletLabel,
action: importWallet,
);
}
Expand All @@ -119,16 +117,16 @@ class CreateImportWalletState extends State<CreateImportWallet> {
name: 'create-or-import-wallet', height: 152)),
SizedBox(height: 16),
Text(
_localization.createImportWalletHeader,
localization.createImportWalletHeader,
style: theme.textTheme.titleLarge,
),
SizedBox(height: 16),
Text(
_localization.createImportWallet01,
localization.createImportWallet01,
style: theme.textTheme.bodyLarge,
),
SizedBox(height: 16),
Text(_localization.createImportWallet02,
Text(localization.createImportWallet02,
style: theme.textTheme.bodyLarge)
],
);
Expand Down
6 changes: 2 additions & 4 deletions lib/screens/create_wallet/create_wallet_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:my_wit_wallet/constants.dart';
import 'package:my_wit_wallet/screens/create_wallet/create_import_wallet.dart';
import 'package:my_wit_wallet/screens/create_wallet/re_establish_wallet_disclaimer.dart';
import 'package:my_wit_wallet/widgets/PaddedButton.dart';
Expand Down Expand Up @@ -40,8 +40,6 @@ class CreateWalletScreenState extends State<CreateWalletScreen> {
bool isLoading = false;
bool hideButton = false;

AppLocalizations get _localization => AppLocalizations.of(context)!;

@override
void initState() {
super.initState();
Expand All @@ -62,7 +60,7 @@ class CreateWalletScreenState extends State<CreateWalletScreen> {
padding: EdgeInsets.only(bottom: 0),
text: nextAction != null
? nextAction().label
: _localization.continueLabel,
: localization.continueLabel,
type: ButtonType.primary,
isLoading: isLoading,
enabled: nextAction != null,
Expand Down
24 changes: 11 additions & 13 deletions lib/screens/create_wallet/disclaimer_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:my_wit_wallet/constants.dart';
import 'package:my_wit_wallet/screens/create_wallet/bloc/create_wallet_bloc.dart';
import 'package:my_wit_wallet/screens/login/bloc/login_bloc.dart';
import 'package:my_wit_wallet/widgets/labeled_checkbox.dart';
Expand Down Expand Up @@ -28,8 +28,6 @@ class DisclaimerCardState extends State<DisclaimerCard>
bool isCheckBoxFocus = false;
FocusNode _checkBoxFocusNode = FocusNode();

AppLocalizations get _localization => AppLocalizations.of(context)!;

@override
void initState() {
WidgetsBinding.instance
Expand Down Expand Up @@ -74,14 +72,14 @@ class DisclaimerCardState extends State<DisclaimerCard>

NavAction prev() {
return NavAction(
label: _localization.backLabel,
label: localization.backLabel,
action: prevAction,
);
}

NavAction next() {
return NavAction(
label: _localization.continueLabel,
label: localization.continueLabel,
action: nextAction,
);
}
Expand All @@ -95,44 +93,44 @@ class DisclaimerCardState extends State<DisclaimerCard>
mainAxisSize: MainAxisSize.max,
children: [
Text(
_localization.walletSecurityHeader,
localization.walletSecurityHeader,
style: theme.textTheme.titleLarge!,
),
SizedBox(
height: 16,
),
Text(
_localization.walletSecurity01,
localization.walletSecurity01,
style: theme.textTheme.bodyLarge,
),
SizedBox(
height: 10,
),
Text(_localization.walletSecurity02, style: theme.textTheme.bodyLarge),
Text(localization.walletSecurity02, style: theme.textTheme.bodyLarge),
SizedBox(
height: 10,
),
Text(_localization.walletSecurity03, style: theme.textTheme.bodyLarge),
Text(localization.walletSecurity03, style: theme.textTheme.bodyLarge),
SizedBox(
height: 10,
),
Text(_localization.walletSecurity04, style: theme.textTheme.bodyLarge),
Text(localization.walletSecurity04, style: theme.textTheme.bodyLarge),
SizedBox(
height: 10,
),
Text(_localization.walletSecurity05, style: theme.textTheme.bodyLarge),
Text(localization.walletSecurity05, style: theme.textTheme.bodyLarge),
SizedBox(
height: 10,
),
Text(_localization.walletSecurity06, style: theme.textTheme.bodyLarge),
Text(localization.walletSecurity06, style: theme.textTheme.bodyLarge),
SizedBox(
height: 10,
),
LabeledCheckbox(
focusNode: _checkBoxFocusNode,
isFocus: isCheckBoxFocus,
checked: isNextAllow,
label: _localization.walletSecurityConfirmLabel,
label: localization.walletSecurityConfirmLabel,
onChanged: (value) => {
setState(() {
isNextAllow = !isNextAllow;
Expand Down
Loading

0 comments on commit f6f5bfb

Please sign in to comment.