Skip to content

Commit e046eb6

Browse files
tommasiniCal-Ljoaoloureiropmetamaskbot
authored
chore: Convert browser tab to typescript (#12740)
## **Description** Refactor of browser tab to typescript Please visit this issue that includes a bigger description: MetaMask/mobile-planning#2087 ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **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** - [ ] 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). - [ ] 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-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. --------- Co-authored-by: Cal-L <cleun007@gmail.com> Co-authored-by: João Loureiro <175489935+joaoloureirop@users.noreply.github.com> Co-authored-by: Cal Leung <cal.leung@consensys.net> Co-authored-by: metamaskbot <metamaskbot@users.noreply.github.com>
1 parent afbd917 commit e046eb6

File tree

75 files changed

+6199
-2921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+6199
-2921
lines changed

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ android {
179179
minSdkVersion rootProject.ext.minSdkVersion
180180
targetSdkVersion rootProject.ext.targetSdkVersion
181181
versionName "7.37.1"
182-
versionCode 1520
182+
versionCode 1534
183183
testBuildType System.getProperty('testBuildType', 'debug')
184184
missingDimensionStrategy 'react-native-camera', 'general'
185185
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

app/actions/browser/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ export function addToHistory({ url, name }) {
3636
/**
3737
* Clears the entire browser history
3838
*/
39-
export function clearHistory() {
39+
export function clearHistory(metricsEnabled, marketingEnabled) {
4040
return {
4141
type: 'CLEAR_BROWSER_HISTORY',
4242
id: Date.now(),
43+
metricsEnabled,
44+
marketingEnabled,
4345
};
4446
}
4547

app/component-library/components/Avatars/Avatar/variants/AvatarFavicon/AvatarFavicon.tsx

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ICONSIZE_BY_AVATARSIZE } from '../../Avatar.constants';
1212
import AvatarBase from '../../foundation/AvatarBase';
1313

1414
// Internal dependencies.
15-
import { isNumber } from 'lodash';
1615
import { isFaviconSVG } from '../../../../../../util/favicon';
1716
import {
1817
AVATARFAVICON_IMAGE_TESTID,
@@ -28,9 +27,14 @@ const AvatarFavicon = ({
2827
style,
2928
...props
3029
}: AvatarFaviconProps) => {
31-
// TODO: Replace "any" with type
32-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33-
const [error, setError] = useState<any>(undefined);
30+
const isRequireSource = !!(imageSource && typeof imageSource === 'number');
31+
const isRemoteSource = !!(
32+
imageSource &&
33+
typeof imageSource === 'object' &&
34+
'uri' in imageSource
35+
);
36+
const isValidSource = isRequireSource || isRemoteSource;
37+
const [error, setError] = useState<Error | undefined>(undefined);
3438
const [svgSource, setSvgSource] = useState<string>('');
3539
const { styles } = useStyles(stylesheet, { style });
3640

@@ -40,9 +44,7 @@ const AvatarFavicon = ({
4044
[setError],
4145
);
4246

43-
// TODO: Replace "any" with type
44-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
45-
const onSvgError = useCallback((e: any) => setError(e), [setError]);
47+
const onSvgError = useCallback((e: Error) => setError(e), [setError]);
4648

4749
// TODO add the fallback with uppercase letter initial
4850
// requires that the domain is passed in as a prop from the parent
@@ -53,30 +55,29 @@ const AvatarFavicon = ({
5355
/>
5456
);
5557

58+
// Checks if image is SVG
5659
useEffect(() => {
60+
if (!isRemoteSource) return;
61+
5762
const checkSvgContentType = async (uri: string) => {
5863
try {
5964
const response = await fetch(uri, { method: 'HEAD' });
6065
const contentType = response.headers.get('Content-Type');
6166
return contentType?.includes('image/svg+xml');
62-
// TODO: Replace "any" with type
63-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
64-
} catch (err: any) {
67+
} catch (_) {
6568
return false;
6669
}
6770
};
6871

69-
if (imageSource && !isNumber(imageSource) && 'uri' in imageSource) {
70-
const svg = isFaviconSVG(imageSource);
71-
if (svg) {
72-
checkSvgContentType(svg).then((isSvg) => {
73-
if (isSvg) {
74-
setSvgSource(svg);
75-
}
76-
});
77-
}
72+
const svg = isFaviconSVG(imageSource);
73+
if (svg) {
74+
checkSvgContentType(svg).then((isSvg) => {
75+
if (isSvg) {
76+
setSvgSource(svg);
77+
}
78+
});
7879
}
79-
}, [imageSource]);
80+
}, [imageSource, isRemoteSource]);
8081

8182
const renderSvg = () =>
8283
svgSource ? (
@@ -86,9 +87,7 @@ const AvatarFavicon = ({
8687
height="100%"
8788
uri={svgSource}
8889
style={styles.image}
89-
// TODO: Replace "any" with type
90-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
91-
onError={(e: any) => onSvgError(e)}
90+
onError={(e: unknown) => onSvgError(e as Error)}
9291
/>
9392
) : null;
9493

@@ -106,7 +105,7 @@ const AvatarFavicon = ({
106105

107106
return (
108107
<AvatarBase size={size} style={styles.base} {...props}>
109-
{error ? renderFallbackFavicon() : renderFavicon()}
108+
{error || !isValidSource ? renderFallbackFavicon() : renderFavicon()}
110109
</AvatarBase>
111110
);
112111
};

app/components/Nav/Main/MainNavigator.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import { colors as importedColors } from '../../../styles/common';
6060
import OrderDetails from '../../UI/Ramp/Views/OrderDetails';
6161
import SendTransaction from '../../UI/Ramp/Views/SendTransaction';
6262
import TabBar from '../../../component-library/components/Navigation/TabBar';
63-
import BrowserUrlModal from '../../Views/BrowserUrlModal';
6463
///: BEGIN:ONLY_INCLUDE_IF(external-snaps)
6564
import { SnapsSettingsList } from '../../Views/Snaps/SnapsSettingsList';
6665
import { SnapSettings } from '../../Views/Snaps/SnapSettings';
@@ -212,11 +211,10 @@ const BrowserFlow = () => (
212211
cardStyle: { backgroundColor: importedColors.transparent },
213212
}}
214213
>
215-
<Stack.Screen name={Routes.BROWSER.VIEW} component={Browser} />
216214
<Stack.Screen
217-
name={Routes.BROWSER.URL_MODAL}
218-
component={BrowserUrlModal}
219-
options={{ animationEnabled: false, headerShown: false }}
215+
name={Routes.BROWSER.VIEW}
216+
component={Browser}
217+
options={{ headerShown: false }}
220218
/>
221219
</Stack.Navigator>
222220
);
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
11
import { StyleSheet } from 'react-native';
2-
32
import { Theme } from '../../../util/theme/models';
3+
import { fontStyles } from '../../../styles/common';
4+
import Device from '../../../util/device';
45

5-
const styleSheet = (params: { theme: Theme }) =>
6+
const styleSheet = ({
7+
theme: { colors },
8+
vars: { isUrlBarFocused },
9+
}: {
10+
theme: Theme;
11+
vars: { isUrlBarFocused: boolean };
12+
}) =>
613
StyleSheet.create({
714
main: {
815
flexDirection: 'row',
916
alignItems: 'center',
17+
flex: 1,
18+
borderRadius: 999,
19+
marginHorizontal: 16,
20+
backgroundColor: isUrlBarFocused
21+
? colors.background.alternative
22+
: colors.background.default,
23+
},
24+
connectionIcon: {
25+
marginRight: 8,
26+
},
27+
textInputWrapper: {
28+
flex: 1,
29+
},
30+
textInput: {
31+
flex: 1,
32+
height: 44,
33+
paddingVertical: 0,
34+
margin: 0,
35+
paddingLeft: isUrlBarFocused ? 16 : 0,
36+
...fontStyles.normal,
37+
fontSize: Device.isAndroid() ? 16 : 14,
38+
color: colors.text.default,
39+
},
40+
browserUrlBarWrapper: {
41+
flexDirection: 'row',
42+
alignItems: 'center',
43+
},
44+
clearButton: {
45+
marginRight: 8,
46+
marginLeft: 4,
47+
},
48+
cancelButton: {
49+
marginRight: 16,
50+
justifyContent: 'center',
1051
},
11-
text: {
12-
marginLeft: 8,
13-
color: params.theme.colors.text.alternative,
52+
cancelButtonText: {
53+
fontSize: 14,
54+
color: colors.primary.default,
55+
...fontStyles.normal,
1456
},
57+
rightButton: { height: 50, justifyContent: 'center' },
1558
});
1659

1760
export default styleSheet;

0 commit comments

Comments
 (0)