1
1
import { useEffect , useState , Dispatch , SetStateAction } from 'react' ;
2
2
import { useApi } from '../api' ;
3
3
import { useLocalStorageKeystore } from '../services/LocalStorageKeystore' ;
4
+ import { useTranslation } from 'react-i18next' ;
4
5
6
+ export enum HandleOutboundRequestError {
7
+ INSUFFICIENT_CREDENTIALS = "INSUFFICIENT_CREDENTIALS" ,
8
+ }
5
9
6
10
function useCheckURL ( urlToCheck : string ) : {
7
11
showSelectCredentialsPopup : boolean ,
@@ -10,7 +14,11 @@ function useCheckURL(urlToCheck: string): {
10
14
conformantCredentialsMap : any ,
11
15
showPinInputPopup : boolean ,
12
16
setShowPinInputPopup : Dispatch < SetStateAction < boolean > > ,
13
- verifierDomainName : string
17
+ verifierDomainName : string ,
18
+ showMessagePopup : boolean ;
19
+ setMessagePopup : Dispatch < SetStateAction < boolean > > ;
20
+ textMessagePopup : { title : string , description : string } ;
21
+ typeMessagePopup : string ;
14
22
} {
15
23
const api = useApi ( ) ;
16
24
const isLoggedIn : boolean = api . isLoggedIn ( ) ;
@@ -19,8 +27,11 @@ function useCheckURL(urlToCheck: string): {
19
27
const [ selectionMap , setSelectionMap ] = useState < string | null > ( null ) ;
20
28
const [ conformantCredentialsMap , setConformantCredentialsMap ] = useState ( null ) ;
21
29
const [ verifierDomainName , setVerifierDomainName ] = useState ( "" ) ;
22
-
30
+ const [ showMessagePopup , setMessagePopup ] = useState < boolean > ( false ) ;
31
+ const [ textMessagePopup , setTextMessagePopup ] = useState < { title : string , description : string } > ( { title : "" , description : "" } ) ;
32
+ const [ typeMessagePopup , setTypeMessagePopup ] = useState < string > ( "" ) ;
23
33
const keystore = useLocalStorageKeystore ( ) ;
34
+ const { t } = useTranslation ( ) ;
24
35
25
36
useEffect ( ( ) => {
26
37
@@ -29,8 +40,14 @@ function useCheckURL(urlToCheck: string): {
29
40
const wwwallet_camera_was_used = new URL ( url ) . searchParams . get ( 'wwwallet_camera_was_used' ) ;
30
41
31
42
const res = await api . post ( '/communication/handle' , { url, camera_was_used : ( wwwallet_camera_was_used != null && wwwallet_camera_was_used === 'true' ) } ) ;
32
- const { redirect_to, conformantCredentialsMap, verifierDomainName, preauth, ask_for_pin } = res . data ;
33
-
43
+ const { redirect_to, conformantCredentialsMap, verifierDomainName, preauth, ask_for_pin, error } = res . data ;
44
+ if ( error && error == HandleOutboundRequestError . INSUFFICIENT_CREDENTIALS ) {
45
+ console . error ( `${ HandleOutboundRequestError . INSUFFICIENT_CREDENTIALS } ` ) ;
46
+ setTextMessagePopup ( { title : `${ t ( 'messagePopup.insufficientCredentials.title' ) } ` , description : `${ t ( 'messagePopup.insufficientCredentials.description' ) } ` } ) ;
47
+ setTypeMessagePopup ( 'error' ) ;
48
+ setMessagePopup ( true ) ;
49
+ return false ;
50
+ }
34
51
if ( preauth && preauth == true ) {
35
52
if ( ask_for_pin ) {
36
53
setShowPinInputPopup ( true ) ;
@@ -65,7 +82,7 @@ function useCheckURL(urlToCheck: string): {
65
82
66
83
if ( urlToCheck && isLoggedIn && window . location . pathname === "/cb" ) {
67
84
( async ( ) => {
68
- await communicationHandler ( urlToCheck ) ;
85
+ await communicationHandler ( urlToCheck ) ;
69
86
} ) ( ) ;
70
87
}
71
88
@@ -89,7 +106,7 @@ function useCheckURL(urlToCheck: string): {
89
106
}
90
107
} , [ api , keystore , selectionMap ] ) ;
91
108
92
- return { showSelectCredentialsPopup, setShowSelectCredentialsPopup, setSelectionMap, conformantCredentialsMap, showPinInputPopup, setShowPinInputPopup, verifierDomainName } ;
109
+ return { showSelectCredentialsPopup, setShowSelectCredentialsPopup, setSelectionMap, conformantCredentialsMap, showPinInputPopup, setShowPinInputPopup, verifierDomainName, showMessagePopup , setMessagePopup , textMessagePopup , typeMessagePopup } ;
93
110
}
94
111
95
112
export default useCheckURL ;
0 commit comments