Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Convert browser tab to typescript #12740

Merged
merged 121 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
f0c5d88
Convert browser tab to typescript
tommasini Dec 17, 2024
cbdca18
fix snapshot
tommasini Dec 17, 2024
ca3e7d4
fix snapshot
tommasini Dec 17, 2024
805f954
Abstract types, consts, and styles
Cal-L Dec 17, 2024
4173703
Merge branch 'fix/browser-tab-convert-ts' of github.com:MetaMask/meta…
Cal-L Dec 17, 2024
e50280f
Store original browser tab in BrowserTab file
Cal-L Dec 18, 2024
ce3f381
Create simplified webview that prevents spoofing issues
Cal-L Dec 18, 2024
a483b90
Clean up code
Cal-L Dec 18, 2024
f83509c
Also handle spoof scenarios for Android
Cal-L Dec 18, 2024
f62820a
small fix, import react on simple webview
tommasini Dec 18, 2024
765a24a
Merge branch 'fix/browser-tab-convert-ts' of github.com:MetaMask/meta…
Cal-L Dec 18, 2024
50c8db6
types and eslint browser tab final version
tommasini Dec 18, 2024
e150c07
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Dec 18, 2024
f9dee5a
update browser tab utils Url variable name
tommasini Dec 18, 2024
c9eb384
Replace browser tab input
Cal-L Dec 19, 2024
0f074f5
Handle condition where load ends with same origins
Cal-L Dec 19, 2024
df78228
move to browser tab utils getMaskedUrl and isEnsUrl function
tommasini Dec 19, 2024
796f340
fix back to safety button on phishing modal
joaoloureirop Dec 19, 2024
3f40e3d
Update origin name to prevent type conflicts
Cal-L Dec 19, 2024
371de9f
Merge branch 'fix/browser-tab-convert-ts' of github.com:MetaMask/meta…
Cal-L Dec 19, 2024
bea6ba3
inApp Browser: fix home button
joaoloureirop Dec 19, 2024
d464e1e
isolated phishing modal
tommasini Dec 19, 2024
84d5d1c
Clean up AccountRightButton press tracking logic
Cal-L Dec 19, 2024
0abfec9
Merge branch 'fix/browser-tab-convert-ts' of github.com:MetaMask/meta…
Cal-L Dec 19, 2024
b32283a
abstract options logic from browser tab component
tommasini Dec 20, 2024
83e7781
Abstract and test IpfsBanner in BrowserTab
tommasini Dec 20, 2024
6236086
Move elements into BrowserUrlBar
Cal-L Dec 20, 2024
df3a5e6
Remove browser nav bar
Cal-L Dec 20, 2024
bd35a28
Convert UrlAutocomplete to TS
Cal-L Dec 20, 2024
adcc68d
Remove setting browser navigation bar
Cal-L Dec 20, 2024
7c8b036
Remove redundant BrowserTab
Cal-L Dec 20, 2024
4b8fc9e
Update types and styles of BrowserTab
Cal-L Dec 20, 2024
0277dd0
Consolidate BrowserUrlBar
Cal-L Dec 20, 2024
3b78c8c
Merge branch 'fix/browser-tab-convert-ts' of github.com:MetaMask/meta…
Cal-L Dec 20, 2024
fefc6b5
go to homepage
tommasini Dec 20, 2024
c7fc7fc
active url to save with useState
tommasini Dec 20, 2024
e696d04
fix browser back & forward nav
joaoloureirop Dec 20, 2024
f4e93c2
fix eslint add dependency activeUrl to sendAllNotifications function …
tommasini Dec 20, 2024
fd986dd
remove unneeded onLoad property from webview
tommasini Dec 20, 2024
9ad5c2d
replace go for onSubmitEditing function at goToHomePage and returnHom…
tommasini Dec 20, 2024
b1a54a2
refactor PhishingModal go property
tommasini Dec 20, 2024
3cdd541
remove console log from options
tommasini Dec 20, 2024
294da93
Make connection icon more intuitive
Cal-L Jan 7, 2025
d5438e3
Reset progress bar when website cannot be reached
Cal-L Jan 7, 2025
957ca45
Remove duplicate sanitize function for browser url
Cal-L Jan 7, 2025
c15b2e1
portfolio new tab with metrics and marketing stored value to not repe…
tommasini Jan 7, 2025
1479693
Add blank SVG
Cal-L Jan 8, 2025
5bd74a7
Fix fallback display url when website cannot be loaded
Cal-L Jan 8, 2025
30e2538
Remove unused code in Browser
Cal-L Jan 8, 2025
d440261
Update browser tabs to use AvatarFavicon
Cal-L Jan 8, 2025
f573d41
Make ref names more obvious
Cal-L Jan 8, 2025
d7e7e0a
Fix favicon fallback when uri is missing from remote source
Cal-L Jan 8, 2025
e4a50aa
Defer loading webview until focused
Cal-L Jan 8, 2025
db739fd
Resolve conflicts
Cal-L Jan 8, 2025
40915ca
Add missing enum
Cal-L Jan 8, 2025
7e9ca0a
handle ens ipfs content fixed
tommasini Jan 9, 2025
cf94f0c
Hide reload and favorites for undefined url
Cal-L Jan 9, 2025
c77b538
Fix handling error
Cal-L Jan 9, 2025
ca0fe8e
Reset error when going back
Cal-L Jan 9, 2025
74a66d9
Remove old browser url modal
Cal-L Jan 10, 2025
f3e371e
Remove unused params from browser nav
Cal-L Jan 10, 2025
dcb04e8
Abstract style from Browser
Cal-L Jan 10, 2025
5236437
Remove unused event
Cal-L Jan 10, 2025
959eeba
Properly handle connection icon state
Cal-L Jan 10, 2025
387b347
Add clear button to address bar
Cal-L Jan 10, 2025
c79b923
Hide bottom bar when focusing input
Cal-L Jan 11, 2025
3151d7a
Fix url unexpectedly changing after hitting submit
Cal-L Jan 12, 2025
9c41b3d
Fix persisting submitted entered and autocomplete urls when address b…
Cal-L Jan 12, 2025
935702b
Clean go home logic
Cal-L Jan 12, 2025
b00202c
Force resolve url when using webview back button
Cal-L Jan 12, 2025
466d9a4
remove go function and using onSubmitEditing, also refactores initial…
tommasini Jan 12, 2025
1da16b9
s
tommasini Jan 12, 2025
4257197
handleFirst Url after getEntryScriptWeb3
tommasini Jan 12, 2025
3bb1f85
Remove unused ens code from browserUrlBar
Cal-L Jan 13, 2025
0d0d10f
Merge branch 'main' of github.com:MetaMask/metamask-mobile into fix/b…
Cal-L Jan 13, 2025
8065462
Fix lint issues
Cal-L Jan 13, 2025
512a18a
Handle undefined ENS conditions
Cal-L Jan 13, 2025
24a0426
Fix lint issue
Cal-L Jan 13, 2025
221f8ed
Fix Favicon tests
Cal-L Jan 14, 2025
0dd38c5
Update snapshots
Cal-L Jan 14, 2025
3e1bc1c
Fix browser util test
Cal-L Jan 14, 2025
b32ff91
Write unit tests for browser tab utils
Cal-L Jan 14, 2025
f7d979d
Fix snapshots for mocked png
Cal-L Jan 14, 2025
a27bc98
Fix lint issues in tests
Cal-L Jan 14, 2025
2c2c9c5
Ignore import/no-commonjs for png mock
Cal-L Jan 14, 2025
0cf5d5c
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 14, 2025
4e4ef0d
Pass correct params to portfolio homepage
Cal-L Jan 14, 2025
5d6ea99
Fix lint issues
Cal-L Jan 14, 2025
328102b
Merge branch 'fix/browser-tab-convert-ts' of github.com:MetaMask/meta…
Cal-L Jan 14, 2025
892e781
Merge branch 'main' of github.com:MetaMask/metamask-mobile into fix/b…
Cal-L Jan 14, 2025
fffa613
Merge branch 'main' of github.com:MetaMask/metamask-mobile into fix/b…
Cal-L Jan 14, 2025
1788423
Simplify bridge creation logic on BrowserTab
Cal-L Jan 14, 2025
ce68cf8
Simplify component did mount
Cal-L Jan 14, 2025
0462187
fix ts issue
tommasini Jan 15, 2025
2eaa191
Merge branch 'main' into fix/browser-tab-convert-ts
Cal-L Jan 15, 2025
1f82de4
Merge branch 'fix/browser-tab-convert-ts' of github.com:MetaMask/meta…
Cal-L Jan 15, 2025
5d0505d
Remove blank icon
Cal-L Jan 15, 2025
d501bd1
Remove remaining blank name
Cal-L Jan 15, 2025
806edad
add snapshot testing to browserUrlBar
tommasini Jan 16, 2025
566d9df
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 16, 2025
e5e7b11
replacing resolvedUrlRef for a useState resolvedUrl, so it can grab t…
tommasini Jan 16, 2025
82e379f
add missing dependencies to useCallback that were missing
tommasini Jan 16, 2025
f0be3f2
add snapshot test for when the browserUrlBar is not focused
tommasini Jan 16, 2025
52af73a
add snapshot for DeleteWalletModal component
tommasini Jan 16, 2025
9259401
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 16, 2025
b926bbc
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 16, 2025
66a9fbc
default browser page to google
tommasini Jan 16, 2025
b3a349b
add 4 seconds to wait for tapping network avatar button
tommasini Jan 16, 2025
eba3eb7
increase unit test coverage of browser url bar component
tommasini Jan 16, 2025
7a5e07e
revert to use the ref of urlResolvedRed instead of state to reduce re…
tommasini Jan 16, 2025
46aebe7
address code quality issues detected by sonar cloud; refactor update …
tommasini Jan 17, 2025
35adfe6
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 17, 2025
11f6065
re add delay of 4 seconds to wait to tap on network avatar while conn…
tommasini Jan 17, 2025
a7a333a
chore: Refactor whitelist inapp browser (#13049)
tommasini Jan 17, 2025
55fbb57
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 22, 2025
54579ef
Bump version number to 1534
metamaskbot Jan 22, 2025
0eeab0c
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 22, 2025
8f0fc7e
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 22, 2025
c3442b7
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 23, 2025
9053522
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 23, 2025
be33a09
Merge branch 'main' into fix/browser-tab-convert-ts
tommasini Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionName "7.37.1"
versionCode 1520
versionCode 1534
testBuildType System.getProperty('testBuildType', 'debug')
missingDimensionStrategy 'react-native-camera', 'general'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
4 changes: 3 additions & 1 deletion app/actions/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ export function addToHistory({ url, name }) {
/**
* Clears the entire browser history
*/
export function clearHistory() {
export function clearHistory(metricsEnabled, marketingEnabled) {
return {
type: 'CLEAR_BROWSER_HISTORY',
id: Date.now(),
metricsEnabled,
tommasini marked this conversation as resolved.
Show resolved Hide resolved
marketingEnabled,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ICONSIZE_BY_AVATARSIZE } from '../../Avatar.constants';
import AvatarBase from '../../foundation/AvatarBase';

// Internal dependencies.
import { isNumber } from 'lodash';
import { isFaviconSVG } from '../../../../../../util/favicon';
import {
AVATARFAVICON_IMAGE_TESTID,
Expand All @@ -28,9 +27,14 @@ const AvatarFavicon = ({
style,
...props
}: AvatarFaviconProps) => {
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [error, setError] = useState<any>(undefined);
const isRequireSource = !!(imageSource && typeof imageSource === 'number');
const isRemoteSource = !!(
imageSource &&
typeof imageSource === 'object' &&
'uri' in imageSource
);
const isValidSource = isRequireSource || isRemoteSource;
const [error, setError] = useState<Error | undefined>(undefined);
const [svgSource, setSvgSource] = useState<string>('');
const { styles } = useStyles(stylesheet, { style });

Expand All @@ -40,9 +44,7 @@ const AvatarFavicon = ({
[setError],
);

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

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

// Checks if image is SVG
useEffect(() => {
if (!isRemoteSource) return;

const checkSvgContentType = async (uri: string) => {
try {
const response = await fetch(uri, { method: 'HEAD' });
const contentType = response.headers.get('Content-Type');
return contentType?.includes('image/svg+xml');
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
} catch (_) {
return false;
}
};

if (imageSource && !isNumber(imageSource) && 'uri' in imageSource) {
const svg = isFaviconSVG(imageSource);
if (svg) {
checkSvgContentType(svg).then((isSvg) => {
if (isSvg) {
setSvgSource(svg);
}
});
}
const svg = isFaviconSVG(imageSource);
if (svg) {
checkSvgContentType(svg).then((isSvg) => {
if (isSvg) {
setSvgSource(svg);
}
});
}
}, [imageSource]);
}, [imageSource, isRemoteSource]);

const renderSvg = () =>
svgSource ? (
Expand All @@ -86,9 +87,7 @@ const AvatarFavicon = ({
height="100%"
uri={svgSource}
style={styles.image}
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onError={(e: any) => onSvgError(e)}
onError={(e: unknown) => onSvgError(e as Error)}
/>
) : null;

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

return (
<AvatarBase size={size} style={styles.base} {...props}>
{error ? renderFallbackFavicon() : renderFavicon()}
{error || !isValidSource ? renderFallbackFavicon() : renderFavicon()}
</AvatarBase>
);
};
Expand Down
8 changes: 3 additions & 5 deletions app/components/Nav/Main/MainNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import { colors as importedColors } from '../../../styles/common';
import OrderDetails from '../../UI/Ramp/Views/OrderDetails';
import SendTransaction from '../../UI/Ramp/Views/SendTransaction';
import TabBar from '../../../component-library/components/Navigation/TabBar';
import BrowserUrlModal from '../../Views/BrowserUrlModal';
///: BEGIN:ONLY_INCLUDE_IF(external-snaps)
import { SnapsSettingsList } from '../../Views/Snaps/SnapsSettingsList';
import { SnapSettings } from '../../Views/Snaps/SnapSettings';
Expand Down Expand Up @@ -212,11 +211,10 @@ const BrowserFlow = () => (
cardStyle: { backgroundColor: importedColors.transparent },
}}
>
<Stack.Screen name={Routes.BROWSER.VIEW} component={Browser} />
<Stack.Screen
name={Routes.BROWSER.URL_MODAL}
component={BrowserUrlModal}
options={{ animationEnabled: false, headerShown: false }}
name={Routes.BROWSER.VIEW}
component={Browser}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
Expand Down
53 changes: 48 additions & 5 deletions app/components/UI/BrowserUrlBar/BrowserUrlBar.styles.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
import { StyleSheet } from 'react-native';

import { Theme } from '../../../util/theme/models';
import { fontStyles } from '../../../styles/common';
import Device from '../../../util/device';

const styleSheet = (params: { theme: Theme }) =>
const styleSheet = ({
theme: { colors },
vars: { isUrlBarFocused },
}: {
theme: Theme;
vars: { isUrlBarFocused: boolean };
}) =>
StyleSheet.create({
main: {
flexDirection: 'row',
alignItems: 'center',
flex: 1,
borderRadius: 999,
marginHorizontal: 16,
backgroundColor: isUrlBarFocused
? colors.background.alternative
: colors.background.default,
},
connectionIcon: {
marginRight: 8,
},
textInputWrapper: {
flex: 1,
},
textInput: {
flex: 1,
height: 44,
paddingVertical: 0,
margin: 0,
paddingLeft: isUrlBarFocused ? 16 : 0,
...fontStyles.normal,
fontSize: Device.isAndroid() ? 16 : 14,
color: colors.text.default,
},
browserUrlBarWrapper: {
flexDirection: 'row',
alignItems: 'center',
},
clearButton: {
marginRight: 8,
marginLeft: 4,
},
cancelButton: {
marginRight: 16,
justifyContent: 'center',
},
text: {
marginLeft: 8,
color: params.theme.colors.text.alternative,
cancelButtonText: {
fontSize: 14,
color: colors.primary.default,
...fontStyles.normal,
},
rightButton: { height: 50, justifyContent: 'center' },
});

export default styleSheet;
Loading
Loading