diff --git a/app/scripts/controllers/detect-tokens.test.js b/app/scripts/controllers/detect-tokens.test.js index feef8d19a..8a3685f22 100644 --- a/app/scripts/controllers/detect-tokens.test.js +++ b/app/scripts/controllers/detect-tokens.test.js @@ -9,9 +9,9 @@ import { TokensController, AssetsContractController, } from '@metamask/assets-controllers'; +import { convertHexToDecimal } from '@metamask/controller-utils'; import { NETWORK_TYPES } from '../../../shared/constants/network'; import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils'; -import { hexToDecimal } from '../../../shared/lib/metamask-controller-utils'; import DetectTokensController from './detect-tokens'; import NetworkController, { NETWORK_EVENTS } from './network'; import PreferencesController from './preferences'; @@ -88,7 +88,7 @@ describe('DetectTokensController', function () { ...networkState, providerConfig: { ...networkState.provider, - chainId: hexToDecimal(networkState.provider.chainId), + chainId: convertHexToDecimal(networkState.provider.chainId), }, }; return cb(modifiedNetworkState); diff --git a/app/scripts/controllers/incoming-transactions.js b/app/scripts/controllers/incoming-transactions.js index f74957c50..10f79539c 100644 --- a/app/scripts/controllers/incoming-transactions.js +++ b/app/scripts/controllers/incoming-transactions.js @@ -2,7 +2,7 @@ import { ObservableStore } from '@metamask/obs-store'; import log from 'loglevel'; import BN from 'bn.js'; import createId from '../../../shared/modules/random-id'; -import { bnToHex, previousValueComparator } from '../lib/util'; +import { previousValueComparator } from '../lib/util'; import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout'; import { @@ -14,6 +14,7 @@ import { CHAIN_ID_TO_NETWORK_ID_MAP, CHAIN_ID_TO_TYPE_MAP, } from '../../../shared/constants/network'; +import { bnToHex } from '../../../shared/modules/conversion.utils'; const fetchWithTimeout = getFetchWithTimeout(); diff --git a/app/scripts/controllers/swaps.js b/app/scripts/controllers/swaps.js index 3bafff418..468d90ece 100644 --- a/app/scripts/controllers/swaps.js +++ b/app/scripts/controllers/swaps.js @@ -8,6 +8,7 @@ import { conversionUtil, decGWEIToHexWEI, addCurrencies, + sumHexes, } from '../../../shared/modules/conversion.utils'; import { DEFAULT_ERC20_APPROVE_GAS, @@ -25,7 +26,6 @@ import { } from '../../../shared/constants/smartTransactions'; import { isSwapsDefaultTokenAddress } from '../../../shared/modules/swaps.utils'; -import { sumHexes } from '../../../ui/helpers/utils/transactions.util'; import { fetchTradesInfo as defaultFetchTradesInfo, diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index c90f3c527..09fb19ec7 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -12,7 +12,6 @@ import { merge, pickBy } from 'lodash'; import cleanErrorStack from '../../lib/cleanErrorStack'; import { hexToBn, - bnToHex, BnMultiplyByFraction, addHexPrefix, getChainType, @@ -33,7 +32,13 @@ import { CUSTOM_GAS_ESTIMATE, PRIORITY_LEVELS, } from '../../../../shared/constants/gas'; -import { decGWEIToHexWEI } from '../../../../shared/modules/conversion.utils'; +import { + bnToHex, + decGWEIToHexWEI, + decimalToHex, + hexWEIToDecETH, + hexWEIToDecGWEI, +} from '../../../../shared/modules/conversion.utils'; import { isSwapsDefaultTokenAddress } from '../../../../shared/modules/swaps.utils'; import { EVENT } from '../../../../shared/constants/metametrics'; import { @@ -50,10 +55,7 @@ import { import { ORIGIN_METAMASK } from '../../../../shared/constants/app'; import { calcGasTotal, - decimalToHex, getSwapsTokensReceivedFromTxMeta, - hexWEIToDecETH, - hexWEIToDecGWEI, TRANSACTION_ENVELOPE_TYPE_NAMES, } from '../../../../shared/lib/transactions-controller-utils'; import TransactionStateManager from './tx-state-manager'; diff --git a/app/scripts/controllers/transactions/tx-gas-utils.js b/app/scripts/controllers/transactions/tx-gas-utils.js index 35648e710..006de767f 100644 --- a/app/scripts/controllers/transactions/tx-gas-utils.js +++ b/app/scripts/controllers/transactions/tx-gas-utils.js @@ -2,7 +2,8 @@ import EthQuery from 'ethjs-query'; import log from 'loglevel'; import { addHexPrefix } from 'ethereumjs-util'; import { cloneDeep } from 'lodash'; -import { hexToBn, BnMultiplyByFraction, bnToHex } from '../../lib/util'; +import { hexToBn, BnMultiplyByFraction } from '../../lib/util'; +import { bnToHex } from '../../../../shared/modules/conversion.utils'; /** * Result of gas analysis, including either a gas estimate for a successful analysis, or diff --git a/app/scripts/controllers/transactions/tx-gas-utils.test.js b/app/scripts/controllers/transactions/tx-gas-utils.test.js index ed512f596..97858da26 100644 --- a/app/scripts/controllers/transactions/tx-gas-utils.test.js +++ b/app/scripts/controllers/transactions/tx-gas-utils.test.js @@ -1,7 +1,8 @@ import { strict as assert } from 'assert'; import { TransactionFactory } from '@ethereumjs/tx'; import Common from '@ethereumjs/common'; -import { hexToBn, bnToHex } from '../../lib/util'; +import { hexToBn } from '../../lib/util'; +import { bnToHex } from '../../../../shared/modules/conversion.utils'; import TxUtils from './tx-gas-utils'; describe('txUtils', function () { diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index b482be97f..2acbc3c99 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -135,16 +135,6 @@ const addHexPrefix = (str) => { return `0x${str}`; }; -/** - * Converts a BN object to a hex string with a '0x' prefix - * - * @param {BN} inputBn - The BN to convert to a hex string - * @returns {string} A '0x' prefixed hex string - */ -function bnToHex(inputBn) { - return addHexPrefix(inputBn.toString(16)); -} - function getChainType(chainId) { if (chainId === CHAIN_IDS.MAINNET) { return 'mainnet'; @@ -172,7 +162,6 @@ export { BnMultiplyByFraction, checkForError, addHexPrefix, - bnToHex, getChainType, checkAlarmExists, }; diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 8c20da34e..2ac906f43 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -102,11 +102,9 @@ import { getTokenIdParam } from '../../shared/lib/token-util'; import { isEqualCaseInsensitive } from '../../shared/modules/string-utils'; import { parseStandardTokenTransactionData } from '../../shared/modules/transaction.utils'; import { STATIC_MAINNET_TOKEN_LIST } from '../../shared/constants/tokens'; -import { - getTokenValueParam, - hexToDecimal, -} from '../../shared/lib/metamask-controller-utils'; +import { getTokenValueParam } from '../../shared/lib/metamask-controller-utils'; import { isManifestV3 } from '../../shared/modules/mv3.utils'; +import { hexToDecimal } from '../../shared/modules/conversion.utils'; import { onMessageReceived, checkForMultipleVersionsRunning, diff --git a/shared/lib/metamask-controller-utils.js b/shared/lib/metamask-controller-utils.js index 77b171fe5..dcc76476f 100644 --- a/shared/lib/metamask-controller-utils.js +++ b/shared/lib/metamask-controller-utils.js @@ -1,12 +1,3 @@ -import { conversionUtil } from '../modules/conversion.utils'; - -export function hexToDecimal(hexValue) { - return conversionUtil(hexValue, { - fromNumericBase: 'hex', - toNumericBase: 'dec', - }); -} - export function getTokenValueParam(tokenData = {}) { return tokenData?.args?._value?.toString(); } diff --git a/shared/lib/swaps-utils.js b/shared/lib/swaps-utils.js index 549c56a8e..fb6aec752 100644 --- a/shared/lib/swaps-utils.js +++ b/shared/lib/swaps-utils.js @@ -14,8 +14,8 @@ import { SECOND } from '../constants/time'; import { isValidHexAddress } from '../modules/hexstring-utils'; import { isEqualCaseInsensitive } from '../modules/string-utils'; import { addHexPrefix } from '../../app/scripts/lib/util'; +import { decimalToHex } from '../modules/conversion.utils'; import fetchWithCache from './fetch-with-cache'; -import { decimalToHex } from './transactions-controller-utils'; const TEST_CHAIN_IDS = [CHAIN_IDS.GOERLI, CHAIN_IDS.LOCALHOST]; diff --git a/shared/lib/transactions-controller-utils.js b/shared/lib/transactions-controller-utils.js index 02ef738f6..194c7de85 100644 --- a/shared/lib/transactions-controller-utils.js +++ b/shared/lib/transactions-controller-utils.js @@ -1,7 +1,6 @@ import BigNumber from 'bignumber.js'; import { TransactionEnvelopeType } from '../constants/transaction'; import { - conversionUtil, multiplyCurrencies, subtractCurrencies, } from '../modules/conversion.utils'; @@ -145,28 +144,3 @@ export const TRANSACTION_ENVELOPE_TYPE_NAMES = { FEE_MARKET: 'fee-market', LEGACY: 'legacy', }; - -export function hexWEIToDecGWEI(decGWEI) { - return conversionUtil(decGWEI, { - fromNumericBase: 'hex', - toNumericBase: 'dec', - fromDenomination: 'WEI', - toDenomination: 'GWEI', - }); -} - -export function decimalToHex(decimal) { - return conversionUtil(decimal, { - fromNumericBase: 'dec', - toNumericBase: 'hex', - }); -} - -export function hexWEIToDecETH(hexWEI) { - return conversionUtil(hexWEI, { - fromNumericBase: 'hex', - toNumericBase: 'dec', - fromDenomination: 'WEI', - toDenomination: 'ETH', - }); -} diff --git a/shared/modules/conversion.utils.js b/shared/modules/conversion.utils.js index e2a37deb2..d413ed013 100644 --- a/shared/modules/conversion.utils.js +++ b/shared/modules/conversion.utils.js @@ -24,7 +24,8 @@ import BigNumber from 'bignumber.js'; -import { BN } from 'ethereumjs-util'; +import { addHexPrefix, BN } from 'ethereumjs-util'; +import { ETH, WEI } from '../../ui/helpers/constants/common'; import { stripHexPrefix } from './hexstring-utils'; @@ -298,6 +299,141 @@ function decGWEIToHexWEI(decGWEI) { }); } +export function subtractHexes(aHexWEI, bHexWEI) { + return subtractCurrencies(aHexWEI, bHexWEI, { + aBase: 16, + bBase: 16, + toNumericBase: 'hex', + numberOfDecimals: 6, + }); +} + +export function addHexes(aHexWEI, bHexWEI) { + return addCurrencies(aHexWEI, bHexWEI, { + aBase: 16, + bBase: 16, + toNumericBase: 'hex', + numberOfDecimals: 6, + }); +} + +export function decWEIToDecETH(hexWEI) { + return conversionUtil(hexWEI, { + fromNumericBase: 'dec', + toNumericBase: 'dec', + fromDenomination: 'WEI', + toDenomination: 'ETH', + }); +} + +export function hexWEIToDecETH(hexWEI) { + return conversionUtil(hexWEI, { + fromNumericBase: 'hex', + toNumericBase: 'dec', + fromDenomination: 'WEI', + toDenomination: 'ETH', + }); +} + +export function decEthToConvertedCurrency( + ethTotal, + convertedCurrency, + conversionRate, +) { + return conversionUtil(ethTotal, { + fromNumericBase: 'dec', + toNumericBase: 'dec', + fromCurrency: 'ETH', + toCurrency: convertedCurrency, + numberOfDecimals: 2, + conversionRate, + }); +} + +export function getWeiHexFromDecimalValue({ + value, + fromCurrency, + conversionRate, + fromDenomination, + invertConversionRate, +}) { + return conversionUtil(value, { + fromNumericBase: 'dec', + toNumericBase: 'hex', + toCurrency: ETH, + fromCurrency, + conversionRate, + invertConversionRate, + fromDenomination, + toDenomination: WEI, + }); +} + +/** + * Converts a BN object to a hex string with a '0x' prefix + * + * @param {BN} inputBn - The BN to convert to a hex string + * @returns {string} A '0x' prefixed hex string + */ +export function bnToHex(inputBn) { + return addHexPrefix(inputBn.toString(16)); +} + +export function getValueFromWeiHex({ + value, + fromCurrency = ETH, + toCurrency, + conversionRate, + numberOfDecimals, + toDenomination, +}) { + return conversionUtil(value, { + fromNumericBase: 'hex', + toNumericBase: 'dec', + fromCurrency, + toCurrency, + numberOfDecimals, + fromDenomination: WEI, + toDenomination, + conversionRate, + }); +} + +export function sumHexes(...args) { + const total = args.reduce((acc, hexAmount) => { + return addCurrencies(acc, hexAmount, { + toNumericBase: 'hex', + aBase: 16, + bBase: 16, + }); + }); + + return addHexPrefix(total); +} + +export function hexWEIToDecGWEI(decGWEI) { + return conversionUtil(decGWEI, { + fromNumericBase: 'hex', + toNumericBase: 'dec', + fromDenomination: 'WEI', + toDenomination: 'GWEI', + }); +} + +export function decimalToHex(decimal) { + return conversionUtil(decimal, { + fromNumericBase: 'dec', + toNumericBase: 'hex', + }); +} + +export function hexToDecimal(hexValue) { + return conversionUtil(hexValue, { + fromNumericBase: 'hex', + toNumericBase: 'dec', + }); +} + export { conversionUtil, addCurrencies, diff --git a/shared/modules/conversion.utils.test.js b/shared/modules/conversion.utils.test.js index 735d0edf2..c6b064a94 100644 --- a/shared/modules/conversion.utils.test.js +++ b/shared/modules/conversion.utils.test.js @@ -1,8 +1,12 @@ import BigNumber from 'bignumber.js'; +import { ETH } from '../../ui/helpers/constants/common'; import { addCurrencies, conversionUtil, + decWEIToDecETH, divideCurrencies, + getValueFromWeiHex, + getWeiHexFromDecimalValue, } from './conversion.utils'; describe('conversion utils', () => { @@ -202,4 +206,51 @@ describe('conversion utils', () => { }).toThrow('Must specify valid dividendBase and divisorBase'); }); }); + + describe('decWEIToDecETH', () => { + it('converts 10000000000000 WEI to ETH', () => { + const ethDec = decWEIToDecETH('10000000000000'); + expect('0.00001').toStrictEqual(ethDec); + }); + + it('converts 9358749494527040 WEI to ETH', () => { + const ethDec = decWEIToDecETH('9358749494527040'); + expect('0.009358749').toStrictEqual(ethDec); + }); + }); + + describe('getWeiHexFromDecimalValue', () => { + it('should correctly convert 0 in ETH', () => { + const weiValue = getWeiHexFromDecimalValue({ + value: '0', + fromCurrency: ETH, + fromDenomination: ETH, + }); + expect(weiValue).toStrictEqual('0'); + }); + }); + + describe('getValueFromWeiHex', () => { + it('should get the transaction amount in ETH', () => { + const ethTransactionAmount = getValueFromWeiHex({ + value: '0xde0b6b3a7640000', + toCurrency: 'ETH', + conversionRate: 468.58, + numberOfDecimals: 6, + }); + + expect(ethTransactionAmount).toStrictEqual('1'); + }); + + it('should get the transaction amount in fiat', () => { + const fiatTransactionAmount = getValueFromWeiHex({ + value: '0xde0b6b3a7640000', + toCurrency: 'usd', + conversionRate: 468.58, + numberOfDecimals: 2, + }); + + expect(fiatTransactionAmount).toStrictEqual('468.58'); + }); + }); }); diff --git a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js index d7a7a282e..bf114ce0d 100644 --- a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js +++ b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js @@ -8,7 +8,6 @@ import { } from '../../../../../../shared/constants/gas'; import { PRIMARY } from '../../../../../helpers/constants/common'; import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util'; -import { decGWEIToHexWEI } from '../../../../../helpers/utils/conversions.util'; import { getAdvancedGasFeeValues } from '../../../../../selectors'; import { useGasFeeContext } from '../../../../../contexts/gasFee'; import { useI18nContext } from '../../../../../hooks/useI18nContext'; @@ -19,6 +18,7 @@ import FormField from '../../../../ui/form-field'; import { useAdvancedGasFeePopoverContext } from '../../context'; import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext'; +import { decGWEIToHexWEI } from '../../../../../../shared/modules/conversion.utils'; const validateBaseFee = (value, gasFeeEstimates, maxPriorityFeePerGas) => { if (bnGreaterThan(maxPriorityFeePerGas, value)) { diff --git a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js index 48598051b..dd051a19c 100644 --- a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js +++ b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js @@ -7,7 +7,6 @@ import { PRIORITY_LEVELS, } from '../../../../../../shared/constants/gas'; import { PRIMARY } from '../../../../../helpers/constants/common'; -import { decGWEIToHexWEI } from '../../../../../helpers/utils/conversions.util'; import { getAdvancedGasFeeValues } from '../../../../../selectors'; import { useCurrencyDisplay } from '../../../../../hooks/useCurrencyDisplay'; import { useGasFeeContext } from '../../../../../contexts/gasFee'; @@ -19,6 +18,7 @@ import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util'; import { useAdvancedGasFeePopoverContext } from '../../context'; import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext'; +import { decGWEIToHexWEI } from '../../../../../../shared/modules/conversion.utils'; const validatePriorityFee = (value, gasFeeEstimates) => { if (value < 0) { diff --git a/ui/components/app/advanced-gas-inputs/advanced-gas-inputs.container.js b/ui/components/app/advanced-gas-inputs/advanced-gas-inputs.container.js index 3f21df94d..dc2b09a17 100644 --- a/ui/components/app/advanced-gas-inputs/advanced-gas-inputs.container.js +++ b/ui/components/app/advanced-gas-inputs/advanced-gas-inputs.container.js @@ -1,11 +1,11 @@ import { connect } from 'react-redux'; -import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util'; import { getNetworkSupportsSettingGasFees } from '../../../selectors/selectors'; import { MIN_GAS_LIMIT_DEC } from '../../../pages/send/send.constants'; import { + decGWEIToHexWEI, decimalToHex, hexWEIToDecGWEI, -} from '../../../../shared/lib/transactions-controller-utils'; +} from '../../../../shared/modules/conversion.utils'; import AdvancedGasInputs from './advanced-gas-inputs.component'; function convertGasPriceForInputs(gasPriceInHexWEI) { diff --git a/ui/components/app/cancel-speedup-popover/cancel-speedup-popover.test.js b/ui/components/app/cancel-speedup-popover/cancel-speedup-popover.test.js index 3e8293804..9ea165bed 100644 --- a/ui/components/app/cancel-speedup-popover/cancel-speedup-popover.test.js +++ b/ui/components/app/cancel-speedup-popover/cancel-speedup-popover.test.js @@ -11,9 +11,11 @@ import mockEstimates from '../../../../test/data/mock-estimates.json'; import mockState from '../../../../test/data/mock-state.json'; import { GasFeeContextProvider } from '../../../contexts/gasFee'; import configureStore from '../../../store/store'; -import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util'; import InfoTooltip from '../../ui/info-tooltip'; -import { hexWEIToDecETH } from '../../../../shared/lib/transactions-controller-utils'; +import { + decGWEIToHexWEI, + hexWEIToDecETH, +} from '../../../../shared/modules/conversion.utils'; import CancelSpeedupPopover from './cancel-speedup-popover'; const MAXFEEPERGAS_ABOVE_MOCK_MEDIUM_HEX = '0x174876e800'; diff --git a/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js b/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js index 94753f90a..0f3c3de61 100755 --- a/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js +++ b/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js @@ -9,7 +9,7 @@ import { transactionMatchesNetwork } from '../../../../../shared/modules/transac import { I18nContext } from '../../../../contexts/i18n'; import { CONFIRM_TRANSACTION_ROUTE } from '../../../../helpers/constants/routes'; import { clearConfirmTransaction } from '../../../../ducks/confirm-transaction/confirm-transaction.duck'; -import { hexToDecimal } from '../../../../../shared/lib/metamask-controller-utils'; +import { hexToDecimal } from '../../../../../shared/modules/conversion.utils'; const ConfirmPageContainerNavigation = () => { const t = useContext(I18nContext); diff --git a/ui/components/app/currency-input/currency-input.js b/ui/components/app/currency-input/currency-input.js index a822a9db9..0d5ea0873 100644 --- a/ui/components/app/currency-input/currency-input.js +++ b/ui/components/app/currency-input/currency-input.js @@ -3,10 +3,6 @@ import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import UnitInput from '../../ui/unit-input'; import CurrencyDisplay from '../../ui/currency-display'; -import { - getValueFromWeiHex, - getWeiHexFromDecimalValue, -} from '../../../helpers/utils/conversions.util'; import { ETH } from '../../../helpers/constants/common'; import { I18nContext } from '../../../contexts/i18n'; import { @@ -14,6 +10,10 @@ import { getNativeCurrency, } from '../../../ducks/metamask/metamask'; import { getCurrentCurrency, getShouldShowFiat } from '../../../selectors'; +import { + getValueFromWeiHex, + getWeiHexFromDecimalValue, +} from '../../../../shared/modules/conversion.utils'; /** * Component that allows user to enter currency values as a number, and props receive a converted diff --git a/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js b/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js index 303d72ffb..1d292e188 100644 --- a/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js +++ b/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js @@ -6,7 +6,6 @@ import { PRIORITY_LEVELS, } from '../../../../../shared/constants/gas'; import { getMaximumGasTotalInHexWei } from '../../../../../shared/modules/gas.utils'; -import { decGWEIToHexWEI } from '../../../../helpers/utils/conversions.util'; import { addTenPercentAndRound, gasEstimateGreaterThanGasUsedPlusTenPercent, @@ -14,9 +13,10 @@ import { import { getAdvancedGasFeeValues } from '../../../../selectors'; import { useGasFeeContext } from '../../../../contexts/gasFee'; import { + decGWEIToHexWEI, decimalToHex, hexWEIToDecGWEI, -} from '../../../../../shared/lib/transactions-controller-utils'; +} from '../../../../../shared/modules/conversion.utils'; import { useCustomTimeEstimate } from './useCustomTimeEstimate'; export const useGasItemFeeDetails = (priorityLevel) => { diff --git a/ui/components/app/edit-gas-popover/edit-gas-popover.component.js b/ui/components/app/edit-gas-popover/edit-gas-popover.component.js index 9b29ed991..3e2dd96c5 100644 --- a/ui/components/app/edit-gas-popover/edit-gas-popover.component.js +++ b/ui/components/app/edit-gas-popover/edit-gas-popover.component.js @@ -10,8 +10,6 @@ import { GAS_RECOMMENDATIONS, } from '../../../../shared/constants/gas'; -import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util'; - import Popover from '../../ui/popover'; import Button from '../../ui/button'; import EditGasDisplay from '../edit-gas-display'; @@ -27,8 +25,11 @@ import { } from '../../../store/actions'; import LoadingHeartBeat from '../../ui/loading-heartbeat'; import { useIncrementedGasFees } from '../../../hooks/useIncrementedGasFees'; -import { hexToDecimal } from '../../../../shared/lib/metamask-controller-utils'; -import { decimalToHex } from '../../../../shared/lib/transactions-controller-utils'; +import { + decGWEIToHexWEI, + decimalToHex, + hexToDecimal, +} from '../../../../shared/modules/conversion.utils'; export default function EditGasPopover({ popoverTitle = '', diff --git a/ui/components/app/edit-gas-popover/edit-gas-popover.stories.js b/ui/components/app/edit-gas-popover/edit-gas-popover.stories.js index 80a78998c..205cefe36 100644 --- a/ui/components/app/edit-gas-popover/edit-gas-popover.stories.js +++ b/ui/components/app/edit-gas-popover/edit-gas-popover.stories.js @@ -1,6 +1,5 @@ import React from 'react'; import { Provider } from 'react-redux'; -import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util'; import configureStore from '../../../store/store'; import testData from '../../../../.storybook/test-data'; import { @@ -8,6 +7,7 @@ import { GAS_RECOMMENDATIONS, } from '../../../../shared/constants/gas'; +import { decGWEIToHexWEI } from '../../../../shared/modules/conversion.utils'; import EditGasPopover from '.'; const store = configureStore(testData); diff --git a/ui/components/app/multilayer-fee-message/multi-layer-fee-message.js b/ui/components/app/multilayer-fee-message/multi-layer-fee-message.js index 99075a532..57a268438 100644 --- a/ui/components/app/multilayer-fee-message/multi-layer-fee-message.js +++ b/ui/components/app/multilayer-fee-message/multi-layer-fee-message.js @@ -6,8 +6,8 @@ import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee'; import { SECONDARY } from '../../../helpers/constants/common'; import { I18nContext } from '../../../contexts/i18n'; -import { sumHexes } from '../../../helpers/utils/transactions.util'; import { + sumHexes, toBigNumber, toNormalizedDenomination, } from '../../../../shared/modules/conversion.utils'; diff --git a/ui/components/app/transaction-activity-log/transaction-activity-log.component.js b/ui/components/app/transaction-activity-log/transaction-activity-log.component.js index b322b5877..c041f351b 100644 --- a/ui/components/app/transaction-activity-log/transaction-activity-log.component.js +++ b/ui/components/app/transaction-activity-log/transaction-activity-log.component.js @@ -3,9 +3,9 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import { getBlockExplorerLink } from '@metamask/etherscan-link'; -import { getValueFromWeiHex } from '../../../helpers/utils/conversions.util'; import { formatDate, getURLHostName } from '../../../helpers/utils/util'; import { EVENT } from '../../../../shared/constants/metametrics'; +import { getValueFromWeiHex } from '../../../../shared/modules/conversion.utils'; import TransactionActivityLogIcon from './transaction-activity-log-icon'; import { CONFIRMED_STATUS } from './transaction-activity-log.constants'; diff --git a/ui/components/app/transaction-activity-log/transaction-activity-log.util.js b/ui/components/app/transaction-activity-log/transaction-activity-log.util.js index e722cf45a..9e12dbdbe 100644 --- a/ui/components/app/transaction-activity-log/transaction-activity-log.util.js +++ b/ui/components/app/transaction-activity-log/transaction-activity-log.util.js @@ -1,6 +1,6 @@ import { TransactionType } from '../../../../shared/constants/transaction'; +import { sumHexes } from '../../../../shared/modules/conversion.utils'; import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util'; -import { sumHexes } from '../../../helpers/utils/transactions.util'; import { // event constants diff --git a/ui/components/app/transaction-breakdown/transaction-breakdown.container.js b/ui/components/app/transaction-breakdown/transaction-breakdown.container.js index 31d752223..ed70719ba 100644 --- a/ui/components/app/transaction-breakdown/transaction-breakdown.container.js +++ b/ui/components/app/transaction-breakdown/transaction-breakdown.container.js @@ -5,10 +5,12 @@ import { } from '../../../selectors'; import { getNativeCurrency } from '../../../ducks/metamask/metamask'; import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util'; -import { subtractHexes } from '../../../helpers/utils/conversions.util'; -import { sumHexes } from '../../../helpers/utils/transactions.util'; import { isEIP1559Transaction } from '../../../../shared/modules/transaction.utils'; +import { + subtractHexes, + sumHexes, +} from '../../../../shared/modules/conversion.utils'; import TransactionBreakdown from './transaction-breakdown.component'; const mapStateToProps = (state, ownProps) => { diff --git a/ui/components/app/transaction-decoding/transaction-decoding.component.js b/ui/components/app/transaction-decoding/transaction-decoding.component.js index 993963d58..f68dd6a77 100644 --- a/ui/components/app/transaction-decoding/transaction-decoding.component.js +++ b/ui/components/app/transaction-decoding/transaction-decoding.component.js @@ -10,7 +10,7 @@ import fetchWithCache from '../../../../shared/lib/fetch-with-cache'; import { getSelectedAccount, getCurrentChainId } from '../../../selectors'; import { I18nContext } from '../../../contexts/i18n'; import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; -import { hexToDecimal } from '../../../../shared/lib/metamask-controller-utils'; +import { hexToDecimal } from '../../../../shared/modules/conversion.utils'; import { transformTxDecoding } from './transaction-decoding.util'; import { FETCH_PROJECT_INFO_URI, diff --git a/ui/components/ui/hex-to-decimal/hex-to-decimal.component.js b/ui/components/ui/hex-to-decimal/hex-to-decimal.component.js index 290fc45cd..ee7d998ff 100644 --- a/ui/components/ui/hex-to-decimal/hex-to-decimal.component.js +++ b/ui/components/ui/hex-to-decimal/hex-to-decimal.component.js @@ -1,6 +1,6 @@ import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; -import { hexToDecimal } from '../../../../shared/lib/metamask-controller-utils'; +import { hexToDecimal } from '../../../../shared/modules/conversion.utils'; export default class HexToDecimal extends PureComponent { static propTypes = { diff --git a/ui/components/ui/token-input/token-input.component.js b/ui/components/ui/token-input/token-input.component.js index 783480bdc..f659770bf 100644 --- a/ui/components/ui/token-input/token-input.component.js +++ b/ui/components/ui/token-input/token-input.component.js @@ -3,9 +3,9 @@ import PropTypes from 'prop-types'; import BigNumber from 'bignumber.js'; import UnitInput from '../unit-input'; import CurrencyDisplay from '../currency-display'; -import { getWeiHexFromDecimalValue } from '../../../helpers/utils/conversions.util'; import { conversionUtil, + getWeiHexFromDecimalValue, multiplyCurrencies, } from '../../../../shared/modules/conversion.utils'; diff --git a/ui/ducks/confirm-transaction/confirm-transaction.duck.js b/ui/ducks/confirm-transaction/confirm-transaction.duck.js index e94dbc3b3..bb846a204 100644 --- a/ui/ducks/confirm-transaction/confirm-transaction.duck.js +++ b/ui/ducks/confirm-transaction/confirm-transaction.duck.js @@ -6,16 +6,17 @@ import { import { getNativeCurrency, getTokens } from '../metamask/metamask'; import { - getValueFromWeiHex, getTransactionFee, getHexGasTotal, addFiat, addEth, } from '../../helpers/utils/confirm-tx.util'; -import { sumHexes } from '../../helpers/utils/transactions.util'; - -import { conversionUtil } from '../../../shared/modules/conversion.utils'; +import { + conversionUtil, + getValueFromWeiHex, + sumHexes, +} from '../../../shared/modules/conversion.utils'; import { getAveragePriceEstimateInHexWEI } from '../../selectors/custom-gas'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils'; diff --git a/ui/ducks/metamask/metamask.js b/ui/ducks/metamask/metamask.js index 04e8f61bc..4ca87f16c 100644 --- a/ui/ducks/metamask/metamask.js +++ b/ui/ducks/metamask/metamask.js @@ -13,11 +13,11 @@ import { } from '../../selectors'; import { updateTransactionGasFees } from '../../store/actions'; import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck'; -import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util'; import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; import { stripHexPrefix } from '../../../shared/modules/hexstring-utils'; +import { decGWEIToHexWEI } from '../../../shared/modules/conversion.utils'; export default function reduceMetamask(state = {}, action) { const metamaskState = { diff --git a/ui/ducks/send/send.js b/ui/ducks/send/send.js index 1b1f2cb13..ac4fadeda 100644 --- a/ui/ducks/send/send.js +++ b/ui/ducks/send/send.js @@ -6,8 +6,10 @@ import { v4 as uuidv4 } from 'uuid'; import { conversionGreaterThan, conversionUtil, + getValueFromWeiHex, multiplyCurrencies, subtractCurrencies, + sumHexes, } from '../../../shared/modules/conversion.utils'; import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas'; import { @@ -89,10 +91,7 @@ import { isValidHexAddress, toChecksumHexAddress, } from '../../../shared/modules/hexstring-utils'; -import { - isSmartContractAddress, - sumHexes, -} from '../../helpers/utils/transactions.util'; +import { isSmartContractAddress } from '../../helpers/utils/transactions.util'; import fetchEstimatedL1Fee from '../../helpers/utils/optimism/fetchEstimatedL1Fee'; import { ETH } from '../../helpers/constants/common'; @@ -104,7 +103,6 @@ import { } from '../../../shared/constants/transaction'; import { INVALID_ASSET_TYPE } from '../../helpers/constants/error-keys'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; -import { getValueFromWeiHex } from '../../helpers/utils/confirm-tx.util'; import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils'; import { getTokenValueParam } from '../../../shared/lib/metamask-controller-utils'; import { diff --git a/ui/ducks/swaps/swaps.js b/ui/ducks/swaps/swaps.js index bc4234203..9d42d1bc2 100644 --- a/ui/ducks/swaps/swaps.js +++ b/ui/ducks/swaps/swaps.js @@ -52,11 +52,13 @@ import { stxErrorTypes, } from '../../pages/swaps/swaps.util'; import { - getValueFromWeiHex, - decGWEIToHexWEI, addHexes, -} from '../../helpers/utils/conversions.util'; -import { conversionLessThan } from '../../../shared/modules/conversion.utils'; + conversionLessThan, + decGWEIToHexWEI, + decimalToHex, + getValueFromWeiHex, + hexWEIToDecGWEI, +} from '../../../shared/modules/conversion.utils'; import { getSelectedAccount, getTokenExchangeRates, @@ -88,8 +90,6 @@ import { ORIGIN_METAMASK } from '../../../shared/constants/app'; import { calcGasTotal, calcTokenAmount, - decimalToHex, - hexWEIToDecGWEI, } from '../../../shared/lib/transactions-controller-utils'; export const GAS_PRICES_LOADING_STATES = { diff --git a/ui/helpers/utils/confirm-tx.util.js b/ui/helpers/utils/confirm-tx.util.js index 86d154d1a..315cbcc55 100644 --- a/ui/helpers/utils/confirm-tx.util.js +++ b/ui/helpers/utils/confirm-tx.util.js @@ -60,26 +60,6 @@ export function addFiat(...args) { }); } -export function getValueFromWeiHex({ - value, - fromCurrency = 'ETH', - toCurrency, - conversionRate, - numberOfDecimals, - toDenomination, -}) { - return conversionUtil(value, { - fromNumericBase: 'hex', - toNumericBase: 'dec', - fromCurrency, - toCurrency, - numberOfDecimals, - fromDenomination: 'WEI', - toDenomination, - conversionRate, - }); -} - export function getTransactionFee({ value, fromCurrency = 'ETH', diff --git a/ui/helpers/utils/confirm-tx.util.test.js b/ui/helpers/utils/confirm-tx.util.test.js index 71cd49a5a..d0f4971a8 100644 --- a/ui/helpers/utils/confirm-tx.util.test.js +++ b/ui/helpers/utils/confirm-tx.util.test.js @@ -89,30 +89,6 @@ describe('Confirm Transaction utils', () => { }); }); - describe('getValueFromWeiHex', () => { - it('should get the transaction amount in ETH', () => { - const ethTransactionAmount = utils.getValueFromWeiHex({ - value: '0xde0b6b3a7640000', - toCurrency: 'ETH', - conversionRate: 468.58, - numberOfDecimals: 6, - }); - - expect(ethTransactionAmount).toStrictEqual('1'); - }); - - it('should get the transaction amount in fiat', () => { - const fiatTransactionAmount = utils.getValueFromWeiHex({ - value: '0xde0b6b3a7640000', - toCurrency: 'usd', - conversionRate: 468.58, - numberOfDecimals: 2, - }); - - expect(fiatTransactionAmount).toStrictEqual('468.58'); - }); - }); - describe('getTransactionFee', () => { it('should get the transaction fee in ETH', () => { const ethTransactionFee = utils.getTransactionFee({ diff --git a/ui/helpers/utils/conversions.util.js b/ui/helpers/utils/conversions.util.js deleted file mode 100644 index 18f189637..000000000 --- a/ui/helpers/utils/conversions.util.js +++ /dev/null @@ -1,202 +0,0 @@ -import { ETH, GWEI, WEI } from '../constants/common'; -import { addHexPrefix } from '../../../app/scripts/lib/util'; -import { - conversionUtil, - addCurrencies, - subtractCurrencies, -} from '../../../shared/modules/conversion.utils'; -import { formatCurrency } from './confirm-tx.util'; - -export function bnToHex(inputBn) { - return addHexPrefix(inputBn.toString(16)); -} - -export function getEthConversionFromWeiHex({ - value, - fromCurrency = ETH, - conversionRate, - numberOfDecimals = 6, -}) { - const denominations = [fromCurrency, GWEI, WEI]; - - let nonZeroDenomination; - - for (let i = 0; i < denominations.length; i++) { - const convertedValue = getValueFromWeiHex({ - value, - conversionRate, - fromCurrency, - toCurrency: fromCurrency, - numberOfDecimals, - toDenomination: denominations[i], - }); - - if (convertedValue !== '0' || i === denominations.length - 1) { - nonZeroDenomination = `${convertedValue} ${denominations[i]}`; - break; - } - } - - return nonZeroDenomination; -} - -export function getValueFromWeiHex({ - value, - fromCurrency = ETH, - toCurrency, - conversionRate, - numberOfDecimals, - toDenomination, -}) { - return conversionUtil(value, { - fromNumericBase: 'hex', - toNumericBase: 'dec', - fromCurrency, - toCurrency, - numberOfDecimals, - fromDenomination: WEI, - toDenomination, - conversionRate, - }); -} - -export function getWeiHexFromDecimalValue({ - value, - fromCurrency, - conversionRate, - fromDenomination, - invertConversionRate, -}) { - return conversionUtil(value, { - fromNumericBase: 'dec', - toNumericBase: 'hex', - toCurrency: ETH, - fromCurrency, - conversionRate, - invertConversionRate, - fromDenomination, - toDenomination: WEI, - }); -} - -export function addHexWEIsToDec(aHexWEI, bHexWEI) { - return addCurrencies(aHexWEI, bHexWEI, { - aBase: 16, - bBase: 16, - fromDenomination: 'WEI', - numberOfDecimals: 6, - }); -} - -export function subtractHexWEIsToDec(aHexWEI, bHexWEI) { - return subtractCurrencies(aHexWEI, bHexWEI, { - aBase: 16, - bBase: 16, - fromDenomination: 'WEI', - numberOfDecimals: 6, - }); -} - -export function decEthToConvertedCurrency( - ethTotal, - convertedCurrency, - conversionRate, -) { - return conversionUtil(ethTotal, { - fromNumericBase: 'dec', - toNumericBase: 'dec', - fromCurrency: 'ETH', - toCurrency: convertedCurrency, - numberOfDecimals: 2, - conversionRate, - }); -} - -export function decGWEIToHexWEI(decGWEI) { - return conversionUtil(decGWEI, { - fromNumericBase: 'dec', - toNumericBase: 'hex', - fromDenomination: 'GWEI', - toDenomination: 'WEI', - }); -} - -export function decETHToDecWEI(decEth) { - return conversionUtil(decEth, { - fromNumericBase: 'dec', - toNumericBase: 'dec', - fromDenomination: 'ETH', - toDenomination: 'WEI', - }); -} - -export function hexWEIToDecETH(hexWEI) { - return conversionUtil(hexWEI, { - fromNumericBase: 'hex', - toNumericBase: 'dec', - fromDenomination: 'WEI', - toDenomination: 'ETH', - }); -} - -export function decWEIToDecETH(hexWEI) { - return conversionUtil(hexWEI, { - fromNumericBase: 'dec', - toNumericBase: 'dec', - fromDenomination: 'WEI', - toDenomination: 'ETH', - }); -} - -export function addHexes(aHexWEI, bHexWEI) { - return addCurrencies(aHexWEI, bHexWEI, { - aBase: 16, - bBase: 16, - toNumericBase: 'hex', - numberOfDecimals: 6, - }); -} - -export function subtractHexes(aHexWEI, bHexWEI) { - return subtractCurrencies(aHexWEI, bHexWEI, { - aBase: 16, - bBase: 16, - toNumericBase: 'hex', - numberOfDecimals: 6, - }); -} - -export function sumHexWEIs(hexWEIs) { - return hexWEIs.filter(Boolean).reduce(addHexes); -} - -export function sumHexWEIsToUnformattedFiat( - hexWEIs, - convertedCurrency, - conversionRate, -) { - const hexWEIsSum = sumHexWEIs(hexWEIs); - const convertedTotal = decEthToConvertedCurrency( - getValueFromWeiHex({ - value: hexWEIsSum, - toCurrency: 'ETH', - numberOfDecimals: 4, - }), - convertedCurrency, - conversionRate, - ); - return convertedTotal; -} - -export function sumHexWEIsToRenderableFiat( - hexWEIs, - convertedCurrency, - conversionRate, -) { - const convertedTotal = sumHexWEIsToUnformattedFiat( - hexWEIs, - convertedCurrency, - conversionRate, - ); - return formatCurrency(convertedTotal, convertedCurrency); -} diff --git a/ui/helpers/utils/conversions.util.test.js b/ui/helpers/utils/conversions.util.test.js deleted file mode 100644 index af2f0d7a0..000000000 --- a/ui/helpers/utils/conversions.util.test.js +++ /dev/null @@ -1,54 +0,0 @@ -import { ETH } from '../constants/common'; -import * as utils from './conversions.util'; - -describe('conversion utils', () => { - describe('getWeiHexFromDecimalValue', () => { - it('should correctly convert 0 in ETH', () => { - const weiValue = utils.getWeiHexFromDecimalValue({ - value: '0', - fromCurrency: ETH, - fromDenomination: ETH, - }); - expect(weiValue).toStrictEqual('0'); - }); - }); - - describe('decETHToDecWEI', () => { - it('should correctly convert 1 ETH to WEI', () => { - const weiValue = utils.decETHToDecWEI('1'); - expect(weiValue).toStrictEqual('1000000000000000000'); - }); - - it('should correctly convert 0.000000000000000001 ETH to WEI', () => { - const weiValue = utils.decETHToDecWEI('0.000000000000000001'); - expect(weiValue).toStrictEqual('1'); - }); - - it('should correctly convert 1000000.000000000000000001 ETH to WEI', () => { - const weiValue = utils.decETHToDecWEI('1000000.000000000000000001'); - expect(weiValue).toStrictEqual('1000000000000000000000001'); - }); - - it('should correctly convert 9876.543210 ETH to WEI', () => { - const weiValue = utils.decETHToDecWEI('9876.543210'); - expect(weiValue).toStrictEqual('9876543210000000000000'); - }); - - it('should correctly convert 1.0000000000000000 ETH to WEI', () => { - const weiValue = utils.decETHToDecWEI('1.0000000000000000'); - expect(weiValue).toStrictEqual('1000000000000000000'); - }); - }); - - describe('decWEIToDecETH', () => { - it('converts 10000000000000 WEI to ETH', () => { - const ethDec = utils.decWEIToDecETH('10000000000000'); - expect('0.00001').toStrictEqual(ethDec); - }); - - it('converts 9358749494527040 WEI to ETH', () => { - const ethDec = utils.decWEIToDecETH('9358749494527040'); - expect('0.009358749').toStrictEqual(ethDec); - }); - }); -}); diff --git a/ui/helpers/utils/gas.js b/ui/helpers/utils/gas.js index d9e3f3558..0355a3449 100644 --- a/ui/helpers/utils/gas.js +++ b/ui/helpers/utils/gas.js @@ -5,8 +5,10 @@ import { GAS_RECOMMENDATIONS, EDIT_GAS_MODES, } from '../../../shared/constants/gas'; -import { multiplyCurrencies } from '../../../shared/modules/conversion.utils'; -import { hexWEIToDecGWEI } from '../../../shared/lib/transactions-controller-utils'; +import { + hexWEIToDecGWEI, + multiplyCurrencies, +} from '../../../shared/modules/conversion.utils'; import { bnGreaterThan, isNullish, diff --git a/ui/helpers/utils/transactions.util.js b/ui/helpers/utils/transactions.util.js index 80b7ced4f..77a0f5410 100644 --- a/ui/helpers/utils/transactions.util.js +++ b/ui/helpers/utils/transactions.util.js @@ -8,7 +8,6 @@ import { TransactionStatus, TransactionEnvelopeType, } from '../../../shared/constants/transaction'; -import { addCurrencies } from '../../../shared/modules/conversion.utils'; import { readAddressAsContract } from '../../../shared/modules/contract-utils'; import fetchWithCache from '../../../shared/lib/fetch-with-cache'; @@ -135,18 +134,6 @@ export async function isSmartContractAddress(address) { return isContractAddress; } -export function sumHexes(...args) { - const total = args.reduce((acc, hexAmount) => { - return addCurrencies(acc, hexAmount, { - toNumericBase: 'hex', - aBase: 16, - bBase: 16, - }); - }); - - return addHexPrefix(total); -} - export function isLegacyTransaction(txParams) { return txParams?.type === TransactionEnvelopeType.legacy; } diff --git a/ui/hooks/gasFeeInput/useGasEstimates.js b/ui/hooks/gasFeeInput/useGasEstimates.js index 47619ef7a..33ccf7fe2 100644 --- a/ui/hooks/gasFeeInput/useGasEstimates.js +++ b/ui/hooks/gasFeeInput/useGasEstimates.js @@ -11,12 +11,14 @@ import { import { PRIMARY } from '../../helpers/constants/common'; import { checkNetworkAndAccountSupports1559 } from '../../selectors'; -import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; import { useCurrencyDisplay } from '../useCurrencyDisplay'; import { useUserPreferencedCurrency } from '../useUserPreferencedCurrency'; -import { decimalToHex } from '../../../shared/lib/transactions-controller-utils'; +import { + decGWEIToHexWEI, + decimalToHex, +} from '../../../shared/modules/conversion.utils'; /** * @typedef {object} GasEstimatesReturnType diff --git a/ui/hooks/gasFeeInput/useGasEstimates.test.js b/ui/hooks/gasFeeInput/useGasEstimates.test.js index a0c207f36..5ccf31e8f 100644 --- a/ui/hooks/gasFeeInput/useGasEstimates.test.js +++ b/ui/hooks/gasFeeInput/useGasEstimates.test.js @@ -3,8 +3,10 @@ import { getMaximumGasTotalInHexWei, getMinimumGasTotalInHexWei, } from '../../../shared/modules/gas.utils'; -import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util'; -import { decimalToHex } from '../../../shared/lib/transactions-controller-utils'; +import { + decGWEIToHexWEI, + decimalToHex, +} from '../../../shared/modules/conversion.utils'; import { FEE_MARKET_ESTIMATE_RETURN_VALUE, LEGACY_GAS_ESTIMATE_RETURN_VALUE, diff --git a/ui/hooks/gasFeeInput/useGasFeeErrors.js b/ui/hooks/gasFeeInput/useGasFeeErrors.js index ca0796388..49771b837 100644 --- a/ui/hooks/gasFeeInput/useGasFeeErrors.js +++ b/ui/hooks/gasFeeInput/useGasFeeErrors.js @@ -4,12 +4,12 @@ import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas'; import { conversionLessThan, conversionGreaterThan, + addHexes, } from '../../../shared/modules/conversion.utils'; import { checkNetworkAndAccountSupports1559, getSelectedAccount, } from '../../selectors'; -import { addHexes } from '../../helpers/utils/conversions.util'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; import { bnGreaterThan, bnLessThan } from '../../helpers/utils/util'; import { GAS_FORM_ERRORS } from '../../helpers/constants/gas'; diff --git a/ui/hooks/gasFeeInput/useGasFeeInputs.js b/ui/hooks/gasFeeInput/useGasFeeInputs.js index 6805c1819..57657fa91 100644 --- a/ui/hooks/gasFeeInput/useGasFeeInputs.js +++ b/ui/hooks/gasFeeInput/useGasFeeInputs.js @@ -16,7 +16,7 @@ import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; import { useGasFeeEstimates } from '../useGasFeeEstimates'; import { editGasModeIsSpeedUpOrCancel } from '../../helpers/utils/gas'; -import { hexToDecimal } from '../../../shared/lib/metamask-controller-utils'; +import { hexToDecimal } from '../../../shared/modules/conversion.utils'; import { useGasFeeErrors } from './useGasFeeErrors'; import { useGasPriceInput } from './useGasPriceInput'; import { useMaxFeePerGasInput } from './useMaxFeePerGasInput'; diff --git a/ui/hooks/gasFeeInput/useGasPriceInput.js b/ui/hooks/gasFeeInput/useGasPriceInput.js index a931c0ff9..2c7f9f87b 100644 --- a/ui/hooks/gasFeeInput/useGasPriceInput.js +++ b/ui/hooks/gasFeeInput/useGasPriceInput.js @@ -7,7 +7,7 @@ import { } from '../../../shared/constants/gas'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; -import { hexWEIToDecGWEI } from '../../../shared/lib/transactions-controller-utils'; +import { hexWEIToDecGWEI } from '../../../shared/modules/conversion.utils'; import { feeParamsAreCustom } from './utils'; function getGasPriceEstimate(gasFeeEstimates, gasEstimateType, estimateToUse) { diff --git a/ui/hooks/gasFeeInput/useMaxFeePerGasInput.js b/ui/hooks/gasFeeInput/useMaxFeePerGasInput.js index cc8788fb8..8971e4b84 100644 --- a/ui/hooks/gasFeeInput/useMaxFeePerGasInput.js +++ b/ui/hooks/gasFeeInput/useMaxFeePerGasInput.js @@ -4,7 +4,7 @@ import { useSelector } from 'react-redux'; import { checkNetworkAndAccountSupports1559 } from '../../selectors'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; -import { hexWEIToDecGWEI } from '../../../shared/lib/transactions-controller-utils'; +import { hexWEIToDecGWEI } from '../../../shared/modules/conversion.utils'; import { feeParamsAreCustom, getGasFeeEstimate } from './utils'; const getMaxFeePerGasFromTransaction = (transaction, gasFeeEstimates) => { diff --git a/ui/hooks/gasFeeInput/useMaxPriorityFeePerGasInput.js b/ui/hooks/gasFeeInput/useMaxPriorityFeePerGasInput.js index 478039ca1..d41d0ec85 100644 --- a/ui/hooks/gasFeeInput/useMaxPriorityFeePerGasInput.js +++ b/ui/hooks/gasFeeInput/useMaxPriorityFeePerGasInput.js @@ -4,7 +4,7 @@ import { useEffect, useState } from 'react'; import { checkNetworkAndAccountSupports1559 } from '../../selectors'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; -import { hexWEIToDecGWEI } from '../../../shared/lib/transactions-controller-utils'; +import { hexWEIToDecGWEI } from '../../../shared/modules/conversion.utils'; import { feeParamsAreCustom, getGasFeeEstimate } from './utils'; const getMaxPriorityFeePerGasFromTransaction = ( diff --git a/ui/hooks/gasFeeInput/useTransactionFunctions.js b/ui/hooks/gasFeeInput/useTransactionFunctions.js index fab8376f2..15af059f6 100644 --- a/ui/hooks/gasFeeInput/useTransactionFunctions.js +++ b/ui/hooks/gasFeeInput/useTransactionFunctions.js @@ -1,9 +1,11 @@ import { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { decimalToHex } from '../../../shared/lib/transactions-controller-utils'; import { EDIT_GAS_MODES, PRIORITY_LEVELS } from '../../../shared/constants/gas'; -import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util'; +import { + decGWEIToHexWEI, + decimalToHex, +} from '../../../shared/modules/conversion.utils'; import { addTenPercentAndRound, editGasModeIsSpeedUpOrCancel, diff --git a/ui/hooks/useCurrencyDisplay.js b/ui/hooks/useCurrencyDisplay.js index da413de83..eb675428b 100644 --- a/ui/hooks/useCurrencyDisplay.js +++ b/ui/hooks/useCurrencyDisplay.js @@ -1,16 +1,16 @@ import { useMemo } from 'react'; import { useSelector } from 'react-redux'; -import { - formatCurrency, - getValueFromWeiHex, -} from '../helpers/utils/confirm-tx.util'; +import { formatCurrency } from '../helpers/utils/confirm-tx.util'; import { getCurrentCurrency } from '../selectors'; import { getConversionRate, getNativeCurrency, } from '../ducks/metamask/metamask'; -import { conversionUtil } from '../../shared/modules/conversion.utils'; +import { + conversionUtil, + getValueFromWeiHex, +} from '../../shared/modules/conversion.utils'; import { TEST_NETWORK_TICKER_MAP } from '../../shared/constants/network'; /** diff --git a/ui/hooks/useEthFiatAmount.js b/ui/hooks/useEthFiatAmount.js index 17c1d98ce..de6d4488e 100644 --- a/ui/hooks/useEthFiatAmount.js +++ b/ui/hooks/useEthFiatAmount.js @@ -1,9 +1,9 @@ import { useMemo } from 'react'; import { useSelector } from 'react-redux'; import { getCurrentCurrency, getShouldShowFiat } from '../selectors'; -import { decEthToConvertedCurrency } from '../helpers/utils/conversions.util'; import { formatCurrency } from '../helpers/utils/confirm-tx.util'; import { getConversionRate } from '../ducks/metamask/metamask'; +import { decEthToConvertedCurrency } from '../../shared/modules/conversion.utils'; /** * Get an Eth amount converted to fiat and formatted for display diff --git a/ui/hooks/useIncrementedGasFees.js b/ui/hooks/useIncrementedGasFees.js index 3577f3ed4..14e58391b 100644 --- a/ui/hooks/useIncrementedGasFees.js +++ b/ui/hooks/useIncrementedGasFees.js @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js'; import { useMemo } from 'react'; +import { decGWEIToHexWEI } from '../../shared/modules/conversion.utils'; import { isEIP1559Transaction } from '../../shared/modules/transaction.utils'; -import { decGWEIToHexWEI } from '../helpers/utils/conversions.util'; import { addTenPercent } from '../helpers/utils/gas'; import { useGasFeeEstimates } from './useGasFeeEstimates'; diff --git a/ui/pages/confirm-approve/confirm-approve.util.js b/ui/pages/confirm-approve/confirm-approve.util.js index 48fc367ba..d44b38c9c 100644 --- a/ui/pages/confirm-approve/confirm-approve.util.js +++ b/ui/pages/confirm-approve/confirm-approve.util.js @@ -1,8 +1,8 @@ import { calcTokenValue } from '../../../shared/lib/swaps-utils'; -import { decimalToHex } from '../../../shared/lib/transactions-controller-utils'; import { TransactionType } from '../../../shared/constants/transaction'; import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils'; import { getTokenAddressParam } from '../../helpers/utils/token-util'; +import { decimalToHex } from '../../../shared/modules/conversion.utils'; export function getCustomTxParamsData( data, diff --git a/ui/pages/confirm-token-transaction-base/confirm-token-transaction-base.js b/ui/pages/confirm-token-transaction-base/confirm-token-transaction-base.js index 6caf0371c..153b7c9e0 100644 --- a/ui/pages/confirm-token-transaction-base/confirm-token-transaction-base.js +++ b/ui/pages/confirm-token-transaction-base/confirm-token-transaction-base.js @@ -12,7 +12,6 @@ import { roundExponential, } from '../../helpers/utils/confirm-tx.util'; import { ETH, PRIMARY } from '../../helpers/constants/common'; -import { getWeiHexFromDecimalValue } from '../../helpers/utils/conversions.util'; import { contractExchangeRateSelector, getCurrentCurrency, @@ -22,7 +21,10 @@ import { getNativeCurrency, } from '../../ducks/metamask/metamask'; import { TokenStandard } from '../../../shared/constants/transaction'; -import { hexWEIToDecETH } from '../../../shared/lib/transactions-controller-utils'; +import { + getWeiHexFromDecimalValue, + hexWEIToDecETH, +} from '../../../shared/modules/conversion.utils'; export default function ConfirmTokenTransactionBase({ image = '', diff --git a/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js index 923c8b67e..19eaf03c5 100644 --- a/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js @@ -6,7 +6,6 @@ import { stripHexPrefix } from 'ethereumjs-util'; import ConfirmPageContainer from '../../components/app/confirm-page-container'; import TransactionDecoding from '../../components/app/transaction-decoding'; import { isBalanceSufficient } from '../send/send.utils'; -import { addHexes } from '../../helpers/utils/conversions.util'; import { DEFAULT_ROUTE } from '../../helpers/constants/routes'; import { INSUFFICIENT_FUNDS_ERROR_KEY, @@ -57,8 +56,6 @@ import { import { MIN_GAS_LIMIT_DEC } from '../send/send.constants'; -import { hexToDecimal } from '../../../shared/lib/metamask-controller-utils'; -import { hexWEIToDecGWEI } from '../../../shared/lib/transactions-controller-utils'; ///: BEGIN:ONLY_INCLUDE_IN(flask) import { SnapInsight } from '../../components/app/confirm-page-container/flask/snap-insight'; import { DropdownTab, Tab } from '../../components/ui/tabs'; @@ -71,6 +68,11 @@ import { ///: END:ONLY_INCLUDE_IN } from '../../../shared/constants/network'; import TransactionAlerts from '../../components/app/transaction-alerts'; +import { + addHexes, + hexToDecimal, + hexWEIToDecGWEI, +} from '../../../shared/modules/conversion.utils'; const renderHeartBeatIfNotInTest = () => process.env.IN_TEST ? null : ; diff --git a/ui/pages/send/gas-display/gas-display.js b/ui/pages/send/gas-display/gas-display.js index 09f096bbe..9f0398e47 100644 --- a/ui/pages/send/gas-display/gas-display.js +++ b/ui/pages/send/gas-display/gas-display.js @@ -5,7 +5,6 @@ import classNames from 'classnames'; import { I18nContext } from '../../../contexts/i18n'; import { useGasFeeContext } from '../../../contexts/gasFee'; import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; -import { hexWEIToDecGWEI } from '../../../../shared/lib/transactions-controller-utils'; import UserPreferencedCurrencyDisplay from '../../../components/app/user-preferenced-currency-display'; import GasTiming from '../../../components/app/gas-timing'; import InfoTooltip from '../../../components/ui/info-tooltip'; @@ -38,13 +37,14 @@ import { getUseCurrencyRateCheck, } from '../../../selectors'; -import { - hexWEIToDecETH, - addHexes, -} from '../../../helpers/utils/conversions.util'; import { INSUFFICIENT_TOKENS_ERROR } from '../send.constants'; import { getCurrentDraftTransaction } from '../../../ducks/send'; import { showModal } from '../../../store/actions'; +import { + addHexes, + hexWEIToDecETH, + hexWEIToDecGWEI, +} from '../../../../shared/modules/conversion.utils'; export default function GasDisplay({ gasError }) { const t = useContext(I18nContext); diff --git a/ui/pages/send/send-content/send-gas-row/send-gas-row.container.js b/ui/pages/send/send-content/send-gas-row/send-gas-row.container.js index 269db0421..43efb887c 100644 --- a/ui/pages/send/send-content/send-gas-row/send-gas-row.container.js +++ b/ui/pages/send/send-content/send-gas-row/send-gas-row.container.js @@ -14,7 +14,7 @@ import { setCustomGasPrice, setCustomGasLimit, } from '../../../../ducks/gas/gas.duck'; -import { hexToDecimal } from '../../../../../shared/lib/metamask-controller-utils'; +import { hexToDecimal } from '../../../../../shared/modules/conversion.utils'; import SendGasRow from './send-gas-row.component'; export default connect(mapStateToProps, mapDispatchToProps)(SendGasRow); diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.js b/ui/pages/settings/networks-tab/networks-form/networks-form.js index 23466bb27..5f00e60ce 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.js @@ -36,8 +36,8 @@ import { infuraProjectId, FEATURED_RPCS, } from '../../../../../shared/constants/network'; -import { decimalToHex } from '../../../../../shared/lib/transactions-controller-utils'; import { ORIGIN_METAMASK } from '../../../../../shared/constants/app'; +import { decimalToHex } from '../../../../../shared/modules/conversion.utils'; /** * Attempts to convert the given chainId to a decimal string, for display diff --git a/ui/pages/swaps/build-quote/build-quote.js b/ui/pages/swaps/build-quote/build-quote.js index fd5e2fc04..b5b3bed7d 100644 --- a/ui/pages/swaps/build-quote/build-quote.js +++ b/ui/pages/swaps/build-quote/build-quote.js @@ -72,7 +72,6 @@ import { getUseCurrencyRateCheck, } from '../../../selectors'; -import { getValueFromWeiHex } from '../../../helpers/utils/conversions.util'; import { getURLHostName } from '../../../helpers/utils/util'; import { usePrevious } from '../../../hooks/usePrevious'; import { useTokenTracker } from '../../../hooks/useTokenTracker'; @@ -106,9 +105,12 @@ import { } from '../swaps.util'; import SwapsFooter from '../swaps-footer'; import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils'; -import { hexToDecimal } from '../../../../shared/lib/metamask-controller-utils'; import { calcTokenAmount } from '../../../../shared/lib/transactions-controller-utils'; import { shouldEnableDirectWrapping } from '../../../../shared/lib/swaps-utils'; +import { + getValueFromWeiHex, + hexToDecimal, +} from '../../../../shared/modules/conversion.utils'; const fuseSearchKeys = [ { name: 'name', weight: 0.499 }, diff --git a/ui/pages/swaps/swaps.util.js b/ui/pages/swaps/swaps.util.js index 3f5227fb9..56286026f 100644 --- a/ui/pages/swaps/swaps.util.js +++ b/ui/pages/swaps/swaps.util.js @@ -19,7 +19,6 @@ import { isSwapsDefaultTokenSymbol, } from '../../../shared/modules/swaps.utils'; import { CHAIN_IDS, CURRENCY_SYMBOLS } from '../../../shared/constants/network'; -import { getValueFromWeiHex } from '../../helpers/utils/conversions.util'; import { formatCurrency } from '../../helpers/utils/confirm-tx.util'; import fetchWithCache from '../../../shared/lib/fetch-with-cache'; @@ -27,7 +26,6 @@ import { isValidHexAddress } from '../../../shared/modules/hexstring-utils'; import { calcGasTotal, calcTokenAmount, - decimalToHex, toPrecisionWithoutTrailingZeros, } from '../../../shared/lib/transactions-controller-utils'; import { @@ -35,7 +33,11 @@ import { truthyString, validateData, } from '../../../shared/lib/swaps-utils'; -import { sumHexes } from '../../helpers/utils/transactions.util'; +import { + decimalToHex, + getValueFromWeiHex, + sumHexes, +} from '../../../shared/modules/conversion.utils'; const CACHE_REFRESH_FIVE_MINUTES = 300000; const USD_CURRENCY_CODE = 'usd'; diff --git a/ui/pages/swaps/view-quote/view-quote.js b/ui/pages/swaps/view-quote/view-quote.js index f5d4e256a..3b53b8923 100644 --- a/ui/pages/swaps/view-quote/view-quote.js +++ b/ui/pages/swaps/view-quote/view-quote.js @@ -82,11 +82,6 @@ import { SWAPS_ERROR_ROUTE, AWAITING_SWAP_ROUTE, } from '../../../helpers/constants/routes'; -import { - decGWEIToHexWEI, - addHexes, - decWEIToDecETH, -} from '../../../helpers/utils/conversions.util'; import MainQuoteSummary from '../main-quote-summary'; import { getCustomTxParamsData } from '../../confirm-approve/confirm-approve.util'; import ActionableMessage from '../../../components/ui/actionable-message/actionable-message'; @@ -109,14 +104,19 @@ import { getTokenValueParam } from '../../../../shared/lib/metamask-controller-u import { calcGasTotal, calcTokenAmount, - decimalToHex, - hexWEIToDecGWEI, toPrecisionWithoutTrailingZeros, } from '../../../../shared/lib/transactions-controller-utils'; import { addHexPrefix } from '../../../../app/scripts/lib/util'; import { calcTokenValue } from '../../../../shared/lib/swaps-utils'; import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee'; -import { sumHexes } from '../../../helpers/utils/transactions.util'; +import { + addHexes, + decGWEIToHexWEI, + decimalToHex, + decWEIToDecETH, + hexWEIToDecGWEI, + sumHexes, +} from '../../../../shared/modules/conversion.utils'; import ViewQuotePriceDifference from './view-quote-price-difference'; let intervalId; diff --git a/ui/selectors/confirm-transaction.js b/ui/selectors/confirm-transaction.js index cd199f954..a93d930be 100644 --- a/ui/selectors/confirm-transaction.js +++ b/ui/selectors/confirm-transaction.js @@ -2,12 +2,10 @@ import { createSelector } from 'reselect'; import txHelper from '../helpers/utils/tx-helper'; import { roundExponential, - getValueFromWeiHex, getTransactionFee, addFiat, addEth, } from '../helpers/utils/confirm-tx.util'; -import { sumHexes } from '../helpers/utils/transactions.util'; import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils'; import { getGasEstimateType, @@ -15,7 +13,6 @@ import { getNativeCurrency, } from '../ducks/metamask/metamask'; import { TransactionEnvelopeType } from '../../shared/constants/transaction'; -import { decGWEIToHexWEI } from '../helpers/utils/conversions.util'; import { GAS_ESTIMATE_TYPES, CUSTOM_GAS_ESTIMATE, @@ -26,6 +23,11 @@ import { } from '../../shared/modules/gas.utils'; import { isEqualCaseInsensitive } from '../../shared/modules/string-utils'; import { calcTokenAmount } from '../../shared/lib/transactions-controller-utils'; +import { + decGWEIToHexWEI, + getValueFromWeiHex, + sumHexes, +} from '../../shared/modules/conversion.utils'; import { getAveragePriceEstimateInHexWEI } from './custom-gas'; import { getCurrentChainId, deprecatedGetCurrentNetworkId } from './selectors'; import { checkNetworkAndAccountSupports1559 } from '.'; diff --git a/ui/selectors/custom-gas.js b/ui/selectors/custom-gas.js index b2ac4b8b4..1a0b276ca 100644 --- a/ui/selectors/custom-gas.js +++ b/ui/selectors/custom-gas.js @@ -2,9 +2,9 @@ import { addHexPrefix } from '../../app/scripts/lib/util'; import { conversionUtil, conversionGreaterThan, + decEthToConvertedCurrency, } from '../../shared/modules/conversion.utils'; import { formatCurrency } from '../helpers/utils/confirm-tx.util'; -import { decEthToConvertedCurrency as ethTotalToConvertedCurrency } from '../helpers/utils/conversions.util'; import { formatETHFee } from '../helpers/utils/formatters'; import { getGasPrice } from '../ducks/send'; @@ -193,7 +193,7 @@ export function getRenderableConvertedCurrencyFee( toNumericBase: 'hex', }); const fee = basicPriceEstimateToETHTotal(value, gasLimit); - const feeInCurrency = ethTotalToConvertedCurrency( + const feeInCurrency = decEthToConvertedCurrency( fee, convertedCurrency, conversionRate, diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 1d6df6047..ec0a3d226 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -49,7 +49,6 @@ import { getAccountByAddress, getURLHostName, } from '../helpers/utils/util'; -import { getValueFromWeiHex } from '../helpers/utils/conversions.util'; import { TEMPLATED_CONFIRMATION_MESSAGE_TYPES } from '../pages/confirmation/templates'; import { STATIC_MAINNET_TOKEN_LIST } from '../../shared/constants/tokens'; @@ -69,9 +68,12 @@ import { getLedgerTransportStatus, } from '../ducks/app/app'; import { isEqualCaseInsensitive } from '../../shared/modules/string-utils'; -import { hexToDecimal } from '../../shared/lib/metamask-controller-utils'; import { formatMoonpaySymbol } from '../helpers/utils/moonpay'; import { TransactionStatus } from '../../shared/constants/transaction'; +import { + getValueFromWeiHex, + hexToDecimal, +} from '../../shared/modules/conversion.utils'; ///: BEGIN:ONLY_INCLUDE_IN(flask) import { SNAPS_VIEW_ROUTE } from '../helpers/constants/routes'; import { getPermissionSubjects } from './permissions'; diff --git a/ui/selectors/transactions.js b/ui/selectors/transactions.js index d4cdddf0c..684541327 100644 --- a/ui/selectors/transactions.js +++ b/ui/selectors/transactions.js @@ -10,7 +10,7 @@ import { SmartTransactionStatus, } from '../../shared/constants/transaction'; import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils'; -import { hexToDecimal } from '../../shared/lib/metamask-controller-utils'; +import { hexToDecimal } from '../../shared/modules/conversion.utils'; import { getCurrentChainId, deprecatedGetCurrentNetworkId, diff --git a/ui/store/actions.js b/ui/store/actions.js index 1f039b3e2..97efb5605 100644 --- a/ui/store/actions.js +++ b/ui/store/actions.js @@ -41,11 +41,11 @@ import { isEqualCaseInsensitive } from '../../shared/modules/string-utils'; import { NOTIFICATIONS_EXPIRATION_DELAY } from '../helpers/constants/notifications'; ///: END:ONLY_INCLUDE_IN import { setNewCustomNetworkAdded } from '../ducks/app/app'; -import { decimalToHex } from '../../shared/lib/transactions-controller-utils'; import { fetchLocale, loadRelativeTimeFormatLocaleData, } from '../helpers/utils/i18n-helper'; +import { decimalToHex } from '../../shared/modules/conversion.utils'; import * as actionConstants from './actionConstants'; import { generateActionId,