Skip to content

Commit 3f53110

Browse files
committed
fix cross compatibility of expiry date
1 parent 6c47e35 commit 3f53110

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/components/Credentials/CredentialLayout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const CredentialLayout = ({ children, title = null }) => {
6161
if ('error' in c) {
6262
return;
6363
}
64-
setIsExpired(CheckExpired(c.beautifiedForm.expiry_date))
64+
setIsExpired(CheckExpired(c.beautifiedForm.expiry_date ?? c.beautifiedForm.exp))
6565
setCredentialFriendlyName(c.credentialFriendlyName);
6666
});
6767
}, [vcEntity, container]);

src/components/Credentials/ExpiredRibbon.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const ExpiredRibbon = ({ parsedCredential }) => {
88

99
return (
1010
<>
11-
{parsedCredential && CheckExpired(parsedCredential.expiry_date) &&
12-
<div className={`absolute bottom-0 right-0 text-white text-xs py-1 px-3 rounded-tl-lg rounded-br-2xl border-t border-l border-white ${CheckExpired(parsedCredential.expirationDate) ? 'bg-red-600' : 'bg-green-500'}`}>
11+
{parsedCredential && CheckExpired(parsedCredential.exp ?? parsedCredential.expiry_date) &&
12+
<div className={`absolute bottom-0 right-0 text-white text-xs py-1 px-3 rounded-tl-lg rounded-br-2xl border-t border-l border-white ${CheckExpired(parsedCredential.exp ?? parsedCredential.expiry_date) ? 'bg-red-600' : 'bg-green-500'}`}>
1313
{t('expiredRibbon.expired')}
1414
</div>
1515
}

src/components/Credentials/RenderCustomSvgTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const renderCustomSvgTemplate = async ({ beautifiedForm, name, description, logo
4949
.replace(/{{textColor}}/g, textColor)
5050
.replace(/{{description}}/g, description);
5151

52-
const expiryDate = jsonpointer.get(beautifiedForm, "/expiry_date");
52+
const expiryDate = jsonpointer.get(beautifiedForm, "/expiry_date") ?? new Date(jsonpointer.get(beautifiedForm, "/exp") * 1000).toISOString();
5353
svgContent = svgContent.replace(/{{\/expiry_date}}/g, expiryDate ? `Expiry Date: ${formatDate(expiryDate, 'date')}` : '');
5454

5555
return `data:image/svg+xml;utf8,${encodeURIComponent(svgContent)}`;

src/functions/CheckExpired.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// CheckExpired.js
22
export function CheckExpired(expiry_date) {
3+
if (!expiry_date) {
4+
return false;
5+
}
6+
7+
const parsedExpiryDate = typeof expiry_date == 'string' ? expiry_date : new Date(expiry_date * 1000).toISOString();
38
const today = new Date();
4-
const expirationDate = new Date(expiry_date);
9+
const expirationDate = new Date(parsedExpiryDate);
510
return expirationDate < today;
611
};

0 commit comments

Comments
 (0)