Skip to content

Commit

Permalink
[Trivial] use es6 namespaced Number.parseInt (#1416)
Browse files Browse the repository at this point in the history
* update parseInt to es6 namespaced Number.parseInt

* enforce with lint rule
  • Loading branch information
nateReiners authored Oct 10, 2024
1 parent df81d47 commit 1bd8d67
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions packages/wallet-sdk/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-sdk/src/core/type/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet-sdk/src/vendor-js/eth-eip712-util/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ function elementaryName (name) {

// Parse N from type<N>
function parseTypeN (type) {
return parseInt(/^\D+(\d+)$/.exec(type)[1], 10)
return Number.parseInt(/^\D+(\d+)$/.exec(type)[1], 10)
}

// Parse N,M from type<N>x<M>
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[<N>] 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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1bd8d67

Please sign in to comment.