diff options
idStore - seperate signTx and sendTx
-rw-r--r-- | app/scripts/background.js | 1 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 42 |
2 files changed, 30 insertions, 13 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 6a1b7404f..53acaa290 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -80,6 +80,7 @@ function handleInternalCommunication(remotePort){ setSelectedAddress: idStore.setSelectedAddress.bind(idStore), signTransaction: idStore.signTransaction.bind(idStore), cancelTransaction: idStore.cancelTransaction.bind(idStore), + sendTransaction: idStore.sendTransaction.bind(idStore), setLocked: idStore.setLocked.bind(idStore), }) duplex.pipe(connection).pipe(duplex) diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 73992caa4..fa5e1fa67 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -105,32 +105,48 @@ IdentityStore.prototype.signTransaction = function(password, txId, cb){ var txData = self._currentState.unconfTxs[txId] var txParams = txData.txParams - self._signTransaction(txParams, function(err, rawTx, txHash){ + self._signTransaction(password, txParams, function(err, rawTx, txHash){ if (err) { - throw err + cb(err) txData.status = 'error' txData.error = err self._didUpdate() return } + txData.rawTx = rawTx txData.hash = txHash - txData.status = 'pending' + txData.status = 'signed' - // for now just remove it - delete self._currentState.unconfTxs[txData.id] - - // rpc callback - var txSigCb = self._unconfTxCbs[txId] || noop - txSigCb(null, rawTx) - - // confirm tx callback + // confirm tx signed cb() - self._didUpdate() }) } +IdentityStore.prototype.sendTransaction = function(txId, cb){ + const self = this + + var txData = self._currentState.unconfTxs[txId] + + if (!txData || txData.status !== 'signed') { + return cb(new Error('IdentityStore - Transaction not signed:', txId)) + } + + var rawTx = txData.rawTx + + // for now just remove it + delete self._currentState.unconfTxs[txData.id] + + // rpc callback + var txSigCb = self._unconfTxCbs[txId] || noop + txSigCb(null, rawTx) + + // confirm tx sent + cb() + self._didUpdate() +} + IdentityStore.prototype.cancelTransaction = function(txId){ const self = this @@ -144,7 +160,7 @@ IdentityStore.prototype.cancelTransaction = function(txId){ // // internal - actually signs the tx -IdentityStore.prototype._signTransaction = function(txParams, cb){ +IdentityStore.prototype._signTransaction = function(password, txParams, cb){ const self = this try { // console.log('signing tx:', txParams) |