189 lines
6.3 KiB
TypeScript
189 lines
6.3 KiB
TypeScript
// Metro module 6758 (f6759).
|
|
import { useRef, useState, useCallback, useEffect, useMemo } from "react";
|
|
import { View } from "react-native";
|
|
import { AGE_VERIFICATION_MODAL_KEY } from "../AgeVerificationConstants";
|
|
import { AgeVerificationIncodeResultStatus, buildIncodeFallbackSessionInjection, parseIncodeWebViewMessage } from "../AgeVerificationIncodeWebViewConstants";
|
|
import Logger from "../../debug/Logger";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import { isModalOpen } from "../../main_tabs_v2/helpers/NavigationRouteUtils.native";
|
|
import { useWatchAgeVerificationStatusChange, isAgeVerified } from "../AgeVerificationUtils";
|
|
import { registerIncodeInterview, requestIncodeSessionBootstrap } from "../AgeVerificationURLActionCreators";
|
|
import Linking from "../../../lib/native/Linking";
|
|
import Module6759 from "../../../_bundle/Module6759";
|
|
import { ActivityIndicator } from "../../../design/components/ActivityIndicator/native/ActivityIndicator.native";
|
|
let c4343_12 = new Logger("AgeVerificationWebViewScreen");
|
|
const useStyles = createStyles({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: Module712.colors.BACKGROUND_BASE_LOWEST
|
|
},
|
|
loadingOverlay: {
|
|
position: "absolute",
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
backgroundColor: Module712.colors.BACKGROUND_BASE_LOWEST
|
|
},
|
|
webView: {
|
|
flex: 1,
|
|
backgroundColor: Module712.colors.BACKGROUND_BASE_LOWEST
|
|
}
|
|
});
|
|
export default function AgeVerificationWebViewScreen(props) {
|
|
let callback2, callback3, memo;
|
|
const { webviewUrl, onComplete, onClose, injectedJavaScriptBeforeContentLoaded } = props;
|
|
callback2 = void 0;
|
|
callback3 = void 0;
|
|
memo = void 0;
|
|
const ref = useRef(null);
|
|
const ref2 = useRef(false);
|
|
const ref3 = useRef(false);
|
|
let [state, setState] = useState(true);
|
|
const callback = useCallback(() => {
|
|
if (!ref3.current) {
|
|
ref3.current = true;
|
|
setState(false);
|
|
}
|
|
}, []);
|
|
useEffect(() => {
|
|
let c25992_0 = setTimeout(() => {
|
|
if (!ref3.current) {
|
|
c4343_12.warn("WebView initial load timed out", {
|
|
timeoutMs: 15000
|
|
});
|
|
}
|
|
callback();
|
|
}, 15000);
|
|
return () => clearTimeout(c25992_0);
|
|
}, [callback]);
|
|
callback2 = useCallback(() => {
|
|
if (!ref2.current) {
|
|
ref2.current = true;
|
|
onComplete();
|
|
onClose();
|
|
}
|
|
}, [onComplete, onClose]);
|
|
useWatchAgeVerificationStatusChange(useCallback(() => {
|
|
if (isModalOpen(AGE_VERIFICATION_MODAL_KEY) && isAgeVerified()) {
|
|
callback2();
|
|
}
|
|
}, [callback2]));
|
|
callback3 = useCallback((a0) => {
|
|
const current = ref.current;
|
|
if (current != null) {
|
|
current.injectJavaScript(buildIncodeFallbackSessionInjection(a0));
|
|
}
|
|
}, []);
|
|
const callback4 = useCallback((a0) => {
|
|
L14: {
|
|
L13: {
|
|
L16: {
|
|
L11: {
|
|
try {
|
|
const r10 = parseIncodeWebViewMessage(a0.nativeEvent.data);
|
|
if (r10 == null) {
|
|
break L14;
|
|
}
|
|
if (r10.kind === "capture_complete") {
|
|
registerIncodeInterview(r10.interviewId).then(() => {
|
|
const current = ref2.current;
|
|
if (current ? !current : isAgeVerified()) {
|
|
callback2();
|
|
}
|
|
}).catch((a0) => {
|
|
c4343_12.warn("Failed to register Incode interview from WebView", {
|
|
error: a0
|
|
});
|
|
});
|
|
break L13;
|
|
}
|
|
if (r10.kind === "fallback_request") {
|
|
requestIncodeSessionBootstrap({
|
|
previousInterviewId: r10.previousInterviewId
|
|
}).then(({ incode_parameters }) => {
|
|
if (incode_parameters?.session_token != null && incode_parameters.interview_id != null) {
|
|
callback3({
|
|
sessionToken: incode_parameters.session_token,
|
|
interviewId: incode_parameters.interview_id
|
|
});
|
|
} else {
|
|
callback3({
|
|
error: true
|
|
});
|
|
}
|
|
}).catch((a0) => {
|
|
c4343_12.warn("Failed to bootstrap Incode fallback session from WebView", {
|
|
error: a0
|
|
});
|
|
callback3({
|
|
error: true
|
|
});
|
|
});
|
|
break L11;
|
|
}
|
|
if (r10.status !== AgeVerificationIncodeResultStatus.COMPLETED) {
|
|
if (ref2.current) {
|
|
break L16;
|
|
}
|
|
ref2.current = true;
|
|
onClose();
|
|
break L16;
|
|
}
|
|
callback2();
|
|
} catch ($e) {
|
|
c4343_12.warn("Failed to parse WebView message", {
|
|
error: $e
|
|
});
|
|
break L16;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
}, [callback2, callback3, onClose]);
|
|
memo = useMemo(() => new URL(webviewUrl).origin, [webviewUrl]);
|
|
const callback5 = useCallback((a0) => {
|
|
let origin;
|
|
if (a0.isTopFrame != null && !a0.isTopFrame) {
|
|
return true;
|
|
}
|
|
try {
|
|
origin = new URL(a0.url).origin;
|
|
} catch ($e) {
|
|
origin = null;
|
|
}
|
|
let r19 = origin === memo;
|
|
if (!r19) {
|
|
Linking.openURL(a0.url);
|
|
r19 = false;
|
|
}
|
|
return r19;
|
|
}, [memo]);
|
|
const styles = useStyles();
|
|
const r80 = [<Module6759 ref={ref} allowsInlineMediaPlayback mediaCapturePermissionGrantType="grant" javaScriptEnabled source={{
|
|
uri: webviewUrl
|
|
}} onShouldStartLoadWithRequest={callback5} onMessage={callback4} onError={(event) => {
|
|
c4343_12.warn("WebView load error", {
|
|
code: event.nativeEvent.code
|
|
});
|
|
callback();
|
|
}} onLoadEnd={() => {
|
|
callback();
|
|
}} injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded} style={styles.webView} containerStyle={styles.webView} />, ,];
|
|
if (state) {
|
|
state = <View style={styles.loadingOverlay}>
|
|
<ActivityIndicator />
|
|
</View>;
|
|
}
|
|
r80[1] = state;
|
|
return <View style={styles.container}>{r80}</View>;
|
|
};
|