import React, { useState, useEffect } from 'react' import { getLicenseFlag, saveEncryptionFlag } from '../local-storage' import { openDb } from '../db' import App from './app' import AppLoadingView from './common/app-loading' import AppStatusBar from './common/app-status-bar' import AcceptLicense from './AcceptLicense' import PasswordPrompt from './PasswordPrompt' export default function AppWrapper() { const [isLoading, setIsLoading] = useState(true) const [isLicenseAccepted, setIsLicenseAccepted] = useState(false) const [isDbEncrypted, setIsDbEncrypted] = useState(false) const checkIsLicenseAccepted = async () => { const isLicenseFlagSet = await getLicenseFlag() setIsLicenseAccepted(isLicenseFlagSet) setIsLoading(false) } const checkIsDbEncrypted = async () => { const isEncrypted = !(await openDb()) if (isEncrypted) setIsDbEncrypted(true) await saveEncryptionFlag(isEncrypted) } useEffect(() => { checkIsLicenseAccepted() checkIsDbEncrypted() }, []) if (isLoading) { return } if (!isLicenseAccepted) { return setIsLicenseAccepted(true)} /> } return ( <> {isDbEncrypted ? ( setIsDbEncrypted(false)} /> ) : ( checkIsDbEncrypted()} /> )} ) }