A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/app/components/pages/create-account/connect-hardware/account-list.js

144 lines
4.0 KiB

6 years ago
const { Component } = require('react')
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
6 years ago
const genAccountLink = require('../../../../../lib/account-link.js')
6 years ago
6 years ago
class AccountList extends Component {
6 years ago
constructor (props, context) {
super(props)
}
renderHeader () {
return (
h('div.hw-connect', [
h('h3.hw-connect__title', {}, this.context.t('selectAnAccount')),
h('p.hw-connect__msg', {}, this.context.t('selectAnAccountHelp')),
])
)
}
6 years ago
renderAccounts () {
return h('div.hw-account-list', [
6 years ago
this.props.accounts.map((a, i) => {
6 years ago
6 years ago
return h('div.hw-account-list__item', { key: a.address }, [
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}`,
},
[
h('span.hw-account-list__item__index', a.index + 1),
`${a.address.slice(0, 4)}...${a.address.slice(-4)}`,
h('span.hw-account-list__item__balance', `${a.balance}`),
]),
6 years ago
]),
6 years ago
h(
6 years ago
'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' })
6 years ago
),
6 years ago
])
}),
6 years ago
])
}
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 () {
const disabled = this.props.selectedAccount === null
const buttonProps = {}
if (disabled) {
buttonProps.disabled = true
}
return h('div.new-account-connect-form__buttons', {}, [
6 years ago
h(
'button.btn-default.btn--large.new-account-connect-form__button',
6 years ago
{
6 years ago
onClick: this.props.onCancel.bind(this),
6 years ago
},
[this.context.t('cancel')]
),
h(
`button.btn-primary.btn--large.new-account-connect-form__button ${disabled ? '.btn-primary--disabled' : ''}`,
6 years ago
{
6 years ago
onClick: this.props.onUnlockAccount.bind(this),
...buttonProps,
6 years ago
},
[this.context.t('unlock')]
),
])
}
renderForgetDevice () {
return h('div.hw-forget-device-container', {}, [
h('a', {
onClick: this.props.onForgetDevice.bind(this),
}, this.context.t('forgetDevice')),
])
}
6 years ago
render () {
return h('div.new-account-connect-form', {}, [
this.renderHeader(),
6 years ago
this.renderAccounts(),
this.renderPagination(),
this.renderButtons(),
this.renderForgetDevice(),
6 years ago
])
6 years ago
}
}
AccountList.propTypes = {
6 years ago
accounts: PropTypes.array.isRequired,
6 years ago
onAccountChange: PropTypes.func.isRequired,
onForgetDevice: PropTypes.func.isRequired,
6 years ago
getPage: PropTypes.func.isRequired,
network: PropTypes.string,
6 years ago
selectedAccount: PropTypes.string,
6 years ago
history: PropTypes.object,
6 years ago
onUnlockAccount: PropTypes.func,
onCancel: PropTypes.func,
6 years ago
}
AccountList.contextTypes = {
t: PropTypes.func,
}
6 years ago
module.exports = AccountList