update nfc handling

This commit is contained in:
Michele Balistreri 2024-10-01 16:27:01 +02:00
parent b542c32e6d
commit 9c8ca28e2f
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
4 changed files with 19 additions and 21 deletions

18
package-lock.json generated
View File

@ -13,7 +13,7 @@
"react": "18.3.1", "react": "18.3.1",
"react-native": "0.75.3", "react-native": "0.75.3",
"react-native-modal": "^13.0.1", "react-native-modal": "^13.0.1",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.0", "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.1",
"react-native-vector-icons": "^10.1.0", "react-native-vector-icons": "^10.1.0",
"react-native-vision-camera": "^4.5.3" "react-native-vision-camera": "^4.5.3"
}, },
@ -6666,9 +6666,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.5.29", "version": "1.5.30",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.29.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.30.tgz",
"integrity": "sha512-PF8n2AlIhCKXQ+gTpiJi0VhcHDb69kYX4MtCiivctc2QD3XuNZ/XIOlbGzt7WAjjEev0TtaH6Cu3arZExm5DOw==", "integrity": "sha512-sXI35EBN4lYxzc/pIGorlymYNzDBOqkSlVRe6MkgBsW/hW1tpC/HDJ2fjG7XnjakzfLEuvdmux0Mjs6jHq4UOA==",
"license": "ISC" "license": "ISC"
}, },
"node_modules/emittery": { "node_modules/emittery": {
@ -7206,9 +7206,9 @@
} }
}, },
"node_modules/eslint-plugin-react": { "node_modules/eslint-plugin-react": {
"version": "7.37.0", "version": "7.37.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.37.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.37.1.tgz",
"integrity": "sha512-IHBePmfWH5lKhJnJ7WB1V+v/GolbB0rjS8XYVCSQCZKaQCAUhMoVoOEn1Ef8Z8Wf0a7l8KTJvuZg5/e4qrZ6nA==", "integrity": "sha512-xwTnwDqzbDRA8uJ7BMxPs/EXRB3i8ZfnOIp8BsxEQkT0nHPp+WWceqGgo6rKb9ctNi8GJLDT4Go5HAWELa/WMg==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -13012,8 +13012,8 @@
} }
}, },
"node_modules/react-native-status-keycard": { "node_modules/react-native-status-keycard": {
"version": "2.6.0", "version": "2.6.1",
"resolved": "git+ssh://git@github.com/status-im/react-native-status-keycard.git#7da38ff5f7c6b821445765466c40f2562b55da4b", "resolved": "git+ssh://git@github.com/status-im/react-native-status-keycard.git#2f9d46b2c720a8f2d76b510259bf8f538463ffa3",
"license": "MPL 2.0" "license": "MPL 2.0"
}, },
"node_modules/react-native-vector-icons": { "node_modules/react-native-vector-icons": {

View File

@ -16,7 +16,7 @@
"react": "18.3.1", "react": "18.3.1",
"react-native": "0.75.3", "react-native": "0.75.3",
"react-native-modal": "^13.0.1", "react-native-modal": "^13.0.1",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.0", "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.1",
"react-native-vector-icons": "^10.1.0", "react-native-vector-icons": "^10.1.0",
"react-native-vision-camera": "^4.5.3" "react-native-vision-camera": "^4.5.3"
}, },

View File

@ -37,7 +37,6 @@ const Main = () => {
const stepRef = useRef(step); const stepRef = useRef(step);
const pinRef = useRef(""); const pinRef = useRef("");
const mnemonicRef = useRef(""); const mnemonicRef = useRef("");
const isListeningCard = useRef(false);
const walletKey = useRef(""); const walletKey = useRef("");
const sessionRef = useRef("") const sessionRef = useRef("")
const challengeRef = useRef("") const challengeRef = useRef("")
@ -88,10 +87,6 @@ const Main = () => {
} }
const keycardConnectHandler = async () => { const keycardConnectHandler = async () => {
if (!isListeningCard.current) {
return;
}
var newPinCounter = pinCounter; var newPinCounter = pinCounter;
var loginReq = ""; var loginReq = "";
@ -162,8 +157,7 @@ const Main = () => {
setPinCounter(newPinCounter); setPinCounter(newPinCounter);
await Keycard.stopNFC(""); await stopNFC();
setIsModalVisible(false);
if (loginReq) { if (loginReq) {
console.log(loginReq); console.log(loginReq);
@ -189,7 +183,6 @@ const Main = () => {
useEffect(() => { useEffect(() => {
stepRef.current = step; stepRef.current = step;
isListeningCard.current = isModalVisible;
const eventEmitter = new NativeEventEmitter(Keycard); const eventEmitter = new NativeEventEmitter(Keycard);
let onConnectedListener = eventEmitter.addListener('keyCardOnConnected', keycardConnectHandler); let onConnectedListener = eventEmitter.addListener('keyCardOnConnected', keycardConnectHandler);
@ -265,6 +258,11 @@ const Main = () => {
return pinCounter == PIN_MAX_RETRY ? -1 : pinCounter; return pinCounter == PIN_MAX_RETRY ? -1 : pinCounter;
} }
const stopNFC = async () => {
await Keycard.stopNFC("");
setIsModalVisible(false);
}
return ( return (
<SafeAreaView style={styles.container}> <SafeAreaView style={styles.container}>
{step == Step.Discovery && <DiscoveryScreen onPressFunc={connectCard} onFactoryResetFunc={startFactoryReset}></DiscoveryScreen>} {step == Step.Discovery && <DiscoveryScreen onPressFunc={connectCard} onFactoryResetFunc={startFactoryReset}></DiscoveryScreen>}
@ -273,7 +271,7 @@ const Main = () => {
{step == Step.Authentication && <Dialpad pinRetryCounter={pinDisplayCounter()} prompt={"Choose PIN"} onCancelFunc={cancel} onNextFunc={authenticate}></Dialpad>} {step == Step.Authentication && <Dialpad pinRetryCounter={pinDisplayCounter()} prompt={"Choose PIN"} onCancelFunc={cancel} onNextFunc={authenticate}></Dialpad>}
{step == Step.Home && <HomeScreen walletKey={walletKey.current} onPressFunc={login} onCancelFunc={cancel}></HomeScreen>} {step == Step.Home && <HomeScreen walletKey={walletKey.current} onPressFunc={login} onCancelFunc={cancel}></HomeScreen>}
{step == Step.FactoryReset && <FactoryResetScreen pinRetryCounter={pinDisplayCounter()} onPressFunc={connectCard} onCancelFunc={cancel}></FactoryResetScreen>} {step == Step.FactoryReset && <FactoryResetScreen pinRetryCounter={pinDisplayCounter()} onPressFunc={connectCard} onCancelFunc={cancel}></FactoryResetScreen>}
<NFCModal isVisible={isModalVisible} onChangeFunc={setIsModalVisible}></NFCModal> <NFCModal isVisible={isModalVisible} onChangeFunc={stopNFC}></NFCModal>
</SafeAreaView> </SafeAreaView>
); );
} }

View File

@ -6,7 +6,7 @@ import Button from "./components/Button";
type NFCModalProps = { type NFCModalProps = {
isVisible: boolean; isVisible: boolean;
onChangeFunc: (val: boolean) => void; onChangeFunc: () => void;
}; };
const NFCModal: FC<NFCModalProps> = props => { const NFCModal: FC<NFCModalProps> = props => {
@ -20,7 +20,7 @@ const NFCModal: FC<NFCModalProps> = props => {
<Icon name="smartphone" size={40} style={modalStyle.icon}/> <Icon name="smartphone" size={40} style={modalStyle.icon}/>
</View> </View>
<Text style={modalStyle.prompt}>Tap your Keycard</Text> <Text style={modalStyle.prompt}>Tap your Keycard</Text>
<Button label="Cancel" disabled={false} btnColor="white" btnBorderColor="white" btnFontSize={13} btnBorderWidth={1} btnWidth="100%" onChangeFunc={() => onChangeFunc(!isVisible)} btnJustifyContent='center'></Button> <Button label="Cancel" disabled={false} btnColor="white" btnBorderColor="white" btnFontSize={13} btnBorderWidth={1} btnWidth="100%" onChangeFunc={() => onChangeFunc()} btnJustifyContent='center'></Button>
</View> </View>
</Modal> </Modal>
)}; )};