import React, { useEffect, useState } from 'react'; import { View, Text, StyleSheet, Image, TouchableOpacity, Modal, ActivityIndicator, ScrollView, Dimensions, Linking, Clipboard } from 'react-native'; import QRCode from 'react-native-qrcode-svg'; import { Ionicons, MaterialCommunityIcons, SimpleLineIcons } from '@expo/vector-icons'; import { getQRCodeDetails } from '../api/qrCodeAPI'; import SecureWebView from '../components/SecureWebView'; const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); interface ScannedDataBoxProps { qrCodeId: string; clearScanData: () => void; } const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData }) => { const [isModalVisible, setIsModalVisible] = useState(false); const [isRedirectModalVisible, setIsRedirectModalVisible] = useState(false); const [isContentModalVisible, setIsContentModalVisible] = useState(false); const [qrDetails, setQrDetails] = useState(null); const [isWebViewVisible, setIsWebViewVisible] = useState(false); const [webViewUrl, setWebViewUrl] = useState(''); useEffect(() => { const fetchQRDetails = async () => { try { const details = await getQRCodeDetails(qrCodeId); setQrDetails(details.qrcode); console.log('details for scannedDataBOX:', details); } catch (error) { console.error('Error fetching QR details:', error); } }; if (qrCodeId) { fetchQRDetails(); } }, [qrCodeId]); if (!qrDetails) { return ( ); } const data = qrDetails.data || {}; const details = qrDetails.details || {}; const type = data.info?.type || 'Undefined'; const contents = data.contents || 'Undefined'; const result = data.result || 'Unknown'; const ssid = details.ssid || 'Undefined'; const encryption = details.encryption || 'NO'; const hidden = details.hidden ? 'Hidden' : 'Visible'; // Function to get security text and icon based on the URL description const getSecurityStatus = () => { if (data.info?.description === "Secure Uniform Resource Locator") { return { text: 'Secure Connection', icon: }; } else { return { text: 'Not Secure', icon: }; } }; const { text: securityText, icon: securityIcon } = getSecurityStatus(); // Function to get result text and color based on the security status const getResultStatus = () => { if (result === 'UNSAFE') { return { text: 'DANGEROUS', color: '#ff0000' }; // Red } else if (result === 'SAFE') { return { text: 'SAFE', color: '#44c167' }; // Green } else if (result === 'WARNING') { return { text: 'WARNING', color: '#ffa500' }; // Orange } else if (result === '') { return { text: 'UNKNOWN', color: '#000000' }; // Black for unknown } else { return { text: 'UNKNOWN', color: '#000000' }; // Default to Black for unknown } }; const { text: resultText, color: resultColor } = getResultStatus(); // Function to determine security header status const getSecurityHeaderStatus = (headers) => { const filteredHeaders = headers.filter( (header) => header !== "Not an HTTPS connection" && header !== "No HSTS Header detected" ); if (filteredHeaders.length > 0) { return { text: 'Security Headers', color: '#44c167', hasHeaders: true }; // Green with headers } else { return { text: 'No Security Headers', color: '#ffa500', hasHeaders: false }; // Orange without headers } }; const securityHeaderStatus = getSecurityHeaderStatus(details.hstsHeader || []); // Truncate content string to specified length const truncateContent = (content: string, length: number) => { if (content.length > length) { return `${content.substring(0, length)}...`; } return content; }; // 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)); }; // Function to copy text content to clipboard const handleCopyToClipboard = () => { Clipboard.setString(contents); }; // Function to send SMS const handleSendSMS = () => { const smsUrl = `sms:${contents}`; Linking.openURL(smsUrl).catch(err => console.error('Error sending SMS:', err)); }; // Function to make a phone call const handleMakeCall = () => { const telUrl = `tel:${contents}`; Linking.openURL(telUrl).catch(err => console.error('Error making call:', err)); }; return ( {/* The Top Scan Icon with payload, truncated */} setIsContentModalVisible(true)}> {truncateContent(contents, 30)} {/* Display QR Code , timestamp and Description */} {data.createdAt ? new Date(data.createdAt).toLocaleString() : 'Invalid Date'} Description: {type} {/* The Main Result in appropriate color */} Result: {resultText} {/* URL Type */} {type === 'URL' && ( <> {securityIcon} {securityText} {/* Security Headers Button */} {securityHeaderStatus.hasHeaders ? ( setIsModalVisible(true)}> {securityHeaderStatus.text} ) : ( {securityHeaderStatus.text} )} {/* Redirects Button */} setIsRedirectModalVisible(true)}> 1 ? "#ff0000" : "#44c167"} /> Redirects {/* Divider */} {/* Action Buttons */} Copy Link handleOpenUrl(contents)}> Open Link { setWebViewUrl(contents); setIsWebViewVisible(true); }}> SecureWebView )} {/* WIFI Type */} {type === 'WIFI' && ( <> SSID: {ssid} Encryption: {encryption} Visibility: {hidden === 'Hidden' ? '✔️' : '❌'} )} {/* TEXT Type */} {type === 'TEXT' && ( Copy )} {/* SMS Type */} {type === 'SMS' && ( Send SMS )} {/* TEL Type */} {type === 'TEL' && ( Call )} {/* Full Content Modal */} setIsContentModalVisible(false)} > Full Content {contents} setIsContentModalVisible(false)}> Close {/*POP UP Security Header and Redirect button*/} {/* Security Headers Modal */} setIsModalVisible(false)} > Security Headers {details.hstsHeader?.map((header: string, index: number) => ( {header} ))} setIsModalVisible(false)}> Close {/* Redirect Chain Modal */} setIsRedirectModalVisible(false)} > Redirect Chain {details.redirectChain?.map((redirect: string, index: number) => ( {redirect} ))} setIsRedirectModalVisible(false)}> Close {/* WebView Modal */} setIsWebViewVisible(false)} > setIsWebViewVisible(false)}> Close ); }; const styles = StyleSheet.create({ row: { flexDirection: 'row', alignItems: 'center', }, scan_icon: { width: screenWidth * 0.09, height: screenWidth * 0.09, marginRight: screenWidth * 0.015, }, payload: { fontSize: screenWidth * 0.0375, color: '#000', flex: 1, }, dataBox: { padding: screenWidth * 0.0375, backgroundColor: '#ffe6f0', borderRadius: screenWidth * 0.01875, shadowColor: '#000', shadowOffset: { width: 0, height: screenHeight * 0.001875 }, shadowOpacity: 0.15, shadowRadius: screenWidth * 0.01875, elevation: screenWidth * 0.0135, zIndex: 1, }, mainContent: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', padding: screenWidth * 0.0525, }, qrSection: { flex: 1, alignItems: 'center', }, dividerVertical: { width: screenWidth * 0.001875, height: '100%', backgroundColor: '#ddd', marginHorizontal: screenWidth * 0.025, }, detailsSection: { flex: 2, }, timestampText: { fontSize: screenWidth * 0.03, color: '#000', marginBottom: screenWidth * 0.01875, }, resultText: { fontSize: screenWidth * 0.045, marginBottom: screenWidth * 0.01875, textAlign: 'center', }, typeText: { fontSize: screenWidth * 0.03, color: '#000', marginBottom: screenWidth * 0.01875, }, moreInfoButtonText: { fontSize: screenWidth * 0.03, color: '#000', marginLeft: screenWidth * 0.01875, }, iconContainer: { flexDirection: 'row', justifyContent: 'space-around', alignItems: 'center', marginTop: screenWidth * 0.01875, }, iconButton: { flexDirection: 'column', alignItems: 'center', marginHorizontal: screenWidth * 0.05, // Add margin between buttons }, iconText: { color: '#2196F3', marginTop: screenWidth * 0.01, textAlign: 'center', fontSize: screenWidth * 0.03, }, dividerHorizontal: { width: '100%', height: 1, backgroundColor: '#ddd', marginVertical: screenWidth * 0.025, }, moreInfoButton: { flexDirection: 'row', alignItems: 'center', paddingVertical: screenWidth * 0.01875, paddingHorizontal: screenWidth * 0.028125, backgroundColor: '#ffe6f0', borderRadius: screenWidth * 0.01875, marginTop: screenWidth * 0.01875, borderWidth: 1, borderColor: '#ff69b4', }, displayCheck: { flexDirection: 'row', alignItems: 'center', paddingVertical: screenWidth * 0.01875, paddingHorizontal: screenWidth * 0.028125, backgroundColor: '#ffe6f0', borderRadius: screenWidth * 0.01875, marginTop: screenWidth * 0.01875, }, closeButton: { position: 'absolute', top: screenWidth * 0.01875, right: screenWidth * 0.01875, zIndex: 2, }, modalContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0, 0, 0, 0.5)', }, modalContent: { width: '80%', backgroundColor: 'white', borderRadius: screenWidth * 0.01875, padding: screenWidth * 0.0375, alignItems: 'center', }, modalTitle: { fontSize: screenWidth * 0.045, fontWeight: 'bold', marginBottom: screenWidth * 0.01875, }, modalText: { fontSize: screenWidth * 0.03, marginBottom: screenWidth * 0.009375, textAlign: 'left', width: '100%', }, modalScrollContent: { maxHeight: 200, }, closeModalButton: { marginTop: screenWidth * 0.0375, paddingVertical: screenWidth * 0.01875, paddingHorizontal: screenWidth * 0.0375, backgroundColor: '#ff69b4', borderRadius: screenWidth * 0.009375, }, chevronIcon: { marginLeft: 'auto', }, closeModalButtonText: { fontSize: screenWidth * 0.03, color: '#fff', }, loadingContainer: { justifyContent: 'center', alignItems: 'center', }, webViewContainer: { width: '100%', height: '80%', backgroundColor: 'white', borderRadius: screenWidth * 0.01875, overflow: 'hidden', }, shadowBox: { shadowColor: '#000', shadowOffset: { width: 0, height: screenHeight * 0.001875 }, shadowOpacity: 0.15, shadowRadius: screenWidth * 0.01875, elevation: screenWidth * 0.0135, }, }); export default ScannedDataBox;