Skip to content

Commit bdf1c49

Browse files
authored
Set terms and conditions page without library link (#3866)
* add terms without library link * removed comment line * replaced loading with fetching * removed html in markdown for codacy fix * add description for image to avoid codacy minor alert * update manual legal part in profile manager * removed unnecessary image * adjust error text * removed unused function * use import for links * made 3 functions out of 1 to simplify watch function * set manual link from manual.ts instead of absolute * fixed import of manual.ts * import manual * updated manual.ts with link * revert to previous configuration * removed unused import * update image format to take all screen's width
1 parent a474c51 commit bdf1c49

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

packages/grid_client/src/modules/tfchain.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ class TFChain implements blockchainInterface {
477477
});
478478
}
479479
await (
480-
await client.termsAndConditions.accept({ documentLink: "https://library.threefold.me/info/legal/#/" })
480+
await client.termsAndConditions.accept({
481+
documentLink: "https://manual.grid.tf/knowledge_base/legal/terms_conditions_all3.html",
482+
})
481483
).apply();
482484
const ret = await (await client.twins.create({ relay })).apply();
483485
if (disconnect) await client.disconnect();

packages/playground/src/utils/manual.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import urlJoin from "url-join";
22

33
const BASE = window.env.MANUAL_URL;
4+
5+
const GITHUB = {
6+
RAW_BASE: "https://raw.githubusercontent.com/threefoldtech/info_grid/master/src",
7+
LEGAL_PATH: "knowledge_base/legal",
8+
};
9+
10+
const LEGAL_HEADER_IMG = "img/legal_header.jpg";
11+
412
export const manual = {
513
dedicated_machines: urlJoin(BASE, "/documentation/dashboard/deploy/node_finder.html#dedicated-nodes"),
614
tft_bridges: urlJoin(BASE, "/documentation/threefold_token/tft_bridges/tft_bridges.html"),
@@ -19,4 +27,8 @@ export const manual = {
1927
minting_receipts: urlJoin(BASE, "/documentation/farmers/3node_building/minting_receipts.html"),
2028
minting_process: urlJoin(BASE, "/documentation/farmers/farming_optimization/minting_process.html"),
2129
minting_reports: urlJoin(BASE, "/documentation/dashboard/tfchain/tf_minting_reports.html"),
30+
manual_raw_legal: urlJoin(GITHUB.RAW_BASE, GITHUB.LEGAL_PATH, "terms_conditions_all3.md"),
31+
manual_raw_legal_img: urlJoin(GITHUB.RAW_BASE, GITHUB.LEGAL_PATH, LEGAL_HEADER_IMG),
32+
manual_legal_base: urlJoin(BASE, GITHUB.LEGAL_PATH),
33+
legal_header_img: LEGAL_HEADER_IMG,
2234
};

packages/playground/src/weblets/profile_manager.vue

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ import { validateMnemonic } from "bip39";
429429
import Cryptr from "cryptr";
430430
import { marked } from "marked";
431431
import md5 from "md5";
432+
import urlJoin from "url-join";
432433
import { computed, onMounted, type Ref, ref, watch } from "vue";
433434
import { nextTick } from "vue";
434435
import { useTheme } from "vuetify";
@@ -832,45 +833,36 @@ function validateConfirmPassword(value: string) {
832833
}
833834
}
834835
835-
function parseAcceptTermsImage(tempDiv: HTMLDivElement, url: string) {
836-
const imageElements = tempDiv.querySelectorAll("img");
837-
imageElements.forEach(imgElement => {
838-
imgElement.setAttribute("src", url + "legal__legal_header_.jpg");
839-
// Update the style of the image.
840-
imgElement.setAttribute("class", "info-legal-image");
836+
const replaceMarkdownLinks = (content: string, pattern: RegExp, baseUrl: string) => {
837+
return content.replace(pattern, (_, linkText, path) => {
838+
const relativePath = path.replace("./", "");
839+
return `[${linkText}](${urlJoin(baseUrl, `${relativePath}.html`)})`;
841840
});
842-
}
841+
};
842+
843+
const processMarkdownContent = (content: string, baseUrl: string) => {
844+
let processedContent = content.replace(
845+
"./" + manual.legal_header_img,
846+
`${manual.manual_raw_legal_img}" class="info-legal-image`
847+
);
848+
849+
const patterns = [/\[([^\]]+)\]\((\.\/[^)]+)\.md\)/g, /\[([^\]]+)\]\((\.\/[^)]+\/[^)]+)\.md\)/g];
850+
851+
for (const pattern of patterns) {
852+
processedContent = replaceMarkdownLinks(processedContent, pattern, baseUrl);
853+
}
854+
855+
return processedContent;
856+
};
843857
844-
function parseAcceptTermsLink(tempDiv: HTMLDivElement) {
845-
const url = "https://library.threefold.me/info/legal#";
846-
const linkElements = tempDiv.querySelectorAll("a");
847-
linkElements.forEach(linkElement => {
848-
const currentDomainMatch = linkElement.href.match(/^(https?:\/\/[^\\/]+)/);
849-
if (
850-
(currentDomainMatch && linkElement.href.includes("localhost")) ||
851-
(currentDomainMatch && linkElement.href.includes("dashboard")) // To update only internal links
852-
) {
853-
const currentDomain = currentDomainMatch[1];
854-
linkElement.href = linkElement.href.replace(currentDomain, url);
855-
}
856-
});
857-
}
858858
watch(openAcceptTerms, async () => {
859859
if (openAcceptTerms.value) {
860860
try {
861-
const url = "https://library.threefold.me/info/legal/";
862-
const response = await fetch(url + "readme.md");
861+
const response = await fetch(manual.manual_raw_legal);
863862
const mdContent = await response.text();
864-
const parsedContent = marked.parse(mdContent);
865-
866-
const tempDiv = document.createElement("div");
867-
tempDiv.innerHTML = parsedContent;
868-
869-
parseAcceptTermsImage(tempDiv, url);
870-
parseAcceptTermsLink(tempDiv);
871863
872-
const updatedHtmlContent = tempDiv.innerHTML;
873-
acceptTermsContent.value = updatedHtmlContent;
864+
const processedContent = processMarkdownContent(mdContent, manual.manual_legal_base);
865+
acceptTermsContent.value = marked.parse(processedContent);
874866
} catch (error) {
875867
console.error("Error fetching or parsing Markdown content:", error);
876868
} finally {

0 commit comments

Comments
 (0)