mirror of
https://github.com/status-im/keycard-exit.git
synced 2025-01-31 13:05:39 +00:00
fix step flow
This commit is contained in:
parent
deca2bea34
commit
1a5e6c9a37
17
src/Main.tsx
17
src/Main.tsx
@ -18,15 +18,17 @@ enum Step {
|
||||
const Main = () => {
|
||||
const isDarkMode = useColorScheme() === 'dark';
|
||||
const [isModalVisible, setIsModalVisible] = useState<boolean>(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 (
|
||||
<SafeAreaView style={[backgroundStyle, styles.container]}>
|
||||
{step == Step.Discovery && <DiscoveryScreen onPressFunc={connectCard}></DiscoveryScreen>}
|
||||
{step == Step.Initialization && <InitializationScreen onPressFunc={connectCard}></InitializationScreen>}
|
||||
{step == Step.Initialization && <InitializationScreen onPressFunc={initPin} ></InitializationScreen>}
|
||||
<NFCModal isVisible={isModalVisible} onChangeFunc={setIsModalVisible}></NFCModal>
|
||||
</SafeAreaView>
|
||||
);
|
||||
|
@ -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<InitializationScreenProps> = props => {
|
||||
@ -13,7 +13,7 @@ const InitializationScreen: FC<InitializationScreenProps> = props => {
|
||||
<View>
|
||||
<View>
|
||||
<Text style={styles.heading}> Hello world</Text>
|
||||
<Button label="Next" disabled={false} btnColor="#4A646C" btnWidth="100%" onChangeFunc={onPressFunc} btnJustifyContent='center'></Button>
|
||||
<Button label="Next" disabled={false} btnColor="#4A646C" btnWidth="100%" onChangeFunc={() => {onPressFunc("000000")}} btnJustifyContent='center'></Button>
|
||||
</View>
|
||||
<View>
|
||||
</View>
|
||||
|
Loading…
x
Reference in New Issue
Block a user