Skip to content

Commit 79adebf

Browse files
Merge pull request #258 from ManojNathIC/multi-issuer-selection
Task #249332 feat: add issuer field to document uploads and fix issue
2 parents 77c5fcc + 554d428 commit 79adebf

File tree

8 files changed

+1191
-873
lines changed

8 files changed

+1191
-873
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@
7272
"typescript": "^5.5.3",
7373
"typescript-eslint": "^8.18.0",
7474
"vite": "^5.4.8"
75-
}
75+
},
76+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
7677
}

src/components/DocumentScanner.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface Document {
2828
label: string;
2929
documentSubType: string;
3030
docType: string;
31+
issuer?: string;
3132
}
3233

3334
interface UserDocument {
@@ -152,6 +153,7 @@ const DocumentScanner: React.FC<DocumentScannerProps> = ({
152153
label: doc.label,
153154
documentSubType: doc.documentSubType,
154155
docType: doc.docType,
156+
issuer: doc.issuer,
155157
}));
156158
setDocuments(formattedDocuments);
157159
} catch (error) {
@@ -214,6 +216,7 @@ const DocumentScanner: React.FC<DocumentScannerProps> = ({
214216
imported_from: 'QR Code',
215217
doc_datatype: 'Application/JSON',
216218
doc_data_link: vcUrl,
219+
issuer: docConfig.issuer,
217220
},
218221
];
219222

@@ -228,7 +231,7 @@ const DocumentScanner: React.FC<DocumentScannerProps> = ({
228231
title: t('DOCUMENT_SCANNER_SUCCESS_TITLE'),
229232
description: t('DOCUMENT_SCANNER_SUCCESS_UPLOAD'),
230233
status: 'success',
231-
duration: 3000,
234+
duration: 3000,
232235
isClosable: true,
233236
});
234237

@@ -242,7 +245,8 @@ const DocumentScanner: React.FC<DocumentScannerProps> = ({
242245
if (Array.isArray(apiErrors) && apiErrors.length > 0) {
243246
const errorMessages =
244247
apiErrors.length === 1
245-
? (apiErrors[0].error ?? t('DOCUMENT_SCANNER_ERROR_UNEXPECTED'))
248+
? (apiErrors[0].error ??
249+
t('DOCUMENT_SCANNER_ERROR_UNEXPECTED'))
246250
: apiErrors
247251
.map(
248252
(errObj, idx) =>

src/components/common/UploadDocumentEwallet.tsx

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import { getDocumentsList, getUser } from '../../services/auth/auth';
44
import { AuthContext } from '../../utils/context/checkToken';
55
import CommonButton from './button/Button';
66
import { useTranslation } from 'react-i18next';
7-
import { Box, Text, Alert, AlertIcon, IconButton, useToast, Progress } from '@chakra-ui/react';
7+
import {
8+
Box,
9+
Text,
10+
Alert,
11+
AlertIcon,
12+
IconButton,
13+
useToast,
14+
Progress,
15+
} from '@chakra-ui/react';
816
import { ArrowBackIcon } from '@chakra-ui/icons';
917

1018
// Type definitions for better type safety
@@ -30,6 +38,7 @@ interface UploadPayload {
3038
imported_from: string;
3139
doc_datatype: string;
3240
doc_data_link: string;
41+
issuer?: string;
3342
}
3443

3544
interface ProcessResult {
@@ -118,7 +127,9 @@ const UploadDocumentEwallet = () => {
118127
new URL(VITE_EWALLET_IFRAME_SRC);
119128
} catch (error) {
120129
console.error('Invalid wallet URL configuration:', error);
121-
setError('Invalid wallet URL configuration. Please check your environment variables.');
130+
setError(
131+
'Invalid wallet URL configuration. Please check your environment variables.'
132+
);
122133
return;
123134
}
124135

@@ -134,21 +145,25 @@ const UploadDocumentEwallet = () => {
134145
// Send authentication data to iframe
135146
const sendAuthToIframe = () => {
136147
if (!iframeRef.current) return;
137-
148+
138149
// Get specific wallet authentication data
139150
const walletToken = localStorage.getItem('walletToken');
140151
const userStr = localStorage.getItem('user');
141-
152+
142153
if (!walletToken || !userStr) {
143-
setError('Wallet authentication data not found. Please ensure wallet is properly configured.');
154+
setError(
155+
'Wallet authentication data not found. Please ensure wallet is properly configured.'
156+
);
144157
return;
145158
}
146159

147160
let user;
148161
try {
149162
user = JSON.parse(userStr);
150163
} catch {
151-
setError('Invalid user data found. Please check wallet configuration.');
164+
setError(
165+
'Invalid user data found. Please check wallet configuration.'
166+
);
152167
return;
153168
}
154169

@@ -239,6 +254,7 @@ const UploadDocumentEwallet = () => {
239254
imported_from: 'e-wallet',
240255
doc_datatype: 'Application/JSON',
241256
doc_data_link: doc_data_link,
257+
issuer: 'dhiway',
242258
},
243259
];
244260
};
@@ -268,18 +284,29 @@ const UploadDocumentEwallet = () => {
268284
Failed to Upload:
269285
</Text>
270286
{failedDocs.map((doc, idx) => {
271-
const showFullError = doc.fullError && doc.error === 'Document type not accepted';
287+
const showFullError =
288+
doc.fullError &&
289+
doc.error === 'Document type not accepted';
272290
return (
273291
<Box key={doc.docName ?? idx} ml={2} mb={2}>
274292
<Text color="red.700" fontWeight="semibold">
275293
{doc.docName}
276294
</Text>
277295
{showFullError ? (
278-
<Text ml={4} fontSize="sm" mt={1} color="red.600">
296+
<Text
297+
ml={4}
298+
fontSize="sm"
299+
mt={1}
300+
color="red.600"
301+
>
279302
{doc.fullError}
280303
</Text>
281304
) : (
282-
<Text ml={4} fontSize="sm" color="red.600">
305+
<Text
306+
ml={4}
307+
fontSize="sm"
308+
color="red.600"
309+
>
283310
{doc.error}
284311
</Text>
285312
)}
@@ -316,12 +343,19 @@ const UploadDocumentEwallet = () => {
316343
} else {
317344
parsedJson = vc.json;
318345
}
319-
const documentName = parsedJson?.credentialSchema?.title ?? 'Unknown document';
346+
const documentName =
347+
parsedJson?.credentialSchema?.title ?? 'Unknown document';
320348
let errorMessage;
321-
if (docError instanceof Error && docError.message.includes('does not match any of the accepted document types')) {
349+
if (
350+
docError instanceof Error &&
351+
docError.message.includes(
352+
'does not match any of the accepted document types'
353+
)
354+
) {
322355
errorMessage = 'Document type not accepted';
323356
} else if (isApiError(docError)) {
324-
errorMessage = docError.response?.data?.message || 'API error occurred';
357+
errorMessage =
358+
docError.response?.data?.message || 'API error occurred';
325359
} else if (docError instanceof Error) {
326360
errorMessage = docError.message;
327361
} else {
@@ -331,7 +365,7 @@ const UploadDocumentEwallet = () => {
331365
success: false,
332366
docName: documentName,
333367
error: errorMessage,
334-
fullError: docError instanceof Error ? docError.message : undefined
368+
fullError: docError instanceof Error ? docError.message : undefined,
335369
};
336370
};
337371

@@ -408,23 +442,31 @@ const UploadDocumentEwallet = () => {
408442

409443
// Listen for messages from the iframe
410444
useEffect(() => {
411-
const processingToastIdRef = { current: undefined as string | number | undefined };
445+
const processingToastIdRef = {
446+
current: undefined as string | number | undefined,
447+
};
412448

413449
const handleMessage = async (event: MessageEvent) => {
414450
if (event.origin !== VITE_EWALLET_ORIGIN) return;
415451

416452
try {
417453
// Type check the event data structure
418454
if (!event.data || typeof event.data !== 'object') {
419-
console.warn('Received invalid message format:', event.data);
455+
console.warn(
456+
'Received invalid message format:',
457+
event.data
458+
);
420459
return;
421460
}
422461

423462
const { type, data } = event.data;
424463
console.log('Received message from wallet:', type, data);
425464

426465
if (!type || typeof type !== 'string') {
427-
console.warn('Received message without valid type:', event.data);
466+
console.warn(
467+
'Received message without valid type:',
468+
event.data
469+
);
428470
return;
429471
}
430472

@@ -442,7 +484,11 @@ const UploadDocumentEwallet = () => {
442484
}
443485
toast({
444486
title: 'Error',
445-
description: (error instanceof Error ? error.message : undefined) ?? 'Failed to process documents',
487+
description:
488+
(error instanceof Error
489+
? error.message
490+
: undefined) ??
491+
'Failed to process documents',
446492
status: 'error',
447493
duration: 5000,
448494
isClosable: true,
@@ -548,7 +594,9 @@ const UploadDocumentEwallet = () => {
548594
setTimeout(() => sendAuthToIframe());
549595
}}
550596
onError={() => {
551-
setError('Failed to load wallet interface. Please check your connection and try again.');
597+
setError(
598+
'Failed to load wallet interface. Please check your connection and try again.'
599+
);
552600
}}
553601
allow="camera"
554602
style={{
@@ -582,7 +630,11 @@ const UploadDocumentEwallet = () => {
582630
textAlign="center"
583631
maxW="sm"
584632
>
585-
<Text mb={4} fontSize="lg" fontWeight="medium">
633+
<Text
634+
mb={4}
635+
fontSize="lg"
636+
fontWeight="medium"
637+
>
586638
Processing Documents...
587639
</Text>
588640
<Progress

src/locales/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@
146146
"DOCUMENTCONFIG_VC_FIELDS_PLACEHOLDER": "{\"field1\": {\"type\": \"string\"}, \"field2\": {\"type\": \"number\"}}",
147147
"DOCUMENTCONFIG_ISSUE_VC_LABEL": "Issue VC",
148148
"DOCUMENTCONFIG_DOC_QR_CONTAINS_LABEL": "Doc QR Contains",
149+
"DOCUMENTCONFIG_ISSUER_LABEL": "Document Issuer",
150+
"DOCUMENTCONFIG_SELECT_DOCTYPE_FIRST": "Select document type first",
151+
"DOCUMENTCONFIG_LOADING_ISSUERS": "Loading issuers...",
152+
"DOCUMENTCONFIG_ISSUERS_FAILED": "Failed to load issuers",
153+
"DOCUMENTCONFIG_NO_ISSUERS_AVAILABLE": "No issuers available for this document type",
154+
"DOCUMENTCONFIG_SELECT_ISSUER": "Select issuer",
155+
"DOCUMENTCONFIG_FETCH_ISSUERS_ERROR": "Failed to fetch issuers",
149156
"EDITPROFILE_ANNUAL_INCOME_LABEL": "Annual Income",
150157
"EDITPROFILE_BANK_ACCOUNT_HOLDER_NAME_LABEL": "Bank Account Holder Name",
151158
"EDITPROFILE_BANK_ACCOUNT_NUMBER_HELP": "Enter valid 9-18 digit account number",

0 commit comments

Comments
 (0)