aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/account-panel.js
blob: 112b897d59bb64b94f970dea4795730bdcbe651e (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
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const formatBalance = require('../util').formatBalance
const addressSummary = require('../util').addressSummary

const Panel = require('./panel')

module.exports = AccountPanel

inherits(AccountPanel, Component)
function AccountPanel () {
  Component.call(this)
}

AccountPanel.prototype.render = function () {
  var state = this.props
  var identity = state.identity || {}
  var account = state.account || {}
  var isFauceting = state.isFauceting

  var panelOpts = {
    key: `accountPanel${identity.address}`,
    onClick: (event) => {
      if (state.onShowDetail) {
        state.onShowDetail(identity.address, event)
      }
    },
    identiconKey: identity.address,
    identiconLabel: identity.name,
    attributes: [
      {
        key: 'ADDRESS',
        value: addressSummary(identity.address),
      },
      balanceOrFaucetingIndication(account, isFauceting),
    ],
  }

  return h(Panel, panelOpts,
  !state.onShowDetail ? null : h('.arrow-right.cursor-pointer', [
    h('i.fa.fa-chevron-right.fa-lg'),
  ]))
}

function balanceOrFaucetingIndication (account, isFauceting) {
  // Temporarily deactivating isFauceting indication
  // because it shows fauceting for empty restored accounts.
  if (/* isFauceting*/ false) {
    return {
      key: 'Account is auto-funding.',
      value: 'Please wait.',
    }
  } else {
    return {
      key: 'BALANCE',
      value: formatBalance(account.balance),
    }
  }
}