diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-02-02 03:54:01 +0800 |
---|---|---|
committer | Frankie <frankie.diamond@gmail.com> | 2017-02-02 03:54:01 +0800 |
commit | 1b16b4624186265ccbb6f8106e1bf9ff997e2528 (patch) | |
tree | 56dad7e72c2983b786c454a398ed098415eff290 /app/scripts/lib | |
parent | f40629e5ae7d284e871d9dcd8b62fce34b6f2b39 (diff) | |
download | tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.gz tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.bz2 tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.lz tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.xz tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.zst tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.zip |
code clan up and tests
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/message-manager.js | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/app/scripts/lib/message-manager.js b/app/scripts/lib/message-manager.js index bc9a9e6c8..490cd4d1c 100644 --- a/app/scripts/lib/message-manager.js +++ b/app/scripts/lib/message-manager.js @@ -11,7 +11,7 @@ module.exports = class MessageManager extends EventEmitter{ getState() { return { - unapprovedMsgs: this.unapprovedMsgs(), + unapprovedMsgs: this.getUnapprovedMsgs(), messages: this.getMsgList(), } } @@ -21,22 +21,15 @@ module.exports = class MessageManager extends EventEmitter{ } get unapprovedMsgCount () { - return Object.keys(this.unapprovedMsgs()).length + return Object.keys(this.getUnapprovedMsgs()).length } - unapprovedMsgs () { + getUnapprovedMsgs () { let messages = this.getMsgList() return messages.filter(msg => msg.status === 'unapproved') .reduce((result, msg) => { result[msg.id] = msg; return result }, {}) } - _saveMsgList (msgList) { - this.emit('updateBadge') - let state = this.memStore.getState() - state.messages = msgList - this.memStore.putState(state) - } - addUnapprovedMessage (msgParams) { // create txData obj with parameters and meta data var time = (new Date()).getTime() @@ -70,33 +63,29 @@ module.exports = class MessageManager extends EventEmitter{ return matching.length > 0 ? matching[0] : null } - brodcastMessage (rawSig, msgId, status) { - this.emit(`${msgId}:finished`, {status, rawSig}) - } - approveMessage (msgParams) { - this.setMessageApproved(msgParams.metamaskId) + this.setMsgStatusApproved(msgParams.metamaskId) return this.prepMsgForSigning(msgParams) } - setMessageApproved (msgId) { + setMsgStatusApproved (msgId) { this._setMsgStatus(msgId, 'approved') } + prepMsgForSigning (msgParams) { delete msgParams.metamaskId return Promise.resolve(msgParams) } - cancelMessage (msgId) { - // reject tx - // clean up + rejectMsg (msgId) { this.brodcastMessage(null, msgId, 'rejected') - this.rejectMsg(msgId) + this._setMsgStatus(msgId, 'rejected') } - rejectMsg (msgId) { - this._setMsgStatus(msgId, 'rejected') + brodcastMessage (rawSig, msgId, status) { + this.emit(`${msgId}:finished`, {status, rawSig}) } +// PRIVATE METHODS _setMsgStatus (msgId, status) { let msg = this.getMsg(msgId) @@ -112,4 +101,13 @@ module.exports = class MessageManager extends EventEmitter{ } this._saveMsgList(messages) } + + _saveMsgList (msgList) { + this.emit('updateBadge') + let state = this.memStore.getState() + state.messages = msgList + this.memStore.putState(state) + } + + } |