Skip to content

Commit

Permalink
Add typing and show 404 if deployment is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Aug 30, 2023
1 parent fb9a843 commit 3a151da
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ const useStyles = makeStyles()(theme => ({
}
}));

export function DeploymentDepositModal({ handleCancel, onDeploymentDeposit, min = 0, infoText = null }) {
type Props = {
handleCancel: () => void;
onDeploymentDeposit: (deposit: number, depositorAddress: string) => void;
min?: number;
infoText?: string | JSX.Element;
};

export function DeploymentDepositModal({ handleCancel, onDeploymentDeposit, min = 0, infoText = null }: Props) {
const { classes } = useStyles();
const formRef = useRef(null);
const { settings } = useSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ export const ManifestEdit: React.FunctionComponent<Props> = ({ editedManifest, s
setIsDepositingDeployment(true);
};

const onDeploymentDeposit = async (deposit, depositorAddress) => {
const onDeploymentDeposit = async (deposit: number, depositorAddress: string) => {
setIsDepositingDeployment(false);
await handleCreateClick(deposit, depositorAddress);
};

async function handleCreateClick(deposit, depositorAddress) {
async function handleCreateClick(deposit: number, depositorAddress: string) {
setIsCreatingDeployment(true);
const dd = await createAndValidateDeploymentData(editedManifest, null, deposit, depositorAddress);

Expand All @@ -167,7 +167,8 @@ export const ManifestEdit: React.FunctionComponent<Props> = ({ editedManifest, s
try {
const messages = [];
const hasValidCert = isCertificateValidated && isLocalCertificateValidated;
let _crtpem, _encryptedKey;
let _crtpem: string;
let _encryptedKey: string;

// Create a cert if the user doesn't have one
if (!hasValidCert) {
Expand Down
2 changes: 1 addition & 1 deletion deploy-web/src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FourOhFour: React.FunctionComponent<Props> = ({}) => {
<NextSeo title="Page not found" />

<PageContainer>
<Box sx={{ textAlign: "center" }}>
<Box sx={{ textAlign: "center", marginTop: 10 }}>
<Typography variant="h1">404</Typography>

<Title value="Page not found." />
Expand Down
23 changes: 21 additions & 2 deletions deploy-web/src/pages/deployments/[dseq].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Layout from "@src/components/layout/Layout";
import { NextSeo } from "next-seo";
import { DeploymentDetailTopBar } from "@src/components/deploymentDetail/DeploymentDetailTopBar";
import { DeploymentSubHeader } from "@src/components/deploymentDetail/DeploymentSubHeader";
import { Alert, Box, Button, CircularProgress, Tab, Tabs } from "@mui/material";
import { Alert, Box, Button, CircularProgress, Tab, Tabs, Typography } from "@mui/material";
import { LeaseRow } from "@src/components/deploymentDetail/LeaseRow";
import { useRouter } from "next/router";
import { createRef, useEffect, useState } from "react";
Expand All @@ -23,6 +23,8 @@ import { AnalyticsEvents } from "@src/utils/analytics";
import { RouteStepKeys } from "@src/utils/constants";
import { useSettings } from "@src/context/SettingsProvider";
import PageContainer from "@src/components/shared/PageContainer";
import Link from "next/link";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";

type Props = {
dseq: string;
Expand Down Expand Up @@ -54,7 +56,8 @@ const DeploymentDetailPage: React.FunctionComponent<Props> = ({ dseq }) => {
const {
data: deployment,
isFetching: isLoadingDeployment,
refetch: getDeploymentDetail
refetch: getDeploymentDetail,
error: deploymentError
} = useDeploymentDetail(address, dseq, {
enabled: false,
onSuccess: _deploymentDetail => {
Expand Down Expand Up @@ -94,6 +97,7 @@ const DeploymentDetailPage: React.FunctionComponent<Props> = ({ dseq }) => {
}
}
});
const isDeploymentNotFound = deploymentError && (deploymentError as any).response?.data?.message?.includes("Deployment not found");
const hasLeases = leases && leases.length > 0;
const { isLocalCertMatching, localCert, isCreatingCert, createCertificate } = useCertificate();
const [deploymentManifest, setDeploymentManifest] = useState(null);
Expand Down Expand Up @@ -161,6 +165,21 @@ const DeploymentDetailPage: React.FunctionComponent<Props> = ({ dseq }) => {
deployment={deployment}
/>

{isDeploymentNotFound && (
<Box sx={{ textAlign: "center", marginTop: 10 }}>
<Typography variant="h1">404</Typography>
<Typography variant="subtitle1">This deployment does not exist or it was created using another wallet.</Typography>
<Box sx={{ paddingTop: "1rem" }}>
<Link href={UrlService.home()} passHref>
<Button variant="contained" color="secondary" sx={{ display: "inline-flex", alignItems: "center", textTransform: "initial" }}>
Go to homepage&nbsp;
<ArrowForwardIcon fontSize="small" />
</Button>
</Link>
</Box>
</Box>
)}

{deployment && (
<>
<DeploymentSubHeader deployment={deployment} leases={leases} />
Expand Down
6 changes: 3 additions & 3 deletions deploy-web/src/utils/certificateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export const generateCertificate = (address: string) => {
const prv = kp.prvKeyObj;
const pub = kp.pubKeyObj;

const encryptedKey = rs.KEYUTIL.getPEM(prv, "PKCS8PRV");
const encryptedKey = rs.KEYUTIL.getPEM(prv, "PKCS8PRV") as string;

const pubpem = rs.KEYUTIL.getPEM(pub, "PKCS8PUB").replaceAll("PUBLIC KEY", "EC PUBLIC KEY");
const pubpem = rs.KEYUTIL.getPEM(pub, "PKCS8PUB").replaceAll("PUBLIC KEY", "EC PUBLIC KEY") as string;

// STEP2. specify certificate parameters
const cert = new rs.KJUR.asn1.x509.Certificate({
Expand All @@ -70,7 +70,7 @@ export const generateCertificate = (address: string) => {
cakey: prv // can specify private key object or PEM string
});

const crtpem = cert.getPEM();
const crtpem = cert.getPEM() as string;

return { cert, crtpem, pubpem, encryptedKey };
};
Expand Down
3 changes: 3 additions & 0 deletions deploy-web/src/utils/deploymentLocalDataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export type LocalDeploymentData = {
export function getDeploymentLocalData(dseq: string | number) {
const selectedNetworkId = localStorage.getItem("selectedNetworkId");
const selectedWallet = getSelectedStorageWallet();

if (!selectedWallet) return null;

const dataStr = localStorage.getItem(`${selectedNetworkId}/${selectedWallet.address}/deployments/${dseq}.data`);
if (!dataStr) return null;

Expand Down

0 comments on commit 3a151da

Please sign in to comment.