Skip to content

Commit 921b90b

Browse files
committed
chore: fence off legacy BN.js helpers with lint + CODEOWNERS
1 parent 6b1354a commit 921b90b

4 files changed

Lines changed: 140 additions & 25 deletions

File tree

.eslintrc.js

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ module.exports = {
4242
'interface',
4343
],
4444
'@typescript-eslint/no-explicit-any': 'error',
45+
// Surface JSDoc @deprecated annotations at every use-site (warn for now;
46+
// ratchet to 'error' once the BN.js → BigInt migration is complete).
47+
// Pairs with the no-restricted-imports fence on app/util/number below.
48+
'@typescript-eslint/no-deprecated': 'warn',
4549
// Under discussion
4650
'@typescript-eslint/no-duplicate-enum-values': 'off',
4751
'@typescript-eslint/no-shadow': [
@@ -466,8 +470,128 @@ module.exports = {
466470
},
467471
},
468472
{
469-
files: ['app/**/*.{ts,tsx}'],
470-
excludedFiles: ['app/controllers/perps/**/*.{ts,tsx}'],
473+
files: ['app/**/*.{ts,tsx,js,jsx}'],
474+
excludedFiles: [
475+
// Perps controller is exempt from importing itself.
476+
'app/controllers/perps/**/*.{ts,tsx}',
477+
// The legacy module + its tests intentionally import each other for
478+
// parity comparison.
479+
'app/util/number/**',
480+
// BN.js → BigInt migration burn-down list.
481+
// Existing consumers of the deprecated `app/util/number/index.js`
482+
// module. Remove a file from this list as it is migrated to
483+
// `app/util/number/bigint`. New entries should NOT be added — that's
484+
// what the lint fence below prevents. See `app/util/number/bigint.ts`
485+
// for the replacement API and `app/util/number/bigint-migration-reference.test.ts`
486+
// for migration patterns.
487+
'app/component-library/components-temp/CustomSpendCap/CustomInput/CustomInput.tsx',
488+
'app/component-library/components-temp/CustomSpendCap/CustomSpendCap.tsx',
489+
'app/component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentage.tsx',
490+
'app/component-library/components-temp/Price/AggregatedPercentage/utils.ts',
491+
'app/components/UI/AccountInfoCard/index.js',
492+
'app/components/UI/AssetOverview/Price/Price.advanced.tsx',
493+
'app/components/UI/AssetOverview/Price/Price.legacy.tsx',
494+
'app/components/UI/AssetOverview/utils/marketDetails.ts',
495+
'app/components/UI/Bridge/components/QuoteSelectorView/QuoteRow.tsx',
496+
'app/components/UI/Bridge/components/QuoteSelectorView/index.tsx',
497+
'app/components/UI/Bridge/hooks/useBridgeQuoteData/index.ts',
498+
'app/components/UI/Bridge/hooks/useFormattedBalanceWithThreshold/index.ts',
499+
'app/components/UI/Bridge/hooks/useHasSufficientGas/index.ts',
500+
'app/components/UI/Bridge/hooks/useInsufficientBalance/index.ts',
501+
'app/components/UI/Bridge/hooks/useTokenBalanceInUsd/index.ts',
502+
'app/components/UI/Bridge/hooks/useTokensWithBalance/index.ts',
503+
'app/components/UI/Bridge/utils/exchange-rates.ts',
504+
'app/components/UI/Bridge/utils/formatNetworkFee.test.ts',
505+
'app/components/UI/Bridge/utils/formatNetworkFee.ts',
506+
'app/components/UI/Bridge/utils/transaction-history.ts',
507+
'app/components/UI/Card/hooks/useAssetBalances.tsx',
508+
'app/components/UI/Card/hooks/useCardDelegation.test.ts',
509+
'app/components/UI/Card/hooks/useCardDelegation.ts',
510+
'app/components/UI/Card/hooks/useNeedsGasFaucet.ts',
511+
'app/components/UI/Card/sdk/CardSDK.ts',
512+
'app/components/UI/CollectibleOverview/index.js',
513+
'app/components/UI/Earn/Views/EarnInputView/EarnInputView.test.tsx',
514+
'app/components/UI/Earn/Views/EarnLendingDepositConfirmationView/components/Erc20TokenHero/index.tsx',
515+
'app/components/UI/Earn/Views/EarnLendingDepositConfirmationView/index.tsx',
516+
'app/components/UI/Earn/Views/EarnLendingWithdrawalConfirmationView/index.tsx',
517+
'app/components/UI/Earn/Views/EarnWithdrawInputView/EarnWithdrawInputView.tsx',
518+
'app/components/UI/Earn/components/EarnLendingBalance/index.tsx',
519+
'app/components/UI/Earn/components/Earnings/EarningsHistory/EarningsHistory.utils.ts',
520+
'app/components/UI/Earn/components/InputDisplay/InputDisplay.test.tsx',
521+
'app/components/UI/Earn/hooks/useEarnGasFee.ts',
522+
'app/components/UI/Earn/hooks/useEarnInput.ts',
523+
'app/components/UI/Earn/hooks/useEarnings.ts',
524+
'app/components/UI/Earn/hooks/useInput.ts',
525+
'app/components/UI/Earn/hooks/useMultichainInputHandlers.ts',
526+
'app/components/UI/Earn/hooks/useMusdBalance.ts',
527+
'app/components/UI/Earn/hooks/useMusdCtaVisibility.ts',
528+
'app/components/UI/Earn/utils/number.ts',
529+
'app/components/UI/Earn/utils/token/index.ts',
530+
'app/components/UI/Earn/utils/tron.ts',
531+
'app/components/UI/HardwareWallet/AccountDetails/index.tsx',
532+
'app/components/UI/Money/constants/activityStyles.ts',
533+
'app/components/UI/Money/utils/moneyActivityFiat.ts',
534+
'app/components/UI/MultichainBridgeTransactionListItem/MultichainBridgeTransactionListItem.tsx',
535+
'app/components/UI/Notification/TransactionNotification/index.js',
536+
'app/components/UI/Ramp/Aggregator/Views/BuildQuote/BuildQuote.test.tsx',
537+
'app/components/UI/Ramp/Aggregator/Views/BuildQuote/BuildQuote.tsx',
538+
'app/components/UI/Ramp/Aggregator/Views/OrdersList/OrdersList.tsx',
539+
'app/components/UI/Ramp/Aggregator/Views/SendTransaction/SendTransaction.tsx',
540+
'app/components/UI/Ramp/Aggregator/components/OrderDetails.tsx',
541+
'app/components/UI/Ramp/Aggregator/components/OrderListItem/OrderListItem.tsx',
542+
'app/components/UI/Ramp/Aggregator/components/Quote/Quote.tsx',
543+
'app/components/UI/Ramp/Aggregator/hooks/useBalance.test.ts',
544+
'app/components/UI/Ramp/Aggregator/hooks/useBalance.ts',
545+
'app/components/UI/Ramp/Aggregator/hooks/useERC20GasLimitEstimation.ts',
546+
'app/components/UI/Ramp/Aggregator/hooks/useHandleSuccessfulOrder.ts',
547+
'app/components/UI/Ramp/Aggregator/hooks/useIntentAmount.ts',
548+
'app/components/UI/Ramp/Aggregator/utils/index.ts',
549+
'app/components/UI/Ramp/Deposit/utils/index.ts',
550+
'app/components/UI/Ramp/utils/getOrderAmount.ts',
551+
'app/components/UI/Ramp/utils/v2OrderToast.ts',
552+
'app/components/UI/Stake/components/StakingBalance/StakingBanners/ClaimBanner/ClaimBanner.tsx',
553+
'app/components/UI/Stake/components/StakingConfirmation/TokenValueStack/TokenValueStack.test.tsx',
554+
'app/components/UI/Stake/components/StakingConfirmation/TokenValueStack/TokenValueStack.tsx',
555+
'app/components/UI/Stake/components/StakingConfirmation/YouReceiveCard/YouReceiveCard.test.tsx',
556+
'app/components/UI/Stake/components/StakingConfirmation/YouReceiveCard/YouReceiveCard.tsx',
557+
'app/components/UI/Stake/hooks/useBalance.ts',
558+
'app/components/UI/Tokens/util/deriveBalanceFromAssetMarketDetails.test.ts',
559+
'app/components/UI/Tokens/util/deriveBalanceFromAssetMarketDetails.ts',
560+
'app/components/UI/TransactionElement/utils-gas.js',
561+
'app/components/UI/TransactionElement/utils.js',
562+
'app/components/UI/UrlAutocomplete/Result.tsx',
563+
'app/components/Views/AssetDetails/index.tsx',
564+
'app/components/Views/DetectedTokens/components/Token.tsx',
565+
'app/components/Views/GasEducationCarousel/index.js',
566+
'app/components/Views/NetworksManagement/NetworkDetailsView/hooks/useNetworkValidation.ts',
567+
'app/components/Views/UnifiedTransactionsView/useUnifiedTxActions.test.ts',
568+
'app/components/Views/confirmations/components/gas/max-base-fee-input/max-base-fee-input.tsx',
569+
'app/components/Views/confirmations/components/gas/priority-fee-input/priority-fee-input.tsx',
570+
'app/components/Views/confirmations/components/info/typed-sign-v3v4/simulation/components/native-value-display/native-value-display.tsx',
571+
'app/components/Views/confirmations/components/info/typed-sign-v3v4/simulation/components/value-display/value-display.tsx',
572+
'app/components/Views/confirmations/components/transactions/custom-amount/custom-amount.tsx',
573+
'app/components/Views/confirmations/context/send-context/utils.ts',
574+
'app/components/Views/confirmations/external/staking/hooks/useStakingDetails.ts',
575+
'app/components/Views/confirmations/hooks/earn/useCustomAmount.tsx',
576+
'app/components/Views/confirmations/hooks/gas/useCancelSpeedupGas/useCancelSpeedupGas.ts',
577+
'app/components/Views/confirmations/hooks/send/useBalance.ts',
578+
'app/components/Views/confirmations/hooks/send/useCurrencyConversions.ts',
579+
'app/components/Views/confirmations/hooks/send/usePercentageAmount.ts',
580+
'app/components/Views/confirmations/hooks/useTokenAmount.ts',
581+
'app/components/Views/confirmations/legacy/components/CustomNonceModal/index.js',
582+
'app/components/Views/confirmations/legacy/components/WatchAssetRequest/index.js',
583+
'app/components/Views/confirmations/utils/send.ts',
584+
'app/components/hooks/useAddressBalance/useAddressBalance.ts',
585+
'app/components/hooks/useGetFormattedTokensPerChain.tsx',
586+
'app/components/hooks/useGetTotalFiatBalanceCrossChains.tsx',
587+
'app/core/Engine/Engine.ts',
588+
'app/core/Engine/controllers/gas-fee-controller/gas-fee-controller-init.test.ts',
589+
'app/core/GasPolling/GasPolling.ts',
590+
'app/core/NotificationManager.js',
591+
'app/selectors/assets/assets-list.ts',
592+
'app/selectors/earnController/earn/index.ts',
593+
'app/selectors/multichain/evm.ts',
594+
],
471595
rules: {
472596
'no-restricted-imports': [
473597
'error',
@@ -478,6 +602,16 @@ module.exports = {
478602
message:
479603
'Use @metamask/perps-controller instead of relative imports into app/controllers/perps/.',
480604
},
605+
{
606+
group: [
607+
'**/util/number',
608+
'**/util/number/index',
609+
'**/app/util/number',
610+
'**/app/util/number/index',
611+
],
612+
message:
613+
'app/util/number/index.js is deprecated. Import the BigInt-based replacement from app/util/number/bigint instead. See app/util/number/bigint-migration-reference.test.ts for migration patterns.',
614+
},
481615
],
482616
},
483617
],

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ app/core/Engine/README.md @MetaMask/mobile-pla
4343
app/core/Engine/types.ts @MetaMask/mobile-platform
4444
app/core/Engine/controllers/remote-feature-flag-controller/ @MetaMask/mobile-platform
4545
app/core/DeeplinkManager @MetaMask/mobile-platform
46+
# Deprecated BN.js helpers. Gated to discourage adding new exports; consumers
47+
# should migrate to app/util/number/bigint. See .eslintrc.js for the import
48+
# fence and bigint-migration-reference.test.ts for migration patterns.
49+
app/util/number/index.js @MetaMask/mobile-platform
4650
scripts/build.sh @MetaMask/mobile-platform
4751
fingerprint.config.js @MetaMask/mobile-platform
4852
builds.yml @MetaMask/mobile-platform

app/util/number/index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,18 +418,6 @@ export function renderFromWei(value, decimalsToShow = 5) {
418418
return renderWei;
419419
}
420420

421-
/**
422-
* @deprecated no longer used
423-
* Converts token BN value to hex string number to be sent
424-
*
425-
* @param {Object} value - BN instance to convert
426-
* @param {number} decimals - Decimals to be considered on the conversion
427-
* @returns {string} - String of the hex token value
428-
*/
429-
export function calcTokenValueToSend(value, decimals) {
430-
return value ? (value * Math.pow(10, decimals)).toString(16) : 0;
431-
}
432-
433421
/**
434422
* @deprecated Use isBigInt instead from utils/number/bigint
435423
* Checks if a value is a BN instance

app/util/number/index.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
balanceToFiat,
77
balanceToFiatNumber,
88
BNToHex,
9-
calcTokenValueToSend,
109
calculateEthFeeForMultiLayer,
1110
dotAndCommaDecimalFormatter,
1211
fastSplit,
@@ -514,16 +513,6 @@ describe('Number utils :: localizeLargeNumber', () => {
514513
});
515514
});
516515

517-
describe('Number utils :: calcTokenValueToSend', () => {
518-
it('calcTokenValueToSend', () => {
519-
expect(calcTokenValueToSend(new BN4(1337), 0)).toEqual('539');
520-
expect(calcTokenValueToSend(new BN4(1337), 9)).toEqual('1374b68fa00');
521-
expect(calcTokenValueToSend(new BN4(1337), 18)).toEqual(
522-
'487a9a304539440000',
523-
);
524-
});
525-
});
526-
527516
describe('Number utils :: hexToBN', () => {
528517
it('hexToBN', () => {
529518
expect(hexToBN('0x539').toNumber()).toBe(1337);

0 commit comments

Comments
 (0)