Refactor RevertModal to use shared d-tag extraction utility

- Removed duplicated `extractDTagValue` method from `js/ui/components/RevertModal.js`
- Imported and used `getDTagValueFromTags` from `js/nostr/nip71.js`
- Added unit tests for `getDTagValueFromTags` in `tests/nostr/nip71-d-tag.test.mjs`

This reduces code duplication and ensures consistent d-tag extraction logic.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-26 17:37:26 +00:00
1 parent 9913e484ab
commit 931f57eebe
2 files changed
+50 -18

No files matched your search

+3 -18
View File
@@ -1,3 +1,4 @@
import { getDTagValueFromTags } from "../../nostr/nip71.js";
import { Nip71FormManager } from "./nip71FormManager.js";
import { createModalAccessibility } from "./modalAccessibility.js";
import {
@@ -354,7 +355,7 @@ export class RevertModal {
if (this.subtitle) {
const subtitleParts = [];
const dTagValue = this.extractDTagValue(video.tags);
const dTagValue = getDTagValueFromTags(video.tags);
if (dTagValue) {
subtitleParts.push(`d=${dTagValue}`);
}
@@ -604,7 +605,7 @@ export class RevertModal {
typeof version.rawMagnet === "string" ? version.rawMagnet.trim() : "";
const displayMagnet = magnet || rawMagnet;
const isPrivate = version.isPrivate === true;
const dTagValue = this.extractDTagValue(version.tags);
const dTagValue = getDTagValueFromTags(version.tags);
const nip71Metadata = this.buildNip71DisplayMetadata(version);
@@ -1488,21 +1489,5 @@ export class RevertModal {
references,
};
}
extractDTagValue(tags) {
if (!Array.isArray(tags)) {
return "";
}
for (const tag of tags) {
if (!Array.isArray(tag) || tag.length < 2) {
continue;
}
if (tag[0] === "d" && typeof tag[1] === "string") {
return tag[1];
}
}
return "";
}
}