@@ -16,6 +16,12 @@ import {
16
16
import { useEffect , useState } from 'react' ;
17
17
import { circuitInputsFromQR } from '../../src/generateInputs' ;
18
18
19
+ const Toast = ( { message } : { message : string } ) => (
20
+ < View style = { styles . toastContainer } >
21
+ < Text style = { styles . toastText } > { message } </ Text >
22
+ </ View >
23
+ ) ;
24
+
19
25
export default function BenchmarkView ( { setupReady } : { setupReady : boolean } ) {
20
26
const [ complexProof , setComplexProof ] = useState < string | null > ( null ) ;
21
27
const [ publicInputs , setPublicInputs ] = useState < string | null > ( null ) ;
@@ -25,12 +31,21 @@ export default function BenchmarkView({ setupReady }: { setupReady: boolean }) {
25
31
const [ isVerifyingSig , setIsVerifyingSig ] = useState < boolean > ( false ) ;
26
32
const [ isQrScanned , setIsQrScanned ] = useState < boolean > ( false ) ;
27
33
const [ sigVerified , setSigVerified ] = useState < boolean > ( false ) ;
34
+ const [ errorToastMessage , setErrorToastMessage ] = useState < string | null > (
35
+ null
36
+ ) ;
28
37
const [ anonAadhaarArgs , setAnonAadhaarArgs ] = useState < {
29
- aadhaarData : string [ ] ;
30
- aadhaarDataLength : string [ ] ;
38
+ qrDataPadded : string [ ] ;
39
+ qrDataPaddedLength : string [ ] ;
40
+ nonPaddedDataLength : string [ ] ;
41
+ delimiterIndices : string [ ] ;
31
42
signature : string [ ] ;
32
43
pubKey : string [ ] ;
33
44
signalHash : string [ ] ;
45
+ revealGender : string [ ] ;
46
+ revealAgeAbove18 : string [ ] ;
47
+ revealState : string [ ] ;
48
+ revealPinCode : string [ ] ;
34
49
} | null > ( null ) ;
35
50
const [ qrCodeValue , setQrCodeValue ] = useState < string > ( '' ) ;
36
51
const [ executionTime , setExecutionTime ] = useState < {
@@ -59,25 +74,52 @@ export default function BenchmarkView({ setupReady }: { setupReady: boolean }) {
59
74
}
60
75
} , [ qrCodeValue ] ) ;
61
76
77
+ const showToast = ( message : string ) => {
78
+ setErrorToastMessage ( message ) ;
79
+ setTimeout ( ( ) => setErrorToastMessage ( null ) , 3000 ) ; // hide after 3 seconds
80
+ } ;
81
+
62
82
const genProof = async ( ) => {
63
- setIsProving ( true ) ;
64
- const startProof = Date . now ( ) ;
65
- const { proof, inputs } = await generateProof ( anonAadhaarArgs ) ;
66
- setComplexProof ( proof ) ;
67
- setPublicInputs ( inputs ) ;
68
- setExecutionTime ( ( prev ) => ( { ...prev , proof : Date . now ( ) - startProof } ) ) ;
69
- setIsProving ( false ) ;
83
+ try {
84
+ setIsProving ( true ) ;
85
+ const startProof = Date . now ( ) ;
86
+ const { proof, inputs } = await generateProof ( anonAadhaarArgs ) ;
87
+ setComplexProof ( proof ) ;
88
+ setPublicInputs ( inputs ) ;
89
+ setExecutionTime ( ( prev ) => ( { ...prev , proof : Date . now ( ) - startProof } ) ) ;
90
+ setIsProving ( false ) ;
91
+ } catch ( e ) {
92
+ if ( e instanceof Error ) {
93
+ showToast ( e . message ) ;
94
+ } else {
95
+ throw new Error ( 'generateProof: something went wrong!' ) ;
96
+ }
97
+ }
70
98
} ;
71
99
72
100
const verifProof = async ( _proof : any , _publicInputs : any ) => {
73
- const startVerif = Date . now ( ) ;
74
- const res = await verifyProof ( _proof , _publicInputs ) ;
75
- setProofVerified ( res ) ;
76
- setExecutionTime ( ( prev ) => ( { ...prev , verify : Date . now ( ) - startVerif } ) ) ;
101
+ try {
102
+ const startVerif = Date . now ( ) ;
103
+ const res = await verifyProof ( _proof , _publicInputs ) ;
104
+ console . log ( 'Verification result: ' , res ) ;
105
+ setProofVerified ( res ) ;
106
+ setExecutionTime ( ( prev ) => ( {
107
+ ...prev ,
108
+ verify : Date . now ( ) - startVerif ,
109
+ } ) ) ;
110
+ } catch ( e ) {
111
+ if ( e instanceof Error ) {
112
+ showToast ( e . message ) ;
113
+ } else {
114
+ throw new Error ( 'verifProof: something went wrong!' ) ;
115
+ }
116
+ }
77
117
} ;
78
118
79
119
return (
80
120
< View style = { styles . container } >
121
+ { errorToastMessage && < Toast message = { errorToastMessage } /> }
122
+
81
123
< Text style = { styles . title } > Anon Aadhaar Mobile</ Text >
82
124
< View style = { styles . statusRow } >
83
125
< View
@@ -209,4 +251,19 @@ const styles = StyleSheet.create({
209
251
justifyContent : 'center' ,
210
252
alignItems : 'center' ,
211
253
} ,
254
+ toastContainer : {
255
+ position : 'absolute' ,
256
+ bottom : 50 ,
257
+ left : 20 ,
258
+ right : 20 ,
259
+ backgroundColor : 'red' ,
260
+ padding : 15 ,
261
+ borderRadius : 5 ,
262
+ alignItems : 'center' ,
263
+ justifyContent : 'center' ,
264
+ zIndex : 1000 , // Make sure it's above other elements
265
+ } ,
266
+ toastText : {
267
+ color : 'white' ,
268
+ } ,
212
269
} ) ;
0 commit comments