From 6032aebd6a658800a4fc583e01eac34a61b09ad4 Mon Sep 17 00:00:00 2001 From: Isky Date: Mon, 5 Aug 2024 15:14:41 +0800 Subject: [PATCH] Updated ScannedDataBox UI --- components/ScannedDataBox.tsx | 150 +++++++++++++++++++++------------- 1 file changed, 92 insertions(+), 58 deletions(-) diff --git a/components/ScannedDataBox.tsx b/components/ScannedDataBox.tsx index 1618179..2cd7c71 100644 --- a/components/ScannedDataBox.tsx +++ b/components/ScannedDataBox.tsx @@ -1,9 +1,7 @@ import React, { useEffect, useState } from 'react'; import { View, Text, StyleSheet, Image, TouchableOpacity, Modal, ActivityIndicator, Alert } from 'react-native'; import QRCode from 'react-native-qrcode-svg'; -import { Ionicons } from '@expo/vector-icons'; -//import * as Sharing from 'expo-sharing'; -//import * as Clipboard from 'expo-clipboard'; // >.< +import { Ionicons, MaterialCommunityIcons, SimpleLineIcons } from '@expo/vector-icons'; // Import icons import { getQRCodeDetails } from '../api/qrCodeAPI'; import SecureWebView from '../components/SecureWebView'; // Import the SecureWebView component @@ -15,6 +13,7 @@ interface ScannedDataBoxProps { const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData }) => { const [isModalVisible, setIsModalVisible] = useState(false); + const [isRedirectModalVisible, setIsRedirectModalVisible] = useState(false); const [qrDetails, setQrDetails] = useState(null); const [isWebViewVisible, setIsWebViewVisible] = useState(false); const [webViewUrl, setWebViewUrl] = useState(''); @@ -43,33 +42,21 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData ); } - // Clipboard Button KIV...cause it broke everything...... -/* const copyToClipboard = async () => { - try { - const contents = qrDetails.data?.contents || 'Undefined'; - await Clipboard.setStringAsync(contents); - Alert.alert('Copied to Clipboard', 'The QR code content has been copied to your clipboard.'); - } catch (error) { - console.error('Error copying to clipboard:', error); - } - }; - */ - // Handle cases where data might be undefined const data = qrDetails.data || {}; const details = qrDetails.details || {}; const type = data.info?.type || 'Undefined'; const contents = data.contents || 'Undefined'; - const secureConnection = details.hstsHeader?.includes('HSTS Header') ? '✔️' : '✘'; + const secureConnection = details.hstsHeader?.some((header: string) => header.includes('HSTS Header')); const redirects = details.redirect || 0; const securityHeaders = details.hstsHeader || ['No Headers']; const redirectChain = details.redirectChain || ['No Redirects']; // Determine the result text based on scan result const getResultText = () => { - if (secureConnection === '✘' || redirects > 0) { + if (!secureConnection || redirects > 0) { return 'DANGEROUS'; - } else if (secureConnection === '✔️' && redirects === 0) { + } else if (secureConnection && redirects === 0) { return 'SAFE'; } else { return 'WARNING'; @@ -90,6 +77,17 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData } }; + // Determine the appropriate icon for redirects + const getRedirectIcon = () => { + if (redirects === 0) { + return ; + } else if (redirects <= 2) { + return ; + } else { + return ; + } + }; + // Open the WebView for the URL const openWebView = (url: string) => { setWebViewUrl(url); @@ -116,20 +114,34 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData Result: {getResultText()} - + - {/* Display data type */} + {/* Display data type */} + Type: {type} + {'\n'} {/* Display scan checks */} {type === 'URL' && ( <> - Checks - Secure Connection: {secureConnection} - Redirects: {redirects} - Alert.alert('Redirect Chain', redirectChain.join('\n'))}> - Show all redirects + + {secureConnection ? ( + <> + + Secure Connection + + ) : ( + <> + + Not Secure + + )} + + setIsRedirectModalVisible(true)}> + {getRedirectIcon()} + Redirects + )} @@ -147,23 +159,8 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData )} - {/* Action buttons */} - - - - Copy - - {type === 'URL' && ( - openWebView(contents)}> - - Open - - )} - - + - {/* More information button */} - More Information setIsModalVisible(true)}> Security Headers @@ -190,6 +187,37 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData + {/* Modal for redirects */} + setIsRedirectModalVisible(false)} + > + + + Redirect Chain + {redirectChain.map((redirect, index) => ( + {redirect} + ))} + setIsRedirectModalVisible(false)}> + Close + + + + + + {/* Action buttons */} + + + {type === 'URL' && ( + openWebView(contents)}> + + Open + + )} + + {/* SecureWebView Modal */}