Skip to content

Commit

Permalink
move getCurrentCurrency from ui/selectors/selectors.js to `ui/duc…
Browse files Browse the repository at this point in the history
…ks/metamask/metamask.js`

I moved `getCurrentCurrency` into `ui/ducks/` instead of kept in `ui/selectors/` because `ui/ducks/metamask/metamask.js` already exports a `getNativeCurrency`, so it seems to fit in well there.
  • Loading branch information
davidmurdoch committed Oct 4, 2024
1 parent f4f7ba8 commit 1fbb2fa
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 42 deletions.
6 changes: 4 additions & 2 deletions ui/components/app/assets/nfts/nft-details/nft-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { shortenAddress } from '../../../../../helpers/utils/util';
import { getNftImageAlt } from '../../../../../helpers/utils/nfts';
import {
getCurrentChainId,
getCurrentCurrency,
getCurrentNetwork,
getIpfsGateway,
} from '../../../../../selectors';
Expand Down Expand Up @@ -67,7 +66,10 @@ import { Content, Footer, Page } from '../../../../multichain/pages/page';
import { formatCurrency } from '../../../../../helpers/utils/confirm-tx.util';
import { getShortDateFormatterV2 } from '../../../../../pages/asset/util';
import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../../../shared/constants/swaps';
import { getConversionRate } from '../../../../../ducks/metamask/metamask';
import {
getConversionRate,
getCurrentCurrency,
} from '../../../../../ducks/metamask/metamask';
import { Numeric } from '../../../../../../shared/modules/Numeric';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { Text } from '../../../component-library';
import UserPreferencedCurrencyDisplay from '../../../app/user-preferenced-currency-display';
import { PRIMARY } from '../../../../helpers/constants/common';
import { Asset } from '../../../../ducks/send';
import {
getCurrentCurrency,
getSelectedAccountCachedBalance,
} from '../../../../selectors';
import { getSelectedAccountCachedBalance } from '../../../../selectors';
import { AssetType } from '../../../../../shared/constants/transaction';
import {
TextColor,
Expand All @@ -21,6 +18,7 @@ import { getIsFiatPrimary } from '../utils';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { hexToDecimal } from '../../../../../shared/modules/conversion.utils';
import { TokenWithBalance } from '../asset-picker-modal/types';
import { getCurrentCurrency } from '../../../../ducks/metamask/metamask';

export type AssetBalanceTextProps = {
asset: Asset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import mockState from '../../../../../test/data/mock-send-state.json';
import { AssetType } from '../../../../../shared/constants/transaction';
import {
getCurrentChainId,
getCurrentCurrency,
getNativeCurrencyImage,
getPreferences,
getSelectedAccountCachedBalance,
Expand All @@ -25,6 +24,7 @@ import {
getConversionRate,
getNativeCurrency,
getTokens,
getCurrentCurrency,
} from '../../../../ducks/metamask/metamask';
import { getTopAssets } from '../../../../ducks/swaps/swaps';
import { getRenderableTokenData } from '../../../../hooks/useTokensToSearch';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { AssetType } from '../../../../../shared/constants/transaction';
import {
getAllTokens,
getCurrentChainId,
getCurrentCurrency,
getNativeCurrencyImage,
getSelectedAccountCachedBalance,
getSelectedInternalAccount,
Expand All @@ -42,6 +41,7 @@ import {
} from '../../../../selectors';
import {
getConversionRate,
getCurrentCurrency,
getNativeCurrency,
} from '../../../../ducks/metamask/metamask';
import { useTokenTracker } from '../../../../hooks/useTokenTracker';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
getNativeCurrency,
getConversionRate,
getGasFeeEstimates,
getCurrentCurrency,
} from '../../../../../../../ducks/metamask/metamask';
import { getUsedSwapsGasPrice } from '../../../../../../../ducks/swaps/swaps';
import {
getCurrentCurrency,
checkNetworkAndAccountSupports1559,
getCurrentChainId,
getIsSwapsChain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
getConversionRate,
getGasFeeEstimates,
getNativeCurrency,
getCurrentCurrency,
} from '../../../../../../../ducks/metamask/metamask';
import { EtherDenomination } from '../../../../../../../../shared/constants/common';
import {
getCurrentCurrency,
checkNetworkAndAccountSupports1559,
getIsSwapsChain,
} from '../../../../../../../selectors/selectors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import '@testing-library/jest-dom';
import { zeroAddress } from 'ethereumjs-util';
import { getIntlLocale } from '../../../../../ducks/locale/locale';
import {
getCurrentCurrency,
getSelectedAccountCachedBalance,
getTokensMarketData,
} from '../../../../../selectors';
import {
getConversionRate,
getCurrentCurrency,
getNativeCurrency,
} from '../../../../../ducks/metamask/metamask';
import { PercentageAndAmountChange } from './percentage-and-amount-change';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
TextVariant,
} from '../../../../../helpers/constants/design-system';
import {
getCurrentCurrency,
getSelectedAccountCachedBalance,
getTokensMarketData,
} from '../../../../../selectors';
Expand All @@ -19,6 +18,7 @@ import { EtherDenomination } from '../../../../../../shared/constants/common';
import { Numeric } from '../../../../../../shared/modules/Numeric';
import {
getConversionRate,
getCurrentCurrency,
getNativeCurrency,
} from '../../../../../ducks/metamask/metamask';
import {
Expand Down
4 changes: 4 additions & 0 deletions ui/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,7 @@ export function doesUserHaveALedgerAccount(state) {
return kr.type === KeyringType.ledger;
});
}

export function getCurrentCurrency(state) {
return state.metamask.currentCurrency;
}
8 changes: 8 additions & 0 deletions ui/ducks/metamask/metamask.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import reduceMetamask, {
getSendHexDataFeatureFlagState,
getSendToAccounts,
isNotEIP1559Network,
getCurrentCurrency,
} from './metamask';

jest.mock('@metamask/transaction-controller', () => ({
Expand Down Expand Up @@ -384,6 +385,13 @@ describe('MetaMask Reducers', () => {
});
});

describe('getCurrentCurrency', () => {
it('should return the `currentCurrency`', () => {
const currentCurrency = getCurrentCurrency(mockState);
expect(currentCurrency).toStrictEqual('usd');
});
});

describe('getSendHexDataFeatureFlagState()', () => {
it('should return the sendHexData feature flag state', () => {
expect(getSendHexDataFeatureFlagState(mockState)).toStrictEqual(true);
Expand Down
2 changes: 1 addition & 1 deletion ui/hooks/useFiatFormatter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook } from '@testing-library/react-hooks';
import { getIntlLocale } from '../ducks/locale/locale';
import { getCurrentCurrency } from '../selectors';
import { getCurrentCurrency } from '../ducks/metamask/metamask';
import { useFiatFormatter } from './useFiatFormatter';

jest.mock('react-redux', () => ({
Expand Down
2 changes: 1 addition & 1 deletion ui/hooks/useFiatFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSelector } from 'react-redux';
import { getIntlLocale } from '../ducks/locale/locale';
import { getCurrentCurrency } from '../selectors';
import { getCurrentCurrency } from '../ducks/metamask/metamask';
import { shortenString } from '../helpers/utils/util';

/**
Expand Down
6 changes: 4 additions & 2 deletions ui/pages/asset/components/asset-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { EthMethod } from '@metamask/keyring-api';
import { isEqual } from 'lodash';
import { CaipChainId, Hex } from '@metamask/utils';
import {
getCurrentCurrency,
getIsBridgeChain,
getIsSwapsChain,
getSelectedInternalAccount,
Expand Down Expand Up @@ -39,7 +38,10 @@ import TokenCell from '../../../components/app/assets/token-cell';
import TransactionList from '../../../components/app/transaction-list';
import { getPricePrecision, localizeLargeNumber } from '../util';
import { DEFAULT_ROUTE } from '../../../helpers/constants/routes';
import { getConversionRate } from '../../../ducks/metamask/metamask';
import {
getConversionRate,
getCurrentCurrency,
} from '../../../ducks/metamask/metamask';
import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils';
import CoinButtons from '../../../components/app/wallet-overview/coin-buttons';
import { getIsNativeTokenBuyable } from '../../../ducks/ramps';
Expand Down
6 changes: 4 additions & 2 deletions ui/pages/asset/components/native-asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { useSelector } from 'react-redux';
import { getAccountLink } from '@metamask/etherscan-link';
import {
getCurrentChainId,
getCurrentCurrency,
getNativeCurrencyImage,
getRpcPrefsForCurrentProvider,
getSelectedAccountCachedBalance,
getSelectedInternalAccount,
getShouldShowFiat,
} from '../../../selectors';
import { useCurrencyDisplay } from '../../../hooks/useCurrencyDisplay';
import { getNativeCurrency } from '../../../ducks/metamask/metamask';
import {
getCurrentCurrency,
getNativeCurrency,
} from '../../../ducks/metamask/metamask';
import { getProviderConfig } from '../../../selectors/networks';
import { AssetType } from '../../../../shared/constants/transaction';
import { useIsOriginalNativeTokenSymbol } from '../../../hooks/useIsOriginalNativeTokenSymbol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
getValueFromWeiHex,
multiplyHexes,
} from '../../../../../../../shared/modules/conversion.utils';
import { getConversionRate } from '../../../../../../ducks/metamask/metamask';
import {
getConversionRate,
getCurrentCurrency,
} from '../../../../../../ducks/metamask/metamask';
import { useFiatFormatter } from '../../../../../../hooks/useFiatFormatter';
import { useGasFeeEstimates } from '../../../../../../hooks/useGasFeeEstimates';
import { getCurrentCurrency } from '../../../../../../selectors';
import { HEX_ZERO } from '../shared/constants';
import { useEIP1559TxFees } from './useEIP1559TxFees';
import { useSupportsEIP1559 } from './useSupportsEIP1559';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import { BigNumber } from 'bignumber.js';
import { ContractExchangeRates } from '@metamask/assets-controllers';
import { useAsyncResultOrThrow } from '../../../../hooks/useAsyncResult';
import { TokenStandard } from '../../../../../shared/constants/transaction';
import { getConversionRate } from '../../../../ducks/metamask/metamask';
import { getCurrentChainId, getCurrentCurrency } from '../../../../selectors';
import {
getConversionRate,
getCurrentCurrency,
} from '../../../../ducks/metamask/metamask';
import { getCurrentChainId } from '../../../../selectors';
import { fetchTokenExchangeRates } from '../../../../helpers/utils/util';
import { ERC20_DEFAULT_DECIMALS, fetchErc20Decimals } from '../../utils/token';

Expand Down
7 changes: 5 additions & 2 deletions ui/pages/swaps/prepare-swap-page/review-quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
import {
conversionRateSelector,
getSelectedAccount,
getCurrentCurrency,
getTokenExchangeRates,
getSwapsDefaultToken,
getCurrentChainId,
Expand All @@ -65,7 +64,11 @@ import {
getSmartTransactionsOptInStatus,
getSmartTransactionsEnabled,
} from '../../../../shared/modules/selectors';
import { getNativeCurrency, getTokens } from '../../../ducks/metamask/metamask';
import {
getNativeCurrency,
getTokens,
getCurrentCurrency,
} from '../../../ducks/metamask/metamask';
import {
setCustomApproveTxData,
showModal,
Expand Down
7 changes: 5 additions & 2 deletions ui/pages/swaps/view-quote/view-quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
import {
conversionRateSelector,
getSelectedAccount,
getCurrentCurrency,
getTokenExchangeRates,
getSwapsDefaultToken,
getCurrentChainId,
Expand All @@ -66,7 +65,11 @@ import {
getSmartTransactionsOptInStatus,
getSmartTransactionsEnabled,
} from '../../../../shared/modules/selectors';
import { getNativeCurrency, getTokens } from '../../../ducks/metamask/metamask';
import {
getNativeCurrency,
getTokens,
getCurrentCurrency,
} from '../../../ducks/metamask/metamask';
import {
getLayer1GasFee,
safeRefetchQuotes,
Expand Down
11 changes: 5 additions & 6 deletions ui/selectors/multichain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Cryptocurrency } from '@metamask/assets-controllers';
import { InternalAccount } from '@metamask/keyring-api';
import { Hex } from '@metamask/utils';
import { NetworkConfiguration } from '@metamask/network-controller';
import { getNativeCurrency } from '../ducks/metamask/metamask';
import {
getCurrentCurrency,
getNativeCurrency,
} from '../ducks/metamask/metamask';
import {
MULTICHAIN_PROVIDER_CONFIGS,
MultichainNetworks,
Expand Down Expand Up @@ -40,11 +43,7 @@ import {
getMultichainSelectedAccountCachedBalanceIsZero,
getMultichainIsTestnet,
} from './multichain';
import {
getCurrentCurrency,
getSelectedAccountCachedBalance,
getShouldShowFiat,
} from '.';
import { getSelectedAccountCachedBalance, getShouldShowFiat } from '.';

type TestState = MultichainState &
AccountsState & {
Expand Down
2 changes: 1 addition & 1 deletion ui/selectors/multichain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getCompletedOnboarding,
getConversionRate,
getNativeCurrency,
getCurrentCurrency,
} from '../ducks/metamask/metamask';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
Expand All @@ -31,7 +32,6 @@ import {
} from './networks';
import { AccountsState, getSelectedInternalAccount } from './accounts';
import {
getCurrentCurrency,
getIsMainnet,
getMaybeSelectedInternalAccount,
getNativeCurrencyImage,
Expand Down
4 changes: 0 additions & 4 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,6 @@ export function getNftDetectionEnablementToast(state) {
return state.appState.showNftDetectionEnablementToast;
}

export function getCurrentCurrency(state) {
return state.metamask.currentCurrency;
}

export function getTotalUnapprovedCount(state) {
return state.metamask.pendingApprovalCount ?? 0;
}
Expand Down
5 changes: 0 additions & 5 deletions ui/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,6 @@ describe('Selectors', () => {
expect(gasIsLoading).toStrictEqual(false);
});

it('#getCurrentCurrency', () => {
const currentCurrency = selectors.getCurrentCurrency(mockState);
expect(currentCurrency).toStrictEqual('usd');
});

it('#getTotalUnapprovedCount', () => {
const totalUnapprovedCount = selectors.getTotalUnapprovedCount(mockState);
expect(totalUnapprovedCount).toStrictEqual(1);
Expand Down

0 comments on commit 1fbb2fa

Please sign in to comment.