mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
parent
fb002dc44e
commit
9c6c277b8b
@ -177,8 +177,8 @@ module.exports = class MetamaskController {
|
||||
// tx signing
|
||||
approveTransaction: this.newUnsignedTransaction.bind(this),
|
||||
signTransaction: (...args) => {
|
||||
this.setupSigningListners(...args)
|
||||
this.txManager.formatTxForSigining(...args)
|
||||
this.setupSigningListeners(...args)
|
||||
this.txManager.formatTxForSigning(...args)
|
||||
this.sendUpdate()
|
||||
},
|
||||
|
||||
@ -257,7 +257,7 @@ module.exports = class MetamaskController {
|
||||
})
|
||||
}
|
||||
|
||||
setupSigningListners (txParams) {
|
||||
setupSigningListeners (txParams) {
|
||||
var txId = txParams.metamaskId
|
||||
// apply event listeners for signing and formating events
|
||||
this.txManager.once(`${txId}:formatted`, this.keyringController.signTransaction.bind(this.keyringController))
|
||||
|
@ -137,26 +137,33 @@ module.exports = class TransactionManager extends EventEmitter {
|
||||
}
|
||||
|
||||
// formats txParams so the keyringController can sign it
|
||||
formatTxForSigining (txParams, cb) {
|
||||
var address = txParams.from
|
||||
var metaTx = this.getTx(txParams.metamaskId)
|
||||
var gasMultiplier = metaTx.gasMultiplier
|
||||
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16)
|
||||
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100, 10)).div(new BN(100, 10))
|
||||
txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber())
|
||||
formatTxForSigning (txParams, cb) {
|
||||
this.getNetwork((err, networkId) => {
|
||||
if (err) {
|
||||
return cb(err)
|
||||
}
|
||||
|
||||
// normalize values
|
||||
txParams.to = normalize(txParams.to)
|
||||
txParams.from = normalize(txParams.from)
|
||||
txParams.value = normalize(txParams.value)
|
||||
txParams.data = normalize(txParams.data)
|
||||
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
|
||||
txParams.nonce = normalize(txParams.nonce)
|
||||
const ethTx = new Transaction(txParams)
|
||||
var address = txParams.from
|
||||
var metaTx = this.getTx(txParams.metamaskId)
|
||||
var gasMultiplier = metaTx.gasMultiplier
|
||||
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16)
|
||||
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100, 10)).div(new BN(100, 10))
|
||||
txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber())
|
||||
|
||||
// listener is assigned in metamaskController
|
||||
this.emit(`${txParams.metamaskId}:formatted`, ethTx, address, txParams.metamaskId, cb)
|
||||
}
|
||||
// normalize values
|
||||
txParams.to = normalize(txParams.to)
|
||||
txParams.from = normalize(txParams.from)
|
||||
txParams.value = normalize(txParams.value)
|
||||
txParams.data = normalize(txParams.data)
|
||||
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
|
||||
txParams.nonce = normalize(txParams.nonce)
|
||||
|
||||
const ethTx = new Transaction(txParams, parseInt(networkId))
|
||||
|
||||
// listener is assigned in metamaskController
|
||||
this.emit(`${txParams.metamaskId}:formatted`, ethTx, address, txParams.metamaskId, cb)
|
||||
})
|
||||
}
|
||||
|
||||
// receives a signed tx object and updates the tx hash
|
||||
// and pass it to the cb to be sent off
|
||||
|
Loading…
Reference in New Issue
Block a user