diff --git a/App.tsx b/App.tsx index c735d33..7c5c001 100644 --- a/App.tsx +++ b/App.tsx @@ -10,7 +10,7 @@ import CustomTabBar from './components/CustomTabBar'; const Tab = createBottomTabNavigator(); const App: React.FC = () => { - const [qrCodes, setQrCodes] = useState([]); + const [qrCodes, setQrCodes] = useState<{ data: string, bookmarked: boolean, scanResult: { secureConnection: boolean, virusTotalCheck: boolean, redirects: number } }[]>([]); const [scannedData, setScannedData] = useState(''); const clearScanData = () => { @@ -22,11 +22,13 @@ const App: React.FC = () => { } + tabBar={props => } > - {(props) => } + {(props) => } diff --git a/components/ScannedDataBox.tsx b/components/ScannedDataBox.tsx index 2a61c61..57ef1a6 100644 --- a/components/ScannedDataBox.tsx +++ b/components/ScannedDataBox.tsx @@ -11,6 +11,24 @@ interface ScannedDataBoxProps { const ScannedDataBox: React.FC = ({ data, scanResult, dataType }) => { const extractedData = data.split('\n')[1]?.split('Data: ')[1] || ''; + let resultText = 'SAFE'; + let resultColor = styles.safeResult; + + if (scanResult) { + if (!scanResult.secureConnection || !scanResult.virusTotalCheck) { + resultText = 'DANGEROUS'; + resultColor = styles.dangerousResult; + } else if (scanResult.secureConnection && scanResult.virusTotalCheck) { + resultText = 'SAFE'; + resultColor = styles.safeResult; + } else { + resultText = 'WARNING'; + resultColor = styles.warningResult; + } + } else { + resultText = 'WARNING'; + resultColor = styles.warningResult; + } return ( @@ -22,17 +40,17 @@ const ScannedDataBox: React.FC = ({ data, scanResult, dataT {new Date().toLocaleString()} - - Result: {scanResult && scanResult.positive > 0 ? 'DANGEROUS' : 'SAFE'} + + Result: {resultText} Type: {dataType} {'\n'} Checks - Secure Connection: ✘ - Virus Total Check: ✘ - Redirects: 2 + Secure Connection: {scanResult?.secureConnection ? '✔️' : '✘'} + Virus Total Check: {scanResult?.virusTotalCheck ? '✔️' : '✘'} + Redirects: {scanResult?.redirects ?? 'N/A'} @@ -93,10 +111,18 @@ const styles = StyleSheet.create({ }, resultText: { fontSize: 16, - color: '#ff0000', marginBottom: 10, textAlign: 'center', }, + safeResult: { + color: 'green', + }, + warningResult: { + color: 'orange', + }, + dangerousResult: { + color: 'red', + }, typeText: { fontSize: 16, color: '#000', diff --git a/screens/QRCodeProvider.tsx b/screens/QRCodeProvider.tsx index e69de29..2847764 100644 --- a/screens/QRCodeProvider.tsx +++ b/screens/QRCodeProvider.tsx @@ -0,0 +1,59 @@ +import React, { useState, ReactNode } from 'react'; +import { QRCodeContext } from '../types'; + +interface QRCodeProviderProps { + children: ReactNode; +} + +const testData = [ + { + data: 'Type: URL\nData: https://Safe_website.com', + bookmarked: false, + scanResult: { + secureConnection: true, + virusTotalCheck: true, + redirects: 0, + }, + }, + { + data: 'Type: URL\nData: https://unknown_website.com', + bookmarked: false, + scanResult: { + secureConnection: true, + virusTotalCheck: true, + redirects: 2, + }, + }, + { + data: 'Type: URL\nData: http://danger_website.com', + bookmarked: false, + scanResult: { + secureConnection: false, + virusTotalCheck: false, + redirects: 3, + }, + }, +]; + +export const QRCodeProvider: React.FC = ({ children }) => { + const [qrCodes, setQrCodes] = useState(testData); + const [currentScannedData, setCurrentScannedData] = useState(''); + + const toggleBookmark = (index: number) => { + setQrCodes((prev) => { + const newQrCodes = [...prev]; + newQrCodes[index].bookmarked = !newQrCodes[index].bookmarked; + return newQrCodes; + }); + }; + + const deleteQRCode = (index: number) => { + setQrCodes((prev) => prev.filter((_, i) => i !== index)); + }; + + return ( + + {children} + + ); +}; diff --git a/screens/QRScannerScreen.tsx b/screens/QRScannerScreen.tsx index 0707360..539a25c 100644 --- a/screens/QRScannerScreen.tsx +++ b/screens/QRScannerScreen.tsx @@ -244,7 +244,6 @@ const QRScannerScreen: React.FC = ({ clearScanData }) => { - {/* The CONTENT , the popup for the scanned data */} {/* This is called from ../components/ScannedDataBox*/} diff --git a/types.ts b/types.ts index cfe0721..8462059 100644 --- a/types.ts +++ b/types.ts @@ -1,11 +1,21 @@ -import { createContext } from 'react'; +import { createContext } from "react"; + +interface QRCode { + data: string; + bookmarked: boolean; + scanResult: { + secureConnection: boolean; + virusTotalCheck: boolean; + redirects: number; + }; +} interface QRCodeContextProps { - qrCodes: { data: string, bookmarked: boolean }[]; - setQrCodes: (codes: { data: string, bookmarked: boolean }[]) => void; - setCurrentScannedData: (data: string) => void; - toggleBookmark: (index: number) => void; - deleteQRCode: (index: number) => void; + qrCodes: QRCode[]; + setQrCodes: (codes: QRCode[]) => void; + setCurrentScannedData?: (data: string) => void; + toggleBookmark?: (index: number) => void; + deleteQRCode?: (index: number) => void; } export const QRCodeContext = createContext(null);