A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/pages/first-time-flow/seed-phrase/confirm-seed-phrase/confirm-seed-phrase.compone...

285 lines
7.4 KiB

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Button from '../../../../components/ui/button';
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
6 years ago
import {
INITIALIZE_END_OF_FLOW_ROUTE,
INITIALIZE_SEED_PHRASE_ROUTE,
} from '../../../../helpers/constants/routes';
import { exportAsFile } from '../../../../helpers/utils/util';
import DraggableSeed from './draggable-seed.component';
const EMPTY_SEEDS = Array(12).fill(null);
export default class ConfirmSeedPhrase extends PureComponent {
static contextTypes = {
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
6 years ago
metricsEvent: PropTypes.func,
t: PropTypes.func,
};
static defaultProps = {
seedPhrase: '',
};
static propTypes = {
history: PropTypes.object,
seedPhrase: PropTypes.string,
3box integration 2.0 (#6972) * Adds threebox controller * Adds threebox approval modal * Fix unit tests and lint after addition of threebox * Correct threebox behaviour after rejecting request for backup; fixes e2e tests. * Update threebox controller for automatic syncing * Ensure frontend locale updates when preferences are changed via direct update within controller * Add toggle in settings for 3box syncing * Update threebox controller for latest 3box version * Delete unnecessary frontend changes for threebox integration * Backing up address book contacts with threebox * Update unit tests for 3box-integration additions * Only enable threebox by default for new wallets * Mock globals for correct unit tests * 3box '1.10.2' -> '^1.10.2' * Correct capilalization on 3Box * Use log.debug instead of console.log in threebox controller * Update yarn.lock * Remove edge build * Split 3box module into background deps js file * extra bundle opts for bg-libs * sync yarn.lock * new3Box logic * Show confirm threebox restore after import * Remove bg-libs.js from manifest file for dev builds * Switch 3Box controller to using the spaces api (instead of the profile api) * Finalize switching to spaces api and only restoring from 3box after import * Update metamask-controller-test.js for threebox controller changes * Make threebox modal style consistent with others and update success button wording * Use mock 3box when in test * Correct 3box modal header * Remove unnecessary property of threebox controller provider * Remove unnecessary method calls after restoration from 3box in the threebox-restore-confirm modal. * Replace setThreeBoxSyncingPermission calls in routes/index.js with turnThreeBoxSyncingOn * Replace erroneous use of with * Replace erroneous use of threeboxSyncing with threeBoxSyncingAllowed in advancted-tab directory * Lint fixes for 3box changes * Log errors encountered when updating 3Box * Remove unnecessary parameter from state update * Add timeout to initial 3Box sync The initial 3Box sync will now timeout after 1 minute. If the timeout is triggered, 3Box is disabled and cannot be re-enabled unless the initial sync does finally finish. If it never finishes, 3Box cannot be enabled unless the extension is reinstalled. The Advanced Settings page was updated to show this option as disabled in that circumstance, with a new discription explaining why it's disabled. The UI here could certainly be improved. Additionally, "on" and "off" labels were added to the toggle to match the other toggles on the Advanced Settings page. * Use non-minified 3Box module We had previously used the minified 3Box module to avoid a build error encountered when `envify` was processing the `libp2p` module (which is used by 3Box). The build would fail because `esprima` (used by `envify`) is incompatible with the object spread/rest operator (which is used in `libp2p`). That issue has been solved by adding a global Babelify transformation specifically for transpiling out the object rest/spread operator from dependencies. It has been targetted to only affect `libp2p` to avoid extending the build time too much. This workaround can be used until a new version of `esprima` is released that includes this bug fix. * Use app key addresses for threebox * Replace use of modal for confirming 3box restoration with a home notification * Adds e2e tests for restoring from threebox * Update eth-keyring-controller to 5.1.0 * Correct parameters passed to getAppKeyAddress in threebox.js * Add prefix to origin passed to getAppKeyAddress in threebox.js * Remove unused locale message. * Prevent CORS errors in firefox e2e tests * Ensure extraneous scripts are excluded from the local test dev build * Move threeBoxLastUpdate state from home.component to redux * Threebox PR code cleanup * Always use first address when initializing threebox * Replace setRestoredFromThreeBox api with setRestoredFromThreeBoxToFalse and setRestoredFromThreeBoxToTrue * Update development/metamaskbot-build-announce.js to include ui-libs and bg-libs in hard coded bundle list * Update test/e2e/threebox.spec.js to use new helpers added with pull #7144 * Make setFeatureFlag available on the ui window during testing * Hide threebox feature behind a feature flag that can only be activated via dev console * Remove unnecessary migration of threebox feature flag * Prevent this.init() call in threebox constructor if feature flag is not turned on * Prevent threebox notification from showing if feature flag is falsy * http://localhost/8889 -> http://localhost/* in gulp manifest:testing tasks
5 years ago
initializeThreeBox: PropTypes.func,
setSeedPhraseBackedUp: PropTypes.func,
};
state = {
selectedSeedIndices: [],
sortedSeedWords: [],
pendingSeedIndices: [],
draggingSeedIndex: -1,
hoveringIndex: -1,
};
componentDidMount() {
const { seedPhrase = '' } = this.props;
const sortedSeedWords = (seedPhrase.split(' ') || []).sort();
this.setState({ sortedSeedWords });
}
setDraggingSeedIndex = (draggingSeedIndex) =>
this.setState({ draggingSeedIndex });
setHoveringIndex = (hoveringIndex) => this.setState({ hoveringIndex });
onDrop = (targetIndex) => {
const { selectedSeedIndices, draggingSeedIndex } = this.state;
const indices = insert(
selectedSeedIndices,
draggingSeedIndex,
targetIndex,
true,
);
this.setState({
selectedSeedIndices: indices,
pendingSeedIndices: indices,
draggingSeedIndex: -1,
hoveringIndex: -1,
});
};
handleExport = () => {
exportAsFile('', this.props.seedPhrase, 'text/plain');
};
handleSubmit = async () => {
const { history, setSeedPhraseBackedUp, initializeThreeBox } = this.props;
if (!this.isValid()) {
return;
}
try {
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
6 years ago
this.context.metricsEvent({
eventOpts: {
category: 'Onboarding',
action: 'Seed Phrase Setup',
name: 'Verify Complete',
},
});
setSeedPhraseBackedUp(true).then(async () => {
initializeThreeBox();
history.push(INITIALIZE_END_OF_FLOW_ROUTE);
});
} catch (error) {
console.error(error.message);
}
};
handleSelectSeedWord = (index) => {
this.setState({
selectedSeedIndices: [...this.state.selectedSeedIndices, index],
pendingSeedIndices: [...this.state.pendingSeedIndices, index],
});
};
handleDeselectSeedWord = (index) => {
this.setState({
selectedSeedIndices: this.state.selectedSeedIndices.filter(
(i) => index !== i,
),
pendingSeedIndices: this.state.pendingSeedIndices.filter(
(i) => index !== i,
),
});
};
isValid() {
const { seedPhrase } = this.props;
const { selectedSeedIndices, sortedSeedWords } = this.state;
const selectedSeedWords = selectedSeedIndices.map(
(i) => sortedSeedWords[i],
);
return seedPhrase === selectedSeedWords.join(' ');
}
render() {
const { t } = this.context;
const { history } = this.props;
const {
selectedSeedIndices,
sortedSeedWords,
draggingSeedIndex,
} = this.state;
return (
<div className="confirm-seed-phrase">
<div className="confirm-seed-phrase__back-button">
<a
onClick={(e) => {
e.preventDefault();
history.push(INITIALIZE_SEED_PHRASE_ROUTE);
}}
href="#"
>
{`< ${t('back')}`}
</a>
</div>
<div className="first-time-flow__header">
{t('confirmSecretBackupPhrase')}
</div>
<div className="first-time-flow__text-block">
{t('selectEachPhrase')}
</div>
<div
className={classnames('confirm-seed-phrase__selected-seed-words', {
'confirm-seed-phrase__selected-seed-words--dragging':
draggingSeedIndex > -1,
})}
>
{this.renderPendingSeeds()}
{this.renderSelectedSeeds()}
</div>
<div
className="confirm-seed-phrase__sorted-seed-words"
data-testid="seed-phrase-sorted"
>
{sortedSeedWords.map((word, index) => {
const isSelected = selectedSeedIndices.includes(index);
return (
<DraggableSeed
key={index}
seedIndex={index}
index={index}
setHoveringIndex={this.setHoveringIndex}
onDrop={this.onDrop}
className="confirm-seed-phrase__seed-word--sorted"
selected={isSelected}
onClick={() => {
if (isSelected) {
this.handleDeselectSeedWord(index);
} else {
this.handleSelectSeedWord(index);
}
}}
word={word}
/>
);
})}
</div>
<Button
type="primary"
className="first-time-flow__button"
onClick={this.handleSubmit}
disabled={!this.isValid()}
>
{t('confirm')}
</Button>
</div>
);
}
renderSelectedSeeds() {
const {
sortedSeedWords,
selectedSeedIndices,
draggingSeedIndex,
} = this.state;
return EMPTY_SEEDS.map((_, index) => {
const seedIndex = selectedSeedIndices[index];
const word = sortedSeedWords[seedIndex];
return (
<DraggableSeed
key={`selected-${seedIndex}-${index}`}
className="confirm-seed-phrase__selected-seed-words__selected-seed"
index={index}
seedIndex={seedIndex}
word={word}
draggingSeedIndex={draggingSeedIndex}
setDraggingSeedIndex={this.setDraggingSeedIndex}
setHoveringIndex={this.setHoveringIndex}
onDrop={this.onDrop}
draggable
/>
);
});
}
renderPendingSeeds() {
const {
pendingSeedIndices,
sortedSeedWords,
draggingSeedIndex,
hoveringIndex,
} = this.state;
const indices = insert(
pendingSeedIndices,
draggingSeedIndex,
hoveringIndex,
);
return EMPTY_SEEDS.map((_, index) => {
const seedIndex = indices[index];
const word = sortedSeedWords[seedIndex];
return (
<DraggableSeed
key={`pending-${seedIndex}-${index}`}
index={index}
className={classnames(
'confirm-seed-phrase__selected-seed-words__pending-seed',
{
'confirm-seed-phrase__seed-word--hidden':
draggingSeedIndex === seedIndex && index !== hoveringIndex,
},
)}
seedIndex={seedIndex}
word={word}
draggingSeedIndex={draggingSeedIndex}
setDraggingSeedIndex={this.setDraggingSeedIndex}
setHoveringIndex={this.setHoveringIndex}
onDrop={this.onDrop}
droppable={Boolean(word)}
/>
);
});
}
}
function insert(list, value, target, removeOld) {
let nextList = [...list];
if (typeof list[target] === 'number') {
nextList = [...list.slice(0, target), value, ...list.slice(target)];
}
if (removeOld) {
nextList = nextList.filter((seed, i) => {
return seed !== value || i === target;
});
}
return nextList;
}