1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/app/pages/send/to-autocomplete/to-autocomplete.js
Nick Doiron d589d2dec0 Right-to-left CSS (using module for conversion) (#7072)
* Create RTL stylesheets using `gulp-rtl`

* Handle RTL stylesheet special cases

Certain blocks of Sass  were set to bypass "rtlcss" using ignore
comments. Certain icons had to be flipped 180 degrees.

* Switch stylesheets when locale changes

A second stylesheet has been added to each HTML page for use with
right-to-left locales. It is disabled by default. It is enabled on
startup if a RTL locale is set, and when switching to a RTL locale.
Similarly the LTR stylesheet is disabled when a RTL locale is used.

Unfortunately there is an unpleasant flash of unstyled content when
switching between a LTR and a RTL locale. There is also a slightly
longer page load time when using a RTL locale (<1s difference). We
couldn't think of an easy way to avoid these problems.

* Set `dir="auto"` as default on `TextFields`
2019-09-03 14:47:54 -03:00

122 lines
3.1 KiB
JavaScript

const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const inherits = require('util').inherits
const AccountListItem = require('../account-list-item/account-list-item.component').default
const connect = require('react-redux').connect
const Tooltip = require('../../../components/ui/tooltip')
const checksumAddress = require('../../../helpers/utils/util').checksumAddress
ToAutoComplete.contextTypes = {
t: PropTypes.func,
}
module.exports = connect()(ToAutoComplete)
inherits(ToAutoComplete, Component)
function ToAutoComplete () {
Component.call(this)
this.state = { accountsToRender: [] }
}
ToAutoComplete.prototype.getListItemIcon = function (listItemAddress, toAddress) {
const listItemIcon = h(`i.fa.fa-check.fa-lg`, { style: { color: '#02c9b1' } })
return toAddress && listItemAddress === toAddress
? listItemIcon
: null
}
ToAutoComplete.prototype.renderDropdown = function () {
const {
closeDropdown,
onChange,
to,
} = this.props
const { accountsToRender } = this.state
return !!accountsToRender.length && h('div', {}, [
h('div.send-v2__from-dropdown__list', {}, [
...accountsToRender.map(account => h(AccountListItem, {
account,
className: 'account-list-item__dropdown',
handleClick: () => {
onChange(checksumAddress(account.address))
closeDropdown()
},
icon: this.getListItemIcon(account.address, to),
displayBalance: false,
displayAddress: true,
})),
]),
])
}
ToAutoComplete.prototype.handleInputEvent = function (event = {}, cb) {
const {
to,
accounts,
closeDropdown,
openDropdown,
} = this.props
const matchingAccounts = accounts.filter(({ address }) => address.match(to || ''))
const matches = matchingAccounts.length
if (!matches || matchingAccounts[0].address === to) {
this.setState({ accountsToRender: [] })
event.target && event.target.select()
closeDropdown()
} else {
this.setState({ accountsToRender: matchingAccounts })
openDropdown()
}
cb && cb(event.target.value)
}
ToAutoComplete.prototype.componentDidUpdate = function (nextProps) {
if (this.props.to !== nextProps.to) {
this.handleInputEvent()
}
}
ToAutoComplete.prototype.render = function () {
const {
to,
onChange,
inError,
qrScanner,
} = this.props
return h('div.send-v2__to-autocomplete', {}, [
h(`input.send-v2__to-autocomplete__input${qrScanner ? '.with-qr' : ''}`, {
placeholder: this.context.t('recipientAddress'),
className: inError ? `send-v2__error-border` : '',
dir: 'auto',
value: to,
onChange: event => onChange(event.target.value),
onFocus: event => this.handleInputEvent(event),
style: {
borderColor: inError ? 'red' : null,
},
}),
qrScanner && h(Tooltip, {
title: this.context.t('scanQrCode'),
position: 'bottom',
}, h(`i.fa.fa-qrcode.fa-lg.send-v2__to-autocomplete__qr-code`, {
style: { color: '#33333' },
onClick: () => this.props.scanQrCode(),
})),
this.renderDropdown(),
])
}