-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add origin pill to wallet_addEthereumChain confirmation (#29317)
<!-- 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** Adds Origin Pill component and references it on the confirmation template. <!-- 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? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29317?quickstart=1) ## **Related issues** Fixes: #26656 ## **Manual testing steps** 1. Go to the test dApp 2. Add a custom chain ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <img width="472" alt="Screenshot 2024-12-18 at 12 08 31" src="https://github.com/user-attachments/assets/dea99351-e962-4b4c-b465-e2be281705ba" /> <img width="472" alt="Screenshot 2024-12-18 at 11 58 38" src="https://github.com/user-attachments/assets/e8da3a78-9ca4-4d3a-b68e-b5aafbe2532e" /> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/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
1 parent
22490c3
commit eb17dbb
Showing
5 changed files
with
178 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { screen } from '@testing-library/dom'; | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import mockState from '../../../../test/data/mock-state.json'; | ||
import { renderWithProvider } from '../../../../test/lib/render-helpers'; | ||
import OriginPill from './origin-pill'; | ||
|
||
describe('<OriginPill />', () => { | ||
it('renders correct elements', () => { | ||
const defaultProps = { | ||
origin: 'Test Origin', | ||
dataTestId: 'test-data-test-id', | ||
}; | ||
const store = configureMockStore()(mockState); | ||
|
||
renderWithProvider(<OriginPill {...defaultProps} />, store); | ||
|
||
expect(screen.getByTestId(defaultProps.dataTestId)).toBeDefined(); | ||
expect( | ||
screen.getByTestId(`${defaultProps.dataTestId}-avatar-favicon`), | ||
).toBeDefined(); | ||
expect(screen.getByTestId(`${defaultProps.dataTestId}-text`)).toBeDefined(); | ||
expect( | ||
screen.getByTestId(`${defaultProps.dataTestId}-text`), | ||
).toHaveTextContent(defaultProps.origin); | ||
}); | ||
}); |
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,57 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { | ||
AlignItems, | ||
BorderColor, | ||
BorderRadius, | ||
BorderStyle, | ||
Display, | ||
JustifyContent, | ||
TextColor, | ||
TextVariant, | ||
} from '../../../helpers/constants/design-system'; | ||
import { getSubjectMetadata } from '../../../selectors'; | ||
import { AvatarFavicon, Box, Text } from '../../component-library'; | ||
|
||
type OriginPillProps = { | ||
origin: string; | ||
dataTestId: string; | ||
}; | ||
|
||
export default function OriginPill({ origin, dataTestId }: OriginPillProps) { | ||
const subjectMetadata = useSelector(getSubjectMetadata); | ||
|
||
const { iconUrl: siteImage = '' } = subjectMetadata[origin] || {}; | ||
|
||
return ( | ||
<Box | ||
display={Display.Flex} | ||
alignItems={AlignItems.center} | ||
justifyContent={JustifyContent.center} | ||
marginTop={6} | ||
marginRight={4} | ||
marginLeft={4} | ||
padding={2} | ||
borderColor={BorderColor.borderMuted} | ||
borderStyle={BorderStyle.solid} | ||
borderRadius={BorderRadius.pill} | ||
borderWidth={1} | ||
data-testid={dataTestId} | ||
> | ||
<AvatarFavicon | ||
src={siteImage} | ||
name={origin} | ||
data-testid={`${dataTestId}-avatar-favicon`} | ||
/> | ||
<Text | ||
variant={TextVariant.bodySm} | ||
as="h6" | ||
color={TextColor.textAlternative} | ||
marginLeft={1} | ||
data-testid={`${dataTestId}-text`} | ||
> | ||
{origin} | ||
</Text> | ||
</Box> | ||
); | ||
} |
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