import * as React from 'react'; import { Alert, SafeAreaView } from 'react-native'; import { connect } from "react-redux"; import { WebView } from 'react-native-webview'; import { Container } from 'native-base'; import Elements from '../../components/elements' import Theme from '../../components/theme.style.js'; import CustomSafeArea from '../../components/safeArea.component'; class VerificationWebview extends React.Component { constructor(props) { super(props); } state = { loading: false, onBack: false, verificationUrl: this.props.route.params?.verificationUrl, referenceNumber: this.props.route.params?.referenceNumber } componentDidMount() { } componentWillUnmount() { } onStateChange = (webViewState) => { let url = webViewState.url; if(url.includes('https://unioil.com/success') && !webViewState.loading) { if(this.state.onBack) return; this.setState({ onBack: true }); this.props.route.params?.onSuccessAuthentication(this.state.referenceNumber) setTimeout(() => { return this.props.navigation.pop(2); }, 500); } if(url.includes('https://unioil.com/failure') && !webViewState.loading) { if(this.state.onBack) return; this.setState({ onBack: true }); Alert.alert("Error", "Error adding card"); return this.props.navigation.goBack(); } } render() { return ( this.onStateChange(webViewState)} /> ) } } const mapStateToProps = (state) => { return { userinfo: state.appUserInfoReducer.userinfo, app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(VerificationWebview)