aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/ui/account-dropdown-mini/account-dropdown-mini.component.js
blob: 8abe1ab1811895e707f2b7590f0e5e35fca51a18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import AccountListItem from '../../app/send/account-list-item/account-list-item.component'

export default class AccountDropdownMini extends PureComponent {
  static propTypes = {
    accounts: PropTypes.array.isRequired,
    closeDropdown: PropTypes.func,
    disabled: PropTypes.bool,
    dropdownOpen: PropTypes.bool,
    onSelect: PropTypes.func,
    openDropdown: PropTypes.func,
    selectedAccount: PropTypes.object.isRequired,
  }

  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>
    )
  }
}