mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-12 04:37:13 +01:00
3732c5f71e
ESLint rules have been added to enforce our JSDoc conventions. These rules were introduced by updating `@metamask/eslint-config` to v9. Some of the rules have been disabled because the effort to fix all lint errors was too high. It might be easiest to enable these rules one directory at a time, or one rule at a time. Most of the changes in this PR were a result of running `yarn lint:fix`. There were a handful of manual changes that seemed obvious and simple to make. Anything beyond that and the rule was left disabled.
86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
import { ObservableStore } from '@metamask/obs-store';
|
|
import log from 'loglevel';
|
|
|
|
/**
|
|
* @typedef {Object} InitState
|
|
* @property {boolean} seedPhraseBackedUp Indicates whether the user has completed the seed phrase backup challenge
|
|
* @property {boolean} completedOnboarding Indicates whether the user has completed the onboarding flow
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Object} OnboardingOptions
|
|
* @property {InitState} initState The initial controller state
|
|
*/
|
|
|
|
/**
|
|
* Controller responsible for maintaining
|
|
* state related to onboarding
|
|
*/
|
|
export default class OnboardingController {
|
|
/**
|
|
* Creates a new controller instance
|
|
*
|
|
* @param {OnboardingOptions} [opts] - Controller configuration parameters
|
|
*/
|
|
constructor(opts = {}) {
|
|
const initialTransientState = {
|
|
onboardingTabs: {},
|
|
};
|
|
const initState = {
|
|
seedPhraseBackedUp: null,
|
|
firstTimeFlowType: null,
|
|
completedOnboarding: false,
|
|
...opts.initState,
|
|
...initialTransientState,
|
|
};
|
|
this.store = new ObservableStore(initState);
|
|
}
|
|
|
|
setSeedPhraseBackedUp(newSeedPhraseBackUpState) {
|
|
this.store.updateState({
|
|
seedPhraseBackedUp: newSeedPhraseBackUpState,
|
|
});
|
|
}
|
|
|
|
// /**
|
|
// * Sets the completedOnboarding state to true, indicating that the user has completed the
|
|
// * onboarding process.
|
|
// */
|
|
completeOnboarding() {
|
|
this.store.updateState({
|
|
completedOnboarding: true,
|
|
});
|
|
return Promise.resolve(true);
|
|
}
|
|
|
|
/**
|
|
* Setter for the `firstTimeFlowType` property
|
|
*
|
|
* @param {string} type - Indicates the type of first time flow - create or import - the user wishes to follow
|
|
*/
|
|
setFirstTimeFlowType(type) {
|
|
this.store.updateState({ firstTimeFlowType: type });
|
|
}
|
|
|
|
/**
|
|
* Registering a site as having initiated onboarding
|
|
*
|
|
* @param {string} location - The location of the site registering
|
|
* @param {string} tabId - The id of the tab registering
|
|
*/
|
|
registerOnboarding = async (location, tabId) => {
|
|
if (this.completedOnboarding) {
|
|
log.debug('Ignoring registerOnboarding; user already onboarded');
|
|
return;
|
|
}
|
|
const onboardingTabs = { ...this.store.getState().onboardingTabs };
|
|
if (!onboardingTabs[location] || onboardingTabs[location] !== tabId) {
|
|
log.debug(
|
|
`Registering onboarding tab at location '${location}' with tabId '${tabId}'`,
|
|
);
|
|
onboardingTabs[location] = tabId;
|
|
this.store.updateState({ onboardingTabs });
|
|
}
|
|
};
|
|
}
|