aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pages/add-token/token-list/token-list.component.js
blob: 724a68d6eb6d8eccf6d9ee08ba9f6be03c1ae8b9 (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
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { checkExistingAddresses } from '../util'
import TokenListPlaceholder from './token-list-placeholder'

export default class InfoBox extends Component {
  static contextTypes = {
    t: PropTypes.func,
  }

  static propTypes = {
    tokens: PropTypes.array,
    results: PropTypes.array,
    selectedTokens: PropTypes.object,
    onToggleToken: PropTypes.func,
  }

  render () {
    const { results = [], selectedTokens = {}, onToggleToken, tokens = [] } = this.props

    return results.length === 0
      ? <TokenListPlaceholder />
      : (
        <div className="token-list">
          <div className="token-list__title">
            { this.context.t('searchResults') }
          </div>
          <div className="token-list__tokens-container">
            {
              Array(6).fill(undefined)
                .map((_, i) => {
                  const { logo, symbol, name, address } = results[i] || {}
                  const tokenAlreadyAdded = checkExistingAddresses(address, tokens)

                  return Boolean(logo || symbol || name) && (
                    <div
                      className={classnames('token-list__token', {
                        'token-list__token--selected': selectedTokens[address],
                        'token-list__token--disabled': tokenAlreadyAdded,
                      })}
                      onClick={() => !tokenAlreadyAdded && onToggleToken(results[i])}
                      key={i}
                    >
                      <div
                        className="token-list__token-icon"
                        style={{ backgroundImage: logo && `url(images/contract/${logo})` }}>
                      </div>
                      <div className="token-list__token-data">
                        <span className="token-list__token-name">{ `${name} (${symbol})` }</span>
                      </div>
                    </div>
                  )
                })
            }
          </div>
        </div>
      )
  }
}