1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Shuffle tokens

This commit is contained in:
Jacky Chan 2017-08-30 02:05:45 -07:00 committed by Chi Kei Chan
parent 85e485128f
commit 638bbe0428
4 changed files with 44 additions and 25 deletions

View File

@ -1,6 +1,8 @@
import React, {Component, PropTypes} from 'react' import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import classnames from 'classnames' import classnames from 'classnames'
import shuffle from 'lodash.shuffle'
import {compose, onlyUpdateForPropTypes} from 'recompose'
import Identicon from '../../../../ui/app/components/identicon' import Identicon from '../../../../ui/app/components/identicon'
import {confirmSeedWords} from '../../../../ui/app/actions' import {confirmSeedWords} from '../../../../ui/app/actions'
import Breadcrumbs from './breadcrumbs' import Breadcrumbs from './breadcrumbs'
@ -41,6 +43,7 @@ class BackupPhraseScreen extends Component {
address: PropTypes.string.isRequired, address: PropTypes.string.isRequired,
seedWords: PropTypes.string.isRequired, seedWords: PropTypes.string.isRequired,
next: PropTypes.func.isRequired, next: PropTypes.func.isRequired,
confirmSeedWords: PropTypes.func.isRequired,
}; };
static defaultProps = { static defaultProps = {
@ -52,14 +55,19 @@ class BackupPhraseScreen extends Component {
CONFIRM: 'confirm' CONFIRM: 'confirm'
}; };
state = { constructor(props) {
super(props)
this.state = {
isShowingSecret: false, isShowingSecret: false,
page: BackupPhraseScreen.PAGE.SECRET, page: BackupPhraseScreen.PAGE.SECRET,
selectedSeeds: [] selectedSeeds: [],
shuffledSeeds: shuffle(props.seedWords.split(' ')),
}
} }
renderSecretWordsContainer() { renderSecretWordsContainer() {
const { isShowingSecret } = this.state; const { isShowingSecret } = this.state
return ( return (
<div className="backup-phrase__secret"> <div className="backup-phrase__secret">
<div className={classnames('backup-phrase__secret-words', { <div className={classnames('backup-phrase__secret-words', {
@ -84,6 +92,7 @@ class BackupPhraseScreen extends Component {
renderSecretScreen() { renderSecretScreen() {
const { isShowingSecret } = this.state const { isShowingSecret } = this.state
return ( return (
<div className="backup-phrase__content-wrapper"> <div className="backup-phrase__content-wrapper">
<div> <div>
@ -125,8 +134,8 @@ class BackupPhraseScreen extends Component {
renderConfirmationScreen() { renderConfirmationScreen() {
const { seedWords, confirmSeedWords, next } = this.props; const { seedWords, confirmSeedWords, next } = this.props;
const { selectedSeeds } = this.state; const { selectedSeeds, shuffledSeeds } = this.state;
const isValid = seedWords === selectedSeeds.join(' ') const isValid = seedWords === selectedSeeds.map(([_, seed]) => seed).join(' ')
return ( return (
<div className="backup-phrase__content-wrapper"> <div className="backup-phrase__content-wrapper">
@ -136,7 +145,7 @@ class BackupPhraseScreen extends Component {
Please select each phrase in order to make sure it is correct. Please select each phrase in order to make sure it is correct.
</div> </div>
<div className="backup-phrase__confirm-secret"> <div className="backup-phrase__confirm-secret">
{selectedSeeds.map((word, i) => ( {selectedSeeds.map(([_, word], i) => (
<button <button
key={i} key={i}
className="backup-phrase__confirm-seed-option" className="backup-phrase__confirm-seed-option"
@ -146,8 +155,11 @@ class BackupPhraseScreen extends Component {
))} ))}
</div> </div>
<div className="backup-phrase__confirm-seed-options"> <div className="backup-phrase__confirm-seed-options">
{seedWords.split(' ').map((word, i) => { {shuffledSeeds.map((word, i) => {
const isSelected = selectedSeeds.includes(word) const isSelected = selectedSeeds
.filter(([index, seed]) => seed === word && index === i)
.length
return ( return (
<button <button
key={i} key={i}
@ -157,11 +169,12 @@ class BackupPhraseScreen extends Component {
onClick={() => { onClick={() => {
if (!isSelected) { if (!isSelected) {
this.setState({ this.setState({
selectedSeeds: [...selectedSeeds, word] selectedSeeds: [...selectedSeeds, [i, word]]
}) })
} else { } else {
this.setState({ this.setState({
selectedSeeds: selectedSeeds.filter(seed => seed !== word) selectedSeeds: selectedSeeds
.filter(([index, seed]) => !(seed === word && index === i))
}) })
} }
}} }}
@ -225,7 +238,9 @@ class BackupPhraseScreen extends Component {
} }
} }
export default connect( export default compose(
onlyUpdateForPropTypes,
connect(
({ metamask: { selectedAddress, seedWords }, appState: { isLoading } }) => ({ ({ metamask: { selectedAddress, seedWords }, appState: { isLoading } }) => ({
seedWords, seedWords,
isLoading, isLoading,
@ -234,4 +249,5 @@ export default connect(
dispatch => ({ dispatch => ({
confirmSeedWords: () => dispatch(confirmSeedWords()) confirmSeedWords: () => dispatch(confirmSeedWords())
}) })
)
)(BackupPhraseScreen) )(BackupPhraseScreen)

View File

@ -52,7 +52,7 @@ class FirstTimeFlow extends Component {
} = this.props; } = this.props;
const {SCREEN_TYPE} = FirstTimeFlow const {SCREEN_TYPE} = FirstTimeFlow
// return SCREEN_TYPE.IMPORT_ACCOUNT // return SCREEN_TYPE.BACK_UP_PHRASE
if (!isInitialized) { if (!isInitialized) {
return SCREEN_TYPE.CREATE_PASSWORD return SCREEN_TYPE.CREATE_PASSWORD

View File

@ -102,6 +102,9 @@
"jazzicon": "^1.2.0", "jazzicon": "^1.2.0",
"json-rpc-engine": "^3.2.0", "json-rpc-engine": "^3.2.0",
"json-rpc-middleware-stream": "^1.0.1", "json-rpc-middleware-stream": "^1.0.1",
"lodash.debounce": "^4.0.8",
"lodash.memoize": "^4.1.2",
"lodash.shuffle": "^4.2.0",
"loglevel": "^1.4.1", "loglevel": "^1.4.1",
"metamascara": "^1.3.1", "metamascara": "^1.3.1",
"metamask-logo": "^2.1.2", "metamask-logo": "^2.1.2",

View File

@ -440,9 +440,9 @@ App.prototype.renderPrimary = function () {
var props = this.props var props = this.props
const {isMascara, isOnboarding} = props const {isMascara, isOnboarding} = props
// if (isMascara && isOnboarding) { if (isMascara && isOnboarding) {
// return h(MascaraFirstTime) return h(MascaraFirstTime)
// } }
// notices // notices
if (!props.noActiveNotices) { if (!props.noActiveNotices) {