diff options
author | Dan Finlay <flyswatter@users.noreply.github.com> | 2017-07-19 02:05:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-19 02:05:19 +0800 |
commit | 199587383b022a17d56adcb56d6a99ceba71fec7 (patch) | |
tree | f66c331820ef10fa6e61df8e2d8c129d70c8cc4c /ui/responsive/app/components | |
parent | 1e0cd5f3028619d088fedf4cdb1b4a7cb81f9cf1 (diff) | |
parent | 9e8e445695585f47e9cc3f63b2ec8313b4fc4eb8 (diff) | |
download | tangerine-wallet-browser-199587383b022a17d56adcb56d6a99ceba71fec7.tar tangerine-wallet-browser-199587383b022a17d56adcb56d6a99ceba71fec7.tar.gz tangerine-wallet-browser-199587383b022a17d56adcb56d6a99ceba71fec7.tar.bz2 tangerine-wallet-browser-199587383b022a17d56adcb56d6a99ceba71fec7.tar.lz tangerine-wallet-browser-199587383b022a17d56adcb56d6a99ceba71fec7.tar.xz tangerine-wallet-browser-199587383b022a17d56adcb56d6a99ceba71fec7.tar.zst tangerine-wallet-browser-199587383b022a17d56adcb56d6a99ceba71fec7.zip |
Merge pull request #1790 from sdtsui/newui-account-dropdowns
[newui] - Implement Advanced Option Menu & Account Switching Menu
Diffstat (limited to 'ui/responsive/app/components')
-rw-r--r-- | ui/responsive/app/components/account-dropdowns.js | 227 | ||||
-rw-r--r-- | ui/responsive/app/components/account-info-link.js | 41 | ||||
-rw-r--r-- | ui/responsive/app/components/drop-menu-item.js | 59 | ||||
-rw-r--r-- | ui/responsive/app/components/dropdown.js | 44 | ||||
-rw-r--r-- | ui/responsive/app/components/editable-label.js | 7 | ||||
-rw-r--r-- | ui/responsive/app/components/network.js | 1 |
6 files changed, 260 insertions, 119 deletions
diff --git a/ui/responsive/app/components/account-dropdowns.js b/ui/responsive/app/components/account-dropdowns.js new file mode 100644 index 000000000..d1d319477 --- /dev/null +++ b/ui/responsive/app/components/account-dropdowns.js @@ -0,0 +1,227 @@ +const Component = require('react').Component +const PropTypes = require('react').PropTypes +const h = require('react-hyperscript') +const actions = require('../actions') +const genAccountLink = require('../../lib/account-link.js') +const connect = require('react-redux').connect +const Dropdown = require('./dropdown').Dropdown +const DropdownMenuItem = require('./dropdown').DropdownMenuItem +const Identicon = require('./identicon') +const ethUtil = require('ethereumjs-util') +const copyToClipboard = require('copy-to-clipboard') + +class AccountDropdowns extends Component { + constructor (props) { + super(props) + this.state = { + accountSelectorActive: false, + optionsMenuActive: false, + } + } + + renderAccounts () { + const { identities, selected } = this.props + + return Object.keys(identities).map((key) => { + const identity = identities[key] + const isSelected = identity.address === selected + + return h( + DropdownMenuItem, + { + closeMenu: () => {}, + onClick: () => { + this.props.actions.showAccountDetail(identity.address) + }, + }, + [ + h( + Identicon, + { + address: identity.address, + diameter: 16, + }, + ), + h('span', { style: { marginLeft: '10px' } }, identity.name || ''), + h('span', { style: { marginLeft: '10px' } }, isSelected ? h('.check', '✓') : null), + ] + ) + }) + } + + renderAccountSelector () { + const { actions } = this.props + const { accountSelectorActive } = this.state + + return h( + Dropdown, + { + style: { + marginLeft: '-125px', + minWidth: '180px', + }, + isOpen: accountSelectorActive, + onClickOutside: () => { this.setState({ accountSelectorActive: false }) }, + }, + [ + ...this.renderAccounts(), + h( + DropdownMenuItem, + { + closeMenu: () => {}, + onClick: () => actions.addNewAccount(), + }, + [ + h( + Identicon, + { + diameter: 16, + }, + ), + h('span', { style: { marginLeft: '10px' } }, 'Create Account'), + ], + ), + h( + DropdownMenuItem, + { + closeMenu: () => {}, + onClick: () => actions.showImportPage(), + }, + [ + h( + Identicon, + { + diameter: 16, + }, + ), + h('span', { style: { marginLeft: '10px' } }, 'Import Account'), + ] + ), + ] + ) + } + + renderAccountOptions () { + const { actions } = this.props + const { optionsMenuActive } = this.state + + return h( + Dropdown, + { + style: { + marginLeft: '-162px', + minWidth: '180px', + }, + isOpen: optionsMenuActive, + onClickOutside: () => { this.setState({ optionsMenuActive: false }) }, + }, + [ + h( + DropdownMenuItem, + { + closeMenu: () => {}, + onClick: () => actions.showConfigPage(), + }, + 'Account Settings', + ), + h( + DropdownMenuItem, + { + closeMenu: () => {}, + onClick: () => { + const { selected, network } = this.props + const url = genAccountLink(selected, network) + global.platform.openWindow({ url }) + }, + }, + 'View account on Etherscan', + ), + h( + DropdownMenuItem, + { + closeMenu: () => {}, + onClick: () => { + const { selected } = this.props + const checkSumAddress = selected && ethUtil.toChecksumAddress(selected) + copyToClipboard(checkSumAddress) + }, + }, + 'Copy Address to clipboard', + ), + h( + DropdownMenuItem, + { + closeMenu: () => {}, + onClick: () => { + actions.requestAccountExport() + }, + }, + 'Export Private Key', + ), + ] + ) + } + + render () { + const { style } = this.props + const { optionsMenuActive, accountSelectorActive } = this.state + + return h( + 'span', + { + style: style, + }, + [ + h( + 'i.fa.fa-angle-down', + { + style: {}, + onClick: (event) => { + event.stopPropagation() + this.setState({ + accountSelectorActive: !accountSelectorActive, + optionsMenuActive: false, + }) + }, + }, + this.renderAccountSelector(), + ), + h( + 'i.fa.fa-ellipsis-h', + { + style: { 'marginLeft': '10px'}, + onClick: (event) => { + event.stopPropagation() + this.setState({ + accountSelectorActive: false, + optionsMenuActive: !optionsMenuActive, + }) + }, + }, + this.renderAccountOptions() + ), + ] + ) + } +} + +AccountDropdowns.propTypes = { + identities: PropTypes.objectOf(PropTypes.object), + selected: PropTypes.string, +} + +const mapDispatchToProps = (dispatch) => { + return { + actions: { + showConfigPage: () => dispatch(actions.showConfigPage()), + requestAccountExport: () => dispatch(actions.requestExportAccount()), + showAccountDetail: (address) => dispatch(actions.showAccountDetail(address)), + addNewAccount: () => dispatch(actions.addNewAccount()), + showImportPage: () => dispatch(actions.showImportPage()), + }, + } +} + +module.exports = { + AccountDropdowns: connect(null, mapDispatchToProps)(AccountDropdowns), +} diff --git a/ui/responsive/app/components/account-info-link.js b/ui/responsive/app/components/account-info-link.js deleted file mode 100644 index 6526ab502..000000000 --- a/ui/responsive/app/components/account-info-link.js +++ /dev/null @@ -1,41 +0,0 @@ -const Component = require('react').Component -const h = require('react-hyperscript') -const inherits = require('util').inherits -const Tooltip = require('./tooltip') -const genAccountLink = require('../../lib/account-link') - -module.exports = AccountInfoLink - -inherits(AccountInfoLink, Component) -function AccountInfoLink () { - Component.call(this) -} - -AccountInfoLink.prototype.render = function () { - const { selected, network } = this.props - const title = 'View account on Etherscan' - const url = genAccountLink(selected, network) - - if (!url) { - return null - } - - return h('.account-info-link', { - style: { - display: 'flex', - alignItems: 'center', - }, - }, [ - - h(Tooltip, { - title, - }, [ - h('i.fa.fa-info-circle.cursor-pointer.color-orange', { - style: { - margin: '5px', - }, - onClick () { global.platform.openWindow({ url }) }, - }), - ]), - ]) -} diff --git a/ui/responsive/app/components/drop-menu-item.js b/ui/responsive/app/components/drop-menu-item.js deleted file mode 100644 index e42948209..000000000 --- a/ui/responsive/app/components/drop-menu-item.js +++ /dev/null @@ -1,59 +0,0 @@ -const Component = require('react').Component -const h = require('react-hyperscript') -const inherits = require('util').inherits - -module.exports = DropMenuItem - -inherits(DropMenuItem, Component) -function DropMenuItem () { - Component.call(this) -} - -DropMenuItem.prototype.render = function () { - return h('li.drop-menu-item', { - onClick: () => { - this.props.closeMenu() - this.props.action() - }, - style: { - listStyle: 'none', - padding: '6px 16px 6px 5px', - fontFamily: 'Montserrat Regular', - color: 'rgb(125, 128, 130)', - cursor: 'pointer', - display: 'flex', - justifyContent: 'flex-start', - }, - }, [ - this.props.icon, - this.props.label, - this.activeNetworkRender(), - ]) -} - -DropMenuItem.prototype.activeNetworkRender = function () { - const activeNetwork = this.props.activeNetworkRender - const { provider } = this.props - const providerType = provider ? provider.type : null - if (activeNetwork === undefined) return - - switch (this.props.label) { - case 'Main Ethereum Network': - if (providerType === 'mainnet') return h('.check', '✓') - break - case 'Ropsten Test Network': - if (providerType === 'ropsten') return h('.check', '✓') - break - case 'Kovan Test Network': - if (providerType === 'kovan') return h('.check', '✓') - break - case 'Rinkeby Test Network': - if (providerType === 'rinkeby') return h('.check', '✓') - break - case 'Localhost 8545': - if (activeNetwork === 'http://localhost:8545') return h('.check', '✓') - break - default: - if (activeNetwork === 'custom') return h('.check', '✓') - } -} diff --git a/ui/responsive/app/components/dropdown.js b/ui/responsive/app/components/dropdown.js index 6e09cd133..e77b4c40c 100644 --- a/ui/responsive/app/components/dropdown.js +++ b/ui/responsive/app/components/dropdown.js @@ -1,11 +1,13 @@ -const Component = require('react').Component; -const PropTypes = require('react').PropTypes; -const h = require('react-hyperscript'); -const MenuDroppo = require('menu-droppo'); +const Component = require('react').Component +const PropTypes = require('react').PropTypes +const h = require('react-hyperscript') +const MenuDroppo = require('menu-droppo') + +const noop = () => {} class Dropdown extends Component { - render() { - const { isOpen, onClickOutside, style, children } = this.props; + render () { + const { isOpen, onClickOutside, style, children } = this.props return h( MenuDroppo, @@ -30,27 +32,34 @@ class Dropdown extends Component { ` ), ...children, - ], - ); + ] + ) } } +Dropdown.defaultProps = { + isOpen: false, + onClick: noop, +} + Dropdown.propTypes = { - isOpen: PropTypes.func.isRequired, + isOpen: PropTypes.bool.isRequired, onClick: PropTypes.func.isRequired, children: PropTypes.node, - style: PropTypes.object.isRequired, + style: PropTypes.object.isRequired, } class DropdownMenuItem extends Component { - render() { - const { onClick, closeMenu, children } = this.props; + render () { + const { onClick, closeMenu, children } = this.props return h( 'li.dropdown-menu-item', { - onClick, - closeMenu, + onClick: () => { + onClick() + closeMenu() + }, style: { listStyle: 'none', padding: '8px 0px 8px 0px', @@ -60,10 +69,11 @@ class DropdownMenuItem extends Component { cursor: 'pointer', display: 'flex', justifyContent: 'flex-start', + alignItems: 'center', }, }, children - ); + ) } } @@ -71,9 +81,9 @@ DropdownMenuItem.propTypes = { closeMenu: PropTypes.func.isRequired, onClick: PropTypes.func.isRequired, children: PropTypes.node, -}; +} module.exports = { Dropdown, DropdownMenuItem, -};
\ No newline at end of file +} diff --git a/ui/responsive/app/components/editable-label.js b/ui/responsive/app/components/editable-label.js index 41936f5e0..167be7eaf 100644 --- a/ui/responsive/app/components/editable-label.js +++ b/ui/responsive/app/components/editable-label.js @@ -30,7 +30,12 @@ EditableLabel.prototype.render = function () { } else { return h('div.name-label', { onClick: (event) => { - this.setState({ isEditingLabel: true }) + const nameAttribute = event.target.getAttribute('name') + // checks for class to handle smaller CTA above the account name + const classAttribute = event.target.getAttribute('class') + if (nameAttribute === 'edit' || classAttribute === 'edit-text') { + this.setState({ isEditingLabel: true }) + } }, }, this.props.children) } diff --git a/ui/responsive/app/components/network.js b/ui/responsive/app/components/network.js index d5d3e18cd..698a0bbb9 100644 --- a/ui/responsive/app/components/network.js +++ b/ui/responsive/app/components/network.js @@ -39,7 +39,6 @@ Network.prototype.render = function () { }), h('i.fa.fa-sort-desc'), ]) - } else if (providerName === 'mainnet') { hoverText = 'Main Ethereum Network' iconName = 'ethereum-network' |