1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Relocate conversion utils to shared/modules/conversion.utils.js (#17319)

This commit is contained in:
Brad Decker 2023-01-20 11:04:37 -06:00 committed by GitHub
parent 24551b7e9c
commit 92f6ea6f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 328 additions and 473 deletions

View File

@ -9,9 +9,9 @@ import {
TokensController, TokensController,
AssetsContractController, AssetsContractController,
} from '@metamask/assets-controllers'; } from '@metamask/assets-controllers';
import { convertHexToDecimal } from '@metamask/controller-utils';
import { NETWORK_TYPES } from '../../../shared/constants/network'; import { NETWORK_TYPES } from '../../../shared/constants/network';
import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils'; import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils';
import { hexToDecimal } from '../../../shared/lib/metamask-controller-utils';
import DetectTokensController from './detect-tokens'; import DetectTokensController from './detect-tokens';
import NetworkController, { NETWORK_EVENTS } from './network'; import NetworkController, { NETWORK_EVENTS } from './network';
import PreferencesController from './preferences'; import PreferencesController from './preferences';
@ -88,7 +88,7 @@ describe('DetectTokensController', function () {
...networkState, ...networkState,
providerConfig: { providerConfig: {
...networkState.provider, ...networkState.provider,
chainId: hexToDecimal(networkState.provider.chainId), chainId: convertHexToDecimal(networkState.provider.chainId),
}, },
}; };
return cb(modifiedNetworkState); return cb(modifiedNetworkState);

View File

@ -2,7 +2,7 @@ import { ObservableStore } from '@metamask/obs-store';
import log from 'loglevel'; import log from 'loglevel';
import BN from 'bn.js'; import BN from 'bn.js';
import createId from '../../../shared/modules/random-id'; 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 getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
import { import {
@ -14,6 +14,7 @@ import {
CHAIN_ID_TO_NETWORK_ID_MAP, CHAIN_ID_TO_NETWORK_ID_MAP,
CHAIN_ID_TO_TYPE_MAP, CHAIN_ID_TO_TYPE_MAP,
} from '../../../shared/constants/network'; } from '../../../shared/constants/network';
import { bnToHex } from '../../../shared/modules/conversion.utils';
const fetchWithTimeout = getFetchWithTimeout(); const fetchWithTimeout = getFetchWithTimeout();

View File

@ -8,6 +8,7 @@ import {
conversionUtil, conversionUtil,
decGWEIToHexWEI, decGWEIToHexWEI,
addCurrencies, addCurrencies,
sumHexes,
} from '../../../shared/modules/conversion.utils'; } from '../../../shared/modules/conversion.utils';
import { import {
DEFAULT_ERC20_APPROVE_GAS, DEFAULT_ERC20_APPROVE_GAS,
@ -25,7 +26,6 @@ import {
} from '../../../shared/constants/smartTransactions'; } from '../../../shared/constants/smartTransactions';
import { isSwapsDefaultTokenAddress } from '../../../shared/modules/swaps.utils'; import { isSwapsDefaultTokenAddress } from '../../../shared/modules/swaps.utils';
import { sumHexes } from '../../../ui/helpers/utils/transactions.util';
import { import {
fetchTradesInfo as defaultFetchTradesInfo, fetchTradesInfo as defaultFetchTradesInfo,

View File

@ -12,7 +12,6 @@ import { merge, pickBy } from 'lodash';
import cleanErrorStack from '../../lib/cleanErrorStack'; import cleanErrorStack from '../../lib/cleanErrorStack';
import { import {
hexToBn, hexToBn,
bnToHex,
BnMultiplyByFraction, BnMultiplyByFraction,
addHexPrefix, addHexPrefix,
getChainType, getChainType,
@ -33,7 +32,13 @@ import {
CUSTOM_GAS_ESTIMATE, CUSTOM_GAS_ESTIMATE,
PRIORITY_LEVELS, PRIORITY_LEVELS,
} from '../../../../shared/constants/gas'; } 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 { isSwapsDefaultTokenAddress } from '../../../../shared/modules/swaps.utils';
import { EVENT } from '../../../../shared/constants/metametrics'; import { EVENT } from '../../../../shared/constants/metametrics';
import { import {
@ -50,10 +55,7 @@ import {
import { ORIGIN_METAMASK } from '../../../../shared/constants/app'; import { ORIGIN_METAMASK } from '../../../../shared/constants/app';
import { import {
calcGasTotal, calcGasTotal,
decimalToHex,
getSwapsTokensReceivedFromTxMeta, getSwapsTokensReceivedFromTxMeta,
hexWEIToDecETH,
hexWEIToDecGWEI,
TRANSACTION_ENVELOPE_TYPE_NAMES, TRANSACTION_ENVELOPE_TYPE_NAMES,
} from '../../../../shared/lib/transactions-controller-utils'; } from '../../../../shared/lib/transactions-controller-utils';
import TransactionStateManager from './tx-state-manager'; import TransactionStateManager from './tx-state-manager';

View File

@ -2,7 +2,8 @@ import EthQuery from 'ethjs-query';
import log from 'loglevel'; import log from 'loglevel';
import { addHexPrefix } from 'ethereumjs-util'; import { addHexPrefix } from 'ethereumjs-util';
import { cloneDeep } from 'lodash'; 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 * Result of gas analysis, including either a gas estimate for a successful analysis, or

View File

@ -1,7 +1,8 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { TransactionFactory } from '@ethereumjs/tx'; import { TransactionFactory } from '@ethereumjs/tx';
import Common from '@ethereumjs/common'; 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'; import TxUtils from './tx-gas-utils';
describe('txUtils', function () { describe('txUtils', function () {

View File

@ -135,16 +135,6 @@ const addHexPrefix = (str) => {
return `0x${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) { function getChainType(chainId) {
if (chainId === CHAIN_IDS.MAINNET) { if (chainId === CHAIN_IDS.MAINNET) {
return 'mainnet'; return 'mainnet';
@ -172,7 +162,6 @@ export {
BnMultiplyByFraction, BnMultiplyByFraction,
checkForError, checkForError,
addHexPrefix, addHexPrefix,
bnToHex,
getChainType, getChainType,
checkAlarmExists, checkAlarmExists,
}; };

View File

@ -102,11 +102,9 @@ import { getTokenIdParam } from '../../shared/lib/token-util';
import { isEqualCaseInsensitive } from '../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../shared/modules/string-utils';
import { parseStandardTokenTransactionData } from '../../shared/modules/transaction.utils'; import { parseStandardTokenTransactionData } from '../../shared/modules/transaction.utils';
import { STATIC_MAINNET_TOKEN_LIST } from '../../shared/constants/tokens'; import { STATIC_MAINNET_TOKEN_LIST } from '../../shared/constants/tokens';
import { import { getTokenValueParam } from '../../shared/lib/metamask-controller-utils';
getTokenValueParam,
hexToDecimal,
} from '../../shared/lib/metamask-controller-utils';
import { isManifestV3 } from '../../shared/modules/mv3.utils'; import { isManifestV3 } from '../../shared/modules/mv3.utils';
import { hexToDecimal } from '../../shared/modules/conversion.utils';
import { import {
onMessageReceived, onMessageReceived,
checkForMultipleVersionsRunning, checkForMultipleVersionsRunning,

View File

@ -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 = {}) { export function getTokenValueParam(tokenData = {}) {
return tokenData?.args?._value?.toString(); return tokenData?.args?._value?.toString();
} }

View File

@ -14,8 +14,8 @@ import { SECOND } from '../constants/time';
import { isValidHexAddress } from '../modules/hexstring-utils'; import { isValidHexAddress } from '../modules/hexstring-utils';
import { isEqualCaseInsensitive } from '../modules/string-utils'; import { isEqualCaseInsensitive } from '../modules/string-utils';
import { addHexPrefix } from '../../app/scripts/lib/util'; import { addHexPrefix } from '../../app/scripts/lib/util';
import { decimalToHex } from '../modules/conversion.utils';
import fetchWithCache from './fetch-with-cache'; import fetchWithCache from './fetch-with-cache';
import { decimalToHex } from './transactions-controller-utils';
const TEST_CHAIN_IDS = [CHAIN_IDS.GOERLI, CHAIN_IDS.LOCALHOST]; const TEST_CHAIN_IDS = [CHAIN_IDS.GOERLI, CHAIN_IDS.LOCALHOST];

View File

@ -1,7 +1,6 @@
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import { TransactionEnvelopeType } from '../constants/transaction'; import { TransactionEnvelopeType } from '../constants/transaction';
import { import {
conversionUtil,
multiplyCurrencies, multiplyCurrencies,
subtractCurrencies, subtractCurrencies,
} from '../modules/conversion.utils'; } from '../modules/conversion.utils';
@ -145,28 +144,3 @@ export const TRANSACTION_ENVELOPE_TYPE_NAMES = {
FEE_MARKET: 'fee-market', FEE_MARKET: 'fee-market',
LEGACY: 'legacy', 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',
});
}

View File

@ -24,7 +24,8 @@
import BigNumber from 'bignumber.js'; 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'; 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 { export {
conversionUtil, conversionUtil,
addCurrencies, addCurrencies,

View File

@ -1,8 +1,12 @@
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import { ETH } from '../../ui/helpers/constants/common';
import { import {
addCurrencies, addCurrencies,
conversionUtil, conversionUtil,
decWEIToDecETH,
divideCurrencies, divideCurrencies,
getValueFromWeiHex,
getWeiHexFromDecimalValue,
} from './conversion.utils'; } from './conversion.utils';
describe('conversion utils', () => { describe('conversion utils', () => {
@ -202,4 +206,51 @@ describe('conversion utils', () => {
}).toThrow('Must specify valid dividendBase and divisorBase'); }).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');
});
});
}); });

View File

@ -8,7 +8,6 @@ import {
} from '../../../../../../shared/constants/gas'; } from '../../../../../../shared/constants/gas';
import { PRIMARY } from '../../../../../helpers/constants/common'; import { PRIMARY } from '../../../../../helpers/constants/common';
import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util'; import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util';
import { decGWEIToHexWEI } from '../../../../../helpers/utils/conversions.util';
import { getAdvancedGasFeeValues } from '../../../../../selectors'; import { getAdvancedGasFeeValues } from '../../../../../selectors';
import { useGasFeeContext } from '../../../../../contexts/gasFee'; import { useGasFeeContext } from '../../../../../contexts/gasFee';
import { useI18nContext } from '../../../../../hooks/useI18nContext'; import { useI18nContext } from '../../../../../hooks/useI18nContext';
@ -19,6 +18,7 @@ import FormField from '../../../../ui/form-field';
import { useAdvancedGasFeePopoverContext } from '../../context'; import { useAdvancedGasFeePopoverContext } from '../../context';
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext'; import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
import { decGWEIToHexWEI } from '../../../../../../shared/modules/conversion.utils';
const validateBaseFee = (value, gasFeeEstimates, maxPriorityFeePerGas) => { const validateBaseFee = (value, gasFeeEstimates, maxPriorityFeePerGas) => {
if (bnGreaterThan(maxPriorityFeePerGas, value)) { if (bnGreaterThan(maxPriorityFeePerGas, value)) {

View File

@ -7,7 +7,6 @@ import {
PRIORITY_LEVELS, PRIORITY_LEVELS,
} from '../../../../../../shared/constants/gas'; } from '../../../../../../shared/constants/gas';
import { PRIMARY } from '../../../../../helpers/constants/common'; import { PRIMARY } from '../../../../../helpers/constants/common';
import { decGWEIToHexWEI } from '../../../../../helpers/utils/conversions.util';
import { getAdvancedGasFeeValues } from '../../../../../selectors'; import { getAdvancedGasFeeValues } from '../../../../../selectors';
import { useCurrencyDisplay } from '../../../../../hooks/useCurrencyDisplay'; import { useCurrencyDisplay } from '../../../../../hooks/useCurrencyDisplay';
import { useGasFeeContext } from '../../../../../contexts/gasFee'; import { useGasFeeContext } from '../../../../../contexts/gasFee';
@ -19,6 +18,7 @@ import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util';
import { useAdvancedGasFeePopoverContext } from '../../context'; import { useAdvancedGasFeePopoverContext } from '../../context';
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext'; import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
import { decGWEIToHexWEI } from '../../../../../../shared/modules/conversion.utils';
const validatePriorityFee = (value, gasFeeEstimates) => { const validatePriorityFee = (value, gasFeeEstimates) => {
if (value < 0) { if (value < 0) {

View File

@ -1,11 +1,11 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util';
import { getNetworkSupportsSettingGasFees } from '../../../selectors/selectors'; import { getNetworkSupportsSettingGasFees } from '../../../selectors/selectors';
import { MIN_GAS_LIMIT_DEC } from '../../../pages/send/send.constants'; import { MIN_GAS_LIMIT_DEC } from '../../../pages/send/send.constants';
import { import {
decGWEIToHexWEI,
decimalToHex, decimalToHex,
hexWEIToDecGWEI, hexWEIToDecGWEI,
} from '../../../../shared/lib/transactions-controller-utils'; } from '../../../../shared/modules/conversion.utils';
import AdvancedGasInputs from './advanced-gas-inputs.component'; import AdvancedGasInputs from './advanced-gas-inputs.component';
function convertGasPriceForInputs(gasPriceInHexWEI) { function convertGasPriceForInputs(gasPriceInHexWEI) {

View File

@ -11,9 +11,11 @@ import mockEstimates from '../../../../test/data/mock-estimates.json';
import mockState from '../../../../test/data/mock-state.json'; import mockState from '../../../../test/data/mock-state.json';
import { GasFeeContextProvider } from '../../../contexts/gasFee'; import { GasFeeContextProvider } from '../../../contexts/gasFee';
import configureStore from '../../../store/store'; import configureStore from '../../../store/store';
import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util';
import InfoTooltip from '../../ui/info-tooltip'; 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'; import CancelSpeedupPopover from './cancel-speedup-popover';
const MAXFEEPERGAS_ABOVE_MOCK_MEDIUM_HEX = '0x174876e800'; const MAXFEEPERGAS_ABOVE_MOCK_MEDIUM_HEX = '0x174876e800';

View File

@ -9,7 +9,7 @@ import { transactionMatchesNetwork } from '../../../../../shared/modules/transac
import { I18nContext } from '../../../../contexts/i18n'; import { I18nContext } from '../../../../contexts/i18n';
import { CONFIRM_TRANSACTION_ROUTE } from '../../../../helpers/constants/routes'; import { CONFIRM_TRANSACTION_ROUTE } from '../../../../helpers/constants/routes';
import { clearConfirmTransaction } from '../../../../ducks/confirm-transaction/confirm-transaction.duck'; 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 ConfirmPageContainerNavigation = () => {
const t = useContext(I18nContext); const t = useContext(I18nContext);

View File

@ -3,10 +3,6 @@ import PropTypes from 'prop-types';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import UnitInput from '../../ui/unit-input'; import UnitInput from '../../ui/unit-input';
import CurrencyDisplay from '../../ui/currency-display'; import CurrencyDisplay from '../../ui/currency-display';
import {
getValueFromWeiHex,
getWeiHexFromDecimalValue,
} from '../../../helpers/utils/conversions.util';
import { ETH } from '../../../helpers/constants/common'; import { ETH } from '../../../helpers/constants/common';
import { I18nContext } from '../../../contexts/i18n'; import { I18nContext } from '../../../contexts/i18n';
import { import {
@ -14,6 +10,10 @@ import {
getNativeCurrency, getNativeCurrency,
} from '../../../ducks/metamask/metamask'; } from '../../../ducks/metamask/metamask';
import { getCurrentCurrency, getShouldShowFiat } from '../../../selectors'; 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 * Component that allows user to enter currency values as a number, and props receive a converted

View File

@ -6,7 +6,6 @@ import {
PRIORITY_LEVELS, PRIORITY_LEVELS,
} from '../../../../../shared/constants/gas'; } from '../../../../../shared/constants/gas';
import { getMaximumGasTotalInHexWei } from '../../../../../shared/modules/gas.utils'; import { getMaximumGasTotalInHexWei } from '../../../../../shared/modules/gas.utils';
import { decGWEIToHexWEI } from '../../../../helpers/utils/conversions.util';
import { import {
addTenPercentAndRound, addTenPercentAndRound,
gasEstimateGreaterThanGasUsedPlusTenPercent, gasEstimateGreaterThanGasUsedPlusTenPercent,
@ -14,9 +13,10 @@ import {
import { getAdvancedGasFeeValues } from '../../../../selectors'; import { getAdvancedGasFeeValues } from '../../../../selectors';
import { useGasFeeContext } from '../../../../contexts/gasFee'; import { useGasFeeContext } from '../../../../contexts/gasFee';
import { import {
decGWEIToHexWEI,
decimalToHex, decimalToHex,
hexWEIToDecGWEI, hexWEIToDecGWEI,
} from '../../../../../shared/lib/transactions-controller-utils'; } from '../../../../../shared/modules/conversion.utils';
import { useCustomTimeEstimate } from './useCustomTimeEstimate'; import { useCustomTimeEstimate } from './useCustomTimeEstimate';
export const useGasItemFeeDetails = (priorityLevel) => { export const useGasItemFeeDetails = (priorityLevel) => {

View File

@ -10,8 +10,6 @@ import {
GAS_RECOMMENDATIONS, GAS_RECOMMENDATIONS,
} from '../../../../shared/constants/gas'; } from '../../../../shared/constants/gas';
import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util';
import Popover from '../../ui/popover'; import Popover from '../../ui/popover';
import Button from '../../ui/button'; import Button from '../../ui/button';
import EditGasDisplay from '../edit-gas-display'; import EditGasDisplay from '../edit-gas-display';
@ -27,8 +25,11 @@ import {
} from '../../../store/actions'; } from '../../../store/actions';
import LoadingHeartBeat from '../../ui/loading-heartbeat'; import LoadingHeartBeat from '../../ui/loading-heartbeat';
import { useIncrementedGasFees } from '../../../hooks/useIncrementedGasFees'; import { useIncrementedGasFees } from '../../../hooks/useIncrementedGasFees';
import { hexToDecimal } from '../../../../shared/lib/metamask-controller-utils'; import {
import { decimalToHex } from '../../../../shared/lib/transactions-controller-utils'; decGWEIToHexWEI,
decimalToHex,
hexToDecimal,
} from '../../../../shared/modules/conversion.utils';
export default function EditGasPopover({ export default function EditGasPopover({
popoverTitle = '', popoverTitle = '',

View File

@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { decGWEIToHexWEI } from '../../../helpers/utils/conversions.util';
import configureStore from '../../../store/store'; import configureStore from '../../../store/store';
import testData from '../../../../.storybook/test-data'; import testData from '../../../../.storybook/test-data';
import { import {
@ -8,6 +7,7 @@ import {
GAS_RECOMMENDATIONS, GAS_RECOMMENDATIONS,
} from '../../../../shared/constants/gas'; } from '../../../../shared/constants/gas';
import { decGWEIToHexWEI } from '../../../../shared/modules/conversion.utils';
import EditGasPopover from '.'; import EditGasPopover from '.';
const store = configureStore(testData); const store = configureStore(testData);

View File

@ -6,8 +6,8 @@ import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display
import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee'; import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee';
import { SECONDARY } from '../../../helpers/constants/common'; import { SECONDARY } from '../../../helpers/constants/common';
import { I18nContext } from '../../../contexts/i18n'; import { I18nContext } from '../../../contexts/i18n';
import { sumHexes } from '../../../helpers/utils/transactions.util';
import { import {
sumHexes,
toBigNumber, toBigNumber,
toNormalizedDenomination, toNormalizedDenomination,
} from '../../../../shared/modules/conversion.utils'; } from '../../../../shared/modules/conversion.utils';

View File

@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import { getBlockExplorerLink } from '@metamask/etherscan-link'; import { getBlockExplorerLink } from '@metamask/etherscan-link';
import { getValueFromWeiHex } from '../../../helpers/utils/conversions.util';
import { formatDate, getURLHostName } from '../../../helpers/utils/util'; import { formatDate, getURLHostName } from '../../../helpers/utils/util';
import { EVENT } from '../../../../shared/constants/metametrics'; import { EVENT } from '../../../../shared/constants/metametrics';
import { getValueFromWeiHex } from '../../../../shared/modules/conversion.utils';
import TransactionActivityLogIcon from './transaction-activity-log-icon'; import TransactionActivityLogIcon from './transaction-activity-log-icon';
import { CONFIRMED_STATUS } from './transaction-activity-log.constants'; import { CONFIRMED_STATUS } from './transaction-activity-log.constants';

View File

@ -1,6 +1,6 @@
import { TransactionType } from '../../../../shared/constants/transaction'; import { TransactionType } from '../../../../shared/constants/transaction';
import { sumHexes } from '../../../../shared/modules/conversion.utils';
import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util'; import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util';
import { sumHexes } from '../../../helpers/utils/transactions.util';
import { import {
// event constants // event constants

View File

@ -5,10 +5,12 @@ import {
} from '../../../selectors'; } from '../../../selectors';
import { getNativeCurrency } from '../../../ducks/metamask/metamask'; import { getNativeCurrency } from '../../../ducks/metamask/metamask';
import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util'; 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 { isEIP1559Transaction } from '../../../../shared/modules/transaction.utils';
import {
subtractHexes,
sumHexes,
} from '../../../../shared/modules/conversion.utils';
import TransactionBreakdown from './transaction-breakdown.component'; import TransactionBreakdown from './transaction-breakdown.component';
const mapStateToProps = (state, ownProps) => { const mapStateToProps = (state, ownProps) => {

View File

@ -10,7 +10,7 @@ import fetchWithCache from '../../../../shared/lib/fetch-with-cache';
import { getSelectedAccount, getCurrentChainId } from '../../../selectors'; import { getSelectedAccount, getCurrentChainId } from '../../../selectors';
import { I18nContext } from '../../../contexts/i18n'; import { I18nContext } from '../../../contexts/i18n';
import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; 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 { transformTxDecoding } from './transaction-decoding.util';
import { import {
FETCH_PROJECT_INFO_URI, FETCH_PROJECT_INFO_URI,

View File

@ -1,6 +1,6 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; 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 { export default class HexToDecimal extends PureComponent {
static propTypes = { static propTypes = {

View File

@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import UnitInput from '../unit-input'; import UnitInput from '../unit-input';
import CurrencyDisplay from '../currency-display'; import CurrencyDisplay from '../currency-display';
import { getWeiHexFromDecimalValue } from '../../../helpers/utils/conversions.util';
import { import {
conversionUtil, conversionUtil,
getWeiHexFromDecimalValue,
multiplyCurrencies, multiplyCurrencies,
} from '../../../../shared/modules/conversion.utils'; } from '../../../../shared/modules/conversion.utils';

View File

@ -6,16 +6,17 @@ import {
import { getNativeCurrency, getTokens } from '../metamask/metamask'; import { getNativeCurrency, getTokens } from '../metamask/metamask';
import { import {
getValueFromWeiHex,
getTransactionFee, getTransactionFee,
getHexGasTotal, getHexGasTotal,
addFiat, addFiat,
addEth, addEth,
} from '../../helpers/utils/confirm-tx.util'; } from '../../helpers/utils/confirm-tx.util';
import { sumHexes } from '../../helpers/utils/transactions.util'; import {
conversionUtil,
import { conversionUtil } from '../../../shared/modules/conversion.utils'; getValueFromWeiHex,
sumHexes,
} from '../../../shared/modules/conversion.utils';
import { getAveragePriceEstimateInHexWEI } from '../../selectors/custom-gas'; import { getAveragePriceEstimateInHexWEI } from '../../selectors/custom-gas';
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils'; import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils';

View File

@ -13,11 +13,11 @@ import {
} from '../../selectors'; } from '../../selectors';
import { updateTransactionGasFees } from '../../store/actions'; import { updateTransactionGasFees } from '../../store/actions';
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck'; import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util';
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
import { stripHexPrefix } from '../../../shared/modules/hexstring-utils'; import { stripHexPrefix } from '../../../shared/modules/hexstring-utils';
import { decGWEIToHexWEI } from '../../../shared/modules/conversion.utils';
export default function reduceMetamask(state = {}, action) { export default function reduceMetamask(state = {}, action) {
const metamaskState = { const metamaskState = {

View File

@ -6,8 +6,10 @@ import { v4 as uuidv4 } from 'uuid';
import { import {
conversionGreaterThan, conversionGreaterThan,
conversionUtil, conversionUtil,
getValueFromWeiHex,
multiplyCurrencies, multiplyCurrencies,
subtractCurrencies, subtractCurrencies,
sumHexes,
} from '../../../shared/modules/conversion.utils'; } from '../../../shared/modules/conversion.utils';
import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas'; import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas';
import { import {
@ -89,10 +91,7 @@ import {
isValidHexAddress, isValidHexAddress,
toChecksumHexAddress, toChecksumHexAddress,
} from '../../../shared/modules/hexstring-utils'; } from '../../../shared/modules/hexstring-utils';
import { import { isSmartContractAddress } from '../../helpers/utils/transactions.util';
isSmartContractAddress,
sumHexes,
} from '../../helpers/utils/transactions.util';
import fetchEstimatedL1Fee from '../../helpers/utils/optimism/fetchEstimatedL1Fee'; import fetchEstimatedL1Fee from '../../helpers/utils/optimism/fetchEstimatedL1Fee';
import { ETH } from '../../helpers/constants/common'; import { ETH } from '../../helpers/constants/common';
@ -104,7 +103,6 @@ import {
} from '../../../shared/constants/transaction'; } from '../../../shared/constants/transaction';
import { INVALID_ASSET_TYPE } from '../../helpers/constants/error-keys'; import { INVALID_ASSET_TYPE } from '../../helpers/constants/error-keys';
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
import { getValueFromWeiHex } from '../../helpers/utils/confirm-tx.util';
import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils'; import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils';
import { getTokenValueParam } from '../../../shared/lib/metamask-controller-utils'; import { getTokenValueParam } from '../../../shared/lib/metamask-controller-utils';
import { import {

View File

@ -52,11 +52,13 @@ import {
stxErrorTypes, stxErrorTypes,
} from '../../pages/swaps/swaps.util'; } from '../../pages/swaps/swaps.util';
import { import {
getValueFromWeiHex,
decGWEIToHexWEI,
addHexes, addHexes,
} from '../../helpers/utils/conversions.util'; conversionLessThan,
import { conversionLessThan } from '../../../shared/modules/conversion.utils'; decGWEIToHexWEI,
decimalToHex,
getValueFromWeiHex,
hexWEIToDecGWEI,
} from '../../../shared/modules/conversion.utils';
import { import {
getSelectedAccount, getSelectedAccount,
getTokenExchangeRates, getTokenExchangeRates,
@ -88,8 +90,6 @@ import { ORIGIN_METAMASK } from '../../../shared/constants/app';
import { import {
calcGasTotal, calcGasTotal,
calcTokenAmount, calcTokenAmount,
decimalToHex,
hexWEIToDecGWEI,
} from '../../../shared/lib/transactions-controller-utils'; } from '../../../shared/lib/transactions-controller-utils';
export const GAS_PRICES_LOADING_STATES = { export const GAS_PRICES_LOADING_STATES = {

View File

@ -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({ export function getTransactionFee({
value, value,
fromCurrency = 'ETH', fromCurrency = 'ETH',

View File

@ -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', () => { describe('getTransactionFee', () => {
it('should get the transaction fee in ETH', () => { it('should get the transaction fee in ETH', () => {
const ethTransactionFee = utils.getTransactionFee({ const ethTransactionFee = utils.getTransactionFee({

View File

@ -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);
}

View File

@ -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);
});
});
});

View File

@ -5,8 +5,10 @@ import {
GAS_RECOMMENDATIONS, GAS_RECOMMENDATIONS,
EDIT_GAS_MODES, EDIT_GAS_MODES,
} from '../../../shared/constants/gas'; } from '../../../shared/constants/gas';
import { multiplyCurrencies } from '../../../shared/modules/conversion.utils'; import {
import { hexWEIToDecGWEI } from '../../../shared/lib/transactions-controller-utils'; hexWEIToDecGWEI,
multiplyCurrencies,
} from '../../../shared/modules/conversion.utils';
import { import {
bnGreaterThan, bnGreaterThan,
isNullish, isNullish,

View File

@ -8,7 +8,6 @@ import {
TransactionStatus, TransactionStatus,
TransactionEnvelopeType, TransactionEnvelopeType,
} from '../../../shared/constants/transaction'; } from '../../../shared/constants/transaction';
import { addCurrencies } from '../../../shared/modules/conversion.utils';
import { readAddressAsContract } from '../../../shared/modules/contract-utils'; import { readAddressAsContract } from '../../../shared/modules/contract-utils';
import fetchWithCache from '../../../shared/lib/fetch-with-cache'; import fetchWithCache from '../../../shared/lib/fetch-with-cache';
@ -135,18 +134,6 @@ export async function isSmartContractAddress(address) {
return isContractAddress; 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) { export function isLegacyTransaction(txParams) {
return txParams?.type === TransactionEnvelopeType.legacy; return txParams?.type === TransactionEnvelopeType.legacy;
} }

View File

@ -11,12 +11,14 @@ import {
import { PRIMARY } from '../../helpers/constants/common'; import { PRIMARY } from '../../helpers/constants/common';
import { checkNetworkAndAccountSupports1559 } from '../../selectors'; import { checkNetworkAndAccountSupports1559 } from '../../selectors';
import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util';
import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util';
import { useCurrencyDisplay } from '../useCurrencyDisplay'; import { useCurrencyDisplay } from '../useCurrencyDisplay';
import { useUserPreferencedCurrency } from '../useUserPreferencedCurrency'; import { useUserPreferencedCurrency } from '../useUserPreferencedCurrency';
import { decimalToHex } from '../../../shared/lib/transactions-controller-utils'; import {
decGWEIToHexWEI,
decimalToHex,
} from '../../../shared/modules/conversion.utils';
/** /**
* @typedef {object} GasEstimatesReturnType * @typedef {object} GasEstimatesReturnType

View File

@ -3,8 +3,10 @@ import {
getMaximumGasTotalInHexWei, getMaximumGasTotalInHexWei,
getMinimumGasTotalInHexWei, getMinimumGasTotalInHexWei,
} from '../../../shared/modules/gas.utils'; } from '../../../shared/modules/gas.utils';
import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util'; import {
import { decimalToHex } from '../../../shared/lib/transactions-controller-utils'; decGWEIToHexWEI,
decimalToHex,
} from '../../../shared/modules/conversion.utils';
import { import {
FEE_MARKET_ESTIMATE_RETURN_VALUE, FEE_MARKET_ESTIMATE_RETURN_VALUE,
LEGACY_GAS_ESTIMATE_RETURN_VALUE, LEGACY_GAS_ESTIMATE_RETURN_VALUE,

View File

@ -4,12 +4,12 @@ import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas';
import { import {
conversionLessThan, conversionLessThan,
conversionGreaterThan, conversionGreaterThan,
addHexes,
} from '../../../shared/modules/conversion.utils'; } from '../../../shared/modules/conversion.utils';
import { import {
checkNetworkAndAccountSupports1559, checkNetworkAndAccountSupports1559,
getSelectedAccount, getSelectedAccount,
} from '../../selectors'; } from '../../selectors';
import { addHexes } from '../../helpers/utils/conversions.util';
import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util';
import { bnGreaterThan, bnLessThan } from '../../helpers/utils/util'; import { bnGreaterThan, bnLessThan } from '../../helpers/utils/util';
import { GAS_FORM_ERRORS } from '../../helpers/constants/gas'; import { GAS_FORM_ERRORS } from '../../helpers/constants/gas';

View File

@ -16,7 +16,7 @@ import { isLegacyTransaction } from '../../helpers/utils/transactions.util';
import { useGasFeeEstimates } from '../useGasFeeEstimates'; import { useGasFeeEstimates } from '../useGasFeeEstimates';
import { editGasModeIsSpeedUpOrCancel } from '../../helpers/utils/gas'; 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 { useGasFeeErrors } from './useGasFeeErrors';
import { useGasPriceInput } from './useGasPriceInput'; import { useGasPriceInput } from './useGasPriceInput';
import { useMaxFeePerGasInput } from './useMaxFeePerGasInput'; import { useMaxFeePerGasInput } from './useMaxFeePerGasInput';

View File

@ -7,7 +7,7 @@ import {
} from '../../../shared/constants/gas'; } from '../../../shared/constants/gas';
import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; 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'; import { feeParamsAreCustom } from './utils';
function getGasPriceEstimate(gasFeeEstimates, gasEstimateType, estimateToUse) { function getGasPriceEstimate(gasFeeEstimates, gasEstimateType, estimateToUse) {

View File

@ -4,7 +4,7 @@ import { useSelector } from 'react-redux';
import { checkNetworkAndAccountSupports1559 } from '../../selectors'; import { checkNetworkAndAccountSupports1559 } from '../../selectors';
import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; 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'; import { feeParamsAreCustom, getGasFeeEstimate } from './utils';
const getMaxFeePerGasFromTransaction = (transaction, gasFeeEstimates) => { const getMaxFeePerGasFromTransaction = (transaction, gasFeeEstimates) => {

View File

@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
import { checkNetworkAndAccountSupports1559 } from '../../selectors'; import { checkNetworkAndAccountSupports1559 } from '../../selectors';
import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; 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'; import { feeParamsAreCustom, getGasFeeEstimate } from './utils';
const getMaxPriorityFeePerGasFromTransaction = ( const getMaxPriorityFeePerGasFromTransaction = (

View File

@ -1,9 +1,11 @@
import { useCallback } from 'react'; import { useCallback } from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { decimalToHex } from '../../../shared/lib/transactions-controller-utils';
import { EDIT_GAS_MODES, PRIORITY_LEVELS } from '../../../shared/constants/gas'; 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 { import {
addTenPercentAndRound, addTenPercentAndRound,
editGasModeIsSpeedUpOrCancel, editGasModeIsSpeedUpOrCancel,

View File

@ -1,16 +1,16 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { import { formatCurrency } from '../helpers/utils/confirm-tx.util';
formatCurrency,
getValueFromWeiHex,
} from '../helpers/utils/confirm-tx.util';
import { getCurrentCurrency } from '../selectors'; import { getCurrentCurrency } from '../selectors';
import { import {
getConversionRate, getConversionRate,
getNativeCurrency, getNativeCurrency,
} from '../ducks/metamask/metamask'; } 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'; import { TEST_NETWORK_TICKER_MAP } from '../../shared/constants/network';
/** /**

View File

@ -1,9 +1,9 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { getCurrentCurrency, getShouldShowFiat } from '../selectors'; import { getCurrentCurrency, getShouldShowFiat } from '../selectors';
import { decEthToConvertedCurrency } from '../helpers/utils/conversions.util';
import { formatCurrency } from '../helpers/utils/confirm-tx.util'; import { formatCurrency } from '../helpers/utils/confirm-tx.util';
import { getConversionRate } from '../ducks/metamask/metamask'; import { getConversionRate } from '../ducks/metamask/metamask';
import { decEthToConvertedCurrency } from '../../shared/modules/conversion.utils';
/** /**
* Get an Eth amount converted to fiat and formatted for display * Get an Eth amount converted to fiat and formatted for display

View File

@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { decGWEIToHexWEI } from '../../shared/modules/conversion.utils';
import { isEIP1559Transaction } from '../../shared/modules/transaction.utils'; import { isEIP1559Transaction } from '../../shared/modules/transaction.utils';
import { decGWEIToHexWEI } from '../helpers/utils/conversions.util';
import { addTenPercent } from '../helpers/utils/gas'; import { addTenPercent } from '../helpers/utils/gas';
import { useGasFeeEstimates } from './useGasFeeEstimates'; import { useGasFeeEstimates } from './useGasFeeEstimates';

View File

@ -1,8 +1,8 @@
import { calcTokenValue } from '../../../shared/lib/swaps-utils'; import { calcTokenValue } from '../../../shared/lib/swaps-utils';
import { decimalToHex } from '../../../shared/lib/transactions-controller-utils';
import { TransactionType } from '../../../shared/constants/transaction'; import { TransactionType } from '../../../shared/constants/transaction';
import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils'; import { parseStandardTokenTransactionData } from '../../../shared/modules/transaction.utils';
import { getTokenAddressParam } from '../../helpers/utils/token-util'; import { getTokenAddressParam } from '../../helpers/utils/token-util';
import { decimalToHex } from '../../../shared/modules/conversion.utils';
export function getCustomTxParamsData( export function getCustomTxParamsData(
data, data,

View File

@ -12,7 +12,6 @@ import {
roundExponential, roundExponential,
} from '../../helpers/utils/confirm-tx.util'; } from '../../helpers/utils/confirm-tx.util';
import { ETH, PRIMARY } from '../../helpers/constants/common'; import { ETH, PRIMARY } from '../../helpers/constants/common';
import { getWeiHexFromDecimalValue } from '../../helpers/utils/conversions.util';
import { import {
contractExchangeRateSelector, contractExchangeRateSelector,
getCurrentCurrency, getCurrentCurrency,
@ -22,7 +21,10 @@ import {
getNativeCurrency, getNativeCurrency,
} from '../../ducks/metamask/metamask'; } from '../../ducks/metamask/metamask';
import { TokenStandard } from '../../../shared/constants/transaction'; 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({ export default function ConfirmTokenTransactionBase({
image = '', image = '',

View File

@ -6,7 +6,6 @@ import { stripHexPrefix } from 'ethereumjs-util';
import ConfirmPageContainer from '../../components/app/confirm-page-container'; import ConfirmPageContainer from '../../components/app/confirm-page-container';
import TransactionDecoding from '../../components/app/transaction-decoding'; import TransactionDecoding from '../../components/app/transaction-decoding';
import { isBalanceSufficient } from '../send/send.utils'; import { isBalanceSufficient } from '../send/send.utils';
import { addHexes } from '../../helpers/utils/conversions.util';
import { DEFAULT_ROUTE } from '../../helpers/constants/routes'; import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
import { import {
INSUFFICIENT_FUNDS_ERROR_KEY, INSUFFICIENT_FUNDS_ERROR_KEY,
@ -57,8 +56,6 @@ import {
import { MIN_GAS_LIMIT_DEC } from '../send/send.constants'; 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) ///: BEGIN:ONLY_INCLUDE_IN(flask)
import { SnapInsight } from '../../components/app/confirm-page-container/flask/snap-insight'; import { SnapInsight } from '../../components/app/confirm-page-container/flask/snap-insight';
import { DropdownTab, Tab } from '../../components/ui/tabs'; import { DropdownTab, Tab } from '../../components/ui/tabs';
@ -71,6 +68,11 @@ import {
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
} from '../../../shared/constants/network'; } from '../../../shared/constants/network';
import TransactionAlerts from '../../components/app/transaction-alerts'; import TransactionAlerts from '../../components/app/transaction-alerts';
import {
addHexes,
hexToDecimal,
hexWEIToDecGWEI,
} from '../../../shared/modules/conversion.utils';
const renderHeartBeatIfNotInTest = () => const renderHeartBeatIfNotInTest = () =>
process.env.IN_TEST ? null : <LoadingHeartBeat />; process.env.IN_TEST ? null : <LoadingHeartBeat />;

View File

@ -5,7 +5,6 @@ import classNames from 'classnames';
import { I18nContext } from '../../../contexts/i18n'; import { I18nContext } from '../../../contexts/i18n';
import { useGasFeeContext } from '../../../contexts/gasFee'; import { useGasFeeContext } from '../../../contexts/gasFee';
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; 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 UserPreferencedCurrencyDisplay from '../../../components/app/user-preferenced-currency-display';
import GasTiming from '../../../components/app/gas-timing'; import GasTiming from '../../../components/app/gas-timing';
import InfoTooltip from '../../../components/ui/info-tooltip'; import InfoTooltip from '../../../components/ui/info-tooltip';
@ -38,13 +37,14 @@ import {
getUseCurrencyRateCheck, getUseCurrencyRateCheck,
} from '../../../selectors'; } from '../../../selectors';
import {
hexWEIToDecETH,
addHexes,
} from '../../../helpers/utils/conversions.util';
import { INSUFFICIENT_TOKENS_ERROR } from '../send.constants'; import { INSUFFICIENT_TOKENS_ERROR } from '../send.constants';
import { getCurrentDraftTransaction } from '../../../ducks/send'; import { getCurrentDraftTransaction } from '../../../ducks/send';
import { showModal } from '../../../store/actions'; import { showModal } from '../../../store/actions';
import {
addHexes,
hexWEIToDecETH,
hexWEIToDecGWEI,
} from '../../../../shared/modules/conversion.utils';
export default function GasDisplay({ gasError }) { export default function GasDisplay({ gasError }) {
const t = useContext(I18nContext); const t = useContext(I18nContext);

View File

@ -14,7 +14,7 @@ import {
setCustomGasPrice, setCustomGasPrice,
setCustomGasLimit, setCustomGasLimit,
} from '../../../../ducks/gas/gas.duck'; } 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'; import SendGasRow from './send-gas-row.component';
export default connect(mapStateToProps, mapDispatchToProps)(SendGasRow); export default connect(mapStateToProps, mapDispatchToProps)(SendGasRow);

View File

@ -36,8 +36,8 @@ import {
infuraProjectId, infuraProjectId,
FEATURED_RPCS, FEATURED_RPCS,
} from '../../../../../shared/constants/network'; } from '../../../../../shared/constants/network';
import { decimalToHex } from '../../../../../shared/lib/transactions-controller-utils';
import { ORIGIN_METAMASK } from '../../../../../shared/constants/app'; 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 * Attempts to convert the given chainId to a decimal string, for display

View File

@ -72,7 +72,6 @@ import {
getUseCurrencyRateCheck, getUseCurrencyRateCheck,
} from '../../../selectors'; } from '../../../selectors';
import { getValueFromWeiHex } from '../../../helpers/utils/conversions.util';
import { getURLHostName } from '../../../helpers/utils/util'; import { getURLHostName } from '../../../helpers/utils/util';
import { usePrevious } from '../../../hooks/usePrevious'; import { usePrevious } from '../../../hooks/usePrevious';
import { useTokenTracker } from '../../../hooks/useTokenTracker'; import { useTokenTracker } from '../../../hooks/useTokenTracker';
@ -106,9 +105,12 @@ import {
} from '../swaps.util'; } from '../swaps.util';
import SwapsFooter from '../swaps-footer'; import SwapsFooter from '../swaps-footer';
import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils';
import { hexToDecimal } from '../../../../shared/lib/metamask-controller-utils';
import { calcTokenAmount } from '../../../../shared/lib/transactions-controller-utils'; import { calcTokenAmount } from '../../../../shared/lib/transactions-controller-utils';
import { shouldEnableDirectWrapping } from '../../../../shared/lib/swaps-utils'; import { shouldEnableDirectWrapping } from '../../../../shared/lib/swaps-utils';
import {
getValueFromWeiHex,
hexToDecimal,
} from '../../../../shared/modules/conversion.utils';
const fuseSearchKeys = [ const fuseSearchKeys = [
{ name: 'name', weight: 0.499 }, { name: 'name', weight: 0.499 },

View File

@ -19,7 +19,6 @@ import {
isSwapsDefaultTokenSymbol, isSwapsDefaultTokenSymbol,
} from '../../../shared/modules/swaps.utils'; } from '../../../shared/modules/swaps.utils';
import { CHAIN_IDS, CURRENCY_SYMBOLS } from '../../../shared/constants/network'; 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 { formatCurrency } from '../../helpers/utils/confirm-tx.util';
import fetchWithCache from '../../../shared/lib/fetch-with-cache'; import fetchWithCache from '../../../shared/lib/fetch-with-cache';
@ -27,7 +26,6 @@ import { isValidHexAddress } from '../../../shared/modules/hexstring-utils';
import { import {
calcGasTotal, calcGasTotal,
calcTokenAmount, calcTokenAmount,
decimalToHex,
toPrecisionWithoutTrailingZeros, toPrecisionWithoutTrailingZeros,
} from '../../../shared/lib/transactions-controller-utils'; } from '../../../shared/lib/transactions-controller-utils';
import { import {
@ -35,7 +33,11 @@ import {
truthyString, truthyString,
validateData, validateData,
} from '../../../shared/lib/swaps-utils'; } 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 CACHE_REFRESH_FIVE_MINUTES = 300000;
const USD_CURRENCY_CODE = 'usd'; const USD_CURRENCY_CODE = 'usd';

View File

@ -82,11 +82,6 @@ import {
SWAPS_ERROR_ROUTE, SWAPS_ERROR_ROUTE,
AWAITING_SWAP_ROUTE, AWAITING_SWAP_ROUTE,
} from '../../../helpers/constants/routes'; } from '../../../helpers/constants/routes';
import {
decGWEIToHexWEI,
addHexes,
decWEIToDecETH,
} from '../../../helpers/utils/conversions.util';
import MainQuoteSummary from '../main-quote-summary'; import MainQuoteSummary from '../main-quote-summary';
import { getCustomTxParamsData } from '../../confirm-approve/confirm-approve.util'; import { getCustomTxParamsData } from '../../confirm-approve/confirm-approve.util';
import ActionableMessage from '../../../components/ui/actionable-message/actionable-message'; import ActionableMessage from '../../../components/ui/actionable-message/actionable-message';
@ -109,14 +104,19 @@ import { getTokenValueParam } from '../../../../shared/lib/metamask-controller-u
import { import {
calcGasTotal, calcGasTotal,
calcTokenAmount, calcTokenAmount,
decimalToHex,
hexWEIToDecGWEI,
toPrecisionWithoutTrailingZeros, toPrecisionWithoutTrailingZeros,
} from '../../../../shared/lib/transactions-controller-utils'; } from '../../../../shared/lib/transactions-controller-utils';
import { addHexPrefix } from '../../../../app/scripts/lib/util'; import { addHexPrefix } from '../../../../app/scripts/lib/util';
import { calcTokenValue } from '../../../../shared/lib/swaps-utils'; import { calcTokenValue } from '../../../../shared/lib/swaps-utils';
import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee'; 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'; import ViewQuotePriceDifference from './view-quote-price-difference';
let intervalId; let intervalId;

View File

@ -2,12 +2,10 @@ import { createSelector } from 'reselect';
import txHelper from '../helpers/utils/tx-helper'; import txHelper from '../helpers/utils/tx-helper';
import { import {
roundExponential, roundExponential,
getValueFromWeiHex,
getTransactionFee, getTransactionFee,
addFiat, addFiat,
addEth, addEth,
} from '../helpers/utils/confirm-tx.util'; } from '../helpers/utils/confirm-tx.util';
import { sumHexes } from '../helpers/utils/transactions.util';
import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils'; import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils';
import { import {
getGasEstimateType, getGasEstimateType,
@ -15,7 +13,6 @@ import {
getNativeCurrency, getNativeCurrency,
} from '../ducks/metamask/metamask'; } from '../ducks/metamask/metamask';
import { TransactionEnvelopeType } from '../../shared/constants/transaction'; import { TransactionEnvelopeType } from '../../shared/constants/transaction';
import { decGWEIToHexWEI } from '../helpers/utils/conversions.util';
import { import {
GAS_ESTIMATE_TYPES, GAS_ESTIMATE_TYPES,
CUSTOM_GAS_ESTIMATE, CUSTOM_GAS_ESTIMATE,
@ -26,6 +23,11 @@ import {
} from '../../shared/modules/gas.utils'; } from '../../shared/modules/gas.utils';
import { isEqualCaseInsensitive } from '../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../shared/modules/string-utils';
import { calcTokenAmount } from '../../shared/lib/transactions-controller-utils'; import { calcTokenAmount } from '../../shared/lib/transactions-controller-utils';
import {
decGWEIToHexWEI,
getValueFromWeiHex,
sumHexes,
} from '../../shared/modules/conversion.utils';
import { getAveragePriceEstimateInHexWEI } from './custom-gas'; import { getAveragePriceEstimateInHexWEI } from './custom-gas';
import { getCurrentChainId, deprecatedGetCurrentNetworkId } from './selectors'; import { getCurrentChainId, deprecatedGetCurrentNetworkId } from './selectors';
import { checkNetworkAndAccountSupports1559 } from '.'; import { checkNetworkAndAccountSupports1559 } from '.';

View File

@ -2,9 +2,9 @@ import { addHexPrefix } from '../../app/scripts/lib/util';
import { import {
conversionUtil, conversionUtil,
conversionGreaterThan, conversionGreaterThan,
decEthToConvertedCurrency,
} from '../../shared/modules/conversion.utils'; } from '../../shared/modules/conversion.utils';
import { formatCurrency } from '../helpers/utils/confirm-tx.util'; import { formatCurrency } from '../helpers/utils/confirm-tx.util';
import { decEthToConvertedCurrency as ethTotalToConvertedCurrency } from '../helpers/utils/conversions.util';
import { formatETHFee } from '../helpers/utils/formatters'; import { formatETHFee } from '../helpers/utils/formatters';
import { getGasPrice } from '../ducks/send'; import { getGasPrice } from '../ducks/send';
@ -193,7 +193,7 @@ export function getRenderableConvertedCurrencyFee(
toNumericBase: 'hex', toNumericBase: 'hex',
}); });
const fee = basicPriceEstimateToETHTotal(value, gasLimit); const fee = basicPriceEstimateToETHTotal(value, gasLimit);
const feeInCurrency = ethTotalToConvertedCurrency( const feeInCurrency = decEthToConvertedCurrency(
fee, fee,
convertedCurrency, convertedCurrency,
conversionRate, conversionRate,

View File

@ -49,7 +49,6 @@ import {
getAccountByAddress, getAccountByAddress,
getURLHostName, getURLHostName,
} from '../helpers/utils/util'; } from '../helpers/utils/util';
import { getValueFromWeiHex } from '../helpers/utils/conversions.util';
import { TEMPLATED_CONFIRMATION_MESSAGE_TYPES } from '../pages/confirmation/templates'; import { TEMPLATED_CONFIRMATION_MESSAGE_TYPES } from '../pages/confirmation/templates';
import { STATIC_MAINNET_TOKEN_LIST } from '../../shared/constants/tokens'; import { STATIC_MAINNET_TOKEN_LIST } from '../../shared/constants/tokens';
@ -69,9 +68,12 @@ import {
getLedgerTransportStatus, getLedgerTransportStatus,
} from '../ducks/app/app'; } from '../ducks/app/app';
import { isEqualCaseInsensitive } from '../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../shared/modules/string-utils';
import { hexToDecimal } from '../../shared/lib/metamask-controller-utils';
import { formatMoonpaySymbol } from '../helpers/utils/moonpay'; import { formatMoonpaySymbol } from '../helpers/utils/moonpay';
import { TransactionStatus } from '../../shared/constants/transaction'; import { TransactionStatus } from '../../shared/constants/transaction';
import {
getValueFromWeiHex,
hexToDecimal,
} from '../../shared/modules/conversion.utils';
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
import { SNAPS_VIEW_ROUTE } from '../helpers/constants/routes'; import { SNAPS_VIEW_ROUTE } from '../helpers/constants/routes';
import { getPermissionSubjects } from './permissions'; import { getPermissionSubjects } from './permissions';

View File

@ -10,7 +10,7 @@ import {
SmartTransactionStatus, SmartTransactionStatus,
} from '../../shared/constants/transaction'; } from '../../shared/constants/transaction';
import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils'; import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils';
import { hexToDecimal } from '../../shared/lib/metamask-controller-utils'; import { hexToDecimal } from '../../shared/modules/conversion.utils';
import { import {
getCurrentChainId, getCurrentChainId,
deprecatedGetCurrentNetworkId, deprecatedGetCurrentNetworkId,

View File

@ -41,11 +41,11 @@ import { isEqualCaseInsensitive } from '../../shared/modules/string-utils';
import { NOTIFICATIONS_EXPIRATION_DELAY } from '../helpers/constants/notifications'; import { NOTIFICATIONS_EXPIRATION_DELAY } from '../helpers/constants/notifications';
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
import { setNewCustomNetworkAdded } from '../ducks/app/app'; import { setNewCustomNetworkAdded } from '../ducks/app/app';
import { decimalToHex } from '../../shared/lib/transactions-controller-utils';
import { import {
fetchLocale, fetchLocale,
loadRelativeTimeFormatLocaleData, loadRelativeTimeFormatLocaleData,
} from '../helpers/utils/i18n-helper'; } from '../helpers/utils/i18n-helper';
import { decimalToHex } from '../../shared/modules/conversion.utils';
import * as actionConstants from './actionConstants'; import * as actionConstants from './actionConstants';
import { import {
generateActionId, generateActionId,