Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronfigueiredo committed Oct 9, 2024
1 parent 883070c commit f581e9c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('useTokenValues', () => {
await waitForNextUpdate();

expect(result.current).toEqual({
fiatDisplayValue: undefined,
fiatDisplayValue: null,
tokenBalance: '1',
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import { useEffect, useMemo, useState } from 'react';
import { useMemo, useState } from 'react';
import { calcTokenAmount } from '../../../../../../../shared/lib/transactions-controller-utils';
import { toChecksumHexAddress } from '../../../../../../../shared/modules/hexstring-utils';
import { Numeric } from '../../../../../../../shared/modules/Numeric';
import useTokenExchangeRate from '../../../../../../components/app/currency-input/hooks/useTokenExchangeRate';
import { useFiatFormatter } from '../../../../../../hooks/useFiatFormatter';
import { useTokenTracker } from '../../../../../../hooks/useTokenTracker';
Expand Down Expand Up @@ -33,7 +34,7 @@ export const useTokenValues = (

fetchTokenBalances();

const [exchangeRate, setExchangeRate] = useState<any>();
const [exchangeRate, setExchangeRate] = useState<Numeric | undefined>();
const fetchExchangeRate = async () => {
const result = await useTokenExchangeRate(transactionMeta?.txParams?.to);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import mockState from '../../../../../../../../test/data/mock-state.json';
import { getMockTokenTransferConfirmState } from '../../../../../../../../test/data/confirmations/helper';
import { renderWithConfirmContextProvider } from '../../../../../../../../test/lib/confirmations/render-helpers';
import SendHeading from './send-heading';

describe('<SendHeading />', () => {
const middleware = [thunk];
const state = getMockTokenTransferConfirmState({});
const mockStore = configureMockStore(middleware)(state);

it('renders component', () => {
const state = mockState;
const mockStore = configureMockStore(middleware)(state);
const { container } = renderWithConfirmContextProvider(
<SendHeading />,
mockStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../../../../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../../../../hooks/useI18nContext';
import { getWatchedToken } from '../../../../../../../selectors';
import { MultichainState } from '../../../../../../../selectors/multichain';
import { useConfirmContext } from '../../../../../context/confirm';
import { useTokenImage } from '../../hooks/use-token-image';
import { useTokenValues } from '../../hooks/use-token-values';
Expand All @@ -26,7 +27,7 @@ const SendHeading = () => {
const t = useI18nContext();
const { currentConfirmation: transactionMeta } =
useConfirmContext<TransactionMeta>();
const selectedToken = useSelector((state: any) =>
const selectedToken = useSelector((state: MultichainState) =>
getWatchedToken(transactionMeta)(state),
);
const { tokenImage } = useTokenImage(transactionMeta, selectedToken);
Expand Down Expand Up @@ -57,7 +58,7 @@ const SendHeading = () => {
variant={TextVariant.headingLg}
color={TextColor.inherit}
marginTop={3}
>{`${tokenBalance} ${selectedToken?.symbol || t('unknown')}`}</Text>
>{`${tokenBalance || ''} ${selectedToken?.symbol || t('unknown')}`}</Text>
{fiatDisplayValue && (
<Text variant={TextVariant.bodyMd} color={TextColor.textAlternative}>
{fiatDisplayValue}
Expand Down
4 changes: 2 additions & 2 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { MultichainNativeAssets } from '../../shared/constants/multichain/assets
// eslint-disable-next-line import/no-restricted-paths
import { BridgeFeatureFlagsKey } from '../../app/scripts/controllers/bridge/types';
import { hasTransactionData } from '../../shared/modules/transaction.utils';
import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils';
import {
getAllUnapprovedTransactions,
getCurrentNetworkTransactions,
Expand All @@ -123,7 +124,6 @@ import {
} from './permissions';
import { createDeepEqualSelector } from './util';
import { getMultichainBalances, getMultichainNetwork } from './multichain';
import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils';

/**
* Returns true if the currently selected network is inaccessible or whether no
Expand Down Expand Up @@ -524,7 +524,7 @@ export const getWatchedToken = (transactionMeta) =>
createSelector(
[getSelectedAccount, getAllTokens],
(selectedAccount, detectedTokens) => {
const chainId = transactionMeta.chainId;
const { chainId } = transactionMeta;

const selectedToken = detectedTokens?.[chainId]?.[
selectedAccount.address
Expand Down

0 comments on commit f581e9c

Please sign in to comment.