diff --git a/components/ScannedDataBox.tsx b/components/ScannedDataBox.tsx index af1fe5a..01e7fc1 100644 --- a/components/ScannedDataBox.tsx +++ b/components/ScannedDataBox.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { View, Text, StyleSheet, Image, TouchableOpacity, Modal, ActivityIndicator, ScrollView, Dimensions, Clipboard, Platform, Animated } from 'react-native'; +import { View, Text, StyleSheet, Image, TouchableOpacity, Modal, ActivityIndicator, ScrollView, Dimensions, Clipboard, Platform, Animated } from 'react-native'; import QRCode from 'react-native-qrcode-svg'; import { Ionicons, MaterialCommunityIcons, SimpleLineIcons } from '@expo/vector-icons'; import { getQRCodeDetails } from '../api/qrCodeAPI'; @@ -7,7 +7,6 @@ import SecureWebView from '../components/SecureWebView'; import { startActivityAsync, ActivityAction } from 'expo-intent-launcher'; import * as Linking from 'expo-linking'; - const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); interface ScannedDataBoxProps { @@ -19,15 +18,13 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData const [isModalVisible, setIsModalVisible] = useState(false); const [isRedirectModalVisible, setIsRedirectModalVisible] = useState(false); const [isContentModalVisible, setIsContentModalVisible] = useState(false); + const [isTrackingModalVisible, setIsTrackingModalVisible] = useState(false); const [qrDetails, setQrDetails] = useState(null); const [isWebViewVisible, setIsWebViewVisible] = useState(false); const [webViewUrl, setWebViewUrl] = useState(''); const [error, setError] = useState(null); // State to store error message const [bannerOpacity] = useState(new Animated.Value(0)); // State for banner opacity - - - useEffect(() => { const fetchQRDetails = async () => { try { @@ -70,8 +67,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData }); }; - - const data = qrDetails.data || {}; const details = qrDetails.details || {}; const type = data.info?.type || 'Undefined'; @@ -86,7 +81,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData const isShorteningService = details.shorteningService === 'Yes'; const classification = details.classifications || 'Unknown'; - // Function to get security text and icon based on the URL description const getSecurityStatus = () => { if (data.info?.description === "Secure Uniform Resource Locator") { @@ -103,10 +97,7 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData }; const { text: securityText, icon: securityIcon } = getSecurityStatus(); - - - - // Function to get result text and color based on the security status + // Function to get result text and color based on the security status const getResultStatus = () => { if (result === 'UNSAFE') { return { text: 'UNSAFE', color: '#ff5942' }; // Red @@ -122,9 +113,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData }; const { text: resultText, color: resultColor } = getResultStatus(); - - - // Function to determine security header status const getSecurityHeaderStatus = (headers) => { const filteredHeaders = headers.filter( @@ -148,8 +136,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData }; const redirectStatus = getRedirectStatus(details.redirect || 0); - - // Truncate content string to specified length const truncateContent = (content: string, length: number) => { if (content.length > length) { @@ -158,7 +144,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData return content; }; - // Function to get encryption status and icon const getEncryptionStatus = (encryption) => { if (encryption === 'NO') { @@ -186,7 +171,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData const { text: encryptionText, icon: encryptionIcon } = getEncryptionStatus(encryption); - // Function to open the Wi-Fi configuration in the OS const handleOpenUrl = (url: string) => { Linking.openURL(url).catch(err => console.error('Error opening URL:', err)); @@ -216,9 +200,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData } }; - - - const sslStrippingStatus = { hasSSLStripping: details.sslStripping?.some(status => status === true) ?? false, text: details.sslStripping?.some(status => status === true) @@ -227,40 +208,23 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData color: details.sslStripping?.some(status => status === true) ? "#ff5942" : "#44c167", // Green for No SSL Stripping }; - // Log to check what's happening - console.log('SSL Stripping Details:', details.sslStripping); - console.log('SSL Stripping Status:', sslStrippingStatus); - const hasExecutableStatus = { hasExecutable: details.hasExecutable ?? false, text: details.hasExecutable ? "Executable Detected" : "No Executable", - color: details.hasExecutable ? "#FFA500" : "#44c167", + color: details.hasExecutable ? "#ffa500" : "#44c167", // Orange for Executable Detected + iconName: details.hasExecutable ? "alert-circle" : "shield-checkmark", // Orange shield icon for Executable Detected }; - - - // Log to check what's happening - console.log('Executable Details:', details.hasExecutable); - console.log('Executable Status:', hasExecutableStatus); const trackingStatus = { - hasTracking: details.tracking ?? false, - text: details.tracking ? "Tracking Detected" : "No Tracking", - color: details.tracking ? "#ff5942" : "#44c167", // Green for No Tracking + hasTracking: details.trackingDescriptions?.length > 0 ?? false, + text: details.trackingDescriptions?.length > 0 ? "Tracking Detected" : "No Tracking", + color: details.trackingDescriptions?.length > 0 ? "#ff5942" : "#44c167", // Red for Tracking Detected }; - // Log to check what's happening - console.log('Tracking Details:', details.tracking); - console.log('Tracking Status:', trackingStatus); const redirectCount = details.redirect ?? 0; // Default to 0 if undefined - - - return ( - - - @@ -274,7 +238,7 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData - {/* Display QR Code , timestamp and Description */} + {/* Display QR Code, timestamp and Description */} @@ -282,11 +246,10 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData {data.createdAt ? new Date(data.createdAt).toLocaleString() : 'Invalid Date'} Description: {description} - {/* Conditionally display the shortening service message */} - {isShorteningService && ( - This is a shortening service - )} - + {/* Conditionally display the shortening service message */} + {isShorteningService && ( + This is a shortening service + )} @@ -295,79 +258,83 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData Result: {resultText} - {/* URL Type */} {type === 'URL' && ( <> - - Classification: {classification} - + + Classification: {classification} + - {/* Left Container */} - - - {securityIcon} - {securityText} - + {/* Left Container */} + + + {securityIcon} + {securityText} + - {securityHeaderStatus.hasHeaders ? ( - setIsModalVisible(true)}> - - {securityHeaderStatus.text} - - - ) : ( - - - {securityHeaderStatus.text} - - )} + {securityHeaderStatus.hasHeaders ? ( + setIsModalVisible(true)}> + + {securityHeaderStatus.text} + + + ) : ( + + + {securityHeaderStatus.text} + + )} - {/* Redirects Button */} - {redirectCount > 0 ? ( - setIsRedirectModalVisible(true)}> - - {`Redirects: ${redirectCount}`} - - - ) : ( - - - {`Redirects: ${redirectCount}`} - - )} - + {/* Redirects Button */} + {redirectCount > 0 ? ( + setIsRedirectModalVisible(true)}> + + {`Redirects: ${redirectCount}`} + + + ) : ( + + + {`Redirects: ${redirectCount}`} + + )} + - {/* Vertical Divider */} - + {/* Vertical Divider */} + - {/* Right Container */} - - - - {sslStrippingStatus.text} - - -{/* Executtable checking */} - {hasExecutableStatus.hasExecutable ? ( - - - {hasExecutableStatus.text} - -) : ( - - - {hasExecutableStatus.text} - -)} - - - - - - {trackingStatus.text} - - + {/* Right Container */} + + + + {sslStrippingStatus.text} + + {/* Executtable checking */} + {hasExecutableStatus.hasExecutable ? ( + + + {hasExecutableStatus.text} + + ) : ( + + + {hasExecutableStatus.text} + + )} + {/* Tracking checking */} + {trackingStatus.hasTracking ? ( + setIsTrackingModalVisible(true)}> + + {trackingStatus.text} + + + ) : ( + + + {trackingStatus.text} + + )} + {/* Divider */} @@ -394,44 +361,37 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData - {/* Redirect Chain Pop UP */} - setIsRedirectModalVisible(false)} -> - - - Redirect Chain - - {details.redirectChain?.map((redirect: string, index: number) => ( - - {redirect} - - ))} - - setIsRedirectModalVisible(false)}> - Close - - - - - + {/* Redirect Chain Pop UP */} + setIsRedirectModalVisible(false)} + > + + + Redirect Chain + + {details.redirectChain?.map((redirect: string, index: number) => ( + + {redirect} + + ))} + + setIsRedirectModalVisible(false)}> + Close + + + + )} - - - - - {/* WIFI Type */} - {type === 'WIFI' && ( <> {/* SSID */} @@ -467,10 +427,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData )} - - - - {type === 'PHONE Nume' && ( Linking.openURL(contents)}> @@ -507,8 +463,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData )} - - {/* Full Content Modal */} = ({ qrCodeId, clearScanData - - - - {/*POP UP Security Header and Redirect button*/} + {/* POP UP Security Header and Redirect button */} {/* Security Headers Modal */} = ({ qrCodeId, clearScanData - - {/* WebView Modal */} = ({ qrCodeId, clearScanData + + {/* Tracking Descriptions Modal */} + setIsTrackingModalVisible(false)} +> + + + Tracking Descriptions + + {details.trackingDescriptions?.map((description: string, index: number) => ( + + {description} + + ))} + + setIsTrackingModalVisible(false)}> + Close + + + + ); }; @@ -665,6 +642,7 @@ const styles = StyleSheet.create({ borderColor: '#ff69b4', width: '100%', // Make it take full width }, + // Display check styles // Aligning the boxes displayCheck: { @@ -678,6 +656,7 @@ const styles = StyleSheet.create({ marginVertical: screenWidth * 0.01875, width: '100%', // Make it take full width }, + // Details info text styles DetailsInfo: { fontSize: screenWidth * 0.026, @@ -740,7 +719,6 @@ const styles = StyleSheet.create({ flexGrow: 1, // Ensure the content container expands to fit its children }, - // Close modal button styles closeModalButton: { marginTop: screenWidth * 0.0375, @@ -874,6 +852,6 @@ const styles = StyleSheet.create({ textAlign: 'center', marginTop: screenWidth * 0.01875, // Add some spacing above }, - }); -export default ScannedDataBox; \ No newline at end of file + +export default ScannedDataBox;