A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/app/scripts/controllers/address-book.js

47 lines
992 B

const ObservableStore = require('obs-store')
const extend = require('xtend')
class AddressBookController {
constructor (opts = {}) {
const initState = extend({
addressBook: [],
}, opts.initState)
this.store = new ObservableStore(initState)
}
//
// PUBLIC METHODS
//
setAddressBook (address, name) {
return this.addToAddressBook(address, name)
.then((addressBook) => {
this.store.updateState({
addressBook,
})
return Promise.resolve()
})
}
addToAddressBook (address, name) {
let addressBook = this.getAddressBook()
let index = addressBook.findIndex((element) => { return element.address === address || element.name === name })
if (index !== -1) {
addressBook.splice(index, 1)
}
addressBook.push({
address,
name,
})
return Promise.resolve(addressBook)
}
getAddressBook () {
return this.store.getState().addressBook
}
}
module.exports = AddressBookController