-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Email and Registry lookups to Address Selector #3992
Changes from 1 commit
da54424
3b4f997
d7be555
76496bb
6079c57
53e5b4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,10 +225,8 @@ class AddressSelect extends Component { | |
} | ||
|
||
const accounts = regsitryValues | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.map((regsitryValue) => { | ||
const { address, value } = regsitryValue; | ||
const account = { address, name: value, index: address }; | ||
|
||
.map((regsitryValue, index) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo. 😉 |
||
const account = { ...regsitryValue, index: `${regsitryValue.address}_${index}` }; | ||
return this.renderAccountCard(account); | ||
}); | ||
|
||
|
@@ -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); | ||
} | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we are doing this fresh, create strings with |
||
}); | ||
}); | ||
|
||
registry | ||
.getInstance() | ||
.then((registryInstance) => { | ||
this.regLookups.push({ | ||
lookup: (value) => { | ||
return registryInstance | ||
.getAddress.call({}, [ sha3(value), 'A' ]); | ||
}, | ||
describe: (value) => `${value} (from registry)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}); | ||
}); | ||
} | ||
|
||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
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.