-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add url value component for use in re-designed confirmation pag…
…es (#11567) ## **Description** Add url value component for use in re-designed confirmation pages ## **Related issues** Fixes: #11496 ## **Manual testing steps** 1. Run storybook locally 2. Check confirmations -> info row story ## **Screenshots/Recordings** <img width="399" alt="Screenshot 2024-10-02 at 3 08 32 PM" src="https://github.com/user-attachments/assets/6c4427bb-34ac-411b-954f-d5a12964e753"> ## **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 - [ ] 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
11 changed files
with
193 additions
and
17 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
39 changes: 39 additions & 0 deletions
39
app/components/Views/confirmations/components/UI/InfoRow/InfoValue/InfoURL/InfoURL.styles.ts
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,39 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
import { Theme } from '../../../../../../../../util/theme/models'; | ||
import { fontStyles } from '../../../../../../../../styles/common'; | ||
|
||
const styleSheet = (params: { theme: Theme }) => { | ||
const { theme } = params; | ||
|
||
return StyleSheet.create({ | ||
container: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
value: { | ||
color: theme.colors.text.default, | ||
...fontStyles.normal, | ||
fontSize: 14, | ||
marginTop: 8, | ||
}, | ||
warningContainer: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
marginRight: 8, | ||
marginTop: 8, | ||
paddingVertical: 2, | ||
paddingHorizontal: 4, | ||
backgroundColor: theme.colors.error.muted, | ||
borderRadius: 4, | ||
}, | ||
warningText: { | ||
color: theme.colors.error.default, | ||
marginLeft: 4, | ||
}, | ||
}); | ||
}; | ||
|
||
export default styleSheet; |
16 changes: 16 additions & 0 deletions
16
app/components/Views/confirmations/components/UI/InfoRow/InfoValue/InfoURL/InfoURL.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,16 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
|
||
import InfoURL from './index'; | ||
|
||
describe('InfoURL', () => { | ||
it('should display url as expected', async () => { | ||
const container = render(<InfoURL url="https://google.com" />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should show warning if protocol is HTTP', async () => { | ||
const { getByText } = render(<InfoURL url="http://google.com" />); | ||
expect(getByText('HTTP')).toBeDefined(); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
app/components/Views/confirmations/components/UI/InfoRow/InfoValue/InfoURL/InfoURL.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 { Text, View } from 'react-native'; | ||
|
||
import Icon, { | ||
IconColor, | ||
IconName, | ||
IconSize, | ||
} from '../../../../../../../../component-library/components/Icons/Icon'; | ||
import Logger from '../../../../../../../../util/Logger'; | ||
import { useStyles } from '../../../../../../../../component-library/hooks'; | ||
import styleSheet from './InfoURL.styles'; | ||
|
||
interface InfoURLProps { | ||
url: string; | ||
} | ||
|
||
const InfoURL = ({ url }: InfoURLProps) => { | ||
let urlObject; | ||
|
||
try { | ||
urlObject = new URL(url); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
Logger.error(e as Error, `InfoURL: new URL(url) cannot parse ${url}`); | ||
} | ||
|
||
const isHTTP = urlObject?.protocol === 'http:'; | ||
|
||
const urlWithoutProtocol = url?.replace(/https?:\/\//u, ''); | ||
|
||
const { styles } = useStyles(styleSheet, {}); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
{isHTTP && ( | ||
<View style={styles.warningContainer}> | ||
<Icon | ||
color={IconColor.Warning} | ||
size={IconSize.Md} | ||
name={IconName.Danger} | ||
/> | ||
<Text style={styles.warningText}>HTTP</Text> | ||
</View> | ||
)} | ||
<Text style={styles.value}>{urlWithoutProtocol}</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
export default InfoURL; |
27 changes: 27 additions & 0 deletions
27
...confirmations/components/UI/InfoRow/InfoValue/InfoURL/__snapshots__/InfoURL.test.tsx.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`InfoURL should display url as expected 1`] = ` | ||
<View | ||
style={ | ||
{ | ||
"alignItems": "center", | ||
"display": "flex", | ||
"flexDirection": "row", | ||
} | ||
} | ||
> | ||
<Text | ||
style={ | ||
{ | ||
"color": "#141618", | ||
"fontFamily": "EuclidCircularB-Regular", | ||
"fontSize": 14, | ||
"fontWeight": "400", | ||
"marginTop": 8, | ||
} | ||
} | ||
> | ||
google.com | ||
</Text> | ||
</View> | ||
`; |
1 change: 1 addition & 0 deletions
1
app/components/Views/confirmations/components/UI/InfoRow/InfoValue/InfoURL/index.ts
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 @@ | ||
export { default } from './InfoURL'; |
36 changes: 36 additions & 0 deletions
36
app/components/Views/confirmations/components/UI/InfoRow/InfoValue/InfoURL/style.ts
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,36 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
import { Colors } from '../../../../../../../../util/theme/models'; | ||
import { fontStyles } from '../../../../../../../../styles/common'; | ||
|
||
const createStyles = (colors: Colors) => | ||
StyleSheet.create({ | ||
container: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
value: { | ||
color: colors.text.default, | ||
...fontStyles.normal, | ||
fontSize: 14, | ||
marginTop: 8, | ||
}, | ||
warningContainer: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
marginRight: 8, | ||
marginTop: 8, | ||
paddingVertical: 2, | ||
paddingHorizontal: 4, | ||
backgroundColor: colors.error.muted, | ||
borderRadius: 4, | ||
}, | ||
warningText: { | ||
color: colors.error.default, | ||
marginLeft: 4, | ||
}, | ||
}); | ||
|
||
export default createStyles; |