mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add comments.
This commit is contained in:
parent
b34ee4daa1
commit
2ab86b001d
@ -3,6 +3,10 @@ const extend = require('xtend')
|
|||||||
|
|
||||||
class AddressBookController {
|
class AddressBookController {
|
||||||
|
|
||||||
|
|
||||||
|
// Controller in charge of managing the address book functionality from the
|
||||||
|
// recipients field on the send screen. Manages a history of all saved
|
||||||
|
// addresses and all currently owned addresses.
|
||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
const initState = extend({
|
const initState = extend({
|
||||||
addressBook: [],
|
addressBook: [],
|
||||||
@ -14,8 +18,9 @@ class AddressBookController {
|
|||||||
// PUBLIC METHODS
|
// PUBLIC METHODS
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// Sets a new address book in store by accepting a new address and nickname.
|
||||||
setAddressBook (address, name) {
|
setAddressBook (address, name) {
|
||||||
return this.addToAddressBook(address, name)
|
return this._addToAddressBook(address, name)
|
||||||
.then((addressBook) => {
|
.then((addressBook) => {
|
||||||
this.store.updateState({
|
this.store.updateState({
|
||||||
addressBook,
|
addressBook,
|
||||||
@ -24,8 +29,16 @@ class AddressBookController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
addToAddressBook (address, name) {
|
//
|
||||||
let addressBook = this.getAddressBook()
|
// PRIVATE METHODS
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
// Performs the logic to add the address and name into the address book. The
|
||||||
|
// pushed object is an object of two fields. Current behavior does not set an
|
||||||
|
// upper limit to the number of addresses.
|
||||||
|
_addToAddressBook (address, name) {
|
||||||
|
let addressBook = this._getAddressBook()
|
||||||
let index = addressBook.findIndex((element) => { return element.address === address || element.name === name })
|
let index = addressBook.findIndex((element) => { return element.address === address || element.name === name })
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
addressBook.splice(index, 1)
|
addressBook.splice(index, 1)
|
||||||
@ -37,7 +50,9 @@ class AddressBookController {
|
|||||||
return Promise.resolve(addressBook)
|
return Promise.resolve(addressBook)
|
||||||
}
|
}
|
||||||
|
|
||||||
getAddressBook () {
|
// Internal method to get the address book. Current persistence behavior
|
||||||
|
// should not require that this method be called from the UI directly.
|
||||||
|
_getAddressBook () {
|
||||||
return this.store.getState().addressBook
|
return this.store.getState().addressBook
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,6 +698,7 @@ function setRpcTarget (newRpc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calls the addressBookController to add a new address.
|
||||||
function addToAddressBook (recipient, nickname) {
|
function addToAddressBook (recipient, nickname) {
|
||||||
log.debug(`background.addToAddressBook`)
|
log.debug(`background.addToAddressBook`)
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
|
@ -47,11 +47,13 @@ EnsInput.prototype.render = function () {
|
|||||||
style: { width: '100%' },
|
style: { width: '100%' },
|
||||||
}, [
|
}, [
|
||||||
h('input.large-input', opts),
|
h('input.large-input', opts),
|
||||||
|
// The address book functionality.
|
||||||
h('datalist',
|
h('datalist',
|
||||||
{
|
{
|
||||||
id: 'addresses',
|
id: 'addresses',
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
|
// Corresponds to the addresses owned.
|
||||||
Object.keys(props.identities).map((key) => {
|
Object.keys(props.identities).map((key) => {
|
||||||
let identity = props.identities[key]
|
let identity = props.identities[key]
|
||||||
return h('option', {
|
return h('option', {
|
||||||
@ -59,6 +61,7 @@ EnsInput.prototype.render = function () {
|
|||||||
label: identity.name,
|
label: identity.name,
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
// Corresponds to previously sent-to addresses.
|
||||||
props.addressBook.map((identity) => {
|
props.addressBook.map((identity) => {
|
||||||
return h('option', {
|
return h('option', {
|
||||||
value: identity.address,
|
value: identity.address,
|
||||||
@ -118,6 +121,8 @@ EnsInput.prototype.lookupEnsName = function () {
|
|||||||
EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) {
|
EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) {
|
||||||
const state = this.state || {}
|
const state = this.state || {}
|
||||||
const ensResolution = state.ensResolution
|
const ensResolution = state.ensResolution
|
||||||
|
// If an address is sent without a nickname, meaning not from ENS or from
|
||||||
|
// the user's own accounts, a default of a one-space string is used.
|
||||||
const nickname = state.nickname || ' '
|
const nickname = state.nickname || ' '
|
||||||
if (ensResolution && this.props.onChange &&
|
if (ensResolution && this.props.onChange &&
|
||||||
ensResolution !== prevState.ensResolution) {
|
ensResolution !== prevState.ensResolution) {
|
||||||
|
Loading…
Reference in New Issue
Block a user