diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2017-03-10 05:58:42 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2017-03-10 05:58:42 +0800 |
commit | 9f6c04055419f54a730bcbd3f1da4c5f992db94d (patch) | |
tree | 666d9433754e6e38c3b9550aee74bb28187a5fb0 /app/scripts/controllers | |
parent | d270cbc9d2f45b6dae184efbe6c405889ee8cba5 (diff) | |
download | tangerine-wallet-browser-9f6c04055419f54a730bcbd3f1da4c5f992db94d.tar tangerine-wallet-browser-9f6c04055419f54a730bcbd3f1da4c5f992db94d.tar.gz tangerine-wallet-browser-9f6c04055419f54a730bcbd3f1da4c5f992db94d.tar.bz2 tangerine-wallet-browser-9f6c04055419f54a730bcbd3f1da4c5f992db94d.tar.lz tangerine-wallet-browser-9f6c04055419f54a730bcbd3f1da4c5f992db94d.tar.xz tangerine-wallet-browser-9f6c04055419f54a730bcbd3f1da4c5f992db94d.tar.zst tangerine-wallet-browser-9f6c04055419f54a730bcbd3f1da4c5f992db94d.zip |
Create persistence address book.
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/address-book.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/scripts/controllers/address-book.js b/app/scripts/controllers/address-book.js new file mode 100644 index 000000000..824a256d1 --- /dev/null +++ b/app/scripts/controllers/address-book.js @@ -0,0 +1,46 @@ +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 + // + + setAddressList (address, name) { + return this.addToAddressList(address, name) + .then((addressBook) => { + this.store.updateState({ + addressBook, + }) + return Promise.resolve() + }) + } + + addToAddressList (address, name) { + let addressBook = this.getAddressList() + let index = addressBook.findIndex((element) => { return element.address === address }) + if (index !== -1) { + addressBook.splice(index, 1) + } + addressBook.push({ + address, + name, + }) + return Promise.resolve(addressBook) + } + + getAddressList () { + return this.store.getState().addressBook + } + +} + +module.exports = AddressBookController |