-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable account dropdown on signing screens
- Loading branch information
Showing
5 changed files
with
195 additions
and
85 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
ui/app/components/account-dropdown-mini/account-dropdown-mini.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { PureComponent } from 'react' | ||
import PropTypes from 'prop-types' | ||
import AccountListItem from '../send/account-list-item/account-list-item.component' | ||
|
||
export default class AccountDropdownMini extends PureComponent { | ||
static propTypes = { | ||
accounts: PropTypes.array, | ||
closeDropdown: PropTypes.func, | ||
disabled: PropTypes.bool, | ||
dropdownOpen: PropTypes.bool, | ||
onSelect: PropTypes.func, | ||
openDropdown: PropTypes.func, | ||
selectedAccount: PropTypes.object, | ||
} | ||
|
||
static defaultProps = { | ||
closeDropdown: () => {}, | ||
disabled: false, | ||
dropdownOpen: false, | ||
onSelect: () => {}, | ||
openDropdown: () => {}, | ||
} | ||
|
||
getListItemIcon (currentAccount, selectedAccount) { | ||
return currentAccount.address === selectedAccount.address && ( | ||
<i | ||
className="fa fa-check fa-lg" | ||
style={{ color: '#02c9b1' }} | ||
/> | ||
) | ||
} | ||
|
||
renderDropdown () { | ||
const { accounts, selectedAccount, closeDropdown, onSelect } = this.props | ||
|
||
return ( | ||
<div> | ||
<div | ||
className="account-dropdown-mini__close-area" | ||
onClick={closeDropdown} | ||
/> | ||
<div className="account-dropdown-mini__list"> | ||
{ | ||
accounts.map(account => ( | ||
<AccountListItem | ||
key={account.address} | ||
account={account} | ||
displayBalance={false} | ||
displayAddress={false} | ||
handleClick={() => { | ||
onSelect(account) | ||
closeDropdown() | ||
}} | ||
icon={this.getListItemIcon(account, selectedAccount)} | ||
/> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
render () { | ||
const { disabled, selectedAccount, openDropdown, dropdownOpen } = this.props | ||
|
||
return ( | ||
<div className="account-dropdown-mini"> | ||
<AccountListItem | ||
account={selectedAccount} | ||
handleClick={() => !disabled && openDropdown()} | ||
displayBalance={false} | ||
displayAddress={false} | ||
icon={ | ||
!disabled && <i | ||
className="fa fa-caret-down fa-lg" | ||
style={{ color: '#dedede' }} | ||
/> | ||
} | ||
/> | ||
{ !disabled && dropdownOpen && this.renderDropdown() } | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './account-dropdown-mini.component' |
107 changes: 107 additions & 0 deletions
107
ui/app/components/account-dropdown-mini/tests/account-dropdown-mini.component.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from 'react' | ||
import assert from 'assert' | ||
import { shallow } from 'enzyme' | ||
import AccountDropdownMini from '../account-dropdown-mini.component' | ||
import AccountListItem from '../../send/account-list-item/account-list-item.component' | ||
|
||
describe('AccountDropdownMini', () => { | ||
it('should render an account with an icon', () => { | ||
const accounts = [ | ||
{ | ||
address: '0x1', | ||
name: 'account1', | ||
balance: '0x1', | ||
}, | ||
{ | ||
address: '0x2', | ||
name: 'account2', | ||
balance: '0x2', | ||
}, | ||
{ | ||
address: '0x3', | ||
name: 'account3', | ||
balance: '0x3', | ||
}, | ||
] | ||
|
||
const wrapper = shallow( | ||
<AccountDropdownMini | ||
selectedAccount={{ address: '0x1', name: 'account1', balance: '0x1' }} | ||
accounts={accounts} | ||
/> | ||
) | ||
|
||
assert.ok(wrapper) | ||
assert.equal(wrapper.find(AccountListItem).length, 1) | ||
const accountListItemProps = wrapper.find(AccountListItem).at(0).props() | ||
assert.equal(accountListItemProps.account.address, '0x1') | ||
const iconProps = accountListItemProps.icon.props | ||
assert.equal(iconProps.className, 'fa fa-caret-down fa-lg') | ||
}) | ||
|
||
it('should render a list of accounts', () => { | ||
const accounts = [ | ||
{ | ||
address: '0x1', | ||
name: 'account1', | ||
balance: '0x1', | ||
}, | ||
{ | ||
address: '0x2', | ||
name: 'account2', | ||
balance: '0x2', | ||
}, | ||
{ | ||
address: '0x3', | ||
name: 'account3', | ||
balance: '0x3', | ||
}, | ||
] | ||
|
||
const wrapper = shallow( | ||
<AccountDropdownMini | ||
selectedAccount={{ address: '0x1', name: 'account1', balance: '0x1' }} | ||
accounts={accounts} | ||
dropdownOpen={true} | ||
/> | ||
) | ||
|
||
assert.ok(wrapper) | ||
assert.equal(wrapper.find(AccountListItem).length, 4) | ||
}) | ||
|
||
it('should render a single account when disabled', () => { | ||
const accounts = [ | ||
{ | ||
address: '0x1', | ||
name: 'account1', | ||
balance: '0x1', | ||
}, | ||
{ | ||
address: '0x2', | ||
name: 'account2', | ||
balance: '0x2', | ||
}, | ||
{ | ||
address: '0x3', | ||
name: 'account3', | ||
balance: '0x3', | ||
}, | ||
] | ||
|
||
const wrapper = shallow( | ||
<AccountDropdownMini | ||
selectedAccount={{ address: '0x1', name: 'account1', balance: '0x1' }} | ||
accounts={accounts} | ||
dropdownOpen={false} | ||
disabled={true} | ||
/> | ||
) | ||
|
||
assert.ok(wrapper) | ||
assert.equal(wrapper.find(AccountListItem).length, 1) | ||
const accountListItemProps = wrapper.find(AccountListItem).at(0).props() | ||
assert.equal(accountListItemProps.account.address, '0x1') | ||
assert.equal(accountListItemProps.icon, false) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters