Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ENS Address Input #6606

Merged
merged 1 commit into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ui/app/components/app/ens-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ EnsInput.prototype.onChange = function (recipient) {
ensResolution: null,
ensFailure: null,
toError: null,
recipient,
})
}

this.setState({
loadingEns: true,
recipient,
})

this.checkName(recipient)
}

Expand All @@ -56,6 +59,7 @@ EnsInput.prototype.render = function () {
list: 'addresses',
onChange: this.onChange.bind(this),
qrScanner: true,
recipient: (this.state || {}).recipient,
})
return h('div', {
style: { width: '100%', position: 'relative' },
Expand All @@ -79,19 +83,21 @@ EnsInput.prototype.componentDidMount = function () {

EnsInput.prototype.lookupEnsName = function (recipient) {
const { ensResolution } = this.state
recipient = recipient.trim()

log.info(`ENS attempting to resolve name: ${recipient}`)
this.ens.lookup(recipient.trim())
this.ens.lookup(recipient)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use trim here to remove the white space from copy-pastes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I move it above. please see line 86

.then((address) => {
if (address === ZERO_ADDRESS) throw new Error(this.context.t('noAddressForName'))
if (address !== ensResolution) {
this.setState({
loadingEns: false,
ensResolution: address,
nickname: recipient.trim(),
nickname: recipient,
hoverText: address + '\n' + this.context.t('clickCopy'),
ensFailure: false,
toError: null,
recipient,
})
}
})
Expand All @@ -101,11 +107,11 @@ EnsInput.prototype.lookupEnsName = function (recipient) {
ensResolution: recipient,
ensFailure: true,
toError: null,
recipient: null,
}
if (isValidENSAddress(recipient) && reason.message === 'ENS name not defined.') {
setStateObj.hoverText = this.context.t('ensNameNotFound')
setStateObj.toError = 'ensNameNotFound'
setStateObj.ensFailure = false
} else {
log.error(reason)
setStateObj.hoverText = reason.message
Expand All @@ -128,7 +134,7 @@ EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) {
}
if (prevState && ensResolution && this.props.onChange &&
ensResolution !== prevState.ensResolution) {
this.props.onChange({ toAddress: ensResolution, nickname, toError: state.toError, toWarning: state.toWarning })
this.props.onChange({ toAddress: ensResolution, recipient: state.recipient, nickname, toError: state.toError, toWarning: state.toWarning })
}
}

Expand Down
38 changes: 37 additions & 1 deletion ui/app/css/itcss/components/send.scss
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,43 @@
}
}

&__to-autocomplete, &__memo-text-area, &__hex-data {
&__to-autocomplete {
display: flex;
flex-direction: column;
z-index: 1025;
position: relative;
height: 54px;
width: 100%;
border: 1px solid $alto;
border-radius: 4px;
background-color: $white;
color: $tundora;
padding: 0 10px;
font-family: Roboto;
line-height: 21px;

&__input {
font-size: 16px;
height: 100%;
border: none;
}

&__resolved {
font-size: 12px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
height: 30px;
cursor: pointer;

+ .send-v2__to-autocomplete__qr-code {
top: 2px;
right: 0;
}
}
}

&__memo-text-area, &__hex-data {
&__input {
z-index: 1025;
position: relative;
Expand Down
21 changes: 16 additions & 5 deletions ui/app/pages/send/to-autocomplete/to-autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const copyToClipboard = require('copy-to-clipboard')
const inherits = require('util').inherits
const AccountListItem = require('../account-list-item/account-list-item.component').default
const connect = require('react-redux').connect
Expand Down Expand Up @@ -93,24 +94,34 @@ ToAutoComplete.prototype.componentDidUpdate = function (nextProps) {
ToAutoComplete.prototype.render = function () {
const {
to,
recipient,
dropdownOpen,
onChange,
inError,
qrScanner,
} = this.props

return h('div.send-v2__to-autocomplete', {}, [
const isRecipientToDiff = recipient && recipient !== to

return h('div.send-v2__to-autocomplete', {style: {
borderColor: inError ? 'red' : null,
}}, [

h(`input.send-v2__to-autocomplete__input${qrScanner ? '.with-qr' : ''}`, {
placeholder: this.context.t('recipientAddress'),
className: inError ? `send-v2__error-border` : '',
value: to,
value: recipient,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe recipient || to instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmashuang Did you happen to try this out with this branch/changeset?

onChange: event => onChange(event.target.value),
onFocus: event => this.handleInputEvent(event),
style: {
borderColor: inError ? 'red' : null,
},
}),
isRecipientToDiff && h(Tooltip, {title: this.context.t('copyToClipboard')},
h('div.send-v2__to-autocomplete__resolved', {
onClick: (event) => {
event.preventDefault()
event.stopPropagation()
copyToClipboard(to)
},
}, to)),
qrScanner && h(Tooltip, {
title: this.context.t('scanQrCode'),
position: 'bottom',
Expand Down