Skip to content

Commit

Permalink
Add constants for storage keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed Jul 28, 2020
1 parent 2c66d3a commit 5c6135d
Show file tree
Hide file tree
Showing 24 changed files with 219 additions and 126 deletions.
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 } 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 } 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 @@ -15,6 +15,7 @@ import ActionModal from '../../UI/ActionModal';
import SeedphraseModal from '../../UI/SeedphraseModal';
import { getOnboardingNavbarOptions } from '../../UI/Navbar';
import scaling from '../../../util/scaling';
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 @@ -186,9 +187,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
31 changes: 19 additions & 12 deletions app/components/Views/ChoosePassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import AppConstants from '../../../core/AppConstants';
import OnboardingProgress from '../../UI/OnboardingProgress';
import zxcvbn from 'zxcvbn';
import { ONBOARDING, PREVIOUS_SCREEN } from '../../../constants/navigation';
import {
EXISTING_USER,
NEXT_MAKER_REMINDER,
BIOMETRY_CHOICE,
BIOMETRY_CHOICE_DISABLED,
PASSCODE_DISABLED
} from '../../../constants/storage';

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

Expand Down Expand Up @@ -281,8 +288,8 @@ class ChoosePassword extends PureComponent {
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 @@ -298,9 +305,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 @@ -309,11 +316,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 @@ -324,9 +331,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
17 changes: 12 additions & 5 deletions app/components/Views/CreateWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ 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
} from '../../../constants/storage';

const styles = StyleSheet.create({
scroll: {
Expand Down Expand Up @@ -117,13 +124,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
9 changes: 5 additions & 4 deletions app/components/Views/Entry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DeeplinkManager from '../../../core/DeeplinkManager';
import Logger from '../../../util/Logger';
import Device from '../../../util/Device';
import SplashScreen from 'react-native-splash-screen';
import { EXISTING_USER, ONBOARDING_WIZARD, METRICS_OPT_IN } from '../../../constants/storage';

/**
* Entry Screen that decides which screen to show
Expand Down Expand Up @@ -91,7 +92,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 All @@ -106,7 +107,7 @@ class Entry extends PureComponent {
}
const deeplink = params['+non_branch_link'] || uri || null;
if (deeplink) {
const existingUser = await AsyncStorage.getItem('@MetaMask:existingUser');
const existingUser = await AsyncStorage.getItem(EXISTING_USER);
!existingUser ? DeeplinkManager.setDeeplink(deeplink) : DeeplinkManager.parse(deeplink);
}
};
Expand Down Expand Up @@ -161,9 +162,9 @@ class Entry extends PureComponent {
const { KeyringController } = Engine.context;
await KeyringController.submitPassword(credentials.password);
// 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
35 changes: 22 additions & 13 deletions app/components/Views/ImportFromSeed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ import TermsAndConditions from '../TermsAndConditions';
import zxcvbn from 'zxcvbn';
import Icon from 'react-native-vector-icons/FontAwesome';
import Device from '../../../util/Device';
import {
BIOMETRY_CHOICE,
BIOMETRY_CHOICE_DISABLED,
NEXT_MAKER_REMINDER,
PASSCODE_DISABLED,
ONBOARDING_WIZARD,
EXISTING_USER,
METRICS_OPT_IN
} from '../../../constants/storage';

const styles = StyleSheet.create({
mainWrapper: {
Expand Down Expand Up @@ -215,7 +224,7 @@ class ImportFromSeed extends PureComponent {
const biometryType = await SecureKeychain.getSupportedBiometryType();
if (biometryType) {
let enabled = true;
const previouslyDisabled = await AsyncStorage.removeItem('@MetaMask:biometryChoiceDisabled');
const previouslyDisabled = await AsyncStorage.removeItem(BIOMETRY_CHOICE_DISABLED);
if (previouslyDisabled && previouslyDisabled === 'true') {
enabled = false;
}
Expand Down Expand Up @@ -254,7 +263,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 @@ -269,9 +278,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 @@ -280,16 +289,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 @@ -351,9 +360,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
40 changes: 24 additions & 16 deletions app/components/Views/ImportWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import { saveOnboardingEvent } from '../../../actions/onboarding';
import TermsAndConditions from '../TermsAndConditions';
import Device from '../../../util/Device';
import PreventScreenshot from '../../../core/PreventScreenshot';
import {
EXISTING_USER,
BIOMETRY_CHOICE,
BIOMETRY_CHOICE_DISABLED,
PASSCODE_DISABLED,
NEXT_MAKER_REMINDER,
METRICS_OPT_IN
} from '../../../constants/storage';

const SMALL_DEVICE = Device.isSmallDevice();

Expand Down Expand Up @@ -150,7 +158,7 @@ class ImportWallet extends PureComponent {
};

async checkIfExistingUser() {
const existingUser = await AsyncStorage.getItem('@MetaMask:existingUser');
const existingUser = await AsyncStorage.getItem(EXISTING_USER);
if (existingUser !== null) {
this.setState({ existingUser: true });
}
Expand Down Expand Up @@ -282,17 +290,17 @@ class ImportWallet extends PureComponent {
{
text: strings('sync_with_extension.warning_cancel_button'),
onPress: async () => {
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
await AsyncStorage.setItem('@MetaMask:biometryChoiceDisabled', 'true');
await AsyncStorage.removeItem(BIOMETRY_CHOICE);
await AsyncStorage.setItem(BIOMETRY_CHOICE_DISABLED, 'true');
this.finishSync({ biometrics: false, password });
},
style: 'cancel'
},
{
text: strings('sync_with_extension.warning_ok_button'),
onPress: async () => {
await AsyncStorage.setItem('@MetaMask:biometryChoice', biometryType);
await AsyncStorage.removeItem('@MetaMask:biometryChoiceDisabled');
await AsyncStorage.setItem(BIOMETRY_CHOICE, biometryType);
await AsyncStorage.removeItem(BIOMETRY_CHOICE_DISABLED);
this.finishSync({ biometrics: true, biometryType, password });
}
}
Expand All @@ -319,30 +327,30 @@ class ImportWallet extends PureComponent {
try {
if (Device.isIos()) {
await SecureKeychain.getGenericPassword();
await AsyncStorage.setItem('@MetaMask:biometryChoice', opts.biometryType);
await AsyncStorage.setItem(BIOMETRY_CHOICE, opts.biometryType);
}
} catch (e) {
Logger.error(e, 'User cancelled biometrics permission');
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');
}
} else {
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');
}

try {
await AsyncStorage.removeItem('@MetaMask:nextMakerReminder');
await AsyncStorage.removeItem(NEXT_MAKER_REMINDER);
await Engine.resetState();
await Engine.sync({
...this.dataToSync,
seed: this.seedWords,
importedAccounts: this.importedAccounts,
pass: opts.password
});
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
await AsyncStorage.setItem(EXISTING_USER, 'true');
this.props.passwordHasBeenSet();
this.props.setLockTime(AppConstants.DEFAULT_LOCK_TIMEOUT);
this.props.seedphraseBackedUp();
Expand Down Expand Up @@ -378,7 +386,7 @@ class ImportWallet extends PureComponent {
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_IMPORT_WITH_SEEDPHRASE);
return;
}
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
const metricsOptIn = await AsyncStorage.getItem(METRICS_OPT_IN);
if (!metricsOptIn) {
this.props.saveOnboardingEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_IMPORT_WITH_SEEDPHRASE);
}
Expand Down Expand Up @@ -415,7 +423,7 @@ class ImportWallet extends PureComponent {
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_SYNC_WITH_EXTENSION);
return;
}
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
const metricsOptIn = await AsyncStorage.getItem(METRICS_OPT_IN);
if (!metricsOptIn) {
this.props.saveOnboardingEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_SYNC_WITH_EXTENSION);
}
Expand Down
Loading

0 comments on commit 5c6135d

Please sign in to comment.