1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +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,
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);

View File

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

View File

@ -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,

View File

@ -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';

View File

@ -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

View File

@ -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 () {

View File

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

View File

@ -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,

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

View File

@ -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];

View File

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

View File

@ -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,

View File

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

View File

@ -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)) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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';

View File

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

View File

@ -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

View File

@ -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) => {

View File

@ -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 = '',

View File

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

View File

@ -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';

View File

@ -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';

View File

@ -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

View File

@ -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) => {

View File

@ -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,

View File

@ -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 = {

View File

@ -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';

View File

@ -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';

View File

@ -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 = {

View File

@ -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 {

View File

@ -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 = {

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({
value,
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', () => {
it('should get the transaction fee in ETH', () => {
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,
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,

View File

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

View File

@ -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

View File

@ -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,

View File

@ -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';

View File

@ -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';

View File

@ -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) {

View File

@ -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) => {

View File

@ -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 = (

View File

@ -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,

View File

@ -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';
/**

View File

@ -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

View File

@ -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';

View File

@ -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,

View File

@ -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 = '',

View File

@ -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 : <LoadingHeartBeat />;

View File

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

View File

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

View File

@ -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

View File

@ -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 },

View File

@ -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';

View File

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

View File

@ -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 '.';

View File

@ -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,

View File

@ -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';

View File

@ -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,

View File

@ -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,