@@ -38,8 +38,97 @@ export const ScanQRCodeView = ({ onQRCodeScanned }: ScanQRCodeViewProps) => {
3838 // Same device
3939 if ( isConnected && deviceType === 'primary' ) {
4040 changeRequestData ( decodedText ) ;
41- onQRCodeScanned ( ) ;
42- return ;
41+
42+ // Process the QR code data immediately for same-device scanning
43+ let data : string | null = null ;
44+
45+ try {
46+ if (
47+ decodedText . startsWith ( 'openid-credential-offer://' ) ||
48+ decodedText . startsWith ( 'openid://' ) ||
49+ decodedText . startsWith ( 'openid4vp://' )
50+ ) {
51+ data = decodedText ;
52+ } else {
53+ // Check if the QR code contains a Polygon Credential Offer or a Polygon Authorization Request
54+ const jsonDecodedData = JSON . parse ( decodedText ) ;
55+
56+ if ( jsonDecodedData ) {
57+ if (
58+ jsonDecodedData . type ===
59+ 'https://iden3-communication.io/authorization/1.0/request'
60+ ) {
61+ data = decodedText ;
62+ } else if (
63+ jsonDecodedData . type ===
64+ 'https://iden3-communication.io/credentials/1.0/offer'
65+ ) {
66+ data = decodedText ;
67+ }
68+ }
69+ }
70+
71+ if ( ! data ) throw new Error ( 'Unsupported QR code' ) ;
72+
73+ // Process the request data to trigger step progression
74+ const { changeRequest } = useEncryptedSessionStore . getState ( ) ;
75+
76+ if ( data . startsWith ( 'openid-credential-offer://' ) ) {
77+ changeRequest ( {
78+ active : true ,
79+ data,
80+ type : 'credentialOffer' ,
81+ finished : false ,
82+ } ) ;
83+ } else if (
84+ data . startsWith ( 'openid://' ) ||
85+ data . startsWith ( 'openid4vp://' )
86+ ) {
87+ changeRequest ( {
88+ active : true ,
89+ data,
90+ type : 'oidcAuth' ,
91+ finished : false ,
92+ } ) ;
93+ } else {
94+ const jsonDecodedData = JSON . parse ( data ) ;
95+ if (
96+ jsonDecodedData . type ===
97+ 'https://iden3-communication.io/credentials/1.0/offer'
98+ ) {
99+ changeRequest ( {
100+ active : true ,
101+ data,
102+ type : 'polygonCredentialOffer' ,
103+ finished : false ,
104+ } ) ;
105+ } else if (
106+ jsonDecodedData . type ===
107+ 'https://iden3-communication.io/authorization/1.0/request'
108+ ) {
109+ changeRequest ( {
110+ active : true ,
111+ data,
112+ type : 'polygonAuth' ,
113+ finished : false ,
114+ } ) ;
115+ }
116+ }
117+
118+ onQRCodeScanned ( ) ;
119+ return ;
120+ } catch ( e ) {
121+ setTimeout ( ( ) => {
122+ useToastStore . setState ( {
123+ open : true ,
124+ title : t ( 'error' ) ,
125+ type : 'error' ,
126+ loading : false ,
127+ link : null ,
128+ } ) ;
129+ } , 200 ) ;
130+ return ;
131+ }
43132 }
44133
45134 // Cross device (mobile <-> desktop)
0 commit comments