aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Stacey <markjstacey@gmail.com>2019-06-27 23:03:18 +0800
committerGitHub <noreply@github.com>2019-06-27 23:03:18 +0800
commit6d191f261793cfb1f935c5a4ac3d20a62bfe6540 (patch)
treec1bc62e513c7739a8f77813cfeb2853f81d359ab
parentb9f69b535fc8c23e2e2a81d7484d0115778ab5dd (diff)
downloadtangerine-wallet-browser-6d191f261793cfb1f935c5a4ac3d20a62bfe6540.tar.gz
tangerine-wallet-browser-6d191f261793cfb1f935c5a4ac3d20a62bfe6540.tar.zst
tangerine-wallet-browser-6d191f261793cfb1f935c5a4ac3d20a62bfe6540.zip
Refactor account-details-modal (#6751)
Refactor the AccountDetailsModal to follow newer conventions. Changes include: - Create a directory for the component with separate files for the component, the container, and the entrypoint. - Use jsx rather than hyperscript Fixes #6741
-rw-r--r--ui/app/components/app/modals/account-details-modal.js107
-rw-r--r--ui/app/components/app/modals/account-details-modal/account-details-modal.component.js87
-rw-r--r--ui/app/components/app/modals/account-details-modal/account-details-modal.container.js27
-rw-r--r--ui/app/components/app/modals/account-details-modal/index.js1
-rw-r--r--ui/app/components/app/modals/modal.js2
5 files changed, 116 insertions, 108 deletions
diff --git a/ui/app/components/app/modals/account-details-modal.js b/ui/app/components/app/modals/account-details-modal.js
deleted file mode 100644
index 6cffc918b..000000000
--- a/ui/app/components/app/modals/account-details-modal.js
+++ /dev/null
@@ -1,107 +0,0 @@
-const Component = require('react').Component
-const PropTypes = require('prop-types')
-const h = require('react-hyperscript')
-const inherits = require('util').inherits
-const connect = require('react-redux').connect
-const actions = require('../../../store/actions')
-const AccountModalContainer = require('./account-modal-container')
-const { getSelectedIdentity, getRpcPrefsForCurrentProvider } = require('../../../selectors/selectors')
-const genAccountLink = require('../../../../lib/account-link.js')
-const QrView = require('../../ui/qr-code')
-const EditableLabel = require('../../ui/editable-label')
-
-import Button from '../../ui/button'
-
-function mapStateToProps (state) {
- return {
- network: state.metamask.network,
- selectedIdentity: getSelectedIdentity(state),
- keyrings: state.metamask.keyrings,
- rpcPrefs: getRpcPrefsForCurrentProvider(state),
- }
-}
-
-function mapDispatchToProps (dispatch) {
- return {
- // Is this supposed to be used somewhere?
- 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)),
- }
-}
-
-inherits(AccountDetailsModal, Component)
-function AccountDetailsModal () {
- Component.call(this)
-}
-
-AccountDetailsModal.contextTypes = {
- t: PropTypes.func,
-}
-
-module.exports = connect(mapStateToProps, mapDispatchToProps)(AccountDetailsModal)
-
-
-// Not yet pixel perfect todos:
- // fonts of qr-header
-
-AccountDetailsModal.prototype.render = function () {
- const {
- selectedIdentity,
- network,
- showExportPrivateKeyModal,
- setAccountLabel,
- keyrings,
- rpcPrefs,
- } = this.props
- const { name, address } = selectedIdentity
-
- const keyring = keyrings.find((kr) => {
- return kr.accounts.includes(address)
- })
-
- let exportPrivateKeyFeatureEnabled = true
- // This feature is disabled for hardware wallets
- if (keyring && keyring.type.search('Hardware') !== -1) {
- exportPrivateKeyFeatureEnabled = false
- }
-
- return h(AccountModalContainer, {}, [
- h(EditableLabel, {
- className: 'account-modal__name',
- defaultValue: name,
- onSubmit: label => setAccountLabel(address, label),
- }),
-
- h(QrView, {
- Qr: {
- data: address,
- network: network,
- },
- }),
-
- h('div.account-modal-divider'),
-
- h(Button, {
- type: 'secondary',
- className: 'account-modal__button',
- onClick: () => {
- global.platform.openWindow({ url: genAccountLink(address, network, rpcPrefs) })
- },
- }, (rpcPrefs.blockExplorerUrl
- ? this.context.t('blockExplorerView', [rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/)[1]])
- : this.context.t('viewOnEtherscan'))),
-
- // Holding on redesign for Export Private Key functionality
-
- exportPrivateKeyFeatureEnabled ? h(Button, {
- type: 'secondary',
- className: 'account-modal__button',
- onClick: () => showExportPrivateKeyModal(),
- }, this.context.t('exportPrivateKey')) : null,
-
- ])
-}
diff --git a/ui/app/components/app/modals/account-details-modal/account-details-modal.component.js b/ui/app/components/app/modals/account-details-modal/account-details-modal.component.js
new file mode 100644
index 000000000..e3919edcf
--- /dev/null
+++ b/ui/app/components/app/modals/account-details-modal/account-details-modal.component.js
@@ -0,0 +1,87 @@
+import React, { Component} from 'react'
+import PropTypes from 'prop-types'
+import AccountModalContainer from '../account-modal-container'
+import genAccountLink from '../../../../../lib/account-link.js'
+import QrView from '../../../ui/qr-code'
+import EditableLabel from '../../../ui/editable-label'
+import Button from '../../../ui/button'
+
+export default class AccountDetailsModal extends Component {
+ static propTypes = {
+ selectedIdentity: PropTypes.object,
+ network: PropTypes.string,
+ showExportPrivateKeyModal: PropTypes.func,
+ setAccountLabel: PropTypes.func,
+ keyrings: PropTypes.array,
+ rpcPrefs: PropTypes.object,
+ }
+
+ static contextTypes = {
+ t: PropTypes.func,
+ }
+
+ render () {
+ const {
+ selectedIdentity,
+ network,
+ showExportPrivateKeyModal,
+ setAccountLabel,
+ keyrings,
+ rpcPrefs,
+ } = this.props
+ const { name, address } = selectedIdentity
+
+ const keyring = keyrings.find((kr) => {
+ return kr.accounts.includes(address)
+ })
+
+ let exportPrivateKeyFeatureEnabled = true
+ // This feature is disabled for hardware wallets
+ if (keyring && keyring.type.search('Hardware') !== -1) {
+ exportPrivateKeyFeatureEnabled = false
+ }
+
+ return (
+ <AccountModalContainer>
+ <EditableLabel
+ className="account-modal__name"
+ defaultValue={name}
+ onSubmit={label => setAccountLabel(address, label)}
+ />
+
+ <QrView
+ Qr={{
+ data: address,
+ network: network,
+ }}
+ />
+
+ <div className="account-modal-divider"/>
+
+ <Button
+ type="secondary"
+ className="account-modal__button"
+ onClick={() => {
+ global.platform.openWindow({ url: genAccountLink(address, network, rpcPrefs) })
+ }}
+ >
+ {rpcPrefs.blockExplorerUrl
+ ? this.context.t('blockExplorerView', [rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/)[1]])
+ : this.context.t('viewOnEtherscan')
+ }
+ </Button>
+
+ {exportPrivateKeyFeatureEnabled
+ ? <Button
+ type="secondary"
+ className="account-modal__button"
+ onClick={() => showExportPrivateKeyModal()}
+ >
+ {this.context.t('exportPrivateKey')}
+ </Button>
+ : null
+ }
+ </AccountModalContainer>
+ )
+ }
+}
diff --git a/ui/app/components/app/modals/account-details-modal/account-details-modal.container.js b/ui/app/components/app/modals/account-details-modal/account-details-modal.container.js
new file mode 100644
index 000000000..4b2283ced
--- /dev/null
+++ b/ui/app/components/app/modals/account-details-modal/account-details-modal.container.js
@@ -0,0 +1,27 @@
+import { connect } from 'react-redux'
+import actions from '../../../../store/actions'
+import { getSelectedIdentity, getRpcPrefsForCurrentProvider } from '../../../../selectors/selectors'
+import AccountDetailsModal from './account-details-modal.component'
+
+const mapStateToProps = (state) => {
+ return {
+ network: state.metamask.network,
+ selectedIdentity: getSelectedIdentity(state),
+ keyrings: state.metamask.keyrings,
+ rpcPrefs: getRpcPrefsForCurrentProvider(state),
+ }
+}
+
+const mapDispatchToProps = (dispatch) => {
+ return {
+ // Is this supposed to be used somewhere?
+ 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)),
+ }
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(AccountDetailsModal)
diff --git a/ui/app/components/app/modals/account-details-modal/index.js b/ui/app/components/app/modals/account-details-modal/index.js
new file mode 100644
index 000000000..433f4d170
--- /dev/null
+++ b/ui/app/components/app/modals/account-details-modal/index.js
@@ -0,0 +1 @@
+export { default } from './account-details-modal.container'
diff --git a/ui/app/components/app/modals/modal.js b/ui/app/components/app/modals/modal.js
index 90432da96..394367c46 100644
--- a/ui/app/components/app/modals/modal.js
+++ b/ui/app/components/app/modals/modal.js
@@ -12,7 +12,7 @@ const { ENVIRONMENT_TYPE_POPUP } = require('../../../../../app/scripts/lib/enums
// Modal Components
const BuyOptions = require('./buy-options-modal')
const DepositEtherModal = require('./deposit-ether-modal')
-const AccountDetailsModal = require('./account-details-modal')
+import AccountDetailsModal from './account-details-modal'
const EditAccountNameModal = require('./edit-account-name-modal')
const ExportPrivateKeyModal = require('./export-private-key-modal')
const NewAccountModal = require('./new-account-modal')