mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix radix issues (#9247)
See [`radix`](https://eslint.org/docs/rules/radix) for more information. This change enables `radix` and fixes the issues raised by the rule.
This commit is contained in:
parent
eb653dfb6e
commit
b7259e5d6a
@ -72,6 +72,7 @@ module.exports = {
|
||||
'no-useless-concat': 'error',
|
||||
'prefer-rest-params': 'error',
|
||||
'prefer-spread': 'error',
|
||||
'radix': 'error',
|
||||
'require-unicode-regexp': 'error',
|
||||
/* End v2 rules */
|
||||
'arrow-parens': 'error',
|
||||
|
@ -529,6 +529,7 @@ export default class PreferencesController {
|
||||
}
|
||||
if (url !== 'http://localhost:8545') {
|
||||
let checkedChainId
|
||||
// eslint-disable-next-line radix
|
||||
if (!!chainId && !Number.isNaN(parseInt(chainId))) {
|
||||
checkedChainId = chainId
|
||||
}
|
||||
|
@ -133,6 +133,7 @@ export default class TransactionController extends EventEmitter {
|
||||
*/
|
||||
getChainId () {
|
||||
const networkState = this.networkStore.getState()
|
||||
// eslint-disable-next-line radix
|
||||
const integerChainId = parseInt(networkState)
|
||||
if (Number.isNaN(integerChainId)) {
|
||||
return 0
|
||||
|
@ -165,6 +165,7 @@ export default class TypedMessageManager extends EventEmitter {
|
||||
assert.ok(data.primaryType in data.types, `Primary type of "${data.primaryType}" has no type definition.`)
|
||||
assert.equal(validation.errors.length, 0, 'Signing data must conform to EIP-712 schema. See https://git.io/fNtcx.')
|
||||
const chainId = data.domain.chainId
|
||||
// eslint-disable-next-line radix
|
||||
const activeChainId = parseInt(this.networkController.getNetworkState())
|
||||
chainId && assert.equal(chainId, activeChainId, `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`)
|
||||
break
|
||||
|
@ -28,6 +28,7 @@ function transformState (state) {
|
||||
const frequentRpcListDetail = newState.PreferencesController.frequentRpcListDetail
|
||||
if (frequentRpcListDetail) {
|
||||
frequentRpcListDetail.forEach((rpc, index) => {
|
||||
// eslint-disable-next-line radix
|
||||
if (!!rpc.chainId && Number.isNaN(parseInt(rpc.chainId))) {
|
||||
delete frequentRpcListDetail[index].chainId
|
||||
}
|
||||
@ -36,10 +37,12 @@ function transformState (state) {
|
||||
}
|
||||
}
|
||||
if (state.NetworkController) {
|
||||
// eslint-disable-next-line radix
|
||||
if (newState.NetworkController.network && Number.isNaN(parseInt(newState.NetworkController.network))) {
|
||||
delete newState.NetworkController.network
|
||||
}
|
||||
|
||||
// eslint-disable-next-line radix
|
||||
if (newState.NetworkController.provider && newState.NetworkController.provider.chainId && Number.isNaN(parseInt(newState.NetworkController.provider.chainId))) {
|
||||
delete newState.NetworkController.provider.chainId
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ export default class ExtensionPlatform {
|
||||
|
||||
this._subscribeToNotificationClicked()
|
||||
|
||||
const url = explorerLink(txMeta.hash, parseInt(txMeta.metamaskNetworkId))
|
||||
const url = explorerLink(txMeta.hash, txMeta.metamaskNetworkId)
|
||||
const nonce = parseInt(txMeta.txParams.nonce, 16)
|
||||
|
||||
const title = 'Confirmed transaction'
|
||||
|
@ -694,7 +694,7 @@ describe('MetaMaskController', function () {
|
||||
metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs()
|
||||
messages = metamaskController.messageManager.messages
|
||||
msgId = Object.keys(metamaskMsgs)[0]
|
||||
messages[0].msgParams.metamaskId = parseInt(msgId)
|
||||
messages[0].msgParams.metamaskId = parseInt(msgId, 10)
|
||||
})
|
||||
|
||||
it('persists address from msg params', function () {
|
||||
@ -714,7 +714,7 @@ describe('MetaMaskController', function () {
|
||||
})
|
||||
|
||||
it('rejects the message', function () {
|
||||
const msgIdInt = parseInt(msgId)
|
||||
const msgIdInt = parseInt(msgId, 10)
|
||||
metamaskController.cancelMessage(msgIdInt, noop)
|
||||
assert.equal(messages[0].status, 'rejected')
|
||||
})
|
||||
@ -754,7 +754,7 @@ describe('MetaMaskController', function () {
|
||||
metamaskPersonalMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs()
|
||||
personalMessages = metamaskController.personalMessageManager.messages
|
||||
msgId = Object.keys(metamaskPersonalMsgs)[0]
|
||||
personalMessages[0].msgParams.metamaskId = parseInt(msgId)
|
||||
personalMessages[0].msgParams.metamaskId = parseInt(msgId, 10)
|
||||
})
|
||||
|
||||
it('errors with no from in msgParams', async function () {
|
||||
@ -785,7 +785,7 @@ describe('MetaMaskController', function () {
|
||||
})
|
||||
|
||||
it('rejects the message', function () {
|
||||
const msgIdInt = parseInt(msgId)
|
||||
const msgIdInt = parseInt(msgId, 10)
|
||||
metamaskController.cancelPersonalMessage(msgIdInt, noop)
|
||||
assert.equal(personalMessages[0].status, 'rejected')
|
||||
})
|
||||
|
@ -307,7 +307,7 @@ describe('Transaction Controller', function () {
|
||||
txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
|
||||
const rawTx = await txController.signTransaction('1')
|
||||
const ethTx = new EthTx(ethUtil.toBuffer(rawTx))
|
||||
assert.equal(ethTx.getChainId(), parseInt(currentNetworkId))
|
||||
assert.equal(ethTx.getChainId(), 42)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -68,8 +68,8 @@ describe('Typed Message Manager', function () {
|
||||
typedMsgs = typedMessageManager.getUnapprovedMsgs()
|
||||
messages = typedMessageManager.messages
|
||||
msgId = Object.keys(typedMsgs)[0]
|
||||
messages[0].msgParams.metamaskId = parseInt(msgId)
|
||||
numberMsgId = parseInt(msgId)
|
||||
messages[0].msgParams.metamaskId = parseInt(msgId, 10)
|
||||
numberMsgId = parseInt(msgId, 10)
|
||||
})
|
||||
|
||||
it('supports version 1 of signedTypedData', function () {
|
||||
|
@ -55,7 +55,7 @@ describe('migrations', function () {
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
.map((num) => parseInt(num))
|
||||
.map((num) => parseInt(num, 10))
|
||||
})
|
||||
|
||||
it('should include all migrations', function () {
|
||||
@ -75,7 +75,7 @@ describe('migrations', function () {
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
.map((num) => parseInt(num))
|
||||
.map((num) => parseInt(num, 10))
|
||||
|
||||
migrationNumbers.forEach((num) => {
|
||||
if (num >= 33) {
|
||||
|
@ -573,7 +573,7 @@ describe('Actions', function () {
|
||||
metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs()
|
||||
messages = metamaskController.messageManager.messages
|
||||
msgId = Object.keys(metamaskMsgs)[0]
|
||||
messages[0].msgParams.metamaskId = parseInt(msgId)
|
||||
messages[0].msgParams.metamaskId = parseInt(msgId, 10)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
@ -626,7 +626,7 @@ describe('Actions', function () {
|
||||
metamaskMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs()
|
||||
personalMessages = metamaskController.personalMessageManager.messages
|
||||
msgId = Object.keys(metamaskMsgs)[0]
|
||||
personalMessages[0].msgParams.metamaskId = parseInt(msgId)
|
||||
personalMessages[0].msgParams.metamaskId = parseInt(msgId, 10)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
@ -714,7 +714,7 @@ describe('Actions', function () {
|
||||
messages = metamaskController.typedMessageManager.getUnapprovedMsgs()
|
||||
typedMessages = metamaskController.typedMessageManager.messages
|
||||
msgId = Object.keys(messages)[0]
|
||||
typedMessages[0].msgParams.metamaskId = parseInt(msgId)
|
||||
typedMessages[0].msgParams.metamaskId = parseInt(msgId, 10)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
|
@ -111,8 +111,8 @@ export default class MenuDroppoComponent extends Component {
|
||||
<ReactCSSTransitionGroup
|
||||
className="css-transition-group"
|
||||
transitionName="menu-droppo"
|
||||
transitionEnterTimeout={parseInt(speed)}
|
||||
transitionLeaveTimeout={parseInt(speed)}
|
||||
transitionEnterTimeout={parseInt(speed, 10)}
|
||||
transitionLeaveTimeout={parseInt(speed, 10)}
|
||||
>
|
||||
{this.renderPrimary()}
|
||||
</ReactCSSTransitionGroup>
|
||||
|
@ -2,9 +2,9 @@ import ethUtil from 'ethereumjs-util'
|
||||
import { conversionUtil, multiplyCurrencies } from '../../helpers/utils/conversion-util'
|
||||
|
||||
const MIN_GAS_PRICE_DEC = '0'
|
||||
const MIN_GAS_PRICE_HEX = (parseInt(MIN_GAS_PRICE_DEC)).toString(16)
|
||||
const MIN_GAS_PRICE_HEX = (parseInt(MIN_GAS_PRICE_DEC, 10)).toString(16)
|
||||
const MIN_GAS_LIMIT_DEC = '21000'
|
||||
const MIN_GAS_LIMIT_HEX = (parseInt(MIN_GAS_LIMIT_DEC)).toString(16)
|
||||
const MIN_GAS_LIMIT_HEX = (parseInt(MIN_GAS_LIMIT_DEC, 10)).toString(16)
|
||||
|
||||
const MIN_GAS_PRICE_GWEI = ethUtil.addHexPrefix(conversionUtil(MIN_GAS_PRICE_HEX, {
|
||||
fromDenomination: 'WEI',
|
||||
|
@ -206,6 +206,7 @@ export default class NetworkForm extends PureComponent {
|
||||
}
|
||||
|
||||
validateChainId = (chainId) => {
|
||||
// eslint-disable-next-line radix
|
||||
this.setErrorTo('chainId', !!chainId && Number.isNaN(parseInt(chainId))
|
||||
? `${this.context.t('invalidInput')} chainId`
|
||||
: '',
|
||||
|
@ -3,6 +3,7 @@ export default function getAccountLink (address, network, rpcPrefs) {
|
||||
return `${rpcPrefs.blockExplorerUrl.replace(/\/+$/u, '')}/address/${address}`
|
||||
}
|
||||
|
||||
// eslint-disable-next-line radix
|
||||
const net = parseInt(network)
|
||||
switch (net) {
|
||||
case 1: // main net
|
||||
|
Loading…
Reference in New Issue
Block a user