aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/config-manager.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-04-29 05:16:24 +0800
committerkumavis <aaron@kumavis.me>2016-04-29 05:16:24 +0800
commit82983e5effb236474c7eba2ac2ba62ea3fe58f5f (patch)
tree5173113d4b2cc928d87e8673677bed4a40afbb9e /app/scripts/lib/config-manager.js
parent6cc7c08b75bed6ad95698b96cb788366a8334ecd (diff)
downloadtangerine-wallet-browser-82983e5effb236474c7eba2ac2ba62ea3fe58f5f.tar
tangerine-wallet-browser-82983e5effb236474c7eba2ac2ba62ea3fe58f5f.tar.gz
tangerine-wallet-browser-82983e5effb236474c7eba2ac2ba62ea3fe58f5f.tar.bz2
tangerine-wallet-browser-82983e5effb236474c7eba2ac2ba62ea3fe58f5f.tar.lz
tangerine-wallet-browser-82983e5effb236474c7eba2ac2ba62ea3fe58f5f.tar.xz
tangerine-wallet-browser-82983e5effb236474c7eba2ac2ba62ea3fe58f5f.tar.zst
tangerine-wallet-browser-82983e5effb236474c7eba2ac2ba62ea3fe58f5f.zip
idmgmt - eth_sign support + notifications
Diffstat (limited to 'app/scripts/lib/config-manager.js')
-rw-r--r--app/scripts/lib/config-manager.js82
1 files changed, 77 insertions, 5 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 102327c2d..0e7454dfd 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -145,15 +145,25 @@ ConfigManager.prototype.setData = function(data) {
this.migrator.saveData(data)
}
+//
+// Tx
+//
+
ConfigManager.prototype.getTxList = function() {
var data = this.migrator.getData()
- if ('transactions' in data) {
+ if (data.transactions !== undefined) {
return data.transactions
} else {
return []
}
}
+ConfigManager.prototype.unconfirmedTxs = function() {
+ var transactions = this.getTxList()
+ return transactions.filter(tx => tx.status === 'unconfirmed')
+ .reduce((result, tx) => { result[tx.id] = tx; return result }, {})
+}
+
ConfigManager.prototype._saveTxList = function(txList) {
var data = this.migrator.getData()
data.transactions = txList
@@ -201,12 +211,74 @@ ConfigManager.prototype.updateTx = function(tx) {
this._saveTxList(transactions)
}
-ConfigManager.prototype.unconfirmedTxs = function() {
- var transactions = this.getTxList()
- return transactions.filter(tx => tx.status === 'unconfirmed')
- .reduce((result, tx) => { result[tx.id] = tx; return result }, {})
+//
+// Msg
+//
+
+ConfigManager.prototype.getMsgList = function() {
+ var data = this.migrator.getData()
+ if (data.messages !== undefined) {
+ return data.messages
+ } else {
+ return []
+ }
+}
+
+ConfigManager.prototype.unconfirmedMsgs = function() {
+ var messages = this.getMsgList()
+ return messages.filter(msg => msg.status === 'unconfirmed')
+ .reduce((result, msg) => { result[msg.id] = msg; return result }, {})
+}
+
+ConfigManager.prototype._saveMsgList = function(msgList) {
+ var data = this.migrator.getData()
+ data.messages = msgList
+ this.setData(data)
}
+ConfigManager.prototype.addMsg = function(msg) {
+ var messages = this.getMsgList()
+ messages.push(msg)
+ this._saveMsgList(messages)
+}
+
+ConfigManager.prototype.getMsg = function(msgId) {
+ var messages = this.getMsgList()
+ var matching = messages.filter(msg => msg.id === msgId)
+ return matching.length > 0 ? matching[0] : null
+}
+
+ConfigManager.prototype.confirmMsg = function(msgId) {
+ this._setMsgStatus(msgId, 'confirmed')
+}
+
+ConfigManager.prototype.rejectMsg = function(msgId) {
+ this._setMsgStatus(msgId, 'rejected')
+}
+
+ConfigManager.prototype._setMsgStatus = function(msgId, status) {
+ var msg = this.getMsg(msgId)
+ msg.status = status
+ this.updateMsg(msg)
+}
+
+ConfigManager.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)
+}
+
+
+
// observable
ConfigManager.prototype.subscribe = function(fn){