Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs/exposure key count #972

Merged
merged 3 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MainActivity extends ReactActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashTheme);
SplashScreen.show(this);
super.onCreate(savedInstanceState);

bluetoothHelper = new BluetoothHelper(new BluetoothHelper.BluetoothCallback() {
Expand Down
2 changes: 1 addition & 1 deletion ios/BT/ExposureManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ final class ExposureManager: NSObject {

typealias ExposureKeysDictionaryArray = [[String: Any]]

/// Requests the temporary exposure keys used by this device to share with a server. Returns an array of the exposures keys as dictionary or and error if the underlying API fails
/// Requests the temporary exposure keys used by this device to share with a server. Returns an array of the exposures keys as dictionary or an error if the underlying API fails
@objc func fetchExposureKeys(callback: @escaping (ExposureKeysDictionaryArray?, ExposureManagerError?) -> Void) {
getDiagnosisKeys(transform: { (keys) -> ExposureKeysDictionaryArray in
(keys ?? []).map { $0.asDictionary }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.16.1",
"react-native-simple-crypto": "^0.2.15",
"react-native-splash-screen": "^3.2.0",
"react-native-splash-screen": "^3.3.0",
"react-native-static-safe-area-insets": "^2.1.1",
"react-native-svg": "^12.0.3",
"react-native-webview": "^11.2.0",
Expand Down
47 changes: 46 additions & 1 deletion src/ExposureContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import * as NativeModule from "./gaen/nativeModule"
type Posix = number

export interface ExposureState {
exposureKeyDate: Date
exposureKeyCheckCount: number
exposureInfo: ExposureInfo
exposureKeys: ExposureKey[]
getCurrentExposures: () => Promise<ExposureInfo>
getExposureKeys: () => Promise<ExposureKey[]>
getRevisionToken: () => Promise<string>
Expand All @@ -28,6 +31,9 @@ export interface ExposureState {
}

const initialState = {
exposureKeyDate: new Date(),
exposureKeyCheckCount: 0,
exposureKeys: [],
exposureInfo: [],
getCurrentExposures: () => {
return Promise.resolve([])
Expand All @@ -51,9 +57,13 @@ const initialState = {
export const ExposureContext = createContext<ExposureState>(initialState)

const ExposureProvider: FunctionComponent = ({ children }) => {
console.log("exposurePRovider start")
const { trackEvent } = useProductAnalyticsContext()

const [exposureInfo, setExposureInfo] = useState<ExposureInfo>([])
const [exposureKeyDate, setExposureKeyDate] = useState<Date>(new Date())
const [exposureKeyCheckCount, setExposureKeyCheckCount] = useState<number>(0)
const [exposureKeys, setExposureKeys] = useState<ExposureKey[]>([])

const [
lastExposureDetectionDate,
Expand Down Expand Up @@ -95,6 +105,38 @@ const ExposureProvider: FunctionComponent = ({ children }) => {
setLastExposureDetectionDate(detectionDate)
}, [])

const getExposureKeys = useCallback(async (): Promise<ExposureKey[]> => {
const newDate = new Date()
// reset if date bad
if (exposureKeyDate.getUTCDate() != newDate.getUTCDate()) {
console.log("resetting keys date")
setExposureKeyCheckCount(0)
}

// ensure date is set
setExposureKeyDate(newDate)

// if date is less than 3 grab it
if (exposureKeyCheckCount < 3) {
console.log("getting new keys")
// increment key check count
setExposureKeyCheckCount(exposureKeyCheckCount + 1)

//get keys
const keys = await NativeModule.getExposureKeys()

//set keys
setExposureKeys(keys)

return keys || []
}

console.log("returning cached keys")

// fall through return keys in state
return exposureKeys || []
}, [])

const detectExposures = async (): Promise<NativeModule.DetectExposuresResponse> => {
const response = await NativeModule.detectExposures()
if (response.kind === "success") {
Expand Down Expand Up @@ -141,12 +183,15 @@ const ExposureProvider: FunctionComponent = ({ children }) => {
return (
<ExposureContext.Provider
value={{
exposureKeyDate,
exposureKeyCheckCount,
exposureKeys,
exposureInfo,
lastExposureDetectionDate,
refreshExposureInfo,
detectExposures,
getCurrentExposures: NativeModule.getCurrentExposures,
getExposureKeys: NativeModule.getExposureKeys,
getExposureKeys,
getRevisionToken: NativeModule.getRevisionToken,
storeRevisionToken: NativeModule.storeRevisionToken,
}}
Expand Down
3 changes: 3 additions & 0 deletions src/factories/exposureContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Factory } from "fishery"
import { ExposureState } from "../ExposureContext"

export default Factory.define<ExposureState>(() => ({
exposureKeyDate: new Date(),
exposureKeyCheckCount: 0,
exposureInfo: [],
exposureKeys: [],
getCurrentExposures: () => Promise.resolve([]),
getExposureKeys: () => Promise.resolve([]),
lastExposureDetectionDate: null,
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7283,9 +7283,10 @@ react-native-simple-crypto@^0.2.15:
base64-js "^1.3.0"
hex-lite "^1.5.0"

react-native-splash-screen@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.2.0.tgz#d47ec8557b1ba988ee3ea98d01463081b60fff45"
react-native-splash-screen@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.3.0.tgz#3af71ed17afe50fee69590a45aec399d071ead02"
integrity sha512-rGjt6HkoSXxMqH4SQUJ1gnPQlPJV8+J47+4yhgTIan4bVvAwJhEeJH7wWt9hXSdH4+VfwTS0GTaflj1Tw83IhA==

react-native-static-safe-area-insets@^2.1.1:
version "2.1.1"
Expand Down