diff --git a/src/components/KristNameLink.tsx b/src/components/KristNameLink.tsx index f441e35..7f0da1d 100644 --- a/src/components/KristNameLink.tsx +++ b/src/components/KristNameLink.tsx @@ -16,18 +16,20 @@ interface OwnProps { name: string; + text?: string; noLink?: boolean; neverCopyable?: boolean; } type Props = React.HTMLProps & OwnProps; -export function KristNameLink({ name, noLink, neverCopyable, ...props }: Props): JSX.Element | null { +export function KristNameLink({ name, text, noLink, neverCopyable, ...props }: Props): JSX.Element | null { const nameSuffix = useSelector((s: RootState) => s.node.currency.name_suffix); const nameCopyButtons = useBooleanSetting("nameCopyButtons"); const copyNameSuffixes = useBooleanSetting("copyNameSuffixes"); if (!name) return null; const nameWithSuffix = `${name}.${nameSuffix}`; + const content = text || nameWithSuffix; const copyable = !neverCopyable && nameCopyButtons ? { text: copyNameSuffixes ? nameWithSuffix : name } @@ -37,10 +39,10 @@ return {noLink - ? nameWithSuffix + ? content : ( - {nameWithSuffix} + {content} )} ; diff --git a/src/pages/names/NameARecordLink.tsx b/src/pages/names/NameARecordLink.tsx new file mode 100644 index 0000000..cce03ec --- /dev/null +++ b/src/pages/names/NameARecordLink.tsx @@ -0,0 +1,49 @@ +// Copyright (c) 2020-2021 Drew Lemmy +// This file is part of KristWeb 2 under GPL-3.0. +// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt +import React from "react"; + +import { useSelector } from "react-redux"; +import { RootState } from "../../store"; +import { stripNameSuffix } from "../../utils/currency"; + +import { KristNameLink } from "../../components/KristNameLink"; + +function forceURL(link: string): string { + // TODO: this is rather crude + if (!link.startsWith("http")) return "https://" + link; + return link; +} + +interface Props { + a?: string; +} + +export function NameARecordLink({ a }: Props): JSX.Element | null { + const nameSuffix = useSelector((s: RootState) => s.node.currency.name_suffix); + + if (!a) return null; + + // I don't have a citation for this other than a vague memory, but there are + // (as of writing this) 45 names in the database whose A records begin with + // `$` and then point to another name. There is an additional 1 name that + // actually points to a domain, but still begins with `$` and ends with the + // name suffix. 40 of these names end in the `.kst` suffix. Since I cannot + // find any specification or documentation on it right now, I support both + // formats. The suffix is stripped if it is present. + if (a.startsWith("$")) { + // Probably a name redirect + const withoutPrefix = a.replace(/^\$/, ""); + const nameWithoutSuffix = stripNameSuffix(nameSuffix, withoutPrefix); + + return ; + } + + return + {a} + ; +} diff --git a/src/pages/names/NamePage.tsx b/src/pages/names/NamePage.tsx index e64c6a3..88c357b 100644 --- a/src/pages/names/NamePage.tsx +++ b/src/pages/names/NamePage.tsx @@ -25,6 +25,7 @@ import { useBooleanSetting } from "../../utils/settings"; import { NameButtonRow } from "./NameButtonRow"; +import { NameARecordLink } from "./NameARecordLink"; import { NameTransactionsCard } from "./NameTransactionsCard"; import "./NamePage.less"; @@ -124,7 +125,7 @@ } - value={{name.a}} + value={} />