mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
transactions - remove unnecessary keys on txParams
This commit is contained in:
parent
1153120fe8
commit
343f0e9e80
@ -315,6 +315,18 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
//
|
//
|
||||||
|
|
||||||
_normalizeTxParams (txParams) {
|
_normalizeTxParams (txParams) {
|
||||||
|
const acceptableKeys = [
|
||||||
|
'from',
|
||||||
|
'to',
|
||||||
|
'nonce',
|
||||||
|
'value',
|
||||||
|
'data',
|
||||||
|
'gas',
|
||||||
|
'gasPrice',
|
||||||
|
]
|
||||||
|
Object.keys(txParams).forEach((key) => {
|
||||||
|
if (!acceptableKeys.includes(key)) delete txParams[key]
|
||||||
|
})
|
||||||
delete txParams.chainId
|
delete txParams.chainId
|
||||||
|
|
||||||
if ( !txParams.to ) {
|
if ( !txParams.to ) {
|
||||||
|
@ -239,6 +239,7 @@ describe('Transaction Controller', function () {
|
|||||||
from: 'a7df1beDBF813f57096dF77FCd515f0B3900e402',
|
from: 'a7df1beDBF813f57096dF77FCd515f0B3900e402',
|
||||||
to: null,
|
to: null,
|
||||||
data: '68656c6c6f20776f726c64',
|
data: '68656c6c6f20776f726c64',
|
||||||
|
random: 'hello world',
|
||||||
}
|
}
|
||||||
|
|
||||||
txController._normalizeTxParams(txParams)
|
txController._normalizeTxParams(txParams)
|
||||||
@ -247,7 +248,7 @@ describe('Transaction Controller', function () {
|
|||||||
assert(!txParams.to, 'their should be no to address if null')
|
assert(!txParams.to, 'their should be no to address if null')
|
||||||
assert.equal(txParams.from.slice(0, 2), '0x', 'from should be hexPrefixd')
|
assert.equal(txParams.from.slice(0, 2), '0x', 'from should be hexPrefixd')
|
||||||
assert.equal(txParams.data.slice(0, 2), '0x', 'data should be hexPrefixd')
|
assert.equal(txParams.data.slice(0, 2), '0x', 'data should be hexPrefixd')
|
||||||
|
assert(!('random' in txParams), 'their should be no random key in txParams')
|
||||||
txParams.to = 'a7df1beDBF813f57096dF77FCd515f0B3900e402'
|
txParams.to = 'a7df1beDBF813f57096dF77FCd515f0B3900e402'
|
||||||
|
|
||||||
txController._normalizeTxParams(txParams)
|
txController._normalizeTxParams(txParams)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user