address selector: use cached reverses

This commit is contained in:
Jannis R 2017-01-05 17:19:26 +01:00
parent b38aa8d01f
commit 6f492a4945
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
2 changed files with 29 additions and 3 deletions

View File

@ -56,6 +56,7 @@ class AddressSelect extends Component {
contacts: PropTypes.object, contacts: PropTypes.object,
contracts: PropTypes.object, contracts: PropTypes.object,
tokens: PropTypes.object, tokens: PropTypes.object,
reverse: PropTypes.object,
// Optional props // Optional props
allowCopy: PropTypes.bool, allowCopy: PropTypes.bool,
@ -584,10 +585,12 @@ class AddressSelect extends Component {
function mapStateToProps (state) { function mapStateToProps (state) {
const { accountsInfo } = state.personal; const { accountsInfo } = state.personal;
const { balances } = state.balances; const { balances } = state.balances;
const { reverse } = state.registry;
return { return {
accountsInfo, accountsInfo,
balances balances,
reverse
}; };
} }

View File

@ -30,7 +30,29 @@ export default class AddressSelectStore {
@observable registryValues = []; @observable registryValues = [];
initValues = []; initValues = [];
regLookups = []; regLookups = [
(address) => {
const name = this.reverse[address];
if (!name) {
return null;
}
return {
address,
name,
description: (
<FormattedMessage
id='addressSelect.fromRegistry'
defaultMessage='{name} (from registry)'
values={ {
name
} }
/>
)
};
}
];
constructor (api) { constructor (api) {
this.api = api; this.api = api;
@ -114,7 +136,8 @@ export default class AddressSelectStore {
} }
@action setValues (props) { @action setValues (props) {
const { accounts = {}, contracts = {}, contacts = {} } = props; const { accounts = {}, contracts = {}, contacts = {}, reverse = {} } = props;
this.reverse = reverse;
const accountsN = Object.keys(accounts).length; const accountsN = Object.keys(accounts).length;
const contractsN = Object.keys(contracts).length; const contractsN = Object.keys(contracts).length;