aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/idStore.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-05-04 05:32:22 +0800
committerDan Finlay <dan@danfinlay.com>2016-05-04 05:32:22 +0800
commite6c4d63ccdaf93d8b74965d39661e80d774504d8 (patch)
tree28ba41a15fb93ac94f3ea1a8ff0dae637655119b /app/scripts/lib/idStore.js
parentdcbf17af2d547ce676178bf78328d5c01135e31a (diff)
downloadtangerine-wallet-browser-e6c4d63ccdaf93d8b74965d39661e80d774504d8.tar
tangerine-wallet-browser-e6c4d63ccdaf93d8b74965d39661e80d774504d8.tar.gz
tangerine-wallet-browser-e6c4d63ccdaf93d8b74965d39661e80d774504d8.tar.bz2
tangerine-wallet-browser-e6c4d63ccdaf93d8b74965d39661e80d774504d8.tar.lz
tangerine-wallet-browser-e6c4d63ccdaf93d8b74965d39661e80d774504d8.tar.xz
tangerine-wallet-browser-e6c4d63ccdaf93d8b74965d39661e80d774504d8.tar.zst
tangerine-wallet-browser-e6c4d63ccdaf93d8b74965d39661e80d774504d8.zip
Add UI for Signing Messages
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.
Diffstat (limited to 'app/scripts/lib/idStore.js')
-rw-r--r--app/scripts/lib/idStore.js27
1 files changed, 19 insertions, 8 deletions
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index c25d83c9d..b8d825d8b 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -9,6 +9,7 @@ const extend = require('xtend')
const createId = require('web3-provider-engine/util/random-id')
const autoFaucet = require('./auto-faucet')
const configManager = require('./config-manager-singleton')
+const messageManager = require('./message-manager')
const DEFAULT_RPC = 'https://testrpc.metamask.io/'
@@ -32,6 +33,7 @@ function IdentityStore(opts = {}) {
selectedAddress: null,
identities: {},
}
+
// not part of serilized metamask state - only kept in memory
this._unconfTxCbs = {}
this._unconfMsgCbs = {}
@@ -85,6 +87,8 @@ IdentityStore.prototype.getState = function(){
seedWords: seedWords,
unconfTxs: configManager.unconfirmedTxs(),
transactions: configManager.getTxList(),
+ unconfMsgs: messageManager.unconfirmedMsgs(),
+ messages: messageManager.getMsgList(),
selectedAddress: configManager.getSelectedAccount(),
}))
}
@@ -226,7 +230,7 @@ IdentityStore.prototype.addUnconfirmedMessage = function(msgParams, cb){
time: time,
status: 'unconfirmed',
}
- configManager.addMsg(msgData)
+ messageManager.addMsg(msgData)
console.log('addUnconfirmedMessage:', msgData)
// keep the cb around for after approval (requires user interaction)
@@ -241,27 +245,27 @@ IdentityStore.prototype.addUnconfirmedMessage = function(msgParams, cb){
// comes from metamask ui
IdentityStore.prototype.approveMessage = function(msgId, cb){
- var msgData = configManager.getMsg(msgId)
+ var msgData = messageManager.getMsg(msgId)
var approvalCb = this._unconfMsgCbs[msgId] || noop
// accept msg
cb()
approvalCb(null, true)
// clean up
- configManager.confirmMsg(msgId)
+ messageManager.confirmMsg(msgId)
delete this._unconfMsgCbs[msgId]
this._didUpdate()
}
// comes from metamask ui
IdentityStore.prototype.cancelMessage = function(msgId){
- var txData = configManager.getMsg(msgId)
+ var txData = messageManager.getMsg(msgId)
var approvalCb = this._unconfMsgCbs[msgId] || noop
// reject tx
approvalCb(null, false)
// clean up
- configManager.rejectMsg(msgId)
+ messageManager.rejectMsg(msgId)
delete this._unconfTxCbs[msgId]
this._didUpdate()
}
@@ -271,7 +275,14 @@ IdentityStore.prototype.signMessage = function(msgParams, cb){
try {
console.log('signing msg...', msgParams.data)
var rawMsg = this._idmgmt.signMsg(msgParams.from, msgParams.data)
- cb(null, rawMsg)
+ if ('metamaskId' in msgParams) {
+ var id = msgParams.metamaskId
+ delete msgParams.metamaskId
+
+ this.approveMessage(id, cb)
+ } else {
+ cb(null, rawMsg)
+ }
} catch (err) {
cb(err)
}
@@ -426,7 +437,7 @@ function IdManagement(opts) {
var privKeyHex = this.exportPrivateKey(txParams.from)
var privKey = ethUtil.toBuffer(privKeyHex)
tx.sign(privKey)
-
+
// Add the tx hash to the persisted meta-tx object
var txHash = ethUtil.bufferToHex(tx.hash())
var metaTx = configManager.getTx(txParams.metamaskId)
@@ -472,4 +483,4 @@ function concatSig(v, r, s) {
s = ethUtil.toUnsigned(s).toString('hex')
v = ethUtil.stripHexPrefix(ethUtil.intToHex(v))
return ethUtil.addHexPrefix(r.concat(s, v).toString("hex"))
-} \ No newline at end of file
+}