1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-24 04:13:27 +02:00
metamask-extension/ui/app/components/pages/create-account/connect-hardware/account-list.js

120 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-07-05 23:45:28 +02:00
const { Component } = require('react')
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
2018-07-06 02:59:31 +02:00
const genAccountLink = require('../../../../../lib/account-link.js')
2018-07-05 23:45:28 +02:00
2018-07-06 02:59:31 +02:00
class AccountList extends Component {
2018-07-05 23:45:28 +02:00
constructor (props, context) {
super(props)
}
renderAccounts () {
return h('div.hw-account-list', [
2018-07-06 02:59:31 +02:00
h('div.hw-account-list__title_wrapper', [
h('div.hw-account-list__title', {}, [this.context.t('selectAnAddress')]),
h('div.hw-account-list__device', {}, ['Trezor - ETH']),
]),
this.props.accounts.map((a, i) => {
2018-07-05 23:45:28 +02:00
2018-07-06 02:59:31 +02:00
return h('div.hw-account-list__item', { key: a.address }, [
h('span.hw-account-list__item__index', a.index + 1),
h('div.hw-account-list__item__radio', [
h('input', {
type: 'radio',
name: 'selectedAccount',
id: `address-${i}`,
value: a.index,
onChange: (e) => this.props.onAccountChange(e.target.value),
checked: this.props.selectedAccount === a.index.toString(),
}),
h(
'label.hw-account-list__item__label',
{
htmlFor: `address-${i}`,
},
`${a.address.slice(0, 4)}...${a.address.slice(-4)}`
),
]),
2018-07-09 23:24:52 +02:00
h('span.hw-account-list__item__balance', `${a.balance}`),
2018-07-05 23:45:28 +02:00
h(
2018-07-06 02:59:31 +02:00
'a.hw-account-list__item__link',
{
href: genAccountLink(a.address, this.props.network),
target: '_blank',
title: this.context.t('etherscanView'),
},
h('img', { src: 'images/popout.svg' })
2018-07-05 23:45:28 +02:00
),
2018-07-06 02:59:31 +02:00
])
}),
2018-07-05 23:45:28 +02:00
])
}
renderPagination () {
return h('div.hw-list-pagination', [
h(
'button.btn-primary.hw-list-pagination__button',
{
onClick: () => this.props.getPage(-1),
},
`< ${this.context.t('prev')}`
),
h(
'button.btn-primary.hw-list-pagination__button',
{
onClick: () => this.props.getPage(1),
},
`${this.context.t('next')} >`
),
])
}
renderButtons () {
return h('div.new-account-create-form__buttons', {}, [
h(
'button.btn-default.btn--large.new-account-create-form__button',
{
2018-07-06 02:59:31 +02:00
onClick: this.props.onCancel.bind(this),
2018-07-05 23:45:28 +02:00
},
[this.context.t('cancel')]
),
h(
2018-07-06 02:59:31 +02:00
`button.btn-primary.btn--large.new-account-create-form__button ${this.props.selectedAccount === null ? '.btn-primary--disabled' : ''}`,
2018-07-05 23:45:28 +02:00
{
2018-07-06 02:59:31 +02:00
onClick: this.props.onUnlockAccount.bind(this),
2018-07-05 23:45:28 +02:00
},
[this.context.t('unlock')]
),
])
}
render () {
2018-07-06 02:59:31 +02:00
return h('div', {}, [
this.renderAccounts(),
this.renderPagination(),
this.renderButtons(),
])
2018-07-05 23:45:28 +02:00
}
}
AccountList.propTypes = {
2018-07-06 02:59:31 +02:00
accounts: PropTypes.array.isRequired,
2018-07-05 23:45:28 +02:00
onAccountChange: PropTypes.func.isRequired,
getPage: PropTypes.func.isRequired,
network: PropTypes.string,
2018-07-06 02:59:31 +02:00
selectedAccount: PropTypes.string,
2018-07-05 23:45:28 +02:00
history: PropTypes.object,
2018-07-06 02:59:31 +02:00
onUnlockAccount: PropTypes.func,
onCancel: PropTypes.func,
2018-07-05 23:45:28 +02:00
}
AccountList.contextTypes = {
t: PropTypes.func,
}
2018-07-06 02:59:31 +02:00
module.exports = AccountList