1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/ui/app/components/pages/create-account/index.js

114 lines
3.4 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const { Switch, Route, matchPath } = require('react-router-dom')
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const actions = require('../../../actions')
const { getCurrentViewContext } = require('../../../selectors')
const classnames = require('classnames')
const NewAccountCreateForm = require('./new-account')
const NewAccountImportForm = require('./import-account')
2018-06-10 09:52:32 +02:00
const ConnectHardwareForm = require('./connect-hardware')
const {
NEW_ACCOUNT_ROUTE,
IMPORT_ACCOUNT_ROUTE,
2018-07-03 21:46:15 +02:00
CONNECT_HARDWARE_ROUTE,
2018-06-10 09:52:32 +02:00
} = require('../../../routes')
class CreateAccountPage extends Component {
renderTabs () {
const { history, location } = this.props
return h('div.new-account__tabs', [
h('div.new-account__tabs__tab', {
className: classnames('new-account__tabs__tab', {
'new-account__tabs__selected': matchPath(location.pathname, {
path: NEW_ACCOUNT_ROUTE, exact: true,
}),
}),
onClick: () => history.push(NEW_ACCOUNT_ROUTE),
2018-06-06 20:38:57 +02:00
}, [
this.context.t('create'),
]),
h('div.new-account__tabs__tab', {
className: classnames('new-account__tabs__tab', {
'new-account__tabs__selected': matchPath(location.pathname, {
path: IMPORT_ACCOUNT_ROUTE, exact: true,
}),
}),
onClick: () => history.push(IMPORT_ACCOUNT_ROUTE),
2018-06-06 20:38:57 +02:00
}, [
this.context.t('import'),
]),
2018-06-10 09:52:32 +02:00
h(
'div.new-account__tabs__tab',
{
className: classnames('new-account__tabs__tab', {
'new-account__tabs__selected': matchPath(location.pathname, {
path: CONNECT_HARDWARE_ROUTE,
exact: true,
}),
}),
onClick: () => history.push(CONNECT_HARDWARE_ROUTE),
},
this.context.t('connect')
),
])
}
render () {
return h('div.new-account', {}, [
h('div.new-account__header', [
2018-07-03 00:49:33 +02:00
h('div.new-account__title', this.context.t('newAccount')),
this.renderTabs(),
]),
h('div.new-account__form', [
h(Switch, [
h(Route, {
exact: true,
path: NEW_ACCOUNT_ROUTE,
component: NewAccountCreateForm,
}),
h(Route, {
exact: true,
path: IMPORT_ACCOUNT_ROUTE,
component: NewAccountImportForm,
}),
2018-06-10 09:52:32 +02:00
h(Route, {
exact: true,
path: CONNECT_HARDWARE_ROUTE,
component: ConnectHardwareForm,
}),
]),
]),
])
}
}
CreateAccountPage.propTypes = {
location: PropTypes.object,
history: PropTypes.object,
2018-06-06 20:38:57 +02:00
t: PropTypes.func,
}
CreateAccountPage.contextTypes = {
t: PropTypes.func,
}
const mapStateToProps = state => ({
displayedForm: getCurrentViewContext(state),
})
const mapDispatchToProps = dispatch => ({
displayForm: form => dispatch(actions.setNewAccountForm(form)),
showQrView: (selected, identity) => dispatch(actions.showQrView(selected, identity)),
showExportPrivateKeyModal: () => {
dispatch(actions.showModal({ name: 'EXPORT_PRIVATE_KEY' }))
},
hideModal: () => dispatch(actions.hideModal()),
setAccountLabel: (address, label) => dispatch(actions.setAccountLabel(address, label)),
})
module.exports = connect(mapStateToProps, mapDispatchToProps)(CreateAccountPage)