From b46f973fa5f868577916098c1e84d135a29e9107 Mon Sep 17 00:00:00 2001 From: Antonio Georgiev Date: Fri, 12 Jul 2024 16:46:24 +0300 Subject: [PATCH 1/3] domain fixes --- src/pages/Nova/NovaDetails.tsx | 2 +- src/pages/Nova/RegisterDomainDialog.tsx | 35 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/pages/Nova/NovaDetails.tsx b/src/pages/Nova/NovaDetails.tsx index c185043..6c3f49d 100644 --- a/src/pages/Nova/NovaDetails.tsx +++ b/src/pages/Nova/NovaDetails.tsx @@ -471,7 +471,7 @@ const NovaDetails = () => { onClose={() => setOpenDomainDialog(false)} onRegister={async (domain: string) => { const result = await registerDomain({ - domain, + domain: `${domain}.hub`, novaAddress: nova.properties.address, metadataUri: nova.properties.metadataUri }); diff --git a/src/pages/Nova/RegisterDomainDialog.tsx b/src/pages/Nova/RegisterDomainDialog.tsx index 8514635..c38331c 100644 --- a/src/pages/Nova/RegisterDomainDialog.tsx +++ b/src/pages/Nova/RegisterDomainDialog.tsx @@ -7,7 +7,8 @@ import { TextField, Typography, Box, - styled + styled, + InputAdornment } from "@mui/material"; import { AutOsButton } from "@components/AutButton"; @@ -59,26 +60,27 @@ const DomainRegistrationDialog = ({ open, onClose, onRegister }) => { }, [domain]); const validateDomain = (value) => { - const domainRegex = - /^[a-zA-Z0-9](?:[a-zA-Z0-9]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z]{2,})+$/; - const hubEndingRegex = /\.hub$/i; + // Domain regex breakdown: + // ^[a-zA-Z0-9] - Start with a letter or number + // (?:[a-zA-Z0-9]{0,61} - Followed by 0 to 61 letters or numbers + // [a-zA-Z0-9])? - Ending with a letter or number (optional group) + const domainRegex = /^[a-zA-Z0-9](?:[a-zA-Z0-9]{0,61}[a-zA-Z0-9])?$/; const trimmedValue = value.trim().toLowerCase(); if (trimmedValue === "") { setIsValid(false); - setErrorMessage("Domain name is required"); + setErrorMessage("Please enter a domain name"); } else if (trimmedValue.includes("-")) { setIsValid(false); - setErrorMessage("Domain name cannot contain dashes"); + setErrorMessage("Domain name cannot contain hyphens"); } else if (!domainRegex.test(trimmedValue)) { setIsValid(false); - setErrorMessage("Invalid domain format"); + setErrorMessage( + "Please enter a valid domain name (Cannot contain symbols or spaces)" + ); } else if (trimmedValue.length > 253) { setIsValid(false); - setErrorMessage("Domain name is too long (max 253 characters)"); - } else if (!hubEndingRegex.test(trimmedValue)) { - setIsValid(false); - setErrorMessage("Domain must end with '.hub'"); + setErrorMessage("Domain name exceeds maximum length of 253 characters"); } else { setIsValid(true); setErrorMessage(""); @@ -102,13 +104,22 @@ const DomainRegistrationDialog = ({ open, onClose, onRegister }) => { Enter a domain name for your Nova. + + .hub + + + ) + }} autoFocus margin="dense" label="Domain" type="text" fullWidth value={domain} - onChange={(e) => setDomain(e.target.value)} + onChange={(e) => setDomain(e.target.value.toLowerCase())} helperText={errorMessage || " "} error={Boolean(errorMessage)} /> From 512eac3951e455c170048633bb0998458f722934 Mon Sep 17 00:00:00 2001 From: Antonio Georgiev Date: Fri, 12 Jul 2024 19:17:22 +0300 Subject: [PATCH 2/3] small tweak --- src/pages/Nova/NovaDetails.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Nova/NovaDetails.tsx b/src/pages/Nova/NovaDetails.tsx index 6c3f49d..9c3919a 100644 --- a/src/pages/Nova/NovaDetails.tsx +++ b/src/pages/Nova/NovaDetails.tsx @@ -477,7 +477,7 @@ const NovaDetails = () => { }); if ((result as any)?.data?.success) { // hack cause query fails to refetch - setDomain(domain); + setDomain(`${domain}.hub`); } }} > From 33382aceba4300c32e922bcd63743362eaae8d4a Mon Sep 17 00:00:00 2001 From: "taulant.disha" Date: Wed, 17 Jul 2024 21:27:03 +0300 Subject: [PATCH 3/3] fixed null exception --- package-lock.json | 2 ++ src/pages/Nova/NovaDetails.tsx | 50 +++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0f560da..38ae288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4266,6 +4266,8 @@ }, "node_modules/@parcel/watcher-wasm/node_modules/napi-wasm": { "version": "1.1.0", + "resolved": "https://registry.npmjs.org/napi-wasm/-/napi-wasm-1.1.0.tgz", + "integrity": "sha512-lHwIAJbmLSjF9VDRm9GoVOy9AGp3aIvkjv+Kvz9h16QR3uSVYH78PNQUnT2U4X53mhlnV2M7wrhibQ3GHicDmg==", "inBundle": true, "license": "MIT" }, diff --git a/src/pages/Nova/NovaDetails.tsx b/src/pages/Nova/NovaDetails.tsx index 9c3919a..39ed672 100644 --- a/src/pages/Nova/NovaDetails.tsx +++ b/src/pages/Nova/NovaDetails.tsx @@ -432,6 +432,20 @@ const NovaDetails = () => { } }, [nova]); + const canSeeRegisterDomain = useMemo(() => { + if (!nova) { + return false; + } + if (!address) { + return false; + } + + return ( + address.toLowerCase() === nova?.properties.deployer.toLowerCase() && + !nova?.properties.domain + ); + }, [address, nova]); + return ( <> {nova && ( @@ -957,26 +971,24 @@ const NovaDetails = () => { )} - {address.toLowerCase() === - nova.properties.deployer.toLowerCase() && - !nova.properties.domain && ( - - setOpenDomainDialog(true)} - type="button" - color="primary" - variant="outlined" + {canSeeRegisterDomain && ( + + setOpenDomainDialog(true)} + type="button" + color="primary" + variant="outlined" + > + - - Register Domain - - - - )} + Register Domain + + + + )}