Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Add Email and Registry lookups to Address Selector #3992

Merged
merged 6 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions js/src/ui/AccountCard/accountCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
}
}

.description {
font-size: 0.75em;
color: rgba(255, 255, 255, 0.498039);
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it 0.5 alpha, Chrome creates these numbers when inspecting.

}

.accountInfo {
flex: 1;

Expand Down
15 changes: 14 additions & 1 deletion js/src/ui/AccountCard/accountCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class AccountCard extends Component {
const { account } = this.props;
const { copied } = this.state;

const { address, name, meta = {} } = account;
const { address, name, description, meta = {} } = account;

const displayName = (name && name.toUpperCase()) || address;
const { tags = [] } = meta;
Expand All @@ -70,13 +70,26 @@ export default class AccountCard extends Component {
</div>

{ this.renderTags(tags, address) }
{ this.renderDescription(description) }
{ this.renderAddress(displayName, address) }
{ this.renderBalance(address) }
</div>
</div>
);
}

renderDescription (description) {
if (!description) {
return null;
}

return (
<div className={ styles.description }>
<span>{ description }</span>
</div>
);
}

renderAddress (name, address) {
if (name === address) {
return null;
Expand Down
26 changes: 19 additions & 7 deletions js/src/ui/Form/AddressSelect/addressSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ class AddressSelect extends Component {
}

const accounts = regsitryValues
Copy link
Contributor

Choose a reason for hiding this comment

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

registryValues (typo, also registryValue below as well as the function name)

.map((regsitryValue) => {
const { address, value } = regsitryValue;
const account = { address, name: value, index: address };

.map((regsitryValue, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo. 😉

const account = { ...regsitryValue, index: `${regsitryValue.address}_${index}` };
return this.renderAccountCard(account);
});

Expand Down Expand Up @@ -423,7 +421,12 @@ class AddressSelect extends Component {

event.preventDefault();

const nextValues = values[focusedCat || 0];
const firstCat = values.findIndex((cat) => cat.values.length > 0);
const nextCat = focusedCat && values[focusedCat].values.length > 0
? focusedCat
: firstCat;

const nextValues = values[nextCat];
const nextFocus = nextValues ? nextValues.values[0] : null;
return this.focusItem(nextFocus && nextFocus.index || 1);
}
Expand Down Expand Up @@ -457,12 +460,21 @@ class AddressSelect extends Component {

// If right: next category
if (direction === 'right') {
nextCategory = Math.min(prevCategoryIndex + 1, values.length - 1);
const categoryShift = values
.slice(prevCategoryIndex + 1, values.length)
.findIndex((cat) => cat.values.length > 0) + 1;

nextCategory = Math.min(prevCategoryIndex + categoryShift, values.length - 1);
}

// If right: previous category
if (direction === 'left') {
nextCategory = Math.max(prevCategoryIndex - 1, 0);
const categoryShift = values
.slice(0, prevCategoryIndex)
.reverse()
.findIndex((cat) => cat.values.length > 0) + 1;

nextCategory = Math.max(prevCategoryIndex - categoryShift, 0);
}

// If left or right: try to keep the horizontal index
Expand Down
72 changes: 50 additions & 22 deletions js/src/ui/Form/AddressSelect/addressSelectStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { observable, action } from 'mobx';
import { flatMap } from 'lodash';

import Contracts from '~/contracts';
import { sha3 } from '~/api/util/sha3';
Expand All @@ -25,16 +26,36 @@ export default class AddressSelectStore {
@observable regsitryValues = [];

initValues = [];
regLookups = [];

constructor (api) {
this.api = api;

Contracts
.get()
.registry
const { registry } = Contracts.get();

registry
.getContract('emailverification')
.then((emailVerification) => {
this.emailVerification = emailVerification;
this.regLookups.push({
lookup: (value) => {
return emailVerification
.instance
.reverse.call({}, [ sha3(value) ]);
},
describe: (value) => `${value} (from email verification)`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer "Verified using email …", as this is being shown inside and account card.

Copy link
Contributor

Choose a reason for hiding this comment

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

While we are doing this fresh, create strings with FormattedMessage so we don't need to circle back. (Also for the labels in this store)

});
});

registry
.getInstance()
.then((registryInstance) => {
this.regLookups.push({
lookup: (value) => {
return registryInstance
.getAddress.call({}, [ sha3(value), 'A' ]);
},
describe: (value) => `${value} (from registry)`
Copy link
Contributor

Choose a reason for hiding this comment

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

<FormattedMessage
  id='addressSelect.fromRegistry'
  defaultMessage='{value} (from registry)'
  values={ {
    value
  } } />

});
});
}

Expand Down Expand Up @@ -92,24 +113,31 @@ export default class AddressSelectStore {
// Registries Lookup
this.regsitryValues = [];

if (this.emailVerification) {
this
.emailVerification
.instance
.reverse
.call({}, [ sha3(value) ])
.then((result) => {
if (/^(0x)?0*$/.test(result)) {
return;
}

this.regsitryValues.push({
type: 'email',
address: result,
value
});
});
}
const lookups = this.regLookups.map((regLookup) => regLookup.lookup(value));

Promise
.all(lookups)
.then((results) => {
return results
.map((result, index) => {
if (/^(0x)?0*$/.test(result)) {
return;
}

const account = flatMap(this.initValues, (cat) => cat.values)
.find((account) => account.address.toLowerCase() === result.toLowerCase());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to lowercase result each callback? Could do it outside and assign to variable being tested.


return {
description: this.regLookups[index].describe(value),
address: result,
name: account && account.name || value
};
})
.filter((data) => data);
})
.then((regsitryValues) => {
this.regsitryValues = regsitryValues;
});
}

/**
Expand Down