aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pages/first-time-flow/seed-phrase/reveal-seed-phrase/reveal-seed-phrase.component.js
blob: bb822d1d57bfa6325fdef80fe56e9e73fafd154a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import Identicon from '../../../../identicon'
import LockIcon from '../../../../lock-icon'
import Button from '../../../../button'
import Breadcrumbs from '../../../../breadcrumbs'
import { INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE } from '../../../../../routes'
import { exportAsFile } from '../../../../../../app/util'

export default class RevealSeedPhrase extends PureComponent {
  static contextTypes = {
    t: PropTypes.func,
  }

  static propTypes = {
    address: PropTypes.string,
    history: PropTypes.object,
    seedPhrase: PropTypes.string,
  }

  state = {
    isShowingSeedPhrase: false,
  }

  handleExport = () => {
    exportAsFile('MetaMask Secret Backup Phrase', this.props.seedPhrase, 'text/plain')
  }

  handleNext = event => {
    event.preventDefault()
    const { isShowingSeedPhrase } = this.state
    const { history } = this.props

    if (!isShowingSeedPhrase) {
      return
    }

    history.push(INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE)
  }

  renderSecretWordsContainer () {
    const { t } = this.context
    const { seedPhrase } = this.props
    const { isShowingSeedPhrase } = this.state

    return (
      <div className="reveal-seed-phrase__secret">
        <div className={classnames(
          'reveal-seed-phrase__secret-words',
          { 'reveal-seed-phrase__secret-words--hidden': !isShowingSeedPhrase }
        )}>
          { seedPhrase }
        </div>
        {
          !isShowingSeedPhrase && (
            <div
              className="reveal-seed-phrase__secret-blocker"
              onClick={() => this.setState({ isShowingSeedPhrase: true })}
            >
              <LockIcon
                width="28px"
                height="35px"
                fill="#FFFFFF"
              />
              <div className="reveal-seed-phrase__reveal-button">
                { t('clickToRevealSeed') }
              </div>
            </div>
          )
        }
      </div>
    )
  }

  render () {
    const { t } = this.context
    const { address } = this.props
    const { isShowingSeedPhrase } = this.state

    return (
      <div>
        <Identicon
          className="first-time-flow__unique-image"
          address={address}
          diameter={70}
        />
        <div className="seed-phrase__sections">
          <div className="seed-phrase__main">
            <div className="first-time-flow__header">
              { t('secretBackupPhrase') }
            </div>
            <div className="first-time-flow__text-block">
              { t('secretBackupPhraseDescription') }
            </div>
            <div className="first-time-flow__text-block">
              { t('secretBackupPhraseWarning') }
            </div>
            { this.renderSecretWordsContainer() }
          </div>
          <div className="seed-phrase__side">
            <div className="first-time-flow__text-block">
              { `${t('tips')}:` }
            </div>
            <div className="first-time-flow__text-block">
              { t('storePhrase') }
            </div>
            <div className="first-time-flow__text-block">
              { t('writePhrase') }
            </div>
            <div className="first-time-flow__text-block">
              { t('memorizePhrase') }
            </div>
            <div className="first-time-flow__text-block">
              <a
                className="reveal-seed-phrase__export-text"
                onClick={this.handleExport}>
                { t('downloadSecretBackup') }
              </a>
            </div>
          </div>
        </div>
        <Button
          type="first-time"
          className="first-time-flow__button"
          onClick={this.handleNext}
          disabled={!isShowingSeedPhrase}
        >
          { t('next') }
        </Button>
        <Breadcrumbs
          className="first-time-flow__breadcrumbs"
          total={3}
          currentIndex={2}
        />
      </div>
    )
  }
}