Skip to content

Commit

Permalink
Revert "improve NFC reading UX on android #130"
Browse files Browse the repository at this point in the history
  • Loading branch information
remicolin committed Aug 11, 2024
1 parent 86c38b8 commit d363a33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,6 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
import com.facebook.react.bridge.LifecycleEventListener
import com.facebook.react.bridge.Callback

object Messages {
const val SCANNING = "Scanning....."
const val STOP_MOVING = "Stop moving....."
const val AUTH = "Auth....."
const val COMPARING = "Comparing....."
const val COMPLETED = "Scanning completed"
const val RESET = ""
}

class Response(json: String) : JSONObject(json) {
val type: String? = this.optString("type")
val data = this.optJSONArray("data")
Expand Down Expand Up @@ -180,7 +171,6 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)

@ReactMethod
fun scan(opts: ReadableMap, promise: Promise) {
eventMessageEmitter(Messages.SCANNING)
val mNfcAdapter = NfcAdapter.getDefaultAdapter(reactApplicationContext)
// val mNfcAdapter = NfcAdapter.getDefaultAdapter(this.reactContext)
if (mNfcAdapter == null) {
Expand Down Expand Up @@ -271,7 +261,6 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)

override fun doInBackground(vararg params: Void?): Exception? {
try {
eventMessageEmitter(Messages.STOP_MOVING)
isoDep.timeout = 10000
Log.e("MY_LOGS", "This should obvsly log")
val cardService = CardService.getInstance(isoDep)
Expand Down Expand Up @@ -360,7 +349,7 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)
// e.printStackTrace()
// }
// Log.d(TAG, "============LET'S VERIFY THE SIGNATURE=============")
eventMessageEmitter(Messages.AUTH)

doChipAuth(service)
doPassiveAuth()

Expand All @@ -383,7 +372,6 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)
imageBase64 = Base64.encodeToString(buffer, Base64.DEFAULT)
}
} catch (e: Exception) {
eventMessageEmitter(Messages.RESET)
return e
}
return null
Expand Down Expand Up @@ -421,11 +409,8 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)

val dataHashes = sodFile.dataGroupHashes

eventMessageEmitter("Reading DG14.....")
val dg14Hash = if (chipAuthSucceeded) digest.digest(dg14Encoded) else ByteArray(0)
eventMessageEmitter("Reading DG1.....")
val dg1Hash = digest.digest(dg1File.encoded)
eventMessageEmitter("Reading DG2.....")
val dg2Hash = digest.digest(dg2File.encoded)

// val gson = Gson()
Expand All @@ -447,7 +432,7 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)
// Log.d(TAG, "dg2HashjoinToString " + gson.toJson(dg2Hash.joinToString("") { "%02x".format(it) }))

Log.d(TAG, "Comparing data group hashes...")
eventMessageEmitter(Messages.COMPARING)

if (Arrays.equals(dg1Hash, dataHashes[1]) && Arrays.equals(dg2Hash, dataHashes[2])
&& (!chipAuthSucceeded || Arrays.equals(dg14Hash, dataHashes[14]))) {

Expand Down Expand Up @@ -513,7 +498,6 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)
Log.d(TAG, "Passive authentication success: $passiveAuthSuccess")
}
} catch (e: Exception) {
eventMessageEmitter(Messages.RESET)
Log.w(TAG, "Exception in passive authentication", e)
}
}
Expand Down Expand Up @@ -554,7 +538,6 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)
val certificateBytes = certificate.encoded
val certificateBase64 = Base64.encodeToString(certificateBytes, Base64.DEFAULT)
Log.d(TAG, "certificateBase64: ${certificateBase64}")


passport.putString("documentSigningCertificate", certificateBase64)

Expand Down Expand Up @@ -631,9 +614,7 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)
passport.putMap("photo", photo)
// passport.putString("dg2File", gson.toJson(dg2File))

eventMessageEmitter(Messages.COMPLETED)
scanPromise?.resolve(passport)
eventMessageEmitter(Messages.RESET)
resetState()
}
}
Expand All @@ -650,16 +631,6 @@ class RNPassportReaderModule(private val reactContext: ReactApplicationContext)
}
}

private fun eventMessageEmitter(message: String) {
if (reactContext.hasActiveCatalystInstance()) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("NativeEvent", message)
} else {
Log.d(TAG, "Error")
}
}

companion object {
private val TAG = RNPassportReaderModule::class.java.simpleName
private const val PARAM_DOC_NUM = "documentNumber";
Expand Down
40 changes: 7 additions & 33 deletions app/src/screens/MainScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useState, useEffect } from 'react';
import { NativeEventEmitter, NativeModules, Linking, Modal, Platform, Pressable } from 'react-native';
import { YStack, XStack, Text, Button, Tabs, Sheet, Label, Fieldset, Input, Switch, H2, Image, useWindowDimensions, H4, H3, View, Separator } from 'tamagui'
import { HelpCircle, IterationCw, VenetianMask, Cog, CheckCircle2, ChevronLeft, Share, Eraser, ArrowRight, UserPlus, CalendarSearch, X } from '@tamagui/lucide-icons';
import Telegram from '../images/telegram.png'
import Github from '../images/github.png'
import Internet from "../images/internet.png"
import { Linking, Modal, Platform, Pressable } from 'react-native';
import forge from 'node-forge';
import Dialog from "react-native-dialog";
import { ethers } from 'ethers';
// import ressources
import { YStack, XStack, Text, Button, Tabs, Sheet, Label, Fieldset, Input, Switch, H2, Image, useWindowDimensions, H4, H3, Separator } from 'tamagui'
import { HelpCircle, IterationCw, VenetianMask, Cog, CheckCircle2, ChevronLeft, Share, Eraser, CalendarSearch, Cross, X, UserPlus, Wifi, ArrowRight } from '@tamagui/lucide-icons';
import Xlogo from '../images/x.png'
import Telegram from '../images/telegram.png'
import Github from '../images/github.png'
import Internet from "../images/internet.png"
import NFC_IMAGE from '../images/nfc.png'
import { ToastViewport } from '@tamagui/toast';
import { ToastMessage } from '../components/ToastMessage';
Expand Down Expand Up @@ -40,12 +40,6 @@ import AppScreen from './AppScreen';
import { RPC_URL, SignatureAlgorithm } from '../../../common/src/constants/constants';
import { mock_csca_sha256_rsa_4096, mock_dsc_sha256_rsa_4096 } from '../../../common/src/constants/mockCertificates';

const { nativeModule } = NativeModules;
let emitter: NativeEventEmitter | null = null;

if (Platform.OS === 'android') {
emitter = new NativeEventEmitter(nativeModule);
}
import DatePicker from 'react-native-date-picker'
import StartScreen from './StartScreen';
import CustomButton from '../components/CustomButton';
Expand All @@ -56,7 +50,6 @@ import WrongProofScreen from './WrongProofScreen';

const MainScreen: React.FC = () => {
const [NFCScanIsOpen, setNFCScanIsOpen] = useState(false);
const [scanningMessage, setScanningMessage] = useState('');
const [displayOtherOptions, setDisplayOtherOptions] = useState(false);
const [SettingsIsOpen, setSettingsIsOpen] = useState(false);
const [DialogContributeIsOpen, setDialogContributeIsOpen] = useState(false);
Expand Down Expand Up @@ -208,20 +201,6 @@ const MainScreen: React.FC = () => {
setDialogDeleteSecretIsOpen(false);
}

useEffect(() => {
const handleNativeEvent = (event: string) => {
setScanningMessage(event);
};

if (Platform.OS === 'android' && emitter) {
const subscription = emitter.addListener('NativeEvent', handleNativeEvent);

return () => {
subscription.remove();
};
}
}, []);

useEffect(() => {
if (cscaProof && (modalProofStep === ModalProofSteps.MODAL_SERVER_SUCCESS)) {
console.log('CSCA Proof received:', cscaProof);
Expand Down Expand Up @@ -367,13 +346,8 @@ const MainScreen: React.FC = () => {
<Sheet open={nfcSheetIsOpen} onOpenChange={setNfcSheetIsOpen} dismissOnSnapToBottom modal dismissOnOverlayPress={false} disableDrag animation="medium" snapPoints={[35]}>
<Sheet.Overlay />
<Sheet.Frame>

<YStack gap="$5" f={1} pt="$3">
<View>
<H2 textAlign='center'>Ready to scan</H2>
<Text textAlign='center'>{scanningMessage}</Text>
</View>

<H2 textAlign='center'>Ready to scan</H2>
{step >= Steps.NEXT_SCREEN ?
<CheckCircle2
size="$8"
Expand Down
Loading

0 comments on commit d363a33

Please sign in to comment.