Skip to content

Commit 50dc800

Browse files
committed
Merge time and claims tooltips.
1 parent 40ff55c commit 50dc800

File tree

4 files changed

+9
-34
lines changed

4 files changed

+9
-34
lines changed

src/editor/claims-tooltip.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { claimsTooltipElement } from '../dom-elements.js';
2-
import { timeClaims } from './time-tooltip.js';
32
import { stringifyIndentSpaces } from './utils.js';
43
import strings from '../strings.js';
54
import {
@@ -10,6 +9,8 @@ import {
109

1110
import tippy from 'tippy.js';
1211

12+
const timeClaims = ['exp', 'nbf', 'iat', 'auth_time', 'updated_at'];
13+
1314
function hideTooltip() {
1415
decodedElement._tippy.hide();
1516
}
@@ -19,6 +20,10 @@ function showTooltip(text) {
1920
decodedElement._tippy.show();
2021
}
2122

23+
function getTimeText(timeStr) {
24+
return (new Date(parseInt(timeStr, 10) * 1000)).toString();
25+
}
26+
2227
function tooltipHandler(event) {
2328
const editor = event.currentTarget.querySelector('.CodeMirror').CodeMirror;
2429

@@ -46,7 +51,7 @@ function tooltipHandler(event) {
4651
// TODO: merge both tooltip handlers?
4752
const claimEnd = line.indexOf(':');
4853
if(result.ch >= claimEnd && timeClaims.includes(claim)) {
49-
hideTooltip();
54+
showTooltip(getTimeText(matches[2]));
5055
return;
5156
}
5257

src/editor/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
copyTokenLink
55
} from '../utils.js';
66
import { downloadPublicKeyIfPossible } from './public-key-download.js';
7-
import { timeTooltipHandler } from './time-tooltip.js';
87
import { setupClaimsTooltip } from './claims-tooltip.js';
98
import { tokenEditor, headerEditor, payloadEditor } from './instances.js';
109
import {
@@ -367,12 +366,8 @@ function setupEvents() {
367366
// (only verified).
368367
eventManager.addDomEvent(publicKeyTextArea, 'input', verifyToken);
369368

370-
// The following event are never disabled, so it is not necessary to go
369+
// The following events are never disabled, so it is not necessary to go
371370
// through the event manager for them.
372-
373-
// Human readable timestamp tooltips
374-
payloadElement.addEventListener('mousemove', timeTooltipHandler);
375-
376371
setupTabEvents();
377372
}
378373

src/editor/time-tooltip.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
nbf: 'Not valid before (seconds since Unix epoch)',
88
iat: 'Issued at (seconds since Unix epoch)',
99
iss: 'Issuer (who created and signed this token)',
10-
sub: 'Subject (who the token refers to)',
10+
sub: 'Subject (whom the token refers to)',
1111
aud: 'Audience (who or what the token is intended for)',
1212
jti: 'JWT ID (unique identifier for this token)',
1313
typ: 'Type of token',

0 commit comments

Comments
 (0)