diff --git a/packages/wallet-sdk/.eslintrc.js b/packages/wallet-sdk/.eslintrc.js index cdf7a987a2..b681ca8163 100644 --- a/packages/wallet-sdk/.eslintrc.js +++ b/packages/wallet-sdk/.eslintrc.js @@ -68,6 +68,13 @@ module.exports = { // TODO: change this back to error '@typescript-eslint/no-explicit-any': 'warn', 'no-useless-constructor': 'off', + 'no-restricted-globals': [ + 'error', + { + name: 'parseInt', + message: 'Use Number.parseInt instead of parseInt.', + }, + ], }, overrides: [ { diff --git a/packages/wallet-sdk/src/core/type/util.ts b/packages/wallet-sdk/src/core/type/util.ts index 1ba3a4564e..0dede56f59 100644 --- a/packages/wallet-sdk/src/core/type/util.ts +++ b/packages/wallet-sdk/src/core/type/util.ts @@ -19,7 +19,7 @@ export function uint8ArrayToHex(value: Uint8Array) { } export function hexStringToUint8Array(hexString: string): Uint8Array { - return new Uint8Array(hexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))); + return new Uint8Array(hexString.match(/.{1,2}/g)!.map((byte) => Number.parseInt(byte, 16))); } export function hexStringFromBuffer(buf: Buffer, includePrefix = false): HexString { diff --git a/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.ts b/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.ts index 44122010a5..11ed22bbe1 100644 --- a/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.ts +++ b/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.ts @@ -155,7 +155,7 @@ export class WalletLinkSigner implements Signer { throw standardErrors.rpc.invalidParams('nativeCurrency is a required field'); } - const chainIdNumber = parseInt(request.chainId, 16); + const chainIdNumber = Number.parseInt(request.chainId, 16); if (chainIdNumber === this.getChainId()) { return false; @@ -193,7 +193,7 @@ export class WalletLinkSigner implements Signer { const request = params[0] as { chainId: string; }; - const chainId = parseInt(request.chainId, 16); + const chainId = Number.parseInt(request.chainId, 16); const relay = this.initializeRelay(); const res = await relay.switchEthereumChain( @@ -358,7 +358,7 @@ export class WalletLinkSigner implements Signer { } private getChainId(): number { - return parseInt(this._storage.getItem(DEFAULT_CHAIN_ID_KEY) ?? '1', 10); + return Number.parseInt(this._storage.getItem(DEFAULT_CHAIN_ID_KEY) ?? '1', 10); } private async _eth_requestAccounts() { diff --git a/packages/wallet-sdk/src/sign/walletlink/relay/WalletLinkRelay.ts b/packages/wallet-sdk/src/sign/walletlink/relay/WalletLinkRelay.ts index 8261d23edb..8e6fe3bb5a 100644 --- a/packages/wallet-sdk/src/sign/walletlink/relay/WalletLinkRelay.ts +++ b/packages/wallet-sdk/src/sign/walletlink/relay/WalletLinkRelay.ts @@ -122,7 +122,7 @@ export class WalletLinkRelay implements WalletLinkConnectionUpdateListener { }; if (this.chainCallback) { - this.chainCallback(jsonRpcUrl, parseInt(chainId, 10)); + this.chainCallback(jsonRpcUrl, Number.parseInt(chainId, 10)); } }; diff --git a/packages/wallet-sdk/src/sign/walletlink/relay/mocks/fixtures.ts b/packages/wallet-sdk/src/sign/walletlink/relay/mocks/fixtures.ts index 09216aa4c0..f3f2ef2f5d 100644 --- a/packages/wallet-sdk/src/sign/walletlink/relay/mocks/fixtures.ts +++ b/packages/wallet-sdk/src/sign/walletlink/relay/mocks/fixtures.ts @@ -26,7 +26,7 @@ export const MOCK_TYPED_DATA = JSON.stringify({ domain: { name: 'Provider Test', version: '1', - chainId: parseInt('1', 10), + chainId: Number.parseInt('1', 10), verifyingContract: MOCK_ADDERESS, salt: '0xf2d857f4a3edcb9b78b4d503bfe733db1e3f6cdc2b7971ee739626c97e86a558', }, diff --git a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/abi.js b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/abi.js index e3444324c8..88c8400a40 100644 --- a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/abi.js +++ b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/abi.js @@ -30,20 +30,20 @@ function elementaryName (name) { // Parse N from type function parseTypeN (type) { - return parseInt(/^\D+(\d+)$/.exec(type)[1], 10) + return Number.parseInt(/^\D+(\d+)$/.exec(type)[1], 10) } // Parse N,M from typex function parseTypeNxM (type) { var tmp = /^\D+(\d+)x(\d+)$/.exec(type) - return [ parseInt(tmp[1], 10), parseInt(tmp[2], 10) ] + return [ Number.parseInt(tmp[1], 10), Number.parseInt(tmp[2], 10) ] } // Parse N in type[] where "type" can itself be an array type. function parseTypeArray (type) { var tmp = type.match(/(.*)\[(.*?)\]$/) if (tmp) { - return tmp[2] === '' ? 'dynamic' : parseInt(tmp[2], 10) + return tmp[2] === '' ? 'dynamic' : Number.parseInt(tmp[2], 10) } return null } diff --git a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js index 47755cb8d1..cb3d45d99a 100644 --- a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js +++ b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js @@ -24,7 +24,7 @@ function bufferBEFromBigInt(num, length) { // Ensure the hex string length is even if (hex.length % 2 !== 0) hex = '0' + hex; // Convert hex string to a byte array - const byteArray = hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)); + const byteArray = hex.match(/.{1,2}/g).map(byte => Number.parseInt(byte, 16)); // Ensure the byte array is of the specified length while (byteArray.length < length) { byteArray.unshift(0); // Prepend with zeroes if shorter than required length