diff --git a/src/Main.tsx b/src/Main.tsx index 6c2e6a2..1917859 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -18,15 +18,17 @@ enum Step { const Main = () => { const isDarkMode = useColorScheme() === 'dark'; const [isModalVisible, setIsModalVisible] = useState(false); - const didMount = useRef(false); const [step, setStep] = useState(Step.Discovery); const [pin, setPin] = useState(null || String); + const didMount = useRef(false); + const stepRef = useRef(step); + const keycardConnectHandler = async () => { try { const appInfo = await Keycard.getApplicationInfo(); - switch (step) { + switch (stepRef.current) { case Step.Discovery: if (appInfo["initialized?"]) { if (appInfo["has-master-key?"]) { @@ -39,6 +41,7 @@ const Main = () => { } break; case Step.Initialization: + await Keycard.init(pin); setStep(Step.Loading); break; case Step.Loading: @@ -59,9 +62,12 @@ const Main = () => { console.log(err); } + await Keycard.stopNFC(""); setIsModalVisible(false); } useEffect(() => { + stepRef.current = step; + if (!didMount.current) { didMount.current = true; DeviceEventEmitter.addListener("keyCardOnConnected", keycardConnectHandler); @@ -87,10 +93,15 @@ const Main = () => { } } + const initPin = async (p: string) => { + setPin(p); + return connectCard(); + } + return ( {step == Step.Discovery && } - {step == Step.Initialization && } + {step == Step.Initialization && } ); diff --git a/src/components/steps/InitializationScreen.tsx b/src/components/steps/InitializationScreen.tsx index 3a9ab15..d857a8d 100644 --- a/src/components/steps/InitializationScreen.tsx +++ b/src/components/steps/InitializationScreen.tsx @@ -3,7 +3,7 @@ import { StyleSheet, Text, View } from "react-native"; import Button from "../Button"; type InitializationScreenProps = { - onPressFunc: () => void; + onPressFunc: (pin: string) => void; }; const InitializationScreen: FC = props => { @@ -13,7 +13,7 @@ const InitializationScreen: FC = props => { Hello world - +