Skip to content

Commit d0c4336

Browse files
authored
chore: [IOBP-1927] Improved the CGN webview playground usability, added a default user agent (#7261)
## Short description This PR introduces improvements to how the `WebviewComponent` handles user agent headers, as well as refactors the CGN landing playground to use a more robust source object for webview navigation. The main themes are enhanced webview header configuration and improved playground usability. ## List of changes proposed in this pull request * Added a `getDefaultUserAgent` function to set a platform-specific user agent string for webview requests, ensuring consistent identification across iOS, Android, and other platforms that CGN merchants will use. * Edited the webview source prop to always include the correct `User-Agent` header, merging with any existing headers. **Error handling improvements:** * Added a `useEffect` to reset error state when the webview source changes, preventing stale error messages when navigating to new URLs. * Refactored the CGN landing playground to use a `WebViewSourceUri` object for navigation, simplifying state management and making header manipulation more explicit. * Updated the playground to pass the new `playgroundEnabled` prop to the webview component, enabling enhanced testing features that allow merchants to check the error pages if the webview goes into error without showing the standard umbrella. ## How to test ⚠️ It's important to test this implementation with the production environment, ensuring that for those merchants with a landing page discount, the webview with the page is displayed successfully.
1 parent bc8e2f4 commit d0c4336

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

ts/components/WebviewComponent.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import { OperationResultScreenContent } from "./screens/OperationResultScreenCon
1414

1515
type Props = {
1616
source: WebViewSourceUri;
17+
playgroundEnabled?: boolean;
1718
};
1819

19-
const WebviewComponent = ({ source }: Props) => {
20+
const WebviewComponent = ({ source, playgroundEnabled }: Props) => {
2021
const dispatch = useIODispatch();
2122
const [loading, setLoading] = useState(true);
2223
const [hasError, setHasError] = useState(false);
@@ -39,6 +40,10 @@ const WebviewComponent = ({ source }: Props) => {
3940
[dispatch]
4041
);
4142

43+
useEffect(() => {
44+
setHasError(false);
45+
}, [source]);
46+
4247
const handleError = (event: WebViewErrorEvent | WebViewHttpErrorEvent) => {
4348
void mixpanelTrack("CGN_LANDING_PAGE_LOAD_ERROR", {
4449
uri: source.uri,
@@ -58,7 +63,7 @@ const WebviewComponent = ({ source }: Props) => {
5863

5964
return (
6065
<>
61-
{hasError ? (
66+
{hasError && !playgroundEnabled ? (
6267
<OperationResultScreenContent
6368
testID="webview-error"
6469
pictogram="umbrella"

ts/features/settings/devMode/playgrounds/CgnLandingPlayground.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
TextInput,
1414
View
1515
} from "react-native";
16+
import { WebViewSourceUri } from "react-native-webview/lib/WebViewTypes";
1617
import WebviewComponent from "../../../../components/WebviewComponent";
1718
import { useHeaderSecondLevel } from "../../../../hooks/useHeaderSecondLevel";
1819

@@ -33,9 +34,12 @@ const styles = StyleSheet.create({
3334
});
3435

3536
const CgnLandingPlayground = () => {
36-
const [navigationURI, setNavigationUri] = useState("https://");
37+
const [navigationURI, setNavigationUri] = useState("https://google.it");
3738
const [refererValue, setRefererValue] = useState("");
38-
const [loadUri, setLoadUri] = useState("https://google.com");
39+
const [source, setSource] = useState<WebViewSourceUri>({
40+
uri: "https://google.it",
41+
headers: undefined
42+
});
3943
const [reloadKey, setReloadKey] = useState(0);
4044

4145
useHeaderSecondLevel({
@@ -83,22 +87,23 @@ const CgnLandingPlayground = () => {
8387
variant="solid"
8488
label="Invia"
8589
onPress={() => {
86-
setLoadUri(navigationURI);
90+
setSource({
91+
uri: navigationURI,
92+
headers: {
93+
"X-PagoPa-CGN-Referer": refererValue
94+
}
95+
});
8796
}}
8897
accessibilityLabel={"Invia"}
8998
/>
9099
</View>
91100
<VSpacer size={16} />
92101
<View style={{ flex: 1 }}>
93-
{loadUri !== "" && (
102+
{source && (
94103
<WebviewComponent
104+
playgroundEnabled
95105
key={`${reloadKey}_webview`}
96-
source={{
97-
uri: loadUri,
98-
headers: {
99-
"X-PagoPa-CGN-Referer": refererValue
100-
}
101-
}}
106+
source={source}
102107
/>
103108
)}
104109
</View>

0 commit comments

Comments
 (0)