diff --git a/kinode/src/register-ui/build.sh b/kinode/src/register-ui/build.sh old mode 100644 new mode 100755 diff --git a/kinode/src/register-ui/src/App.tsx b/kinode/src/register-ui/src/App.tsx index 12b1ca7d5..7f923270b 100644 --- a/kinode/src/register-ui/src/App.tsx +++ b/kinode/src/register-ui/src/App.tsx @@ -6,7 +6,7 @@ import MintDotOsName from "./pages/MintDotOsName"; import MintCustom from "./pages/MintCustom"; import SetPassword from "./pages/SetPassword"; import Login from './pages/Login' -import ResetDotOsName from './pages/ResetDotOsName' +import ResetName from './pages/ResetName' import KinodeHome from "./pages/KinodeHome" import ImportKeyfile from "./pages/ImportKeyfile"; import { UnencryptedIdentity } from "./lib/types"; @@ -112,7 +112,7 @@ function App() { } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/kinode/src/register-ui/src/components/EnterKnsName.tsx b/kinode/src/register-ui/src/components/EnterKnsName.tsx index 4a7552467..aefa11713 100644 --- a/kinode/src/register-ui/src/components/EnterKnsName.tsx +++ b/kinode/src/register-ui/src/components/EnterKnsName.tsx @@ -1,5 +1,4 @@ import React, { useEffect, useRef, useState } from "react"; -import isValidDomain from "is-valid-domain"; import { toAscii } from "idna-uts46-hx"; import { usePublicClient } from 'wagmi' @@ -13,9 +12,10 @@ export const NAME_INVALID_PUNY = "Unsupported punycode character"; export const NAME_NOT_OWNER = "Name already exists and does not belong to this wallet"; export const NAME_NOT_REGISTERED = "Name is not registered"; -type ClaimOsNameProps = { +type EnterNameProps = { address?: `0x${string}`; name: string; + fixedTlz?: string; setName: React.Dispatch>; nameValidities: string[]; setNameValidities: React.Dispatch>; @@ -28,12 +28,13 @@ function EnterKnsName({ address, name, setName, + fixedTlz, nameValidities, setNameValidities, triggerNameCheck, setTba, isReset = false, -}: ClaimOsNameProps) { +}: EnterNameProps) { const client = usePublicClient(); const debouncer = useRef(null); @@ -43,7 +44,6 @@ function EnterKnsName({ if (debouncer.current) clearTimeout(debouncer.current); debouncer.current = setTimeout(async () => { - let index: number; let validities: string[] = []; setIsPunyfied(''); @@ -54,87 +54,75 @@ function EnterKnsName({ } let normalized = '' - index = validities.indexOf(NAME_INVALID_PUNY); try { - normalized = toAscii(name + ".os"); - if (index !== -1) validities.splice(index, 1); + normalized = toAscii(fixedTlz ? name + fixedTlz : name); } catch (e) { - if (index === -1) validities.push(NAME_INVALID_PUNY); + validities.push(NAME_INVALID_PUNY); } - const len = [...normalized].length - 3; - index = validities.indexOf(NAME_LENGTH); - if (len < 9 && len !== 0) { - if (index === -1) validities.push(NAME_LENGTH); - } else if (index !== -1) validities.splice(index, 1); - - if (normalized !== (name + ".os")) setIsPunyfied(normalized); - - // only check if name is valid punycode - if (normalized && normalized !== '.os') { - index = validities.indexOf(NAME_URL); - if (name !== "" && !isValidDomain(normalized)) { - if (index === -1) validities.push(NAME_URL); - } else if (index !== -1) { - validities.splice(index, 1); + // length check, only for .os + if (fixedTlz === '.os') { + const len = [...normalized].length - 3; + if (len < 9 && len !== 0) { + validities.push(NAME_LENGTH); } + } + + if (normalized !== (fixedTlz ? name + fixedTlz : name)) { + setIsPunyfied(normalized); + } - index = validities.indexOf(NAME_CLAIMED); - - // only check if name is valid and long enough - if (validities.length === 0 || index !== -1 && normalized.length > 2) { - try { - const namehash = kinohash(normalized) - // maybe separate into helper function for readability? - // also note picking the right chain ID & address! - const data = await client?.readContract({ - address: KIMAP, - abi: kimapAbi, - functionName: "get", - args: [namehash] - }) - - const tba = data?.[0]; - if (tba !== undefined) { - setTba ? (setTba(tba)) : null; - } else { - validities.push(NAME_NOT_REGISTERED); - } - - const owner = data?.[1]; - const owner_is_zero = owner === "0x0000000000000000000000000000000000000000"; - - if (!owner_is_zero && !isReset) validities.push(NAME_CLAIMED); - - if (!owner_is_zero && isReset && address && owner !== address) validities.push(NAME_NOT_OWNER); - - if (isReset && owner_is_zero) validities.push(NAME_NOT_REGISTERED); - } catch (e) { - console.error({ e }) - if (index !== -1) validities.splice(index, 1); + // only check ownership if name is otherwise valid + if (validities.length === 0 && normalized.length > 2) { + try { + const namehash = kinohash(normalized) + + const data = await client?.readContract({ + address: KIMAP, + abi: kimapAbi, + functionName: "get", + args: [namehash] + }) + + const tba = data?.[0]; + if (tba !== undefined) { + setTba ? (setTba(tba)) : null; + } else if (isReset) { + validities.push(NAME_NOT_REGISTERED); } + + const owner = data?.[1]; + const owner_is_zero = owner === "0x0000000000000000000000000000000000000000"; + + if (!owner_is_zero && !isReset) validities.push(NAME_CLAIMED); + + if (!owner_is_zero && isReset && address && owner !== address) validities.push(NAME_NOT_OWNER); + + if (isReset && owner_is_zero) validities.push(NAME_NOT_REGISTERED); + } catch (e) { + console.error({ e }) } } setNameValidities(validities); }, 500); }, [name, triggerNameCheck, isReset]); - const noDotsOrSpaces = (e: any) => - e.target.value.indexOf(".") === -1 && e.target.value.indexOf(" ") === -1 && setName(e.target.value); + const noSpaces = (e: any) => + e.target.value.indexOf(" ") === -1 && setName(e.target.value); return (
- .os + {fixedTlz && {fixedTlz}}
{nameValidities.map((x, i) => (

{x}

diff --git a/kinode/src/register-ui/src/pages/CommitDotOsName.tsx b/kinode/src/register-ui/src/pages/CommitDotOsName.tsx index a422a2471..1f4568f6e 100644 --- a/kinode/src/register-ui/src/pages/CommitDotOsName.tsx +++ b/kinode/src/register-ui/src/pages/CommitDotOsName.tsx @@ -52,7 +52,7 @@ function CommitDotOsName({ useEffect(() => setTriggerNameCheck(!triggerNameCheck), [address]) - const enterOsNameProps = { address, name, setName, nameValidities, setNameValidities, triggerNameCheck } + const enterOsNameProps = { address, name, setName, fixedTlz: ".os", nameValidities, setNameValidities, triggerNameCheck } useEffect(() => { if (!address) { diff --git a/kinode/src/register-ui/src/pages/ResetDotOsName.tsx b/kinode/src/register-ui/src/pages/ResetName.tsx similarity index 97% rename from kinode/src/register-ui/src/pages/ResetDotOsName.tsx rename to kinode/src/register-ui/src/pages/ResetName.tsx index 31797e6ba..db56a13b6 100644 --- a/kinode/src/register-ui/src/pages/ResetDotOsName.tsx +++ b/kinode/src/register-ui/src/pages/ResetName.tsx @@ -36,7 +36,7 @@ function ResetKnsName({ const { data: hash, writeContract, isPending, isError, error } = useWriteContract({ mutation: { onSuccess: (data) => { - addRecentTransaction({ hash: data, description: `Reset KNS ID: ${name}.os` }); + addRecentTransaction({ hash: data, description: `Reset KNS ID: ${name}` }); } } }); @@ -46,12 +46,11 @@ function ResetKnsName({ }); const addRecentTransaction = useAddRecentTransaction(); - const [name, setName] = useState(knsName.slice(0, -3)); + const [name, setName] = useState(knsName); const [nameValidities, setNameValidities] = useState([]) const [tba, setTba] = useState(""); const [triggerNameCheck, setTriggerNameCheck] = useState(false); - useEffect(() => { document.title = "Reset"; }, []); @@ -75,7 +74,7 @@ function ResetKnsName({ return; } - setKnsName(name + ".os"); + setKnsName(name); try { const data = await generateNetworkingKeys({