Skip to content

Commit dadeac9

Browse files
authored
fix: use BN from bn.js instead of ethereumjs-util (#28146)
## **Description** - remove redundant resolutions entries - `ethereumjs-util` v5 is no longer present - fix: use `BN` from bn.js (v5) instead of `ethereumjs-util` (deprecated version) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28146?quickstart=1) ## **Related issues** #### Blocking - #28169 - #28171 - #28170 ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent af9ebca commit dadeac9

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

app/scripts/migrations/088.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hasProperty, Hex, isObject, isStrictHexString } from '@metamask/utils';
2-
import { BN } from 'ethereumjs-util';
2+
import BN from 'bn.js';
33
import { cloneDeep, mapKeys } from 'lodash';
44
import log from 'loglevel';
55

@@ -302,6 +302,6 @@ function toHex(value: number | string | BN): Hex {
302302
}
303303
const hexString = BN.isBN(value)
304304
? value.toString(16)
305-
: new BN(value.toString(), 10).toString(16);
305+
: new BN(value.toString(10), 10).toString(16);
306306
return `0x${hexString}`;
307307
}

package.json

-5
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@
180180
"eslint@npm:^8.7.0": "patch:eslint@npm%3A8.57.0#~/.yarn/patches/eslint-npm-8.57.0-4286e12a3a.patch",
181181
"eth-query@^2.1.2": "patch:eth-query@npm%3A2.1.2#./.yarn/patches/eth-query-npm-2.1.2-7c6adc825f.patch",
182182
"eth-query@^2.1.0": "patch:eth-query@npm%3A2.1.2#./.yarn/patches/eth-query-npm-2.1.2-7c6adc825f.patch",
183-
"ethereumjs-util@^5.1.1": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
184-
"ethereumjs-util@^5.1.2": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
185-
"ethereumjs-util@^5.1.5": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
186-
"ethereumjs-util@^5.0.0": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
187-
"ethereumjs-util@^5.2.0": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
188183
"ethereumjs-util@^7.0.10": "patch:ethereumjs-util@npm%3A7.1.5#./.yarn/patches/ethereumjs-util-npm-7.1.5-5bb4d00000.patch",
189184
"ethereumjs-util@^7.1.5": "patch:ethereumjs-util@npm%3A7.1.5#./.yarn/patches/ethereumjs-util-npm-7.1.5-5bb4d00000.patch",
190185
"ethereumjs-util@^7.1.4": "patch:ethereumjs-util@npm%3A7.1.5#./.yarn/patches/ethereumjs-util-npm-7.1.5-5bb4d00000.patch",

shared/modules/conversion.utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Hex } from '@metamask/utils';
22
import { BigNumber } from 'bignumber.js';
3-
import { addHexPrefix, BN } from 'ethereumjs-util';
3+
import BN from 'bn.js';
4+
import { addHexPrefix } from 'ethereumjs-util';
45
import { EtherDenomination } from '../constants/common';
56
import { Numeric, NumericValue } from './Numeric';
67

ui/helpers/utils/util.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import punycode from 'punycode/punycode';
22
import abi from 'human-standard-token-abi';
33
import BigNumber from 'bignumber.js';
4-
import * as ethUtil from 'ethereumjs-util';
4+
import BN from 'bn.js';
55
import { DateTime } from 'luxon';
66
import {
77
getFormattedIpfsUrl,
@@ -168,10 +168,10 @@ export function isOriginContractAddress(to, sendTokenAddress) {
168168
// Takes wei Hex, returns wei BN, even if input is null
169169
export function numericBalance(balance) {
170170
if (!balance) {
171-
return new ethUtil.BN(0, 16);
171+
return new BN(0, 16);
172172
}
173173
const stripped = stripHexPrefix(balance);
174-
return new ethUtil.BN(stripped, 16);
174+
return new BN(stripped, 16);
175175
}
176176

177177
// Takes hex, returns [beforeDecimal, afterDecimal]

ui/helpers/utils/util.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Bowser from 'bowser';
2-
import { BN, toChecksumAddress } from 'ethereumjs-util';
2+
import BN from 'bn.js';
3+
import { toChecksumAddress } from 'ethereumjs-util';
34
import { CHAIN_IDS } from '../../../shared/constants/network';
45
import { addHexPrefixToObjectValues } from '../../../shared/lib/swaps-utils';
56
import { toPrecisionWithoutTrailingZeros } from '../../../shared/lib/transactions-controller-utils';

0 commit comments

Comments
 (0)