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 Main = () => {
|
||||||
const isDarkMode = useColorScheme() === 'dark';
|
const isDarkMode = useColorScheme() === 'dark';
|
||||||
const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
|
const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
|
||||||
const didMount = useRef(false);
|
|
||||||
const [step, setStep] = useState(Step.Discovery);
|
const [step, setStep] = useState(Step.Discovery);
|
||||||
const [pin, setPin] = useState(null || String);
|
const [pin, setPin] = useState(null || String);
|
||||||
|
|
||||||
|
const didMount = useRef(false);
|
||||||
|
const stepRef = useRef(step);
|
||||||
|
|
||||||
const keycardConnectHandler = async () => {
|
const keycardConnectHandler = async () => {
|
||||||
try {
|
try {
|
||||||
const appInfo = await Keycard.getApplicationInfo();
|
const appInfo = await Keycard.getApplicationInfo();
|
||||||
|
|
||||||
switch (step) {
|
switch (stepRef.current) {
|
||||||
case Step.Discovery:
|
case Step.Discovery:
|
||||||
if (appInfo["initialized?"]) {
|
if (appInfo["initialized?"]) {
|
||||||
if (appInfo["has-master-key?"]) {
|
if (appInfo["has-master-key?"]) {
|
||||||
@ -39,6 +41,7 @@ const Main = () => {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Step.Initialization:
|
case Step.Initialization:
|
||||||
|
await Keycard.init(pin);
|
||||||
setStep(Step.Loading);
|
setStep(Step.Loading);
|
||||||
break;
|
break;
|
||||||
case Step.Loading:
|
case Step.Loading:
|
||||||
@ -59,9 +62,12 @@ const Main = () => {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Keycard.stopNFC("");
|
||||||
setIsModalVisible(false);
|
setIsModalVisible(false);
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
stepRef.current = step;
|
||||||
|
|
||||||
if (!didMount.current) {
|
if (!didMount.current) {
|
||||||
didMount.current = true;
|
didMount.current = true;
|
||||||
DeviceEventEmitter.addListener("keyCardOnConnected", keycardConnectHandler);
|
DeviceEventEmitter.addListener("keyCardOnConnected", keycardConnectHandler);
|
||||||
@ -87,10 +93,15 @@ const Main = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initPin = async (p: string) => {
|
||||||
|
setPin(p);
|
||||||
|
return connectCard();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={[backgroundStyle, styles.container]}>
|
<SafeAreaView style={[backgroundStyle, styles.container]}>
|
||||||
{step == Step.Discovery && <DiscoveryScreen onPressFunc={connectCard}></DiscoveryScreen>}
|
{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>
|
<NFCModal isVisible={isModalVisible} onChangeFunc={setIsModalVisible}></NFCModal>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
|
@ -3,7 +3,7 @@ import { StyleSheet, Text, View } from "react-native";
|
|||||||
import Button from "../Button";
|
import Button from "../Button";
|
||||||
|
|
||||||
type InitializationScreenProps = {
|
type InitializationScreenProps = {
|
||||||
onPressFunc: () => void;
|
onPressFunc: (pin: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const InitializationScreen: FC<InitializationScreenProps> = props => {
|
const InitializationScreen: FC<InitializationScreenProps> = props => {
|
||||||
@ -13,7 +13,7 @@ const InitializationScreen: FC<InitializationScreenProps> = props => {
|
|||||||
<View>
|
<View>
|
||||||
<View>
|
<View>
|
||||||
<Text style={styles.heading}> Hello world</Text>
|
<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>
|
<View>
|
||||||
</View>
|
</View>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user