1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 11:01:41 +01:00
metamask-extension/ui/app/components/send/send-content/send-to-row/send-to-row.component.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-04-07 00:29:51 +02:00
import React, { Component } from 'react'
import PropTypes from 'prop-types'
2018-05-15 14:29:23 +02:00
import SendRowWrapper from '../send-row-wrapper/'
2018-04-26 18:38:38 +02:00
import EnsInput from '../../../ens-input'
import { getToErrorObject } from './send-to-row.utils.js'
2018-04-07 00:29:51 +02:00
export default class SendToRow extends Component {
static propTypes = {
closeToDropdown: PropTypes.func,
inError: PropTypes.bool,
network: PropTypes.string,
openToDropdown: PropTypes.func,
2018-04-07 00:29:51 +02:00
to: PropTypes.string,
toAccounts: PropTypes.array,
toDropdownOpen: PropTypes.bool,
updateGas: PropTypes.func,
2018-04-07 00:29:51 +02:00
updateSendTo: PropTypes.func,
updateSendToError: PropTypes.func,
};
static contextTypes = {
t: PropTypes.func,
};
handleToChange (to, nickname = '', toError) {
const { updateSendTo, updateSendToError, updateGas } = this.props
const toErrorObject = getToErrorObject(to, toError)
2018-04-07 00:29:51 +02:00
updateSendTo(to, nickname)
updateSendToError(toErrorObject)
if (toErrorObject.to === null) {
updateGas({ to })
}
2018-04-07 00:29:51 +02:00
}
render () {
const {
closeToDropdown,
inError,
network,
openToDropdown,
2018-04-26 18:38:38 +02:00
to,
toAccounts,
2018-04-26 18:38:38 +02:00
toDropdownOpen,
2018-04-07 00:29:51 +02:00
} = this.props
return (
2018-04-11 16:21:54 +02:00
<SendRowWrapper
errorType={'to'}
2018-05-25 03:00:07 +02:00
label={`${this.context.t('to')}`}
2018-04-11 16:21:54 +02:00
showError={inError}
>
2018-04-07 00:29:51 +02:00
<EnsInput
accounts={toAccounts}
closeDropdown={() => closeToDropdown()}
dropdownOpen={toDropdownOpen}
2018-04-07 00:29:51 +02:00
inError={inError}
name={'address'}
network={network}
onChange={({ toAddress, nickname, toError }) => this.handleToChange(toAddress, nickname, toError)}
openDropdown={() => openToDropdown()}
placeholder={this.context.t('recipientAddress')}
to={to}
2018-04-07 00:29:51 +02:00
/>
</SendRowWrapper>
)
2018-04-07 00:29:51 +02:00
}
}