Skip to content

Commit c34ecbf

Browse files
committed
refactor(unstake): use HeaderStandard instead of getStakingNavbar
1 parent 667412b commit c34ecbf

4 files changed

Lines changed: 290 additions & 138 deletions

File tree

app/components/UI/Earn/Views/EarnWithdrawInputView/EarnWithdrawInputView.styles.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const styleSheet = (params: { theme: Theme }) => {
3838
paddingHorizontal: 16,
3939
paddingVertical: 8,
4040
},
41+
headerWithSubtitle: {
42+
height: 'auto',
43+
minHeight: 72,
44+
paddingVertical: 4,
45+
},
4146
});
4247
};
4348

app/components/UI/Earn/Views/EarnWithdrawInputView/EarnWithdrawInputView.test.tsx

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { MOCK_ACCOUNTS_CONTROLLER_STATE } from '../../../../../util/test/account
1010
import { backgroundState } from '../../../../../util/test/initial-root-state';
1111
import { renderScreen } from '../../../../../util/test/renderWithProvider';
1212
import { flushPromises } from '../../../../../util/test/utils';
13-
import { getStakingNavbar } from '../../../Navbar';
1413
import {
1514
MOCK_ETH_MAINNET_ASSET,
1615
MOCK_GET_POOLED_STAKES_API_RESPONSE,
@@ -26,16 +25,15 @@ import {
2625
import { selectStablecoinLendingEnabledFlag } from '../../selectors/featureFlags';
2726
import { EarnTokenDetails, LendingProtocol } from '../../types/lending.types';
2827
import { getAaveV3MaxRiskAwareWithdrawalAmount } from '../../utils/tempLending';
29-
import EarnWithdrawInputView from './EarnWithdrawInputView';
28+
import EarnWithdrawInputView, {
29+
EARN_WITHDRAW_INPUT_VIEW_BACK_BUTTON_TEST_ID,
30+
EARN_WITHDRAW_INPUT_VIEW_CANCEL_BUTTON_TEST_ID,
31+
} from './EarnWithdrawInputView';
3032
import { EarnWithdrawInputViewProps } from './EarnWithdrawInputView.types';
3133
import { TokenI } from '../../../Tokens/types';
3234
import { trace, TraceName } from '../../../../../util/trace';
3335
import { MAINNET_DISPLAY_NAME } from '../../../../../core/Engine/constants';
3436

35-
jest.mock('../../../Navbar', () => ({
36-
getStakingNavbar: jest.fn().mockReturnValue({}),
37-
}));
38-
3937
jest.mock('../../../../../selectors/multichain', () => ({
4038
selectAccountTokensAcrossChains: jest.fn(() => ({
4139
'0x1': [
@@ -65,6 +63,7 @@ const mockSetOptions = jest.fn();
6563
const mockNavigate = jest.fn();
6664
const mockReset = jest.fn();
6765
const mockPop = jest.fn();
66+
const mockGoBack = jest.fn();
6867

6968
let mockRouteToken: TokenI | undefined;
7069

@@ -74,6 +73,7 @@ jest.mock('@react-navigation/native', () => {
7473
...actualReactNavigation,
7574
useNavigation: () => ({
7675
navigate: mockNavigate,
76+
goBack: mockGoBack,
7777
setOptions: mockSetOptions.mockImplementation(
7878
actualReactNavigation.useNavigation().setOptions,
7979
),
@@ -431,13 +431,13 @@ jest.mock('react-native-fade-in-image', () => {
431431
});
432432

433433
describe('EarnWithdrawInputView', () => {
434-
const mockGetStakingNavbar = jest.mocked(getStakingNavbar);
435434
const mockTrackEvent = jest.fn();
436435
const mockTrace = jest.mocked(trace);
437436

438437
beforeEach(() => {
439438
jest.useFakeTimers();
440439
jest.clearAllMocks();
440+
mockGoBack.mockClear();
441441

442442
// Reset route.param.token
443443
mockRouteToken = undefined;
@@ -589,15 +589,10 @@ describe('EarnWithdrawInputView', () => {
589589
it('renders "Unstake <token name>" for pooled-staking withdrawals', () => {
590590
render(EarnWithdrawInputView);
591591

592-
expect(mockGetStakingNavbar).toHaveBeenCalledWith(
593-
'Unstake ETH',
594-
expect.anything(),
595-
expect.anything(),
596-
expect.anything(),
597-
expect.anything(),
598-
expect.anything(),
599-
null,
600-
);
592+
expect(screen.getByText('Unstake ETH')).toBeOnTheScreen();
593+
expect(
594+
screen.getByTestId(EARN_WITHDRAW_INPUT_VIEW_CANCEL_BUTTON_TEST_ID),
595+
).toBeOnTheScreen();
601596
});
602597

603598
it('renders "Withdraw <token name>" for supported stablecoin lending assets', () => {
@@ -635,15 +630,80 @@ describe('EarnWithdrawInputView', () => {
635630

636631
render(EarnWithdrawInputView, mockLendingToken);
637632

638-
expect(mockGetStakingNavbar).toHaveBeenCalledWith(
639-
'Withdraw USDC',
640-
expect.anything(),
641-
expect.anything(),
642-
expect.anything(),
643-
expect.anything(),
644-
expect.anything(),
645-
null,
633+
expect(screen.getByText('Withdraw USDC')).toBeOnTheScreen();
634+
expect(
635+
screen.getByTestId(EARN_WITHDRAW_INPUT_VIEW_BACK_BUTTON_TEST_ID),
636+
).toBeOnTheScreen();
637+
});
638+
639+
it('emits UNSTAKE_CANCEL_CLICKED and calls navigation.goBack when Cancel is pressed', () => {
640+
render(EarnWithdrawInputView);
641+
mockTrackEvent.mockClear();
642+
643+
fireEvent.press(
644+
screen.getByTestId(EARN_WITHDRAW_INPUT_VIEW_CANCEL_BUTTON_TEST_ID),
645+
);
646+
647+
expect(mockTrackEvent).toHaveBeenCalledWith(
648+
expect.objectContaining({
649+
name: 'Unstake Cancel Clicked',
650+
properties: expect.objectContaining({
651+
location: EVENT_LOCATIONS.UNSTAKE_INPUT_VIEW,
652+
}),
653+
}),
654+
);
655+
expect(mockGoBack).toHaveBeenCalled();
656+
});
657+
658+
it('emits EARN_INPUT_BACK_BUTTON_CLICKED and calls navigation.goBack when back is pressed for lending tokens', () => {
659+
(
660+
selectStablecoinLendingEnabledFlag as jest.MockedFunction<
661+
typeof selectStablecoinLendingEnabledFlag
662+
>
663+
).mockReturnValueOnce(true);
664+
665+
const mockLendingToken: EarnTokenDetails = {
666+
...MOCK_USDC_MAINNET_ASSET,
667+
balanceFormatted: '1000',
668+
balanceMinimalUnit: '1000000000',
669+
balanceFiatNumber: 1000,
670+
tokenUsdExchangeRate: 1,
671+
experiences: [
672+
{
673+
type: EARN_EXPERIENCES.STABLECOIN_LENDING,
674+
apr: '5%',
675+
estimatedAnnualRewardsFormatted: '50',
676+
estimatedAnnualRewardsFiatNumber: 50,
677+
estimatedAnnualRewardsTokenMinimalUnit: '50000000',
678+
estimatedAnnualRewardsTokenFormatted: '50',
679+
},
680+
],
681+
experience: {
682+
type: EARN_EXPERIENCES.STABLECOIN_LENDING,
683+
apr: '5%',
684+
estimatedAnnualRewardsFormatted: '50',
685+
estimatedAnnualRewardsFiatNumber: 50,
686+
estimatedAnnualRewardsTokenMinimalUnit: '50000000',
687+
estimatedAnnualRewardsTokenFormatted: '50',
688+
},
689+
};
690+
691+
mockTrackEvent.mockClear();
692+
render(EarnWithdrawInputView, mockLendingToken);
693+
694+
fireEvent.press(
695+
screen.getByTestId(EARN_WITHDRAW_INPUT_VIEW_BACK_BUTTON_TEST_ID),
696+
);
697+
698+
expect(mockTrackEvent).toHaveBeenCalledWith(
699+
expect.objectContaining({
700+
name: 'Earn Input Back Button Clicked',
701+
properties: expect.objectContaining({
702+
location: EVENT_LOCATIONS.EARN_WITHDRAWAL_INPUT_VIEW,
703+
}),
704+
}),
646705
);
706+
expect(mockGoBack).toHaveBeenCalled();
647707
});
648708
});
649709

0 commit comments

Comments
 (0)