Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Fixed error when using latest metamask
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed Apr 3, 2018
1 parent 28277c8 commit 8222155
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
13 changes: 10 additions & 3 deletions app/scripts/controllers/sendTxCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,20 @@ var sendTxCtrl = function($scope, $sce, walletService, $rootScope) {
}

$scope.parseSignedTx = function( signedTx ) {
if( signedTx.slice(0,2)=="0x" ) signedTx = signedTx.slice(2, signedTx.length )
var txData = {}
var isJSON = false;
$scope.parsedSignedTx = {}
var txData = new ethUtil.Tx(signedTx)
if(Validator.isJSON(signedTx)){
txData = new ethUtil.Tx(JSON.parse(signedTx));
isJSON = true;
} else {
if( signedTx.slice(0,2)=="0x" ) signedTx = signedTx.slice(2, signedTx.length )
txData = new ethUtil.Tx(signedTx)
}
$scope.parsedSignedTx.gasPrice = {}
$scope.parsedSignedTx.txFee = {}
$scope.parsedSignedTx.balance = $scope.wallet.getBalance()
$scope.parsedSignedTx.from = ethFuncs.sanitizeHex(ethUtil.toChecksumAddress(txData.from.toString('hex')))
$scope.parsedSignedTx.from = isJSON ? $scope.wallet.getChecksumAddressString() : ethFuncs.sanitizeHex(ethUtil.toChecksumAddress(txData.from.toString('hex')))
$scope.parsedSignedTx.to = ethFuncs.sanitizeHex(ethUtil.toChecksumAddress(txData.to.toString('hex')))
$scope.parsedSignedTx.value = (txData.value=='0x'||txData.value==''||txData.value==null) ? '0' : etherUnits.toEther(new BigNumber(ethFuncs.sanitizeHex(txData.value.toString('hex'))).toString(), 'wei' )
$scope.parsedSignedTx.gasLimit = new BigNumber(ethFuncs.sanitizeHex(txData.gasLimit.toString('hex'))).toString()
Expand Down
55 changes: 30 additions & 25 deletions app/scripts/uiFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ uiFuncs.generateTx = function(txData, callback) {
value: ethFuncs.sanitizeHex(ethFuncs.decimalToHex(etherUnits.toWei(txData.value, txData.unit))),
data: ethFuncs.sanitizeHex(txData.data)
}
if (ajaxReq.eip155) rawTx.chainId = ajaxReq.chainId;
if (ajaxReq.eip155) rawTx.chainId = ethFuncs.sanitizeHex(new BigNumber(ajaxReq.chainId).toString(16));
rawTx.data = rawTx.data == '' ? '0x' : rawTx.data;
var eTx = new ethUtil.Tx(rawTx);
if ((typeof txData.hwType != "undefined") && (txData.hwType == "ledger")) {
var app = new ledgerEth(txData.hwTransport);
Expand Down Expand Up @@ -188,18 +189,20 @@ uiFuncs.generateTx = function(txData, callback) {
} else if ((typeof txData.hwType != "undefined") && (txData.hwType == "trezor")) {
uiFuncs.signTxTrezor(rawTx, txData, callback);
} else if ((typeof txData.hwType != "undefined") && (txData.hwType == "web3")) {
// for web3, we dont actually sign it here
// instead we put the final params in the "signedTx" field and
// wait for the confirmation dialogue / sendTx method
var txParams = Object.assign({ from: txData.from }, rawTx)
rawTx.rawTx = JSON.stringify(rawTx);
rawTx.signedTx = JSON.stringify(txParams);
rawTx.isError = false;
callback(rawTx)
// for web3, we dont actually sign it here
// instead we put the final params in the "signedTx" field and
// wait for the confirmation dialogue / sendTx method
var txParams = Object.assign({
from: txData.from
}, rawTx)
rawTx.rawTx = JSON.stringify(rawTx);
rawTx.signedTx = JSON.stringify(txParams);
rawTx.isError = false;
callback(rawTx)
} else if ((typeof txData.hwType != "undefined") && (txData.hwType == "digitalBitbox")) {
uiFuncs.signTxDigitalBitbox(eTx, rawTx, txData, callback);
} else if ((typeof txData.hwType != "undefined") && (txData.hwType == "secalot")) {
uiFuncs.signTxSecalot(eTx, rawTx, txData, callback);
uiFuncs.signTxSecalot(eTx, rawTx, txData, callback);
} else {
eTx.sign(new Buffer(txData.privKey, 'hex'));
rawTx.rawTx = JSON.stringify(rawTx);
Expand Down Expand Up @@ -237,19 +240,21 @@ uiFuncs.generateTx = function(txData, callback) {
}
}
uiFuncs.sendTx = function(signedTx, callback) {
// check for web3 late signed tx
if (signedTx.slice(0,2) !== '0x') {
var txParams = JSON.parse(signedTx)
window.web3.eth.sendTransaction(txParams, function(err, txHash){
if (err) {
return callback({
isError: true,
error: err.stack,
})
}
callback({ data: txHash })
});
return
// check for web3 late signed tx
if (signedTx.slice(0, 2) !== '0x') {
var txParams = JSON.parse(signedTx)
window.web3.eth.sendTransaction(txParams, function(err, txHash) {
if (err) {
return callback({
isError: true,
error: err.stack,
})
}
callback({
data: txHash
})
});
return
}

ajaxReq.sendRawTx(signedTx, function(data) {
Expand Down Expand Up @@ -330,5 +335,5 @@ uiFuncs.notifier = {
}
}
},
}
module.exports = uiFuncs;
}
module.exports = uiFuncs;

0 comments on commit 8222155

Please sign in to comment.