-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support standalone confirmation for re-redesigned confirmations (…
…#13550) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> This PR aims to implement support of standalone confirmation for redesigned confirmations. ## **Related issues** Fixes: MetaMask/MetaMask-planning#4217 ## **Manual testing steps** N/A ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [X] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
Showing
17 changed files
with
269 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/components/Views/confirmations/components/Confirm/Info/StakingDeposit/Navbar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
import { getStakingDepositNavbar } from './Navbar'; | ||
|
||
describe('getStakingDepositNavbar', () => { | ||
it('renders the header title correctly', () => { | ||
const title = 'Test Title'; | ||
const { getByText } = render( | ||
<> | ||
{getStakingDepositNavbar({ title, onReject: jest.fn() }).headerTitle()} | ||
</>, | ||
); | ||
|
||
expect(getByText(title)).toBeTruthy(); | ||
}); | ||
|
||
it('calls onReject when the back button is pressed', () => { | ||
const onRejectMock = jest.fn(); | ||
const { getByTestId } = render( | ||
<> | ||
{getStakingDepositNavbar({ | ||
title: 'Test Title', | ||
onReject: onRejectMock, | ||
}).headerLeft()} | ||
</>, | ||
); | ||
|
||
const backButton = getByTestId('staking-deposit-navbar-back-button'); | ||
backButton.props.onPress(); | ||
|
||
expect(onRejectMock).toHaveBeenCalled(); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
app/components/Views/confirmations/components/Confirm/Info/StakingDeposit/Navbar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { | ||
default as MorphText, | ||
TextVariant, | ||
} from '../../../../../../../component-library/components/Texts/Text'; | ||
import ButtonIcon, { | ||
ButtonIconSizes, | ||
} from '../../../../../../../component-library/components/Buttons/ButtonIcon'; | ||
import { IconName } from '../../../../../../../component-library/components/Icons/Icon'; | ||
|
||
export function getStakingDepositNavbar({ | ||
title, | ||
onReject, | ||
}: { | ||
title: string; | ||
onReject: () => void; | ||
}) { | ||
const innerStyles = StyleSheet.create({ | ||
headerLeft: { | ||
marginHorizontal: 16, | ||
}, | ||
headerTitle: { | ||
alignItems: 'center', | ||
}, | ||
}); | ||
|
||
function handleBackPress() { | ||
if (onReject) { | ||
onReject(); | ||
} | ||
} | ||
|
||
return { | ||
headerTitle: () => ( | ||
<View style={innerStyles.headerTitle}> | ||
<MorphText variant={TextVariant.HeadingMD}>{title}</MorphText> | ||
</View> | ||
), | ||
headerLeft: () => ( | ||
<ButtonIcon | ||
size={ButtonIconSizes.Lg} | ||
iconName={IconName.ArrowLeft} | ||
onPress={handleBackPress} | ||
style={innerStyles.headerLeft} | ||
testID="staking-deposit-navbar-back-button" | ||
/> | ||
), | ||
}; | ||
} |
43 changes: 43 additions & 0 deletions
43
...onents/Views/confirmations/components/Confirm/Info/StakingDeposit/StakingDeposit.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
|
||
import renderWithProvider from '../../../../../../../util/test/renderWithProvider'; | ||
import { stakingDepositConfirmationState } from '../../../../../../../util/test/confirm-data-helpers'; | ||
import StakingDeposit from './StakingDeposit'; | ||
|
||
jest.mock('../../../../../../../core/Engine', () => ({ | ||
getTotalFiatAccountBalance: () => ({ tokenFiat: 10 }), | ||
context: { | ||
NetworkController: { | ||
getNetworkConfigurationByNetworkClientId: jest.fn(), | ||
}, | ||
GasFeeController: { | ||
startPolling: jest.fn(), | ||
stopPollingByPollingToken: jest.fn(), | ||
}, | ||
}, | ||
})); | ||
|
||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useNavigation: () => ({ | ||
navigate: jest.fn(), | ||
setOptions: jest.fn(), | ||
}), | ||
}; | ||
}); | ||
|
||
describe('StakingDeposit', () => { | ||
it('should render correctly', () => { | ||
const { getByText } = renderWithProvider(<StakingDeposit />, { | ||
state: stakingDepositConfirmationState, | ||
}); | ||
expect(getByText('APR')).toBeDefined(); | ||
expect(getByText('Est. annual reward')).toBeDefined(); | ||
expect(getByText('Reward frequency')).toBeDefined(); | ||
expect(getByText('Withdrawal time')).toBeDefined(); | ||
expect(getByText('Network Fee')).toBeDefined(); | ||
expect(getByText('Advanced details')).toBeDefined(); | ||
}); | ||
}); |
39 changes: 28 additions & 11 deletions
39
app/components/Views/confirmations/components/Confirm/Info/StakingDeposit/StakingDeposit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import React from 'react'; | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { strings } from '../../../../../../../../locales/i18n'; | ||
import AdvancedDetails from '../../AdvancedDetails/AdvancedDetails'; | ||
import FlatNavHeader from '../../FlatNavHeader'; | ||
import StakingDetails from '../../StakingDetails'; | ||
import TokenHero from '../../TokenHero'; | ||
import GasFeesDetails from '../GasFeesDetails'; | ||
import { getStakingDepositNavbar } from './Navbar'; | ||
|
||
const StakingDeposit = () => ( | ||
<> | ||
<FlatNavHeader title={strings('stake.stake')} /> | ||
<TokenHero /> | ||
<StakingDetails /> | ||
<GasFeesDetails /> | ||
<AdvancedDetails /> | ||
</> | ||
); | ||
const StakingDeposit = () => { | ||
const navigation = useNavigation(); | ||
|
||
const updateNavBar = useCallback(() => { | ||
navigation.setOptions( | ||
getStakingDepositNavbar({ | ||
title: strings('stake.stake'), | ||
onReject: () => navigation.goBack(), | ||
}), | ||
); | ||
}, [navigation]); | ||
|
||
useEffect(() => { | ||
updateNavBar(); | ||
}, [updateNavBar]); | ||
|
||
return ( | ||
<> | ||
<TokenHero /> | ||
<StakingDetails /> | ||
<GasFeesDetails /> | ||
<AdvancedDetails /> | ||
</> | ||
); | ||
}; | ||
export default StakingDeposit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.