Remove more unused components

This commit is contained in:
Victor Baranov 2019-09-03 22:57:32 +03:00
parent 4bce1e4678
commit de56056df4
12 changed files with 1 additions and 1376 deletions

View File

@ -1,6 +1,6 @@
const assert = require('assert')
const currencyFormatter = require('currency-formatter')
const infuraConversion = require('../../ui/app/infura-conversion.json')
const infuraConversion = require('../../old-ui/app/infura-conversion.json')
describe('currencyFormatting', function () {
it('be able to format any infura currency', function (done) {

View File

@ -1,225 +0,0 @@
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const { withRouter } = require('react-router-dom')
const { compose } = require('recompose')
const actions = require('./actions')
const txHelper = require('../lib/tx-helper')
const log = require('loglevel')
const R = require('ramda')
const SignatureRequest = require('./components/signature-request')
const Loading = require('./components/loading-screen')
const { DEFAULT_ROUTE } = require('./routes')
const { getMetaMaskAccounts } = require('./selectors')
module.exports = compose(
withRouter,
connect(mapStateToProps)
)(ConfirmTxScreen)
function mapStateToProps (state) {
const { metamask } = state
const {
unapprovedMsgCount,
unapprovedPersonalMsgCount,
unapprovedTypedMessagesCount,
} = metamask
return {
identities: state.metamask.identities,
accounts: getMetaMaskAccounts(state),
selectedAddress: state.metamask.selectedAddress,
unapprovedTxs: state.metamask.unapprovedTxs,
unapprovedMsgs: state.metamask.unapprovedMsgs,
unapprovedPersonalMsgs: state.metamask.unapprovedPersonalMsgs,
unapprovedTypedMessages: state.metamask.unapprovedTypedMessages,
index: state.appState.currentView.context,
warning: state.appState.warning,
network: state.metamask.network,
provider: state.metamask.provider,
conversionRate: state.metamask.conversionRate,
currentCurrency: state.metamask.currentCurrency,
blockGasLimit: state.metamask.currentBlockGasLimit,
computedBalances: state.metamask.computedBalances,
unapprovedMsgCount,
unapprovedPersonalMsgCount,
unapprovedTypedMessagesCount,
send: state.metamask.send,
selectedAddressTxList: state.metamask.selectedAddressTxList,
}
}
inherits(ConfirmTxScreen, Component)
function ConfirmTxScreen () {
Component.call(this)
}
ConfirmTxScreen.prototype.getUnapprovedMessagesTotal = function () {
const {
unapprovedMsgCount = 0,
unapprovedPersonalMsgCount = 0,
unapprovedTypedMessagesCount = 0,
} = this.props
return unapprovedTypedMessagesCount + unapprovedMsgCount + unapprovedPersonalMsgCount
}
ConfirmTxScreen.prototype.componentDidMount = function () {
const {
unapprovedTxs = {},
network,
send,
} = this.props
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
if (unconfTxList.length === 0 && !send.to && this.getUnapprovedMessagesTotal() === 0) {
this.props.history.push(DEFAULT_ROUTE)
}
}
ConfirmTxScreen.prototype.componentDidUpdate = function (prevProps) {
const {
unapprovedTxs = {},
network,
selectedAddressTxList,
send,
history,
match: { params: { id: transactionId } = {} },
} = this.props
let prevTx
if (transactionId) {
prevTx = R.find(({ id }) => id + '' === transactionId)(selectedAddressTxList)
} else {
const { index: prevIndex, unapprovedTxs: prevUnapprovedTxs } = prevProps
const prevUnconfTxList = txHelper(prevUnapprovedTxs, {}, {}, {}, network)
const prevTxData = prevUnconfTxList[prevIndex] || {}
prevTx = selectedAddressTxList.find(({ id }) => id === prevTxData.id) || {}
}
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
if (prevTx && prevTx.status === 'dropped') {
this.props.dispatch(actions.showModal({
name: 'TRANSACTION_CONFIRMED',
onSubmit: () => history.push(DEFAULT_ROUTE),
}))
return
}
if (unconfTxList.length === 0 && !send.to && this.getUnapprovedMessagesTotal() === 0) {
this.props.history.push(DEFAULT_ROUTE)
}
}
ConfirmTxScreen.prototype.getTxData = function () {
const {
network,
index,
unapprovedTxs,
unapprovedMsgs,
unapprovedPersonalMsgs,
unapprovedTypedMessages,
match: { params: { id: transactionId } = {} },
} = this.props
const unconfTxList = txHelper(
unapprovedTxs,
unapprovedMsgs,
unapprovedPersonalMsgs,
unapprovedTypedMessages,
network
)
log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`)
return transactionId
? R.find(({ id }) => id + '' === transactionId)(unconfTxList)
: unconfTxList[index]
}
ConfirmTxScreen.prototype.render = function () {
const props = this.props
const {
currentCurrency,
conversionRate,
blockGasLimit,
} = props
var txData = this.getTxData() || {}
const { msgParams } = txData
log.debug('msgParams detected, rendering pending msg')
return msgParams
? h(SignatureRequest, {
// Properties
txData: txData,
key: txData.id,
selectedAddress: props.selectedAddress,
accounts: props.accounts,
identities: props.identities,
conversionRate,
currentCurrency,
blockGasLimit,
// Actions
signMessage: this.signMessage.bind(this, txData),
signPersonalMessage: this.signPersonalMessage.bind(this, txData),
signTypedMessage: this.signTypedMessage.bind(this, txData),
cancelMessage: this.cancelMessage.bind(this, txData),
cancelPersonalMessage: this.cancelPersonalMessage.bind(this, txData),
cancelTypedMessage: this.cancelTypedMessage.bind(this, txData),
})
: h(Loading)
}
ConfirmTxScreen.prototype.signMessage = function (msgData, event) {
log.info('conf-tx.js: signing message')
var params = msgData.msgParams
params.metamaskId = msgData.id
this.stopPropagation(event)
return this.props.dispatch(actions.signMsg(params))
}
ConfirmTxScreen.prototype.stopPropagation = function (event) {
if (event.stopPropagation) {
event.stopPropagation()
}
}
ConfirmTxScreen.prototype.signPersonalMessage = function (msgData, event) {
log.info('conf-tx.js: signing personal message')
var params = msgData.msgParams
params.metamaskId = msgData.id
this.stopPropagation(event)
return this.props.dispatch(actions.signPersonalMsg(params))
}
ConfirmTxScreen.prototype.signTypedMessage = function (msgData, event) {
log.info('conf-tx.js: signing typed message')
var params = msgData.msgParams
params.metamaskId = msgData.id
this.stopPropagation(event)
return this.props.dispatch(actions.signTypedMsg(params))
}
ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) {
log.info('canceling message')
this.stopPropagation(event)
return this.props.dispatch(actions.cancelMsg(msgData))
}
ConfirmTxScreen.prototype.cancelPersonalMessage = function (msgData, event) {
log.info('canceling personal message')
this.stopPropagation(event)
return this.props.dispatch(actions.cancelPersonalMsg(msgData))
}
ConfirmTxScreen.prototype.cancelTypedMessage = function (msgData, event) {
log.info('canceling typed message')
this.stopPropagation(event)
return this.props.dispatch(actions.cancelTypedMsg(msgData))
}

View File

@ -1 +0,0 @@
export { default } from './with-method-data.component'

View File

@ -1,52 +0,0 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { getMethodData } from '../../helpers/transactions.util'
export default function withMethodData (WrappedComponent) {
return class MethodDataWrappedComponent extends PureComponent {
static propTypes = {
transaction: PropTypes.object,
}
static defaultProps = {
transaction: {},
}
state = {
methodData: {},
done: false,
error: null,
}
componentDidMount () {
this.fetchMethodData()
}
async fetchMethodData () {
const { transaction } = this.props
const { txParams: { data = '' } = {} } = transaction
if (data) {
try {
const methodData = await getMethodData(data)
this.setState({ methodData, done: true })
} catch (error) {
this.setState({ done: true, error })
}
} else {
this.setState({ done: true })
}
}
render () {
const { methodData, done, error } = this.state
return (
<WrappedComponent
{ ...this.props }
methodData={{ data: methodData, done, error }}
/>
)
}
}
}

View File

@ -1 +0,0 @@
export { default } from './with-modal-props'

View File

@ -1,43 +0,0 @@
import assert from 'assert'
import configureMockStore from 'redux-mock-store'
import { mount } from 'enzyme'
import React from 'react'
import withModalProps from '../with-modal-props'
const mockState = {
appState: {
modal: {
modalState: {
props: {
prop1: 'prop1',
prop2: 2,
prop3: true,
},
},
},
},
}
describe('withModalProps', () => {
it('should return a component wrapped with modal state props', () => {
const TestComponent = props => (
<div className="test">Testing</div>
)
const WrappedComponent = withModalProps(TestComponent)
const store = configureMockStore()(mockState)
const wrapper = mount(
<WrappedComponent store={store} />
)
assert.ok(wrapper)
const testComponent = wrapper.find(TestComponent).at(0)
assert.equal(testComponent.length, 1)
assert.equal(testComponent.find('.test').text(), 'Testing')
const testComponentProps = testComponent.props()
assert.equal(testComponentProps.prop1, 'prop1')
assert.equal(testComponentProps.prop2, 2)
assert.equal(testComponentProps.prop3, true)
assert.equal(typeof testComponentProps.hideModal, 'function')
})
})

View File

@ -1,21 +0,0 @@
import { connect } from 'react-redux'
import { hideModal } from '../../actions'
const mapStateToProps = state => {
const { appState } = state
const { props: modalProps } = appState.modal.modalState
return {
...modalProps,
}
}
const mapDispatchToProps = dispatch => {
return {
hideModal: () => dispatch(hideModal()),
}
}
export default function withModalProps (Component) {
return connect(mapStateToProps, mapDispatchToProps)(Component)
}

View File

@ -1 +0,0 @@
export { default } from './with-token-tracker.component'

View File

@ -1,106 +0,0 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import TokenTracker from 'eth-token-watcher'
export default function withTokenTracker (WrappedComponent) {
return class TokenTrackerWrappedComponent extends Component {
static propTypes = {
userAddress: PropTypes.string.isRequired,
token: PropTypes.object.isRequired,
}
constructor (props) {
super(props)
this.state = {
string: '',
symbol: '',
error: null,
}
this.tracker = null
this.updateBalance = this.updateBalance.bind(this)
this.setError = this.setError.bind(this)
}
componentDidMount () {
this.createFreshTokenTracker()
}
componentDidUpdate (prevProps) {
const { userAddress: newAddress, token: { address: newTokenAddress } } = this.props
const { userAddress: oldAddress, token: { address: oldTokenAddress } } = prevProps
if ((oldAddress === newAddress) && (oldTokenAddress === newTokenAddress)) {
return
}
if ((!oldAddress || !newAddress) && (!oldTokenAddress || !newTokenAddress)) {
return
}
this.createFreshTokenTracker()
}
componentWillUnmount () {
this.removeListeners()
}
createFreshTokenTracker () {
this.removeListeners()
if (!global.ethereumProvider) {
return
}
const { userAddress, token } = this.props
this.tracker = new TokenTracker({
userAddress,
provider: global.ethereumProvider,
tokens: [token],
pollingInterval: 8000,
})
this.tracker.on('update', this.updateBalance)
this.tracker.on('error', this.setError)
this.tracker.updateBalances()
.then(() => this.updateBalance(this.tracker.serialize()))
.catch(error => this.setState({ error: error.message }))
}
setError (error) {
this.setState({ error })
}
updateBalance (tokens = []) {
if (!this.tracker.running) {
return
}
const [{ string, symbol }] = tokens
this.setState({ string, symbol, error: null })
}
removeListeners () {
if (this.tracker) {
this.tracker.stop()
this.tracker.removeListener('update', this.updateBalance)
this.tracker.removeListener('error', this.setError)
}
}
render () {
const { string, symbol, error } = this.state
return (
<WrappedComponent
{ ...this.props }
string={string}
symbol={symbol}
error={error}
/>
)
}
}
}

View File

@ -1,653 +0,0 @@
{
"objects": [
{
"symbol": "ethaud",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "aud",
"name": "Australian Dollar"
}
},
{
"symbol": "ethhkd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "hkd",
"name": "Hong Kong Dollar"
}
},
{
"symbol": "ethsgd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "sgd",
"name": "Singapore Dollar"
}
},
{
"symbol": "ethidr",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "idr",
"name": "Indonesian Rupiah"
}
},
{
"symbol": "ethphp",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "php",
"name": "Philippine Peso"
}
},
{
"symbol": "eth1st",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "1st",
"name": "FirstBlood"
}
},
{
"symbol": "ethadt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "adt",
"name": "adToken"
}
},
{
"symbol": "ethadx",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "adx",
"name": "AdEx"
}
},
{
"symbol": "ethant",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "ant",
"name": "Aragon"
}
},
{
"symbol": "ethbat",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "bat",
"name": "Basic Attention Token"
}
},
{
"symbol": "ethbnt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "bnt",
"name": "Bancor"
}
},
{
"symbol": "ethbtc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "btc",
"name": "Bitcoin"
}
},
{
"symbol": "ethcad",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "cad",
"name": "Canadian Dollar"
}
},
{
"symbol": "ethcfi",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "cfi",
"name": "Cofound.it"
}
},
{
"symbol": "ethcrb",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "crb",
"name": "CreditBit"
}
},
{
"symbol": "ethcvc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "cvc",
"name": "Civic"
}
},
{
"symbol": "ethdash",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "dash",
"name": "Dash"
}
},
{
"symbol": "ethdgd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "dgd",
"name": "DigixDAO"
}
},
{
"symbol": "ethetc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "etc",
"name": "Ethereum Classic"
}
},
{
"symbol": "etheur",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "eur",
"name": "Euro"
}
},
{
"symbol": "ethfun",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "fun",
"name": "FunFair"
}
},
{
"symbol": "ethgbp",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gbp",
"name": "Pound Sterling"
}
},
{
"symbol": "ethgno",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gno",
"name": "Gnosis"
}
},
{
"symbol": "ethgnt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gnt",
"name": "Golem"
}
},
{
"symbol": "ethgup",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gup",
"name": "Matchpool"
}
},
{
"symbol": "ethhmq",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "hmq",
"name": "Humaniq"
}
},
{
"symbol": "ethjpy",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "jpy",
"name": "Japanese Yen"
}
},
{
"symbol": "ethlgd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "lgd",
"name": "Legends Room"
}
},
{
"symbol": "ethlsk",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "lsk",
"name": "Lisk"
}
},
{
"symbol": "ethltc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "ltc",
"name": "Litecoin"
}
},
{
"symbol": "ethlun",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "lun",
"name": "Lunyr"
}
},
{
"symbol": "ethmco",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "mco",
"name": "Monaco"
}
},
{
"symbol": "ethmtl",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "mtl",
"name": "Metal"
}
},
{
"symbol": "ethmyst",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "myst",
"name": "Mysterium"
}
},
{
"symbol": "ethnmr",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "nmr",
"name": "Numeraire"
}
},
{
"symbol": "ethomg",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "omg",
"name": "OmiseGO"
}
},
{
"symbol": "ethpay",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "pay",
"name": "TenX"
}
},
{
"symbol": "ethptoy",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "ptoy",
"name": "Patientory"
}
},
{
"symbol": "ethqrl",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "qrl",
"name": "Quantum-Resistant Ledger"
}
},
{
"symbol": "ethqtum",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "qtum",
"name": "Qtum"
}
},
{
"symbol": "ethrep",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "rep",
"name": "Augur"
}
},
{
"symbol": "ethrlc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "rlc",
"name": "iEx.ec"
}
},
{
"symbol": "ethrub",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "rub",
"name": "Russian Ruble"
}
},
{
"symbol": "ethsc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "sc",
"name": "Siacoin"
}
},
{
"symbol": "ethsngls",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "sngls",
"name": "SingularDTV"
}
},
{
"symbol": "ethsnt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "snt",
"name": "Status"
}
},
{
"symbol": "ethsteem",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "steem",
"name": "Steem"
}
},
{
"symbol": "ethstorj",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "storj",
"name": "Storj"
}
},
{
"symbol": "ethtime",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "time",
"name": "ChronoBank"
}
},
{
"symbol": "ethtkn",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "tkn",
"name": "TokenCard"
}
},
{
"symbol": "ethtrst",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "trst",
"name": "WeTrust"
}
},
{
"symbol": "ethuah",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "uah",
"name": "Ukrainian Hryvnia"
}
},
{
"symbol": "ethusd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "usd",
"name": "United States Dollar"
}
},
{
"symbol": "ethwings",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "wings",
"name": "Wings"
}
},
{
"symbol": "ethxem",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xem",
"name": "NEM"
}
},
{
"symbol": "ethxlm",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xlm",
"name": "Stellar Lumen"
}
},
{
"symbol": "ethxmr",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xmr",
"name": "Monero"
}
},
{
"symbol": "ethxrp",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xrp",
"name": "Ripple"
}
},
{
"symbol": "ethzec",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "zec",
"name": "Zcash"
}
}
]
}

View File

@ -1,91 +0,0 @@
const inherits = require('util').inherits
const Component = require('react').Component
const connect = require('react-redux').connect
const h = require('react-hyperscript')
const actions = require('../../actions')
const exportAsFile = require('../../util').exportAsFile
module.exports = connect(mapStateToProps)(CreateVaultCompleteScreen)
inherits(CreateVaultCompleteScreen, Component)
function CreateVaultCompleteScreen () {
Component.call(this)
}
function mapStateToProps (state) {
return {
seed: state.appState.currentView.seedWords,
cachedSeed: state.metamask.seedWords,
}
}
CreateVaultCompleteScreen.prototype.render = function () {
var state = this.props
var seed = state.seed || state.cachedSeed || ''
return (
h('.initialize-screen.flex-column.flex-center.flex-grow', [
// // subtitle and nav
// h('.section-title.flex-row.flex-center', [
// h('h2.page-subtitle', 'Vault Created'),
// ]),
h('h3.flex-center.text-transform-uppercase', {
style: {
background: '#EBEBEB',
color: '#AEAEAE',
marginTop: 36,
marginBottom: 8,
width: '100%',
fontSize: '20px',
padding: 6,
},
}, [
'Vault Created',
]),
h('div', {
style: {
fontSize: '1em',
marginTop: '10px',
textAlign: 'center',
},
}, [
h('span.error', 'These 12 words are the only way to restore your Nifty Wallet accounts.\nSave them somewhere safe and secret.'),
]),
h('textarea.twelve-word-phrase', {
readOnly: true,
value: seed,
}),
h('button.primary', {
onClick: () => this.confirmSeedWords()
.then(account => this.showAccountDetail(account)),
style: {
margin: '24px',
fontSize: '0.9em',
marginBottom: '10px',
},
}, 'I\'ve copied it somewhere safe'),
h('button.primary', {
onClick: () => exportAsFile(`Nifty Wallet Seed Words`, seed),
style: {
margin: '10px',
fontSize: '0.9em',
},
}, 'Save Seed Words As File'),
])
)
}
CreateVaultCompleteScreen.prototype.confirmSeedWords = function () {
return this.props.dispatch(actions.confirmSeedWords())
}
CreateVaultCompleteScreen.prototype.showAccountDetail = function (account) {
return this.props.dispatch(actions.showAccountDetail(account))
}

View File

@ -1,181 +0,0 @@
const inherits = require('util').inherits
const PropTypes = require('prop-types')
const PersistentForm = require('../../../lib/persistent-form')
const connect = require('react-redux').connect
const h = require('react-hyperscript')
const actions = require('../../actions')
const log = require('loglevel')
RestoreVaultScreen.contextTypes = {
t: PropTypes.func,
}
module.exports = connect(mapStateToProps)(RestoreVaultScreen)
inherits(RestoreVaultScreen, PersistentForm)
function RestoreVaultScreen () {
PersistentForm.call(this)
}
function mapStateToProps (state) {
return {
warning: state.appState.warning,
forgottenPassword: state.appState.forgottenPassword,
}
}
RestoreVaultScreen.prototype.render = function () {
var state = this.props
this.persistentFormParentId = 'restore-vault-form'
return (
h('.initialize-screen.flex-column.flex-center.flex-grow', [
h('h3.flex-center.text-transform-uppercase', {
style: {
background: '#EBEBEB',
color: '#AEAEAE',
marginBottom: 24,
width: '100%',
fontSize: '20px',
padding: 6,
},
}, [
this.context.t('restoreVault'),
]),
// wallet seed entry
h('h3', this.context.t('walletSeed')),
h('textarea.twelve-word-phrase.letter-spacey', {
dataset: {
persistentFormId: 'wallet-seed',
},
placeholder: this.context.t('secretPhrase'),
}),
// password
h('input.large-input.letter-spacey', {
type: 'password',
id: 'password-box',
placeholder: this.context.t('newPassword8Chars'),
dataset: {
persistentFormId: 'password',
},
style: {
width: 260,
marginTop: 12,
},
}),
// confirm password
h('input.large-input.letter-spacey', {
type: 'password',
id: 'password-box-confirm',
placeholder: this.context.t('confirmPassword'),
onKeyPress: this.createOnEnter.bind(this),
dataset: {
persistentFormId: 'password-confirmation',
},
style: {
width: 260,
marginTop: 16,
},
}),
(state.warning) && (
h('span.error.in-progress-notification', state.warning)
),
// submit
h('.flex-row.flex-space-between', {
style: {
marginTop: 30,
width: '50%',
},
}, [
// cancel
h('button.primary', {
onClick: this.showInitializeMenu.bind(this),
style: {
textTransform: 'uppercase',
},
}, this.context.t('cancel')),
// submit
h('button.primary', {
onClick: this.createNewVaultAndRestore.bind(this),
style: {
textTransform: 'uppercase',
},
}, this.context.t('ok')),
]),
])
)
}
RestoreVaultScreen.prototype.showInitializeMenu = function () {
const { dispatch, forgottenPassword } = this.props
dispatch(actions.unMarkPasswordForgotten())
.then(() => {
if (forgottenPassword) {
dispatch(actions.backToUnlockView())
} else {
dispatch(actions.showInitializeMenu())
}
})
}
RestoreVaultScreen.prototype.createOnEnter = function (event) {
if (event.key === 'Enter') {
this.createNewVaultAndRestore()
}
}
RestoreVaultScreen.prototype.createNewVaultAndRestore = function () {
// check password
var passwordBox = document.getElementById('password-box')
var password = passwordBox.value
var passwordConfirmBox = document.getElementById('password-box-confirm')
var passwordConfirm = passwordConfirmBox.value
if (password.length < 8) {
this.warning = this.context.t('passwordNotLongEnough')
this.props.dispatch(actions.displayWarning(this.warning))
return
}
if (password !== passwordConfirm) {
this.warning = this.context.t('passwordsDontMatch')
this.props.dispatch(actions.displayWarning(this.warning))
return
}
// check seed
var seedBox = document.querySelector('textarea.twelve-word-phrase')
var seed = seedBox.value.trim()
// true if the string has more than a space between words.
if (seed.split(' ').length > 1) {
this.warning = this.context.t('spaceBetween')
this.props.dispatch(actions.displayWarning(this.warning))
return
}
// true if seed contains a character that is not between a-z or a space
if (!seed.match(/^[a-z ]+$/)) {
this.warning = this.context.t('loweCaseWords')
this.props.dispatch(actions.displayWarning(this.warning))
return
}
if (seed.split(' ').length !== 12) {
this.warning = this.context.t('seedPhraseReq')
this.props.dispatch(actions.displayWarning(this.warning))
return
}
// submit
this.warning = null
this.props.dispatch(actions.displayWarning(this.warning))
this.props.dispatch(actions.createNewVaultAndRestore(password, seed))
.catch(err => log.error(err.message))
}