1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/ui/app/components/send_/send-content/send-from-row/send-from-row.component.js

64 lines
1.5 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/'
import FromDropdown from './from-dropdown/'
2018-04-07 00:29:51 +02:00
export default class SendFromRow extends Component {
static propTypes = {
closeFromDropdown: PropTypes.func,
2018-04-26 18:38:38 +02:00
conversionRate: PropTypes.number,
from: PropTypes.object,
2018-04-07 00:29:51 +02:00
fromAccounts: PropTypes.array,
fromDropdownOpen: PropTypes.bool,
openFromDropdown: PropTypes.func,
tokenContract: PropTypes.object,
updateSendFrom: PropTypes.func,
setSendTokenBalance: PropTypes.func,
2018-04-07 00:29:51 +02:00
};
async handleFromChange (newFrom) {
const {
updateSendFrom,
tokenContract,
setSendTokenBalance,
2018-04-07 00:29:51 +02:00
} = this.props
if (tokenContract) {
const usersToken = await tokenContract.balanceOf(newFrom.address)
setSendTokenBalance(usersToken)
2018-04-07 00:29:51 +02:00
}
updateSendFrom(newFrom)
}
render () {
const {
closeFromDropdown,
conversionRate,
2018-04-07 00:29:51 +02:00
from,
fromAccounts,
fromDropdownOpen,
openFromDropdown,
} = this.props
2018-04-07 00:29:51 +02:00
return (
<SendRowWrapper label={`${this.context.t('from')}:`}>
<FromDropdown
accounts={fromAccounts}
closeDropdown={() => closeFromDropdown()}
conversionRate={conversionRate}
dropdownOpen={fromDropdownOpen}
onSelect={newFrom => this.handleFromChange(newFrom)}
openDropdown={() => openFromDropdown()}
selectedAccount={from}
2018-04-07 00:29:51 +02:00
/>
</SendRowWrapper>
)
2018-04-07 00:29:51 +02:00
}
}
SendFromRow.contextTypes = {
t: PropTypes.func,
}