Skip to content

Commit

Permalink
chore: adds handling for currency switch setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nickewansmith committed Jan 24, 2025
1 parent d270002 commit ae9acdf
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import { render } from '@testing-library/react-native';
import StakeEarningsHistoryView from './StakeEarningsHistoryView';
import useStakingEarningsHistory from '../../hooks/useStakingEarningsHistory';
import { MOCK_STAKED_ETH_ASSET } from '../../__mocks__/mockData';
import { fireLayoutEvent } from '../../../../../util/testUtils/react-native-svg-charts';
import { getStakingNavbar } from '../../../Navbar';
import renderWithProvider from '../../../../../util/test/renderWithProvider';
import { backgroundState } from '../../../../../util/test/initial-root-state';
import { Hex } from '@metamask/utils';
jest.mock('../../../Navbar');
jest.mock('../../hooks/useStakingEarningsHistory');

Expand Down Expand Up @@ -32,21 +34,51 @@ jest.mock('react-native-svg-charts', () => {
earningsHistory: [
{
dateStr: '2023-01-01',
dailyRewards: '10000000000000',
dailyRewardsUsd: '3000',
sumRewards: '10000000000000',
dailyRewards: '1000000000000000000',
sumRewards: '1000000000000000000',
},
{
dateStr: '2023-01-02',
dailyRewards: '10000000000000',
dailyRewardsUsd: '6000',
sumRewards: '20000000000000',
dailyRewards: '1000000000000000000',
sumRewards: '2000000000000000000',
},
],
isLoading: false,
error: null,
});

const mockInitialState = {
settings: {},
engine: {
backgroundState: {
...backgroundState,
CurrencyRateController: {
currentCurrency: 'usd',
currencyRates: {
ETH: {
conversionRate: 3363.79,
},
},
},
NetworkController: {
selectedNetworkClientId: 'selectedNetworkClientId',
networkConfigurationsByChainId: {
'0x1': {
nativeCurrency: 'ETH',
chainId: '0x1' as Hex,
rpcEndpoints: [
{
networkClientId: 'selectedNetworkClientId',
},
],
defaultRpcEndpointIndex: 0,
},
},
},
},
},
};

const earningsHistoryView = (
<StakeEarningsHistoryView
route={{
Expand All @@ -59,13 +91,17 @@ const earningsHistoryView = (

describe('StakeEarningsHistoryView', () => {
it('renders correctly and matches snapshot', () => {
const renderedView = render(earningsHistoryView);
const renderedView = renderWithProvider(earningsHistoryView, {
state: mockInitialState,
});
fireLayoutEvent(renderedView.root);
expect(renderedView.toJSON()).toMatchSnapshot();
});

it('calls navigation setOptions to get staking navigation bar', () => {
const renderedView = render(earningsHistoryView);
const renderedView = renderWithProvider(earningsHistoryView, {
state: mockInitialState,
});
fireLayoutEvent(renderedView.root);
expect(mockNavigation.setOptions).toHaveBeenCalled();
expect(getStakingNavbar).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ exports[`StakeEarningsHistoryView renders correctly and matches snapshot 1`] = `
}
}
>
0.00002
2
ETH
</Text>
Expand Down Expand Up @@ -899,7 +899,7 @@ exports[`StakeEarningsHistoryView renders correctly and matches snapshot 1`] = `
testID="label"
>
+
0.00002
2
ETH
</Text>
Expand All @@ -918,8 +918,7 @@ exports[`StakeEarningsHistoryView renders correctly and matches snapshot 1`] = `
}
}
>
9000.00
USD
$6727.58
</Text>
</View>
</View>
Expand Down
1 change: 1 addition & 0 deletions app/components/UI/Stake/__mocks__/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Contract } from 'ethers';
import { Stake } from '../sdk/stakeSdkProvider';

export const MOCK_STAKED_ETH_ASSET = {
address: '0x0000000000000000000000000000000000000000',
chainId: '0x1',
balance: '4.9999 ETH',
balanceFiat: '$13,292.20',
Expand Down
Loading

0 comments on commit ae9acdf

Please sign in to comment.