Skip to content

Commit

Permalink
[INJIWEB-920]: exception handling for secure time bound storage (mosi…
Browse files Browse the repository at this point in the history
…p#172)

* [INJIWEB-920]: exception handling for secure time bound storage

Signed-off-by: Vijay <[email protected]>

* [INJIWEB-980]: correct start command in the package.json

Signed-off-by: Vijay <[email protected]>

* [INJIWEB-980]: add translation for the literals involved in toast

Signed-off-by: Vijay <[email protected]>

---------

Signed-off-by: Vijay <[email protected]>
  • Loading branch information
vijay151096 authored Oct 24, 2024
1 parent 5b84f8a commit 47d18e5
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Testing the Layouts of ItemBox Check if the layout is matching with the snapshots 1`] = `
<DocumentFragment>
<div
class="bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-110 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center"
class="bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-105 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center"
data-testid="ItemBox-Outer-Container-1"
role="menuitem"
tabindex="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Testing the Layout of Credentials Check if the layout is matching with the snapshots 1`] = `
<DocumentFragment>
<div
class="bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-110 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center"
class="bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-105 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center"
data-testid="ItemBox-Outer-Container-1"
role="menuitem"
tabindex="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Testing the layout of Issuer Component Check if the layout is matching with the snapshots 1`] = `
<DocumentFragment>
<div
class="bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-110 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center"
class="bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-105 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center"
data-testid="ItemBox-Outer-Container-1"
role="menuitem"
tabindex="0"
Expand Down
2 changes: 1 addition & 1 deletion inji-web/src/components/Common/ItemBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const ItemBox: React.FC<ItemBoxProps> = (props) => {
return <React.Fragment>
<div key={props.index}
data-testid={`ItemBox-Outer-Container-${props.index}`}
className={`bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-110 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center`}
className={`bg-iw-tileBackground w-48 h-48 flex flex-col shadow hover:shadow-lg hover:scale-105 hover:shadow-iw-selectedShadow p-5 m-4 rounded-md cursor-pointer items-center`}
onClick={props.onClick}
onKeyUp={props.onClick}
tabIndex={0}
Expand Down
7 changes: 3 additions & 4 deletions inji-web/src/components/Credentials/Crendential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {CredentialProps} from "../../types/components";
import {CodeChallengeObject, CredentialConfigurationObject} from "../../types/data";
import {RootState} from "../../types/redux";
import {DataShareExpiryModal} from "../../modals/DataShareExpiryModal";
import {storage} from "../../utils/storage";

export const Credential: React.FC<CredentialProps> = (props) => {
const selectedIssuer = useSelector((state: RootState) => state.issuers);
Expand All @@ -19,15 +18,15 @@ export const Credential: React.FC<CredentialProps> = (props) => {
const credentialObject = getObjectForCurrentLanguage(filteredCredentialConfig.display, language);
const vcStorageExpiryLimitInTimes = useSelector((state: RootState) => state.common.vcStorageExpiryLimitInTimes);

const onSuccess = () => {
const onSuccess = (defaultVCStorageExpiryLimit: number = vcStorageExpiryLimitInTimes) => {
const state = generateRandomString();
const code_challenge: CodeChallengeObject = generateCodeChallenge(state);
window.open(api.authorization(selectedIssuer.selected_issuer, props.credentialWellknown, filteredCredentialConfig, state, code_challenge), '_self', 'noopener');
addNewSession({
selectedIssuer: selectedIssuer.selected_issuer,
certificateId: props.credentialId,
codeVerifier: state,
vcStorageExpiryLimitInTimes: vcStorageExpiryLimitInTimes ?? 1,
vcStorageExpiryLimitInTimes: defaultVCStorageExpiryLimit,
state: state,
});
}
Expand All @@ -36,7 +35,7 @@ export const Credential: React.FC<CredentialProps> = (props) => {
<ItemBox index={props.index}
url={credentialObject.logo.url}
title={credentialObject.name}
onClick={() => setCredentialExpiry(true)}/>
onClick={() => {selectedIssuer.selected_issuer.qr_code_type === 'OnlineSharing' ? setCredentialExpiry(true) : onSuccess(-1)} } />
{ credentialExpiry &&
<DataShareExpiryModal onCancel={() => setCredentialExpiry(false)}
onSuccess={onSuccess}
Expand Down
2 changes: 1 addition & 1 deletion inji-web/src/components/DataShare/DataShareContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const DataShareContent:React.FC<DSContentProps> = (props) => {
<div className="relative flex mb-4" onClick={()=>setTimesDropDown(times => !times)}>
<div className={"w-1/3"}></div>
<div className={"w-2/3 py-4 px-4 rounded-lg border-2 border-iw-borderLight flex flex-row items-center"}>
<label className={"w-full h-full"} data-testId={"DataShareContent-Selected-Validity-Times"}>{getExpiryDisplayName(vcStorageExpiryLimitInTimes)}</label>
<label className={"w-full h-full"} data-testid={"DataShareContent-Selected-Validity-Times"}>{getExpiryDisplayName(vcStorageExpiryLimitInTimes)}</label>
<MdOutlineKeyboardArrowDown size={30} color={'var(--iw-color-arrowDown)'} />
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions inji-web/src/components/DataShare/DataShareFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const DataShareFooter:React.FC<DSFooterProps> = (props) => {
className="w-1/2 text-iw-primary font-bold px-6 mr-2 border-2 border-iw-primary py-2 text-sm outline-1 shadow hover:shadow-lg focus:outline-none ease-linear rounded-lg transition-all duration-150"
type="button"
data-testid={"DataShareFooter-Cancel-Button"}
onClick={props.onCancel}> {props.cancelText} </button>
onClick={() => props.onCancel()}> {props.cancelText} </button>
<button
className="w-1/2 bg-iw-primary text-center items-center text-iw-text ml-2 font-bold text-sm px-6 py-3 rounded-lg shadow hover:shadow-lg outline-none focus:outline-none mr-1 ease-linear transition-all duration-150"
type="button"
data-testid={"DataShareFooter-Success-Button"}
onClick={props.onSuccess}> {props.successText} </button>
onClick={() => props.onSuccess()}> {props.successText} </button>
</div>;
}

Expand Down
3 changes: 2 additions & 1 deletion inji-web/src/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@
},
"CustomExpiryModal": {
"title": "الرجاء إدخال عدد المرات التي تريد فيها استخدام بيانات الاعتماد هذه ",
"error": "الرجاء إدخال رقم انتهاء صلاحية صالح، أكبر من الصفر، لتحديد عدد المرات التي يمكن فيها التحقق من بيانات الاعتماد الخاصة بك.",
"metrics": "مرات",
"success": "يتابع",
"cancel": "يلغي"
}
}
}
1 change: 1 addition & 0 deletions inji-web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
},
"CustomExpiryModal": {
"title": "Please enter the number of times you want to use this credential ",
"error": "Please enter a valid expiry number, greater than zero, to limit how many times your credentials can be verified.",
"metrics": "Times",
"success": "Proceed",
"cancel": "Cancel"
Expand Down
3 changes: 2 additions & 1 deletion inji-web/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@
},
"CustomExpiryModal": {
"title": "Veuillez saisir le nombre de fois que vous souhaitez utiliser cet identifiant ",
"error": "Veuillez saisir un numéro d'expiration valide, supérieur à zéro, pour limiter le nombre de fois que vos informations d'identification peuvent être vérifiées.",
"metrics": "Fois",
"success": "Procéder",
"cancel": "Annuler"
}
}
}
3 changes: 2 additions & 1 deletion inji-web/src/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@
},
"CustomExpiryModal": {
"title": "कृपया वह संख्या दर्ज करें जितनी बार आप इस क्रेडेंशियल का उपयोग करना चाहते हैं ",
"error": "आपके क्रेडेंशियल्स को कितनी बार सत्यापित किया जा सकता है, इसे सीमित करने के लिए कृपया शून्य से अधिक वैध समाप्ति संख्या दर्ज करें।",
"metrics": "टाइम्स",
"success": "आगे बढ़ना",
"cancel": "रद्द करना"
}
}
}
3 changes: 2 additions & 1 deletion inji-web/src/locales/kn.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@
},
"CustomExpiryModal": {
"title": "ಈ ರುಜುವಾತುಗಳನ್ನು ನೀವು ಎಷ್ಟು ಬಾರಿ ಬಳಸಲು ಬಯಸುತ್ತೀರಿ ಎಂಬುದನ್ನು ದಯವಿಟ್ಟು ನಮೂದಿಸಿ ",
"error": "ನಿಮ್ಮ ರುಜುವಾತುಗಳನ್ನು ಎಷ್ಟು ಬಾರಿ ಪರಿಶೀಲಿಸಬಹುದು ಎಂಬುದನ್ನು ಮಿತಿಗೊಳಿಸಲು ದಯವಿಟ್ಟು ಶೂನ್ಯಕ್ಕಿಂತ ಹೆಚ್ಚಿನ ಮಾನ್ಯವಾದ ಮುಕ್ತಾಯ ಸಂಖ್ಯೆಯನ್ನು ನಮೂದಿಸಿ.",
"metrics": "ಟೈಮ್ಸ್",
"success": "ಮುಂದುವರೆಯಿರಿ",
"cancel": "ರದ್ದುಮಾಡು"
}
}
}
3 changes: 2 additions & 1 deletion inji-web/src/locales/ta.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@
},
"CustomExpiryModal": {
"title": "இந்த நற்சான்றிதழை நீங்கள் எத்தனை முறை பயன்படுத்த விரும்புகிறீர்கள் என்பதை உள்ளிடவும் ",
"error": "உங்கள் நற்சான்றிதழ்களை எத்தனை முறை சரிபார்க்கலாம் என்பதைக் கட்டுப்படுத்த, பூஜ்ஜியத்தை விட அதிகமான சரியான காலாவதி எண்ணை உள்ளிடவும்.",
"metrics": "நேரங்கள்",
"success": "தொடரவும்",
"cancel": "ரத்து செய்"
}
}
}
15 changes: 13 additions & 2 deletions inji-web/src/modals/CustomExpiryModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@ import {storevcStorageExpiryLimitInTimes} from "../redux/reducers/commonReducer"
import {RootState} from "../types/redux";
import {useTranslation} from "react-i18next";
import {CustomExpiryModalProps} from "../types/components";
import {toast} from "react-toastify";


export const CustomExpiryModal: React.FC<CustomExpiryModalProps> = (props) => {

const vcStorageExpiryLimitInTimes = useSelector((state: RootState) => state.common.vcStorageExpiryLimitInTimes);
const [expiryTime, setExpiryTime] = useState<number>(vcStorageExpiryLimitInTimes);
const [expiryTime, setExpiryTime] = useState<number>(vcStorageExpiryLimitInTimes > 1 ? vcStorageExpiryLimitInTimes : 1 );
const {t} = useTranslation("CustomExpiryModal");
const dispatch = useDispatch();

const onSuccess = () => {
if(expiryTime < 1 || expiryTime > 50){
toast.error(t("error"));
} else {
dispatch(storevcStorageExpiryLimitInTimes(expiryTime));
props.onSuccess()
}
}

return <ModalWrapper header={<CustomExpiryTimesHeader title={t("title")}/>}
content={<CustomExpiryTimesContent expiryTime={expiryTime} setExpiryTime={setExpiryTime}/>}
footer={<DataShareFooter successText={t("success")} cancelText={t("cancel")} onSuccess={() => {dispatch(storevcStorageExpiryLimitInTimes(expiryTime));props.onSuccess()} } onCancel={props.onCancel}/>}
footer={<DataShareFooter successText={t("success")} cancelText={t("cancel")} onSuccess={onSuccess} onCancel={props.onCancel}/>}
size={"sm"}
zIndex={50} />
}
Expand Down
2 changes: 1 addition & 1 deletion inji-web/src/pages/RedirectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const RedirectionPage: React.FC = () => {
const codeVerifier = activeSessionInfo?.codeVerifier;
const issuerId = activeSessionInfo?.selectedIssuer?.credential_issuer ?? "";
const certificateId = activeSessionInfo?.certificateId;
const vcStorageExpiryLimitInTimes = activeSessionInfo?.vcStorageExpiryLimitInTimes;
const vcStorageExpiryLimitInTimes = activeSessionInfo?.vcStorageExpiryLimitInTimes ?? "-1";

const requestBody = new URLSearchParams(getTokenRequestBody(code, codeVerifier, issuerId, certificateId, vcStorageExpiryLimitInTimes));
const apiRequest = api.fetchTokenAnddownloadVc;
Expand Down

0 comments on commit 47d18e5

Please sign in to comment.