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

Add /constants #1728

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 2 additions & 1 deletion app/components/UI/OnboardingWizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Modal from 'react-native-modal';
import Device from '../../../util/Device';
import Analytics from '../../../core/Analytics';
import { ANALYTICS_EVENT_OPTS, ONBOARDING_WIZARD_STEP_DESCRIPTION } from '../../../util/analytics';
import { ONBOARDING_WIZARD, EXPLORED } from '../../../constants/storage';

const MIN_HEIGHT = Dimensions.get('window').height;
const styles = StyleSheet.create({
Expand Down Expand Up @@ -100,7 +101,7 @@ class OnboardingWizard extends PureComponent {
navigation,
wizard: { step }
} = this.props;
await AsyncStorage.setItem('@MetaMask:onboardingWizard', 'explored');
await AsyncStorage.setItem(ONBOARDING_WIZARD, EXPLORED);
setOnboardingWizardStep && setOnboardingWizardStep(0);
navigation && navigation.dispatch(DrawerActions.closeDrawer());
closing &&
Expand Down
7 changes: 4 additions & 3 deletions app/components/UI/OptinMetrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import StyledButton from '../StyledButton';
import Analytics from '../../../core/Analytics';
import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import { clearOnboardingEvents } from '../../../actions/onboarding';
import { ONBOARDING_WIZARD, METRICS_OPT_IN, DENIED, AGREED } from '../../../constants/storage';

const styles = StyleSheet.create({
root: {
Expand Down Expand Up @@ -171,7 +172,7 @@ class OptinMetrics extends PureComponent {
*/
continue = async () => {
// Get onboarding wizard state
const onboardingWizard = await AsyncStorage.getItem('@MetaMask:onboardingWizard');
const onboardingWizard = await AsyncStorage.getItem(ONBOARDING_WIZARD);
if (onboardingWizard) {
this.props.navigation.navigate('HomeNav');
} else {
Expand Down Expand Up @@ -207,7 +208,7 @@ class OptinMetrics extends PureComponent {
}
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_METRICS_OPT_OUT);
this.props.clearOnboardingEvents();
await AsyncStorage.setItem('@MetaMask:metricsOptIn', 'denied');
await AsyncStorage.setItem(METRICS_OPT_IN, DENIED);
Analytics.disableInstance();
});
this.continue();
Expand All @@ -223,7 +224,7 @@ class OptinMetrics extends PureComponent {
}
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_METRICS_OPT_IN);
this.props.clearOnboardingEvents();
await AsyncStorage.setItem('@MetaMask:metricsOptIn', 'agreed');
await AsyncStorage.setItem(METRICS_OPT_IN, AGREED);
});
this.continue();
};
Expand Down
5 changes: 3 additions & 2 deletions app/components/Views/AccountBackupStep1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import SeedphraseModal from '../../UI/SeedphraseModal';
import { getOnboardingNavbarOptions } from '../../UI/Navbar';
import scaling from '../../../util/scaling';
import Engine from '../../../core/Engine';
import { ONBOARDING_WIZARD, METRICS_OPT_IN } from '../../../constants/storage';

const explain_backup_seedphrase = require('../../../images/explain-backup-seedphrase.png'); // eslint-disable-line
const warning_skip_backup = require('../../../images/warning.png'); // eslint-disable-line
Expand Down Expand Up @@ -202,9 +203,9 @@ const AccountBackupStep1 = props => {
const skip = async () => {
hideRemindLaterModal();
// Get onboarding wizard state
const onboardingWizard = await AsyncStorage.getItem('@MetaMask:onboardingWizard');
const onboardingWizard = await AsyncStorage.getItem(ONBOARDING_WIZARD);
// Check if user passed through metrics opt-in screen
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
const metricsOptIn = await AsyncStorage.getItem(METRICS_OPT_IN);
if (!metricsOptIn) {
props.navigation.navigate('OptinMetrics');
} else if (onboardingWizard) {
Expand Down
40 changes: 25 additions & 15 deletions app/components/Views/ChoosePassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import AppConstants from '../../../core/AppConstants';
import OnboardingProgress from '../../UI/OnboardingProgress';
import zxcvbn from 'zxcvbn';
import Logger from '../../../util/Logger';
import { ONBOARDING, PREVIOUS_SCREEN } from '../../../constants/navigation';
import {
EXISTING_USER,
NEXT_MAKER_REMINDER,
BIOMETRY_CHOICE,
BIOMETRY_CHOICE_DISABLED,
PASSCODE_DISABLED,
TRUE
} from '../../../constants/storage';

const steps = [strings('choose_password.title'), strings('choose_password.secure'), strings('choose_password.confirm')];

Expand Down Expand Up @@ -284,12 +293,13 @@ class ChoosePassword extends PureComponent {
try {
this.setState({ loading: true });

const previousScreen = this.props.navigation.getParam(AppConstants.PREVIOUS_SCREEN);
if (previousScreen === 'onboarding') {
const previous_screen = this.props.navigation.getParam(PREVIOUS_SCREEN);

if (previous_screen === ONBOARDING) {
await this.createNewVaultAndKeychain(password);
this.props.seedphraseNotBackedUp();
await AsyncStorage.removeItem('@MetaMask:nextMakerReminder');
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
await AsyncStorage.removeItem(NEXT_MAKER_REMINDER);
await AsyncStorage.setItem(EXISTING_USER, TRUE);
} else {
await this.recreateVault(password);
}
Expand All @@ -305,9 +315,9 @@ class ChoosePassword extends PureComponent {
if (Device.isIos()) {
await SecureKeychain.getGenericPassword();
}
await AsyncStorage.setItem('@MetaMask:biometryChoice', this.state.biometryType);
await AsyncStorage.removeItem('@MetaMask:biometryChoiceDisabled');
await AsyncStorage.removeItem('@MetaMask:passcodeDisabled');
await AsyncStorage.setItem(BIOMETRY_CHOICE, this.state.biometryType);
await AsyncStorage.removeItem(BIOMETRY_CHOICE_DISABLED);
await AsyncStorage.removeItem(PASSCODE_DISABLED);
} else {
if (this.state.rememberMe) {
await SecureKeychain.setGenericPassword('metamask-user', password, {
Expand All @@ -316,11 +326,11 @@ class ChoosePassword extends PureComponent {
} else {
await SecureKeychain.resetGenericPassword();
}
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
await AsyncStorage.setItem('@MetaMask:biometryChoiceDisabled', 'true');
await AsyncStorage.setItem('@MetaMask:passcodeDisabled', 'true');
await AsyncStorage.removeItem(BIOMETRY_CHOICE);
await AsyncStorage.setItem(BIOMETRY_CHOICE_DISABLED, TRUE);
await AsyncStorage.setItem(PASSCODE_DISABLED, TRUE);
}
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
await AsyncStorage.setItem(EXISTING_USER, TRUE);
this.props.passwordSet();
this.props.setLockTime(AppConstants.DEFAULT_LOCK_TIMEOUT);

Expand All @@ -330,9 +340,9 @@ class ChoosePassword extends PureComponent {
await this.recreateVault('');
// Set state in app as it was with no password
await SecureKeychain.setGenericPassword('metamask-user', '');
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
await AsyncStorage.removeItem('@MetaMask:nextMakerReminder');
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
await AsyncStorage.removeItem(BIOMETRY_CHOICE);
await AsyncStorage.removeItem(NEXT_MAKER_REMINDER);
await AsyncStorage.setItem(EXISTING_USER, TRUE);
this.props.passwordUnset();
this.props.setLockTime(-1);
// Should we force people to enable passcode / biometrics?
Expand Down Expand Up @@ -525,7 +535,7 @@ class ChoosePassword extends PureComponent {
<ActivityIndicator size="large" color={Device.isAndroid() ? colors.blue : colors.grey} />
<Text style={styles.title}>
{strings(
previousScreen === 'onboarding'
previousScreen === ONBOARDING
? 'create_wallet.title'
: 'secure_your_wallet.creating_password'
)}
Expand Down
3 changes: 2 additions & 1 deletion app/components/Views/ChoosePassword/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import ChoosePassword from './';
import configureMockStore from 'redux-mock-store';
import { ONBOARDING, PROTECT } from '../../../constants/navigation';

describe('ChoosePassword', () => {
const mockStore = configureMockStore();
Expand All @@ -26,7 +27,7 @@ describe('ChoosePassword', () => {
const wrapper = shallow(
<ChoosePassword
navigation={{
getParam: () => ['onboarding', 'protect'],
getParam: () => [ONBOARDING, PROTECT],
state: { params: {} }
}}
/>,
Expand Down
18 changes: 13 additions & 5 deletions app/components/Views/CreateWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ import setOnboardingWizardStep from '../../../actions/wizard';
import { NavigationActions, withNavigationFocus } from 'react-navigation';
import OnboardingScreenWithBg from '../../UI/OnboardingScreenWithBg';
import Device from '../../../util/Device';
import {
BIOMETRY_CHOICE,
NEXT_MAKER_REMINDER,
EXISTING_USER,
ONBOARDING_WIZARD,
METRICS_OPT_IN,
TRUE
} from '../../../constants/storage';

const styles = StyleSheet.create({
scroll: {
Expand Down Expand Up @@ -117,13 +125,13 @@ class CreateWallet extends PureComponent {
await Engine.resetState();
await KeyringController.createNewVaultAndKeychain('');
await SecureKeychain.setGenericPassword('metamask-user', '');
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
await AsyncStorage.removeItem('@MetaMask:nextMakerReminder');
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
await AsyncStorage.removeItem(BIOMETRY_CHOICE);
await AsyncStorage.removeItem(NEXT_MAKER_REMINDER);
await AsyncStorage.setItem(EXISTING_USER, TRUE);
// Get onboarding wizard state
const onboardingWizard = await AsyncStorage.getItem('@MetaMask:onboardingWizard');
const onboardingWizard = await AsyncStorage.getItem(ONBOARDING_WIZARD);
// Check if user passed through metrics opt-in screen
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
const metricsOptIn = await AsyncStorage.getItem(METRICS_OPT_IN);
// Making sure we reset the flag while going to
// the first time flow
this.props.passwordUnset();
Expand Down
13 changes: 7 additions & 6 deletions app/components/Views/Entry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Logger from '../../../util/Logger';
import Device from '../../../util/Device';
import SplashScreen from 'react-native-splash-screen';
import { recreateVaultWithSamePassword } from '../../../core/Vault';
import { EXISTING_USER, ONBOARDING_WIZARD, METRICS_OPT_IN, ENCRYPTION_LIB, ORIGINAL } from '../../../constants/storage';

/**
* Entry Screen that decides which screen to show
Expand Down Expand Up @@ -96,7 +97,7 @@ class Entry extends PureComponent {
DeeplinkManager.init(this.props.navigation);
this.unsubscribeFromBranch = Branch.subscribe(this.handleDeeplinks);
SplashScreen.hide();
const existingUser = await AsyncStorage.getItem('@MetaMask:existingUser');
const existingUser = await AsyncStorage.getItem(EXISTING_USER);
if (existingUser !== null) {
await this.unlockKeychain();
} else {
Expand Down Expand Up @@ -167,15 +168,15 @@ class Entry extends PureComponent {
// Restore vault with existing credentials

await KeyringController.submitPassword(credentials.password);
const encryptionLib = await AsyncStorage.getItem('@MetaMask:encryptionLib');
if (encryptionLib !== 'original') {
const encryptionLib = await AsyncStorage.getItem(ENCRYPTION_LIB);
if (encryptionLib !== ORIGINAL) {
await recreateVaultWithSamePassword(credentials.password, this.props.selectedAddress);
await AsyncStorage.setItem('@MetaMask:encryptionLib', 'original');
await AsyncStorage.setItem(ENCRYPTION_LIB, ORIGINAL);
}
// Get onboarding wizard state
const onboardingWizard = await AsyncStorage.getItem('@MetaMask:onboardingWizard');
const onboardingWizard = await AsyncStorage.getItem(ONBOARDING_WIZARD);
// Check if user passed through metrics opt-in screen
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
const metricsOptIn = await AsyncStorage.getItem(METRICS_OPT_IN);
if (!metricsOptIn) {
this.animateAndGoTo('OptinMetrics');
} else if (onboardingWizard) {
Expand Down
38 changes: 24 additions & 14 deletions app/components/Views/ImportFromSeed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ import zxcvbn from 'zxcvbn';
import Icon from 'react-native-vector-icons/FontAwesome';
import Device from '../../../util/Device';
import { OutlinedTextField } from 'react-native-material-textfield';
import {
BIOMETRY_CHOICE,
BIOMETRY_CHOICE_DISABLED,
NEXT_MAKER_REMINDER,
PASSCODE_DISABLED,
ONBOARDING_WIZARD,
EXISTING_USER,
METRICS_OPT_IN,
TRUE
} from '../../../constants/storage';

const styles = StyleSheet.create({
mainWrapper: {
Expand Down Expand Up @@ -200,8 +210,8 @@ class ImportFromSeed extends PureComponent {
const biometryType = await SecureKeychain.getSupportedBiometryType();
if (biometryType) {
let enabled = true;
const previouslyDisabled = await AsyncStorage.removeItem('@MetaMask:biometryChoiceDisabled');
if (previouslyDisabled && previouslyDisabled === 'true') {
const previouslyDisabled = await AsyncStorage.removeItem(BIOMETRY_CHOICE_DISABLED);
if (previouslyDisabled && previouslyDisabled === TRUE) {
enabled = false;
}
this.setState({ biometryType, biometryChoice: enabled });
Expand Down Expand Up @@ -239,7 +249,7 @@ class ImportFromSeed extends PureComponent {

const { KeyringController } = Engine.context;
await Engine.resetState();
await AsyncStorage.removeItem('@MetaMask:nextMakerReminder');
await AsyncStorage.removeItem(NEXT_MAKER_REMINDER);
await KeyringController.createNewVaultAndRestore(this.state.password, this.state.seed);

if (this.state.biometryType && this.state.biometryChoice) {
Expand All @@ -254,9 +264,9 @@ class ImportFromSeed extends PureComponent {
if (Device.isIos()) {
await SecureKeychain.getGenericPassword();
}
await AsyncStorage.setItem('@MetaMask:biometryChoice', this.state.biometryType);
await AsyncStorage.removeItem('@MetaMask:biometryChoiceDisabled');
await AsyncStorage.removeItem('@MetaMask:passcodeDisabled');
await AsyncStorage.setItem(BIOMETRY_CHOICE, this.state.biometryType);
await AsyncStorage.removeItem(BIOMETRY_CHOICE_DISABLED);
await AsyncStorage.removeItem(PASSCODE_DISABLED);
} else {
if (this.state.rememberMe) {
await SecureKeychain.setGenericPassword('metamask-user', this.state.password, {
Expand All @@ -265,16 +275,16 @@ class ImportFromSeed extends PureComponent {
} else {
await SecureKeychain.resetGenericPassword();
}
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
await AsyncStorage.setItem('@MetaMask:biometryChoiceDisabled', 'true');
await AsyncStorage.setItem('@MetaMask:passcodeDisabled', 'true');
await AsyncStorage.removeItem(BIOMETRY_CHOICE);
await AsyncStorage.setItem(BIOMETRY_CHOICE_DISABLED, TRUE);
await AsyncStorage.setItem(PASSCODE_DISABLED, TRUE);
}
// Get onboarding wizard state
const onboardingWizard = await AsyncStorage.getItem('@MetaMask:onboardingWizard');
const onboardingWizard = await AsyncStorage.getItem(ONBOARDING_WIZARD);
// Check if user passed through metrics opt-in screen
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
const metricsOptIn = await AsyncStorage.getItem(METRICS_OPT_IN);
// mark the user as existing so it doesn't see the create password screen again
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
await AsyncStorage.setItem(EXISTING_USER, TRUE);
this.setState({ loading: false });
this.props.passwordSet();
this.props.setLockTime(AppConstants.DEFAULT_LOCK_TIMEOUT);
Expand Down Expand Up @@ -336,9 +346,9 @@ class ImportFromSeed extends PureComponent {

updateBiometryChoice = async biometryChoice => {
if (!biometryChoice) {
await AsyncStorage.setItem('@MetaMask:biometryChoiceDisabled', 'true');
await AsyncStorage.setItem(BIOMETRY_CHOICE_DISABLED, TRUE);
} else {
await AsyncStorage.removeItem('@MetaMask:biometryChoiceDisabled');
await AsyncStorage.removeItem(BIOMETRY_CHOICE_DISABLED);
}
this.setState({ biometryChoice });
};
Expand Down
Loading