Skip to content

Commit

Permalink
Merge branch 'main' into mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
taulant.disha authored and taulant.disha committed Jul 17, 2024
2 parents 7cda5b3 + 33382ac commit 0fc77ca
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 33 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 33 additions & 21 deletions src/pages/Nova/NovaDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
Expand Down Expand Up @@ -471,13 +485,13 @@ 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
});
if ((result as any)?.data?.success) {
// hack cause query fails to refetch
setDomain(domain);
setDomain(`${domain}.hub`);
}
}}
></DomainRegistrationDialog>
Expand Down Expand Up @@ -957,26 +971,24 @@ const NovaDetails = () => {
</Typography>
</AutOsButton>
)}
{address.toLowerCase() ===
nova.properties.deployer.toLowerCase() &&
!nova.properties.domain && (
<Box marginTop={theme.spacing(2)}>
<AutOsButton
onClick={() => setOpenDomainDialog(true)}
type="button"
color="primary"
variant="outlined"
{canSeeRegisterDomain && (
<Box marginTop={theme.spacing(2)}>
<AutOsButton
onClick={() => setOpenDomainDialog(true)}
type="button"
color="primary"
variant="outlined"
>
<Typography
fontWeight="700"
fontSize="16px"
lineHeight="26px"
>
<Typography
fontWeight="700"
fontSize="16px"
lineHeight="26px"
>
Register Domain
</Typography>
</AutOsButton>
</Box>
)}
Register Domain
</Typography>
</AutOsButton>
</Box>
)}
</Box>
</Stack>
</LeftWrapper>
Expand Down
35 changes: 23 additions & 12 deletions src/pages/Nova/RegisterDomainDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
TextField,
Typography,
Box,
styled
styled,
InputAdornment
} from "@mui/material";
import { AutOsButton } from "@components/AutButton";

Expand Down Expand Up @@ -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("");
Expand All @@ -102,13 +104,22 @@ const DomainRegistrationDialog = ({ open, onClose, onRegister }) => {
Enter a domain name for your Nova.
</Typography>
<StyledTextField
InputProps={{
endAdornment: (
<InputAdornment position="end">
<Typography variant="body2" color="offWhite.main">
.hub
</Typography>
</InputAdornment>
)
}}
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)}
/>
Expand Down

0 comments on commit 0fc77ca

Please sign in to comment.