Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
915357d
fix(deps): unpin [email protected],x [email protected]
legobeat Oct 23, 2024
64e9f80
fix: add package @types/bn.js
legobeat Oct 23, 2024
82d9427
fix: import BN.js directly instead of through ethereumjs-util
legobeat Oct 23, 2024
3d55e25
fix: validateTokenAmount fix
legobeat Oct 23, 2024
cd7a42e
lint:fix
legobeat Oct 23, 2024
5745eab
chore: remove redundant depcheckrc entry
legobeat Oct 28, 2024
8b41954
chore: rename BN to BN4
legobeat Oct 28, 2024
28ec999
chore(devDeps): [email protected]>^20.27.5 (#12039)
legobeat Oct 28, 2024
f993c51
fix(deps): ethereumjs-util@^6.2.1->^7.1.5
legobeat Oct 21, 2024
71dd460
chore: testfix
legobeat Oct 23, 2024
68d5431
chore: remove usage of bn.js v4
legobeat Oct 28, 2024
fca7026
fix: toBN handle 0x-prefixed strings
legobeat Oct 28, 2024
b1e0cf9
fix: keep treating NaN as 0
legobeat Oct 28, 2024
5dff7dc
deps: number-to-bn -> @metamask/number-to-bn
legobeat Oct 28, 2024
4887e4a
hexToBN backwards-compatibility
legobeat Oct 28, 2024
341884c
toBN backwards-compat: falsey means 0
legobeat Oct 28, 2024
c0bbd6f
fix: treat string "NaN" as 0
legobeat Oct 28, 2024
6a86289
fix: default decimals=0 to prevent NaN calculation
legobeat Oct 28, 2024
f2dc7e4
fix(test): bn.js does not support scientific notation input
legobeat Oct 28, 2024
8561783
fix: toGwei, renderToGwei
legobeat Oct 28, 2024
b31de2d
wip: simplify fromTokenMinimalUnit
legobeat Oct 28, 2024
a240931
chore: update expected results for incorrectly rounding cases
legobeat Oct 28, 2024
6cc0955
fixup
legobeat Oct 28, 2024
6b53e86
use bignum.js for weiToFiatNumber
legobeat Oct 28, 2024
b2dd6bf
fixup
legobeat Oct 28, 2024
24c82e6
fix
legobeat Oct 28, 2024
523eba2
fix: toGwei use BigNumber, not BN
legobeat Oct 28, 2024
db0ac07
fix weiToFiat
legobeat Oct 28, 2024
96b490c
fix weiToFiat
legobeat Oct 28, 2024
f5c4787
fix weiToFiat
legobeat Oct 28, 2024
d7acee3
fix weiToFiatNumber
legobeat Oct 28, 2024
6b4ce3e
fix weiToFiatNumber
legobeat Oct 28, 2024
85cb7d6
fix: update test case that was asserting incorrect behavior
legobeat Oct 28, 2024
d0b5098
chore: fix incorrectly typed controller messages in test
legobeat Oct 28, 2024
89ab6bd
fix(ramps): use single internal representation of amount instead of 3
legobeat Oct 28, 2024
4bb3be6
fix test
legobeat Oct 28, 2024
e9fe643
fix(useBalance): remove balanceBN
legobeat Oct 28, 2024
ef2e7a9
buildquote: add memoizations
legobeat Oct 29, 2024
42d0736
chore: update test snapshot
legobeat Oct 29, 2024
511f945
useBalance refactor, test fix
legobeat Oct 29, 2024
098cd0f
buildquote: add memoizations
legobeat Oct 29, 2024
2db98c3
chore: clean up BuildQuote balance checks
legobeat Oct 29, 2024
9a7c754
chore: ramps test reordering
legobeat Oct 29, 2024
62494c2
fix: buildquote cleanup
legobeat Oct 29, 2024
2524583
fix: weiToFiat validation fix
legobeat Oct 29, 2024
f308077
fix: BuildQuote quickAmounts fix
legobeat Oct 29, 2024
e91a686
fix: simplify toTokenMinimalUnit
legobeat Oct 29, 2024
87fb6a2
fixup toTokenMinimalUnit
legobeat Oct 29, 2024
f3f6be4
fix: toTokenMinimalUnit
legobeat Oct 29, 2024
b4a1d4d
wip: introduce balanceMinimalUnit
legobeat Oct 29, 2024
34e7d2c
fix Ramps useBalance
legobeat Oct 29, 2024
f047310
fix: toTokenMinimalUnit, fromTokenMiimalUnitSTring default decimals=0
legobeat Oct 29, 2024
2623b57
fix: Ramps BuildQuote fix
legobeat Oct 29, 2024
49d73d8
chore: test, jsdoc fix
legobeat Oct 29, 2024
242eb08
wrap toTokenMinimalUnit value
legobeat Oct 29, 2024
e9cbdce
chore: BuildQuote test fix
legobeat Oct 29, 2024
2096f86
lint:fix
legobeat Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: remove usage of bn.js v4
  • Loading branch information
legobeat committed Oct 28, 2024
commit 68d5431c23d08404e6128bc1a07c9cb0b92fc1d6
2 changes: 1 addition & 1 deletion app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
getIsSwapApproveOrSwapTransaction,
isApprovalTransaction,
} from '../../../util/transactions';
import BN from 'bnjs4';
import BN from 'bn.js';
import Logger from '../../../util/Logger';
import TransactionTypes from '../../../core/TransactionTypes';
import { swapsUtils } from '@metamask/swaps-controller';
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/ConfirmAddAsset/ConfirmAddAsset.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import renderWithProvider, {
import useBalance from '../Ramp/hooks/useBalance';
import { toTokenMinimalUnit } from '../../../util/number';
import { fireEvent } from '@testing-library/react-native';
import BN4 from 'bnjs4';
import BN from 'bn.js';
import { RootState } from '../../../reducers';
import { mockNetworkState } from '../../../util/test/network';
import { CHAIN_IDS } from '@metamask/transaction-controller';
Expand Down Expand Up @@ -48,7 +48,7 @@ jest.mock('../../../util/navigation/navUtils', () => ({

const mockUseBalanceInitialValue: Partial<ReturnType<typeof useBalance>> = {
balanceFiat: '$27.02',
balanceBN: toTokenMinimalUnit('5.36385', 18) as BN4,
balanceBN: toTokenMinimalUnit('5.36385', 18) as BN,
};

const mockUseBalanceValues: Partial<ReturnType<typeof useBalance>> = {
Expand Down
18 changes: 9 additions & 9 deletions app/components/UI/Ramp/Views/BuildQuote/BuildQuote.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Limits, Payment } from '@consensys/on-ramp-sdk';
import { act, fireEvent, screen } from '@testing-library/react-native';
import type BN4 from 'bnjs4';
import type BN from 'bn.js';
import { renderScreen } from '../../../../../util/test/renderWithProvider';
import BuildQuote from './BuildQuote';
import useRegions from '../../hooks/useRegions';
Expand Down Expand Up @@ -191,7 +191,7 @@ jest.mock('../../../../hooks/useAddressBalance/useAddressBalance', () =>

const mockUseBalanceInitialValue: Partial<ReturnType<typeof useBalance>> = {
balanceFiat: '$27.02',
balanceBN: toTokenMinimalUnit('5.36385', 18) as BN4,
balanceBN: toTokenMinimalUnit('5.36385', 18) as BN,
};

let mockUseBalanceValues: Partial<ReturnType<typeof useBalance>> = {
Expand Down Expand Up @@ -242,7 +242,7 @@ const mockUseGasPriceEstimationInitialValue: ReturnType<
estimatedGasFee: toTokenMinimalUnit(
'0.01',
mockUseRampSDKInitialValues.selectedAsset?.decimals || 18,
) as BN4,
) as BN,
};

let mockUseGasPriceEstimationValue: ReturnType<typeof useGasPriceEstimation> =
Expand Down Expand Up @@ -669,7 +669,7 @@ describe('BuildQuote View', () => {
mockUseBalanceValues.balanceBN = toTokenMinimalUnit(
'5',
mockUseRampSDKValues.selectedAsset?.decimals || 18,
) as BN4;
) as BN;
render(BuildQuote);
const initialAmount = '0';
const overBalanceAmout = '6';
Expand All @@ -688,7 +688,7 @@ describe('BuildQuote View', () => {
mockUseBalanceValues.balanceBN = toTokenMinimalUnit(
'1',
mockUseRampSDKValues.selectedAsset?.decimals || 18,
) as BN4;
) as BN;
const symbol = mockUseRampSDKValues.selectedAsset?.symbol;
fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`));
fireEvent.press(getByRoleButton('25%'));
Expand Down Expand Up @@ -719,13 +719,13 @@ describe('BuildQuote View', () => {
balanceBN: toTokenMinimalUnit(
'1',
mockUseRampSDKValues.selectedAsset?.decimals || 18,
) as BN4,
) as BN,
};
mockUseGasPriceEstimationValue = {
estimatedGasFee: toTokenMinimalUnit(
'0.27',
mockUseRampSDKValues.selectedAsset?.decimals || 18,
) as BN4,
) as BN,
};
const symbol = mockUseRampSDKValues.selectedAsset?.symbol;
fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`));
Expand All @@ -752,13 +752,13 @@ describe('BuildQuote View', () => {
balanceBN: toTokenMinimalUnit(
'1',
mockUseRampSDKValues.selectedAsset?.decimals || 18,
) as BN4,
) as BN,
};
mockUseGasPriceEstimationValue = {
estimatedGasFee: toTokenMinimalUnit(
'0.27',
mockUseRampSDKValues.selectedAsset?.decimals || 18,
) as BN4,
) as BN,
};
const symbol = mockUseRampSDKValues.selectedAsset?.symbol;
fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`));
Expand Down
12 changes: 6 additions & 6 deletions app/components/UI/Ramp/Views/BuildQuote/BuildQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Animated, {
withTiming,
} from 'react-native-reanimated';
import { useNavigation } from '@react-navigation/native';
import BN4 from 'bnjs4';
import BN from 'bn.js';

import { useRampSDK } from '../../sdk';
import usePaymentMethods from '../../hooks/usePaymentMethods';
Expand Down Expand Up @@ -104,7 +104,7 @@ const BuildQuote = () => {
const [amountFocused, setAmountFocused] = useState(false);
const [amount, setAmount] = useState('0');
const [amountNumber, setAmountNumber] = useState(0);
const [amountBNMinimalUnit, setAmountBNMinimalUnit] = useState<BN4>();
const [amountBNMinimalUnit, setAmountBNMinimalUnit] = useState<BN>();
const [error, setError] = useState<string | null>(null);
const keyboardHeight = useRef(1000);
const keypadOffset = useSharedValue(1000);
Expand Down Expand Up @@ -341,7 +341,7 @@ const BuildQuote = () => {
setAmountNumber(valueAsNumber);
if (isSell) {
setAmountBNMinimalUnit(
toTokenMinimalUnit(`${value}`, selectedAsset?.decimals ?? 0) as BN4,
toTokenMinimalUnit(`${value}`, selectedAsset?.decimals ?? 0) as BN,
);
}
},
Expand All @@ -356,8 +356,8 @@ const BuildQuote = () => {
} else {
const percentage = value * 100;
const amountPercentage = balanceBN
?.mul(new BN4(percentage))
.div(new BN4(100));
?.mul(new BN(percentage))
.div(new BN(100));

if (!amountPercentage) {
return;
Expand Down Expand Up @@ -698,7 +698,7 @@ const BuildQuote = () => {
value: quickAmount,
label: currentFiatCurrency?.denomSymbol + quickAmount.toString(),
})) ?? [];
} else if (balanceBN && !balanceBN.isZero() && maxSellAmount?.gt(new BN4(0))) {
} else if (balanceBN && !balanceBN.isZero() && maxSellAmount?.gt(new BN(0))) {
quickAmounts = [
{ value: 0.25, label: '25%' },
{ value: 0.5, label: '50%' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { ImageSourcePropType, View } from 'react-native';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigation } from '@react-navigation/native';
import BN4 from 'bnjs4';
import BN from 'bn.js';
import { SellOrder } from '@consensys/on-ramp-sdk/dist/API';
import {
TransactionParams,
Expand Down Expand Up @@ -132,7 +132,7 @@ function SendTransaction() {
setIsConfirming(true);
let transactionParams: TransactionParams;
const amount = addHexPrefix(
new BN4(
new BN(
toTokenMinimalUnit(
orderData.cryptoAmount || '0',
orderData.cryptoCurrency.decimals,
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/Ramp/hooks/useGasPriceEstimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type GasFeeController as GasFeeControllerType,
} from '@metamask/gas-fee-controller';

import BN from 'bnjs4';
import BN from 'bn.js';
import Engine from '../../../../core/Engine';
import { decGWEIToHexWEI } from '../../../../util/conversions';
import { selectGasFeeControllerState } from '../../../../selectors/gasFeeController';
Expand Down
6 changes: 3 additions & 3 deletions app/components/UI/Ramp/hooks/useIntentAmount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import type BN4 from 'bnjs4';
import type BN from 'bn.js';
import { useRampSDK } from '../sdk';
import parseAmount from '../utils/parseAmount';
import { toTokenMinimalUnit } from '../../../../util/number';
Expand All @@ -21,7 +21,7 @@ export default function useIntentAmount(
setAmount: (amount: React.SetStateAction<string>) => void,
setAmountNumber: (amount: React.SetStateAction<number>) => void,
setAmountBNMinimalUnit: (
amount: React.SetStateAction<BN4 | undefined>,
amount: React.SetStateAction<BN | undefined>,
) => void,
currentFiatCurrency: FiatCurrency | null,
) {
Expand Down Expand Up @@ -53,7 +53,7 @@ export default function useIntentAmount(
toTokenMinimalUnit(
`${parsedAmount}`,
selectedAsset?.decimals ?? 0,
) as BN4,
) as BN,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import StakeInputView from './StakeInputView';
import { renderScreen } from '../../../../../util/test/renderWithProvider';
import Routes from '../../../../../constants/navigation/Routes';
import { backgroundState } from '../../../../../util/test/initial-root-state';
import BN5 from 'bnjs5';
import BN from 'bn.js';
import { Stake } from '../../sdk/stakeSdkProvider';
import { ChainId, PooledStakingContract } from '@metamask/stake-sdk';
import { Contract } from 'ethers';
Expand Down Expand Up @@ -54,7 +54,7 @@ jest.mock('../../../../../selectors/currencyRateController.ts', () => ({
selectCurrentCurrency: jest.fn(() => 'USD'),
}));

const mockBalanceBN = new BN5('1500000000000000000');
const mockBalanceBN = new BN('1500000000000000000');

const mockPooledStakingContractService: PooledStakingContract = {
chainId: ChainId.ETHEREUM,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useNavigation } from '@react-navigation/native';
import React, { useCallback, useEffect } from 'react';
import BN4 from 'bnjs4';
import BN from 'bn.js';
import UnstakeInputViewBanner from './UnstakeBanner';
import { strings } from '../../../../../../locales/i18n';
import Button, {
Expand Down Expand Up @@ -43,7 +43,7 @@ const UnstakeInputView = () => {
handleAmountPress,
handleKeypadChange,
conversionRate,
} = useStakingInputHandlers(new BN4(stakedBalanceWei));
} = useStakingInputHandlers(new BN(stakedBalanceWei));

const stakeBalanceInEth = renderFromWei(stakedBalanceWei, 5);
const stakeBalanceFiatNumber = weiToFiatNumber(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { strings } from '../../../../../../locales/i18n';
import { renderFromWei } from '../../../../../util/number';
import { getTimeDifferenceFromNow } from '../../../../../util/date';
import { filterExitRequests } from './utils';
import BN4 from 'bnjs4';
import BN from 'bn.js';
import bn from 'bignumber.js';
import {
CommonPercentageInputUnits,
Expand Down Expand Up @@ -82,8 +82,8 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => {
renderFromWei(
claimableRequests.reduce(
(acc, { claimedAssets }) =>
claimedAssets ? acc.add(new BN4(claimedAssets)) : acc,
new BN4(0),
claimedAssets ? acc.add(new BN(claimedAssets)) : acc,
new BN(0),
),
),
[claimableRequests],
Expand Down
14 changes: 7 additions & 7 deletions app/components/UI/Stake/hooks/useStakingInput.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BN4 from 'bnjs4';
import BN from 'bn.js';
import { useState, useMemo, useCallback } from 'react';
import { useSelector } from 'react-redux';
import {
Expand All @@ -17,15 +17,15 @@ import {
import { strings } from '../../../../../locales/i18n';
import useVaultData from './useVaultData';

const useStakingInputHandlers = (balance: BN4) => {
const useStakingInputHandlers = (balance: BN) => {
const [amountEth, setAmountEth] = useState('0');
const [amountWei, setAmountWei] = useState<BN4>(new BN4(0));
const [amountWei, setAmountWei] = useState<BN>(new BN(0));
const [estimatedAnnualRewards, setEstimatedAnnualRewards] = useState('-');

const isNonZeroAmount = useMemo(() => amountWei.gt(new BN4(0)), [amountWei]);
const isNonZeroAmount = useMemo(() => amountWei.gt(new BN(0)), [amountWei]);
const isOverMaximum = useMemo(() => {
const additionalFundsRequired = amountWei.sub(balance || new BN4(0));
return isNonZeroAmount && additionalFundsRequired.gt(new BN4(0));
const additionalFundsRequired = amountWei.sub(balance || new BN(0));
return isNonZeroAmount && additionalFundsRequired.gt(new BN(0));
}, [amountWei, balance, isNonZeroAmount]);

const [fiatAmount, setFiatAmount] = useState('0');
Expand Down Expand Up @@ -92,7 +92,7 @@ const useStakingInputHandlers = (balance: BN4) => {
({ value }: { value: number }) => {
if (!balance) return;
const percentage = value * 100;
const amountPercentage = balance.mul(new BN4(percentage)).div(new BN4(100));
const amountPercentage = balance.mul(new BN(percentage)).div(new BN(100));

const newAmountString = fromTokenMinimalUnitString(
amountPercentage.toString(10),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { fireEvent } from '@testing-library/react-native';
import BN5 from 'bnjs5';
import BN from 'bn.js';
import renderWithProvider from '../../../../../util/test/renderWithProvider';
import { backgroundState } from '../../../../../util/test/initial-root-state';
import AppConstants from '../../../../../../app/core/AppConstants';
Expand Down Expand Up @@ -70,9 +70,9 @@ const initialState = {
},
TokenBalancesController: {
contractBalances: {
'0x00': new BN5(2),
'0x01': new BN5(2),
'0x02': new BN5(0),
'0x00': new BN(2),
'0x01': new BN(2),
'0x02': new BN(0),
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions app/components/UI/Tokens/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
// eslint-disable-next-line @typescript-eslint/no-shadow
import { fireEvent, waitFor } from '@testing-library/react-native';
import Tokens from './';
import BN5 from 'bnjs5';
import BN from 'bn.js';
import renderWithProvider from '../../../util/test/renderWithProvider';
import { createStackNavigator } from '@react-navigation/stack';
import { getAssetTestId } from '../../../../wdio/screen-objects/testIDs/Screens/WalletView.testIds';
Expand Down Expand Up @@ -109,9 +109,9 @@ const initialState = {
},
TokenBalancesController: {
contractBalances: {
'0x00': new BN5(2),
'0x01': new BN5(2),
'0x02': new BN5(0),
'0x00': new BN(2),
'0x01': new BN(2),
'0x02': new BN(0),
},
},
},
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('Tokens', () => {
},
TokenBalancesController: {
contractBalances: {
'0x02': new BN5(1),
'0x02': new BN(1),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
toHexadecimal,
} from '../../../../../../util/number';
import { isValidAddress, addHexPrefix } from 'ethereumjs-util';
import BN from 'bnjs4';
import BN from 'bn.js';
import { strings } from '../../../../../../../locales/i18n';
import { connect } from 'react-redux';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BN from 'bnjs4';
import BN from 'bn.js';
import { validateSufficientBalance, validateSufficientTokenBalance } from './validation';
import { renderFromWei, hexToBN } from '../../../../../util/number';
import {
Expand Down
Loading