Skip to content

Commit

Permalink
fix: use BN from bn.js instead of ethereumjs-util (#28146)
Browse files Browse the repository at this point in the history
## **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.
  • Loading branch information
legobeat authored Nov 26, 2024
1 parent af9ebca commit dadeac9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/scripts/migrations/088.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasProperty, Hex, isObject, isStrictHexString } from '@metamask/utils';
import { BN } from 'ethereumjs-util';
import BN from 'bn.js';
import { cloneDeep, mapKeys } from 'lodash';
import log from 'loglevel';

Expand Down Expand Up @@ -302,6 +302,6 @@ function toHex(value: number | string | BN): Hex {
}
const hexString = BN.isBN(value)
? value.toString(16)
: new BN(value.toString(), 10).toString(16);
: new BN(value.toString(10), 10).toString(16);
return `0x${hexString}`;
}
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@
"eslint@npm:^8.7.0": "patch:eslint@npm%3A8.57.0#~/.yarn/patches/eslint-npm-8.57.0-4286e12a3a.patch",
"eth-query@^2.1.2": "patch:eth-query@npm%3A2.1.2#./.yarn/patches/eth-query-npm-2.1.2-7c6adc825f.patch",
"eth-query@^2.1.0": "patch:eth-query@npm%3A2.1.2#./.yarn/patches/eth-query-npm-2.1.2-7c6adc825f.patch",
"ethereumjs-util@^5.1.1": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
"ethereumjs-util@^5.1.2": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
"ethereumjs-util@^5.1.5": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
"ethereumjs-util@^5.0.0": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
"ethereumjs-util@^5.2.0": "patch:ethereumjs-util@npm%3A5.2.1#./.yarn/patches/ethereumjs-util-npm-5.2.1-72b39f4e7e.patch",
"ethereumjs-util@^7.0.10": "patch:ethereumjs-util@npm%3A7.1.5#./.yarn/patches/ethereumjs-util-npm-7.1.5-5bb4d00000.patch",
"ethereumjs-util@^7.1.5": "patch:ethereumjs-util@npm%3A7.1.5#./.yarn/patches/ethereumjs-util-npm-7.1.5-5bb4d00000.patch",
"ethereumjs-util@^7.1.4": "patch:ethereumjs-util@npm%3A7.1.5#./.yarn/patches/ethereumjs-util-npm-7.1.5-5bb4d00000.patch",
Expand Down
3 changes: 2 additions & 1 deletion shared/modules/conversion.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Hex } from '@metamask/utils';
import { BigNumber } from 'bignumber.js';
import { addHexPrefix, BN } from 'ethereumjs-util';
import BN from 'bn.js';
import { addHexPrefix } from 'ethereumjs-util';
import { EtherDenomination } from '../constants/common';
import { Numeric, NumericValue } from './Numeric';

Expand Down
6 changes: 3 additions & 3 deletions ui/helpers/utils/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import punycode from 'punycode/punycode';
import abi from 'human-standard-token-abi';
import BigNumber from 'bignumber.js';
import * as ethUtil from 'ethereumjs-util';
import BN from 'bn.js';
import { DateTime } from 'luxon';
import {
getFormattedIpfsUrl,
Expand Down Expand Up @@ -168,10 +168,10 @@ export function isOriginContractAddress(to, sendTokenAddress) {
// Takes wei Hex, returns wei BN, even if input is null
export function numericBalance(balance) {
if (!balance) {
return new ethUtil.BN(0, 16);
return new BN(0, 16);
}
const stripped = stripHexPrefix(balance);
return new ethUtil.BN(stripped, 16);
return new BN(stripped, 16);
}

// Takes hex, returns [beforeDecimal, afterDecimal]
Expand Down
3 changes: 2 additions & 1 deletion ui/helpers/utils/util.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Bowser from 'bowser';
import { BN, toChecksumAddress } from 'ethereumjs-util';
import BN from 'bn.js';
import { toChecksumAddress } from 'ethereumjs-util';
import { CHAIN_IDS } from '../../../shared/constants/network';
import { addHexPrefixToObjectValues } from '../../../shared/lib/swaps-utils';
import { toPrecisionWithoutTrailingZeros } from '../../../shared/lib/transactions-controller-utils';
Expand Down

0 comments on commit dadeac9

Please sign in to comment.