mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-30 16:18:07 +01:00
e6c4d63ccd
Calls to `eth.sign` are now transiently persisted in memory, and displayed in a chronological stack with pending transactions (which are still persisted to disk). This allows the user a method to sign/cancel transactions even if they miss the Chrome notification. Improved a lot of the view routing, to avoid cases where routes would show an empty account view, or transition to the accounts list when it shouldn't. Broke the transaction approval view into a couple components so messages and transactions could have their own templates.
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
module.exports = new MessageManager()
|
|
|
|
function MessageManager(opts) {
|
|
this.messages = []
|
|
}
|
|
|
|
MessageManager.prototype.getMsgList = function() {
|
|
return this.messages
|
|
}
|
|
|
|
MessageManager.prototype.unconfirmedMsgs = function() {
|
|
var messages = this.getMsgList()
|
|
return messages.filter(msg => msg.status === 'unconfirmed')
|
|
.reduce((result, msg) => { result[msg.id] = msg; return result }, {})
|
|
}
|
|
|
|
MessageManager.prototype._saveMsgList = function(msgList) {
|
|
this.messages = msgList
|
|
}
|
|
|
|
MessageManager.prototype.addMsg = function(msg) {
|
|
var messages = this.getMsgList()
|
|
messages.push(msg)
|
|
this._saveMsgList(messages)
|
|
}
|
|
|
|
MessageManager.prototype.getMsg = function(msgId) {
|
|
var messages = this.getMsgList()
|
|
var matching = messages.filter(msg => msg.id === msgId)
|
|
return matching.length > 0 ? matching[0] : null
|
|
}
|
|
|
|
MessageManager.prototype.confirmMsg = function(msgId) {
|
|
this._setMsgStatus(msgId, 'confirmed')
|
|
}
|
|
|
|
MessageManager.prototype.rejectMsg = function(msgId) {
|
|
this._setMsgStatus(msgId, 'rejected')
|
|
}
|
|
|
|
MessageManager.prototype._setMsgStatus = function(msgId, status) {
|
|
var msg = this.getMsg(msgId)
|
|
if (msg) msg.status = status
|
|
this.updateMsg(msg)
|
|
}
|
|
|
|
MessageManager.prototype.updateMsg = function(msg) {
|
|
var messages = this.getMsgList()
|
|
var found, index
|
|
messages.forEach((otherMsg, i) => {
|
|
if (otherMsg.id === msg.id) {
|
|
found = true
|
|
index = i
|
|
}
|
|
})
|
|
if (found) {
|
|
messages[index] = msg
|
|
}
|
|
this._saveMsgList(messages)
|
|
}
|
|
|