Skip to content

Commit 43ff1dd

Browse files
authored
Merge branch 'main' into fix/backup-vault-try-catch
2 parents 5866cb0 + aa0bd2a commit 43ff1dd

6 files changed

Lines changed: 48 additions & 76 deletions

File tree

app/components/Nav/App/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ const OnboardingNav = () => {
318318
* child OnboardingNav navigator to push modals on top of it
319319
*/
320320
const SimpleWebviewScreen = () => (
321-
<Stack.Navigator>
321+
<Stack.Navigator screenOptions={{ headerShown: false }}>
322322
<Stack.Screen name={Routes.WEBVIEW.SIMPLE} component={SimpleWebview} />
323323
</Stack.Navigator>
324324
);

app/components/Nav/Main/MainNavigator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ const HomeTabs = () => {
891891
};
892892

893893
const Webview = () => (
894-
<Stack.Navigator>
894+
<Stack.Navigator screenOptions={{ headerShown: false }}>
895895
<Stack.Screen name="SimpleWebview" component={SimpleWebview} />
896896
</Stack.Navigator>
897897
);

app/components/Views/SimpleWebview/index.test.tsx

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,20 @@ import SimpleWebview from './';
44
import { useNavigation } from '@react-navigation/native';
55
import Share from 'react-native-share';
66
import Logger from '../../../util/Logger';
7-
import getHeaderCompactStandardNavbarOptions from '../../../component-library/components-temp/HeaderCompactStandard/getHeaderCompactStandardNavbarOptions';
8-
import Device from '../../../util/device';
7+
import HeaderCompactStandard from '../../../component-library/components-temp/HeaderCompactStandard';
98

109
jest.mock(
11-
'../../../component-library/components-temp/HeaderCompactStandard/getHeaderCompactStandardNavbarOptions',
10+
'../../../component-library/components-temp/HeaderCompactStandard',
1211
() => ({
1312
__esModule: true,
14-
default: jest.fn(() => ({
15-
header: () => null,
16-
})),
13+
default: jest.fn(() => null),
1714
}),
1815
);
1916

20-
jest.mock('../../../util/device', () => ({
21-
__esModule: true,
22-
default: {
23-
isAndroid: jest.fn(() => false),
24-
},
25-
}));
26-
27-
const mockSetOptions = jest.fn();
17+
const mockGoBack = jest.fn();
2818
const mockNavigation = {
29-
goBack: jest.fn(),
30-
setOptions: mockSetOptions,
19+
goBack: mockGoBack,
20+
setOptions: jest.fn(),
3121
};
3222

3323
jest.mock('@react-navigation/native', () => ({
@@ -48,64 +38,38 @@ describe('SimpleWebview', () => {
4838
(Share.open as jest.Mock).mockImplementation(() => Promise.resolve());
4939
});
5040

51-
it('renders correctly', () => {
41+
it('renders the HeaderCompactStandard with safe area top inset', () => {
5242
render(<SimpleWebview />);
5343

54-
expect(getHeaderCompactStandardNavbarOptions).toHaveBeenCalled();
55-
});
56-
57-
it('sets header options from HeaderCompactStandard and Device.isAndroid() for includesTopInset', () => {
58-
render(<SimpleWebview />);
59-
60-
expect(getHeaderCompactStandardNavbarOptions).toHaveBeenCalledWith(
44+
expect(HeaderCompactStandard).toHaveBeenCalledWith(
6145
expect.objectContaining({
6246
title: '',
63-
includesTopInset: false,
64-
twClassName: 'bg-default rounded-t-2xl',
47+
includesTopInset: true,
6548
onBack: expect.any(Function),
6649
endButtonIconProps: expect.arrayContaining([
6750
expect.objectContaining({ onPress: expect.any(Function) }),
6851
]),
6952
}),
70-
);
71-
expect(mockSetOptions).toHaveBeenCalledWith(
72-
expect.objectContaining({
73-
header: expect.any(Function),
74-
}),
75-
);
76-
expect(mockSetOptions.mock.calls[0][0]).not.toHaveProperty('headerStyle');
77-
});
78-
79-
it('passes includesTopInset true when Device.isAndroid() is true', () => {
80-
jest.mocked(Device.isAndroid).mockReturnValueOnce(true);
81-
render(<SimpleWebview />);
82-
83-
expect(getHeaderCompactStandardNavbarOptions).toHaveBeenCalledWith(
84-
expect.objectContaining({
85-
includesTopInset: true,
86-
}),
53+
expect.anything(),
8754
);
8855
});
8956

9057
it('calls navigation.goBack when header onBack is invoked', () => {
9158
render(<SimpleWebview />);
9259

93-
const { onBack } = (getHeaderCompactStandardNavbarOptions as jest.Mock).mock
60+
const headerProps = (HeaderCompactStandard as unknown as jest.Mock).mock
9461
.calls[0][0] as { onBack: () => void };
95-
onBack();
62+
headerProps.onBack();
9663

97-
expect(mockNavigation.goBack).toHaveBeenCalled();
64+
expect(mockGoBack).toHaveBeenCalled();
9865
});
9966

10067
it('calls Share.open when share button onPress is invoked', () => {
10168
render(<SimpleWebview />);
10269

103-
const { endButtonIconProps } = (
104-
getHeaderCompactStandardNavbarOptions as jest.Mock
105-
).mock.calls[0][0] as {
106-
endButtonIconProps: { onPress: () => void }[];
107-
};
108-
endButtonIconProps[0].onPress();
70+
const headerProps = (HeaderCompactStandard as unknown as jest.Mock).mock
71+
.calls[0][0] as { endButtonIconProps: { onPress: () => void }[] };
72+
headerProps.endButtonIconProps[0].onPress();
10973

11074
expect(Share.open).toHaveBeenCalledWith({ url: 'https://etherscan.io' });
11175
});
@@ -116,12 +80,9 @@ describe('SimpleWebview', () => {
11680

11781
render(<SimpleWebview />);
11882

119-
const { endButtonIconProps } = (
120-
getHeaderCompactStandardNavbarOptions as jest.Mock
121-
).mock.calls[0][0] as {
122-
endButtonIconProps: { onPress: () => void }[];
123-
};
124-
endButtonIconProps[0].onPress();
83+
const headerProps = (HeaderCompactStandard as unknown as jest.Mock).mock
84+
.calls[0][0] as { endButtonIconProps: { onPress: () => void }[] };
85+
headerProps.endButtonIconProps[0].onPress();
12586

12687
await waitFor(() => {
12788
expect(log).toHaveBeenCalledWith(

app/components/Views/SimpleWebview/index.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
/* eslint-disable @typescript-eslint/consistent-type-definitions */
2-
import React, { useCallback, useEffect } from 'react';
2+
import React, { useCallback } from 'react';
3+
import { View } from 'react-native';
34
import { WebView } from '@metamask/react-native-webview';
4-
import getHeaderCompactStandardNavbarOptions from '../../../component-library/components-temp/HeaderCompactStandard/getHeaderCompactStandardNavbarOptions';
5+
import HeaderCompactStandard from '../../../component-library/components-temp/HeaderCompactStandard';
56
import { IconName } from '@metamask/design-system-react-native';
7+
import { useTailwind } from '@metamask/design-system-twrnc-preset';
68
import Share from 'react-native-share'; // eslint-disable-line import-x/default
79
import Logger from '../../../util/Logger';
810
import { baseStyles } from '../../../styles/common';
9-
import Device from '../../../util/device';
1011
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
1112

1213
// TODO: This will be replaced with the actual route params type once navigation is refactored
1314
type RouteParams = {
1415
SimpleWebView: {
1516
url: string;
17+
title?: string;
1618
};
1719
};
1820

1921
const SimpleWebView = () => {
22+
const tw = useTailwind();
2023
const navigation = useNavigation();
2124
const route = useRoute<RouteProp<RouteParams, 'SimpleWebView'>>();
2225
const url = route.params.url;
@@ -32,19 +35,17 @@ const SimpleWebView = () => {
3235
}
3336
}, [url]);
3437

35-
useEffect(() => {
36-
navigation.setOptions({
37-
...getHeaderCompactStandardNavbarOptions({
38-
title,
39-
onBack: () => navigation.goBack(),
40-
includesTopInset: Device.isAndroid(),
41-
twClassName: 'bg-default rounded-t-2xl',
42-
endButtonIconProps: [{ iconName: IconName.Share, onPress: share }],
43-
}),
44-
});
45-
}, [navigation, share, title]);
46-
47-
return <WebView containerStyle={baseStyles.flexGrow} source={{ uri: url }} />;
38+
return (
39+
<View style={tw.style('flex-1 bg-default')}>
40+
<HeaderCompactStandard
41+
title={title}
42+
onBack={() => navigation.goBack()}
43+
includesTopInset
44+
endButtonIconProps={[{ iconName: IconName.Share, onPress: share }]}
45+
/>
46+
<WebView containerStyle={baseStyles.flexGrow} source={{ uri: url }} />
47+
</View>
48+
);
4849
};
4950

5051
export default SimpleWebView;

app/core/SDKConnectV2/services/connection-registry.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ describe('ConnectionRegistry', () => {
442442
transport_type: TransportType.MWP,
443443
sdk_version: '2.0.0',
444444
sdk_platform: 'JavaScript',
445+
dapp_name: 'Test DApp',
446+
dapp_url: 'https://test.dapp',
445447
}),
446448
);
447449
});
@@ -583,6 +585,10 @@ describe('ConnectionRegistry', () => {
583585
expect.objectContaining({
584586
remote_session_id: mockConnectionRequest.sessionRequest.id,
585587
transport_type: TransportType.MWP,
588+
sdk_version: '2.0.0',
589+
sdk_platform: 'JavaScript',
590+
dapp_name: 'Test DApp',
591+
dapp_url: 'https://test.dapp',
586592
failure_reason: 'Connection failed',
587593
}),
588594
);

app/core/SDKConnectV2/services/connection-registry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ export class ConnectionRegistry {
258258
transport_type: TransportType.MWP,
259259
sdk_version: connReq.metadata.sdk.version,
260260
sdk_platform: connReq.metadata.sdk.platform,
261+
dapp_name: connReq.metadata.dapp.name,
262+
dapp_url: connReq.metadata.dapp.url,
261263
});
262264

263265
// Defense-in-depth: block connections whose self-reported dapp metadata
@@ -305,6 +307,8 @@ export class ConnectionRegistry {
305307
transport_type: TransportType.MWP,
306308
sdk_version: connReq?.metadata?.sdk?.version,
307309
sdk_platform: connReq?.metadata?.sdk?.platform,
310+
dapp_name: connReq?.metadata?.dapp?.name,
311+
dapp_url: connReq?.metadata?.dapp?.url,
308312
failure_reason: error instanceof Error ? error.message : String(error),
309313
});
310314

0 commit comments

Comments
 (0)