1
0
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:
Whymarrh Whitby 2020-08-18 16:38:22 -02:30 committed by GitHub
parent eb653dfb6e
commit b7259e5d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 26 additions and 17 deletions

View File

@ -72,6 +72,7 @@ module.exports = {
'no-useless-concat': 'error', 'no-useless-concat': 'error',
'prefer-rest-params': 'error', 'prefer-rest-params': 'error',
'prefer-spread': 'error', 'prefer-spread': 'error',
'radix': 'error',
'require-unicode-regexp': 'error', 'require-unicode-regexp': 'error',
/* End v2 rules */ /* End v2 rules */
'arrow-parens': 'error', 'arrow-parens': 'error',

View File

@ -529,6 +529,7 @@ export default class PreferencesController {
} }
if (url !== 'http://localhost:8545') { if (url !== 'http://localhost:8545') {
let checkedChainId let checkedChainId
// eslint-disable-next-line radix
if (!!chainId && !Number.isNaN(parseInt(chainId))) { if (!!chainId && !Number.isNaN(parseInt(chainId))) {
checkedChainId = chainId checkedChainId = chainId
} }

View File

@ -133,6 +133,7 @@ export default class TransactionController extends EventEmitter {
*/ */
getChainId () { getChainId () {
const networkState = this.networkStore.getState() const networkState = this.networkStore.getState()
// eslint-disable-next-line radix
const integerChainId = parseInt(networkState) const integerChainId = parseInt(networkState)
if (Number.isNaN(integerChainId)) { if (Number.isNaN(integerChainId)) {
return 0 return 0

View File

@ -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.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.') assert.equal(validation.errors.length, 0, 'Signing data must conform to EIP-712 schema. See https://git.io/fNtcx.')
const chainId = data.domain.chainId const chainId = data.domain.chainId
// eslint-disable-next-line radix
const activeChainId = parseInt(this.networkController.getNetworkState()) const activeChainId = parseInt(this.networkController.getNetworkState())
chainId && assert.equal(chainId, activeChainId, `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`) chainId && assert.equal(chainId, activeChainId, `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`)
break break

View File

@ -28,6 +28,7 @@ function transformState (state) {
const frequentRpcListDetail = newState.PreferencesController.frequentRpcListDetail const frequentRpcListDetail = newState.PreferencesController.frequentRpcListDetail
if (frequentRpcListDetail) { if (frequentRpcListDetail) {
frequentRpcListDetail.forEach((rpc, index) => { frequentRpcListDetail.forEach((rpc, index) => {
// eslint-disable-next-line radix
if (!!rpc.chainId && Number.isNaN(parseInt(rpc.chainId))) { if (!!rpc.chainId && Number.isNaN(parseInt(rpc.chainId))) {
delete frequentRpcListDetail[index].chainId delete frequentRpcListDetail[index].chainId
} }
@ -36,10 +37,12 @@ function transformState (state) {
} }
} }
if (state.NetworkController) { if (state.NetworkController) {
// eslint-disable-next-line radix
if (newState.NetworkController.network && Number.isNaN(parseInt(newState.NetworkController.network))) { if (newState.NetworkController.network && Number.isNaN(parseInt(newState.NetworkController.network))) {
delete 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))) { if (newState.NetworkController.provider && newState.NetworkController.provider.chainId && Number.isNaN(parseInt(newState.NetworkController.provider.chainId))) {
delete newState.NetworkController.provider.chainId delete newState.NetworkController.provider.chainId
} }

View File

@ -189,7 +189,7 @@ export default class ExtensionPlatform {
this._subscribeToNotificationClicked() 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 nonce = parseInt(txMeta.txParams.nonce, 16)
const title = 'Confirmed transaction' const title = 'Confirmed transaction'

View File

@ -694,7 +694,7 @@ describe('MetaMaskController', function () {
metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs() metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs()
messages = metamaskController.messageManager.messages messages = metamaskController.messageManager.messages
msgId = Object.keys(metamaskMsgs)[0] 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 () { it('persists address from msg params', function () {
@ -714,7 +714,7 @@ describe('MetaMaskController', function () {
}) })
it('rejects the message', function () { it('rejects the message', function () {
const msgIdInt = parseInt(msgId) const msgIdInt = parseInt(msgId, 10)
metamaskController.cancelMessage(msgIdInt, noop) metamaskController.cancelMessage(msgIdInt, noop)
assert.equal(messages[0].status, 'rejected') assert.equal(messages[0].status, 'rejected')
}) })
@ -754,7 +754,7 @@ describe('MetaMaskController', function () {
metamaskPersonalMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs() metamaskPersonalMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs()
personalMessages = metamaskController.personalMessageManager.messages personalMessages = metamaskController.personalMessageManager.messages
msgId = Object.keys(metamaskPersonalMsgs)[0] 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 () { it('errors with no from in msgParams', async function () {
@ -785,7 +785,7 @@ describe('MetaMaskController', function () {
}) })
it('rejects the message', function () { it('rejects the message', function () {
const msgIdInt = parseInt(msgId) const msgIdInt = parseInt(msgId, 10)
metamaskController.cancelPersonalMessage(msgIdInt, noop) metamaskController.cancelPersonalMessage(msgIdInt, noop)
assert.equal(personalMessages[0].status, 'rejected') assert.equal(personalMessages[0].status, 'rejected')
}) })

View File

@ -307,7 +307,7 @@ describe('Transaction Controller', function () {
txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop) txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
const rawTx = await txController.signTransaction('1') const rawTx = await txController.signTransaction('1')
const ethTx = new EthTx(ethUtil.toBuffer(rawTx)) const ethTx = new EthTx(ethUtil.toBuffer(rawTx))
assert.equal(ethTx.getChainId(), parseInt(currentNetworkId)) assert.equal(ethTx.getChainId(), 42)
}) })
}) })

View File

@ -68,8 +68,8 @@ describe('Typed Message Manager', function () {
typedMsgs = typedMessageManager.getUnapprovedMsgs() typedMsgs = typedMessageManager.getUnapprovedMsgs()
messages = typedMessageManager.messages messages = typedMessageManager.messages
msgId = Object.keys(typedMsgs)[0] msgId = Object.keys(typedMsgs)[0]
messages[0].msgParams.metamaskId = parseInt(msgId) messages[0].msgParams.metamaskId = parseInt(msgId, 10)
numberMsgId = parseInt(msgId) numberMsgId = parseInt(msgId, 10)
}) })
it('supports version 1 of signedTypedData', function () { it('supports version 1 of signedTypedData', function () {

View File

@ -55,7 +55,7 @@ describe('migrations', function () {
} }
return acc return acc
}, []) }, [])
.map((num) => parseInt(num)) .map((num) => parseInt(num, 10))
}) })
it('should include all migrations', function () { it('should include all migrations', function () {
@ -75,7 +75,7 @@ describe('migrations', function () {
} }
return acc return acc
}, []) }, [])
.map((num) => parseInt(num)) .map((num) => parseInt(num, 10))
migrationNumbers.forEach((num) => { migrationNumbers.forEach((num) => {
if (num >= 33) { if (num >= 33) {

View File

@ -573,7 +573,7 @@ describe('Actions', function () {
metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs() metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs()
messages = metamaskController.messageManager.messages messages = metamaskController.messageManager.messages
msgId = Object.keys(metamaskMsgs)[0] msgId = Object.keys(metamaskMsgs)[0]
messages[0].msgParams.metamaskId = parseInt(msgId) messages[0].msgParams.metamaskId = parseInt(msgId, 10)
}) })
afterEach(function () { afterEach(function () {
@ -626,7 +626,7 @@ describe('Actions', function () {
metamaskMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs() metamaskMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs()
personalMessages = metamaskController.personalMessageManager.messages personalMessages = metamaskController.personalMessageManager.messages
msgId = Object.keys(metamaskMsgs)[0] msgId = Object.keys(metamaskMsgs)[0]
personalMessages[0].msgParams.metamaskId = parseInt(msgId) personalMessages[0].msgParams.metamaskId = parseInt(msgId, 10)
}) })
afterEach(function () { afterEach(function () {
@ -714,7 +714,7 @@ describe('Actions', function () {
messages = metamaskController.typedMessageManager.getUnapprovedMsgs() messages = metamaskController.typedMessageManager.getUnapprovedMsgs()
typedMessages = metamaskController.typedMessageManager.messages typedMessages = metamaskController.typedMessageManager.messages
msgId = Object.keys(messages)[0] msgId = Object.keys(messages)[0]
typedMessages[0].msgParams.metamaskId = parseInt(msgId) typedMessages[0].msgParams.metamaskId = parseInt(msgId, 10)
}) })
afterEach(function () { afterEach(function () {

View File

@ -111,8 +111,8 @@ export default class MenuDroppoComponent extends Component {
<ReactCSSTransitionGroup <ReactCSSTransitionGroup
className="css-transition-group" className="css-transition-group"
transitionName="menu-droppo" transitionName="menu-droppo"
transitionEnterTimeout={parseInt(speed)} transitionEnterTimeout={parseInt(speed, 10)}
transitionLeaveTimeout={parseInt(speed)} transitionLeaveTimeout={parseInt(speed, 10)}
> >
{this.renderPrimary()} {this.renderPrimary()}
</ReactCSSTransitionGroup> </ReactCSSTransitionGroup>

View File

@ -2,9 +2,9 @@ import ethUtil from 'ethereumjs-util'
import { conversionUtil, multiplyCurrencies } from '../../helpers/utils/conversion-util' import { conversionUtil, multiplyCurrencies } from '../../helpers/utils/conversion-util'
const MIN_GAS_PRICE_DEC = '0' 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_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, { const MIN_GAS_PRICE_GWEI = ethUtil.addHexPrefix(conversionUtil(MIN_GAS_PRICE_HEX, {
fromDenomination: 'WEI', fromDenomination: 'WEI',

View File

@ -206,6 +206,7 @@ export default class NetworkForm extends PureComponent {
} }
validateChainId = (chainId) => { validateChainId = (chainId) => {
// eslint-disable-next-line radix
this.setErrorTo('chainId', !!chainId && Number.isNaN(parseInt(chainId)) this.setErrorTo('chainId', !!chainId && Number.isNaN(parseInt(chainId))
? `${this.context.t('invalidInput')} chainId` ? `${this.context.t('invalidInput')} chainId`
: '', : '',

View File

@ -3,6 +3,7 @@ export default function getAccountLink (address, network, rpcPrefs) {
return `${rpcPrefs.blockExplorerUrl.replace(/\/+$/u, '')}/address/${address}` return `${rpcPrefs.blockExplorerUrl.replace(/\/+$/u, '')}/address/${address}`
} }
// eslint-disable-next-line radix
const net = parseInt(network) const net = parseInt(network)
switch (net) { switch (net) {
case 1: // main net case 1: // main net