diff options
author | Christopher Cooper <christopher.c.cooper@gmail.com> | 2019-08-02 20:36:31 +0800 |
---|---|---|
committer | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2019-08-02 20:36:31 +0800 |
commit | b7eae4ba80e06f1d2069575d9b96dae66ea4496f (patch) | |
tree | 5de1326a5e7c5a1e8c2be5ffc803677dd5a3a03e | |
parent | 3eff4787757ac22d0a469c91599cdcfd97a2a98c (diff) | |
download | tangerine-wallet-browser-b7eae4ba80e06f1d2069575d9b96dae66ea4496f.tar tangerine-wallet-browser-b7eae4ba80e06f1d2069575d9b96dae66ea4496f.tar.gz tangerine-wallet-browser-b7eae4ba80e06f1d2069575d9b96dae66ea4496f.tar.bz2 tangerine-wallet-browser-b7eae4ba80e06f1d2069575d9b96dae66ea4496f.tar.lz tangerine-wallet-browser-b7eae4ba80e06f1d2069575d9b96dae66ea4496f.tar.xz tangerine-wallet-browser-b7eae4ba80e06f1d2069575d9b96dae66ea4496f.tar.zst tangerine-wallet-browser-b7eae4ba80e06f1d2069575d9b96dae66ea4496f.zip |
split AccountDetails into a separate component (#6943)
-rw-r--r-- | test/e2e/from-import-ui.spec.js | 14 | ||||
-rw-r--r-- | test/e2e/metamask-ui.spec.js | 4 | ||||
-rw-r--r-- | ui/app/components/app/account-details/account-details.component.js | 99 | ||||
-rw-r--r-- | ui/app/components/app/account-details/account-details.container.js | 14 | ||||
-rw-r--r-- | ui/app/components/app/account-details/index.js | 1 | ||||
-rw-r--r-- | ui/app/components/app/account-details/index.scss | 79 | ||||
-rw-r--r-- | ui/app/components/app/index.scss | 2 | ||||
-rw-r--r-- | ui/app/components/app/wallet-view.js | 80 | ||||
-rw-r--r-- | ui/app/css/itcss/components/newui-sections.scss | 80 |
9 files changed, 210 insertions, 163 deletions
diff --git a/test/e2e/from-import-ui.spec.js b/test/e2e/from-import-ui.spec.js index 82e811c86..e420f03ed 100644 --- a/test/e2e/from-import-ui.spec.js +++ b/test/e2e/from-import-ui.spec.js @@ -159,7 +159,7 @@ describe('Using MetaMask with an existing account', function () { describe('Show account information', () => { it('shows the correct account address', async () => { - await driver.findElement(By.css('.wallet-view__details-button')).click() + await driver.findElement(By.css('.account-details__details-button')).click() await driver.findElement(By.css('.qr-wrapper')).isDisplayed() await delay(regularDelayMs) @@ -171,7 +171,7 @@ describe('Using MetaMask with an existing account', function () { }) it('shows a QR code for the account', async () => { - await driver.findElement(By.css('.wallet-view__details-button')).click() + await driver.findElement(By.css('.account-details__details-button')).click() await driver.findElement(By.css('.qr-wrapper')).isDisplayed() const detailModal = await driver.findElement(By.css('span .modal')) await delay(regularDelayMs) @@ -232,7 +232,7 @@ describe('Using MetaMask with an existing account', function () { }) it('should show the correct account name', async () => { - const [accountName] = await findElements(driver, By.css('.account-name')) + const [accountName] = await findElements(driver, By.css('.account-details__account-name')) assert.equal(await accountName.getText(), '2nd account') await delay(regularDelayMs) }) @@ -318,13 +318,13 @@ describe('Using MetaMask with an existing account', function () { }) it('should show the correct account name', async () => { - const [accountName] = await findElements(driver, By.css('.account-name')) + const [accountName] = await findElements(driver, By.css('.account-details__account-name')) assert.equal(await accountName.getText(), 'Account 4') await delay(regularDelayMs) }) it('should show the imported label', async () => { - const [importedLabel] = await findElements(driver, By.css('.wallet-view__keyring-label')) + const [importedLabel] = await findElements(driver, By.css('.account-details__keyring-label')) assert.equal(await importedLabel.getText(), 'IMPORTED') await delay(regularDelayMs) }) @@ -350,7 +350,7 @@ describe('Using MetaMask with an existing account', function () { }) it('should open the remove account modal', async () => { - const [accountName] = await findElements(driver, By.css('.account-name')) + const [accountName] = await findElements(driver, By.css('.account-details__account-name')) assert.equal(await accountName.getText(), 'Account 5') await delay(regularDelayMs) @@ -373,7 +373,7 @@ describe('Using MetaMask with an existing account', function () { await delay(regularDelayMs) - const [accountName] = await findElements(driver, By.css('.account-name')) + const [accountName] = await findElements(driver, By.css('.account-details__account-name')) assert.equal(await accountName.getText(), 'Account 1') await delay(regularDelayMs) diff --git a/test/e2e/metamask-ui.spec.js b/test/e2e/metamask-ui.spec.js index 5c3e807fd..ef1ec6d47 100644 --- a/test/e2e/metamask-ui.spec.js +++ b/test/e2e/metamask-ui.spec.js @@ -221,7 +221,7 @@ describe('MetaMask', function () { describe('Show account information', () => { it('shows the QR code for the account', async () => { - await driver.findElement(By.css('.wallet-view__details-button')).click() + await driver.findElement(By.css('.account-details__details-button')).click() await driver.findElement(By.css('.qr-wrapper')).isDisplayed() await delay(regularDelayMs) @@ -273,7 +273,7 @@ describe('MetaMask', function () { }) it('should display correct account name', async () => { - const accountName = await findElement(driver, By.css('.account-name')) + const accountName = await findElement(driver, By.css('.account-details__account-name')) assert.equal(await accountName.getText(), '2nd account') await delay(regularDelayMs) }) diff --git a/ui/app/components/app/account-details/account-details.component.js b/ui/app/components/app/account-details/account-details.component.js new file mode 100644 index 000000000..ecf2f9428 --- /dev/null +++ b/ui/app/components/app/account-details/account-details.component.js @@ -0,0 +1,99 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import classnames from 'classnames' +import Identicon from '../../ui/identicon' +import Tooltip from '../../ui/tooltip-v2' +import copyToClipboard from 'copy-to-clipboard' + +export default class AccountDetails extends Component { + static contextTypes = { + t: PropTypes.func.isRequired, + metricsEvent: PropTypes.func, + } + + static defaultProps = { + hideSidebar: () => {}, + showAccountDetailModal: () => {}, + } + + static propTypes = { + hideSidebar: PropTypes.func, + showAccountDetailModal: PropTypes.func, + label: PropTypes.string.isRequired, + checksummedAddress: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + } + + state = { + hasCopied: false, + copyToClipboardPressed: false, + } + + copyAddress () { + copyToClipboard(this.props.checksummedAddress) + this.context.metricsEvent({ + eventOpts: { + category: 'Navigation', + action: 'Home', + name: 'Copied Address', + }, + }) + this.setState({ hasCopied: true }) + setTimeout(() => this.setState({ hasCopied: false }), 3000) + } + + render () { + const { t } = this.context + + const { + hideSidebar, + showAccountDetailModal, + label, + checksummedAddress, + name, + } = this.props + + const { + hasCopied, + copyToClipboardPressed, + } = this.state + + return ( + <div> + <div className="flex-column account-details"> + <div className="account-details__sidebar-close" onClick={hideSidebar} /> + <div className="account-details__keyring-label allcaps"> + {label} + </div> + <div className="flex-column flex-center account-details__name-container" onClick={showAccountDetailModal}> + <Identicon diameter={54} address={checksummedAddress} /> + <span className="account-details__account-name"> + {name} + </span> + <button className="btn-secondary account-details__details-button"> + {t('details')} + </button> + </div> + </div> + <Tooltip + position={'bottom'} + title={hasCopied ? t('copiedExclamation') : t('copyToClipboard')} + wrapperClassName="account-details__tooltip" + > + <button + className={classnames({ + 'account-details__address': true, + 'account-details__address__pressed': copyToClipboardPressed, + })} + onClick={() => this.copyAddress()} + onMouseDown={() => this.setState({ copyToClipboardPressed: true })} + onMouseUp={() => this.setState({ copyToClipboardPressed: false })} + > + {checksummedAddress.slice(0, 6)}...{checksummedAddress.slice(-4)} + <i className="fa fa-clipboard" style={{ marginLeft: '8px' }} /> + </button> + </Tooltip> + </div> + ) + } +} diff --git a/ui/app/components/app/account-details/account-details.container.js b/ui/app/components/app/account-details/account-details.container.js new file mode 100644 index 000000000..581ff1e2f --- /dev/null +++ b/ui/app/components/app/account-details/account-details.container.js @@ -0,0 +1,14 @@ +import { connect } from 'react-redux' +import { hideSidebar, showModal } from '../../../store/actions' +import AccountDetails from './account-details.component' + +function mapDispatchToProps (dispatch) { + return { + hideSidebar: () => dispatch(hideSidebar()), + showAccountDetailModal: () => { + dispatch(showModal({ name: 'ACCOUNT_DETAILS' })) + }, + } +} + +export default connect(null, mapDispatchToProps)(AccountDetails) diff --git a/ui/app/components/app/account-details/index.js b/ui/app/components/app/account-details/index.js new file mode 100644 index 000000000..dca244fee --- /dev/null +++ b/ui/app/components/app/account-details/index.js @@ -0,0 +1 @@ +export { default } from './account-details.container' diff --git a/ui/app/components/app/account-details/index.scss b/ui/app/components/app/account-details/index.scss new file mode 100644 index 000000000..b0a921df3 --- /dev/null +++ b/ui/app/components/app/account-details/index.scss @@ -0,0 +1,79 @@ +.account-details { + flex: 0 0 auto; + + &__keyring-label { + height: 50px; + color: $dusty-gray; + font-family: Roboto; + font-size: 10px; + text-align: right; + padding: 17px 20px 0; + box-sizing: border-box; + } + + &__name-container { + flex: 0 0 auto; + cursor: pointer; + width: 100%; + margin: 0 auto; + } + + &__account-name { + font-size: 24px; + color: $black; + margin-top: 8px; + margin-bottom: .9rem; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + width: 100%; + padding: 0 8px; + text-align: center; + } + + &__details-button { + font-size: 10px; + border-radius: 17px; + background-color: transparent; + margin: 0 auto; + padding: 4px 12px; + flex: 0 0 auto; + } + + &__tooltip { + display: flex; + justify-content: center; + align-items: center; + padding: 24px; + } + + &__address { + border-radius: 3px; + background-color: $alto; + color: $scorpion; + font-size: 14px; + line-height: 12px; + padding: 4px 12px; + cursor: pointer; + flex: 0 0 auto; + + &__pressed { + background-color: $manatee, + } + } + + &__sidebar-close { + + @media screen and (max-width: 575px) { + &::after { + content: '\00D7'; + font-size: 40px; + color: $tundora; + position: absolute; + top: 12px; + left: 12px; + cursor: pointer; + } + } + } +} diff --git a/ui/app/components/app/index.scss b/ui/app/components/app/index.scss index 1f70ba974..09a97ac28 100644 --- a/ui/app/components/app/index.scss +++ b/ui/app/components/app/index.scss @@ -1,3 +1,5 @@ +@import 'account-details/index'; + @import 'account-menu/index'; @import 'add-token-button/index'; diff --git a/ui/app/components/app/wallet-view.js b/ui/app/components/app/wallet-view.js index b8bae5421..55aeec333 100644 --- a/ui/app/components/app/wallet-view.js +++ b/ui/app/components/app/wallet-view.js @@ -5,12 +5,8 @@ const h = require('react-hyperscript') const { withRouter } = require('react-router-dom') const { compose } = require('recompose') const inherits = require('util').inherits -const classnames = require('classnames') const { checksumAddress } = require('../../helpers/utils/util') -import Identicon from '../ui/identicon' // const AccountDropdowns = require('./dropdowns/index.js').AccountDropdowns -const Tooltip = require('../ui/tooltip-v2.js').default -const copyToClipboard = require('copy-to-clipboard') const actions = require('../../store/actions') import BalanceComponent from '../ui/balance' const TokenList = require('./token-list') @@ -18,6 +14,7 @@ const selectors = require('../../selectors/selectors') const { ADD_TOKEN_ROUTE } = require('../../helpers/constants/routes') import AddTokenButton from './add-token-button' +import AccountDetails from './account-details' module.exports = compose( withRouter, @@ -52,9 +49,6 @@ function mapDispatchToProps (dispatch) { showSendPage: () => dispatch(actions.showSendPage()), hideSidebar: () => dispatch(actions.hideSidebar()), unsetSelectedToken: () => dispatch(actions.setSelectedToken()), - showAccountDetailModal: () => { - dispatch(actions.showModal({ name: 'ACCOUNT_DETAILS' })) - }, showAddTokenPage: () => dispatch(actions.showAddTokenPage()), } } @@ -62,10 +56,6 @@ function mapDispatchToProps (dispatch) { inherits(WalletView, Component) function WalletView () { Component.call(this) - this.state = { - hasCopied: false, - copyToClipboardPressed: false, - } } WalletView.prototype.renderWalletBalance = function () { @@ -130,8 +120,6 @@ WalletView.prototype.render = function () { responsiveDisplayClassname, selectedAddress, keyrings, - showAccountDetailModal, - hideSidebar, identities, network, } = this.props @@ -165,67 +153,11 @@ WalletView.prototype.render = function () { className: responsiveDisplayClassname, }, [ - // TODO: Separate component: wallet account details - h('div.flex-column.wallet-view-account-details', { - style: {}, - }, [ - h('div.wallet-view__sidebar-close', { - onClick: hideSidebar, - }), - - h('div.wallet-view__keyring-label.allcaps', label), - - h('div.flex-column.flex-center.wallet-view__name-container', { - style: { margin: '0 auto' }, - onClick: showAccountDetailModal, - }, [ - h(Identicon, { - diameter: 54, - address: checksummedAddress, - }), - - h('span.account-name', { - style: {}, - }, [ - identities[selectedAddress].name, - ]), - - h('button.btn-secondary.wallet-view__details-button', this.context.t('details')), - ]), - ]), - - h(Tooltip, { - position: 'bottom', - title: this.state.hasCopied ? this.context.t('copiedExclamation') : this.context.t('copyToClipboard'), - wrapperClassName: 'wallet-view__tooltip', - }, [ - h('button.wallet-view__address', { - className: classnames({ - 'wallet-view__address__pressed': this.state.copyToClipboardPressed, - }), - onClick: () => { - copyToClipboard(checksummedAddress) - this.context.metricsEvent({ - eventOpts: { - category: 'Navigation', - action: 'Home', - name: 'Copied Address', - }, - }) - this.setState({ hasCopied: true }) - setTimeout(() => this.setState({ hasCopied: false }), 3000) - }, - onMouseDown: () => { - this.setState({ copyToClipboardPressed: true }) - }, - onMouseUp: () => { - this.setState({ copyToClipboardPressed: false }) - }, - }, [ - `${checksummedAddress.slice(0, 6)}...${checksummedAddress.slice(-4)}`, - h('i.fa.fa-clipboard', { style: { marginLeft: '8px' } }), - ]), - ]), + h(AccountDetails, { + label, + checksummedAddress, + name: identities[selectedAddress].name, + }), this.renderWalletBalance(), diff --git a/ui/app/css/itcss/components/newui-sections.scss b/ui/app/css/itcss/components/newui-sections.scss index 9a0b81aed..ff5f6f6cf 100644 --- a/ui/app/css/itcss/components/newui-sections.scss +++ b/ui/app/css/itcss/components/newui-sections.scss @@ -65,72 +65,6 @@ $wallet-view-bg: $alabaster; @media #{$sub-mid-size-breakpoint-range} { min-width: 160px; } - - .wallet-view-account-details { - flex: 0 0 auto; - } - - &__name-container { - flex: 0 0 auto; - cursor: pointer; - width: 100%; - } - - &__keyring-label { - height: 50px; - color: $dusty-gray; - font-family: Roboto; - font-size: 10px; - text-align: right; - padding: 17px 20px 0; - box-sizing: border-box; - } - - &__details-button { - font-size: 10px; - border-radius: 17px; - background-color: transparent; - margin: 0 auto; - padding: 4px 12px; - flex: 0 0 auto; - } - - &__tooltip { - display: flex; - justify-content: center; - align-items: center; - padding: 24px; - } - - &__address { - border-radius: 3px; - background-color: $alto; - color: $scorpion; - font-size: 14px; - line-height: 12px; - padding: 4px 12px; - cursor: pointer; - flex: 0 0 auto; - - &__pressed { - background-color: $manatee, - } - } - - &__sidebar-close { - - @media screen and (max-width: 575px) { - &::after { - content: '\00D7'; - font-size: 40px; - color: $tundora; - position: absolute; - top: 12px; - left: 12px; - cursor: pointer; - } - } - } } @media screen and (min-width: 576px) { @@ -228,20 +162,6 @@ $wallet-view-bg: $alabaster; } } -// wallet view -.account-name { - font-size: 24px; - color: $black; - margin-top: 8px; - margin-bottom: .9rem; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - width: 100%; - padding: 0 8px; - text-align: center; -} - // account options dropdown .account-options-menu { align-items: center; |