Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jennifer/scan updates #1661

Merged
merged 17 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/obscuroscan_v3/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev -p 80",
"build": "next build",
"start": "next start",
"start": "next start -p 80",
"lint": "next lint"
},
"dependencies": {
Expand Down
38 changes: 38 additions & 0 deletions tools/obscuroscan_v3/frontend/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ErrorType } from "@/src/types/interfaces";
import Error from "./_error";

export function Custom404Error({
customPageTitle,
showRedirectText,
redirectText,
isFullWidth,
message,
showMessage = true,
redirectLink,
children,
}: ErrorType) {
return (
<Error
heading={` ${customPageTitle || "Oops! Page"} Not Found`}
statusText={`We can't seem to find the ${
customPageTitle || "page"
} you're looking for.`}
statusCode={404}
showRedirectText={showRedirectText}
redirectText={redirectText || "Home Page"}
message={
message ||
`The ${
customPageTitle || "page"
} you are looking for might have been removed, had its name changed, or is temporarily unavailable.`
}
isFullWidth={isFullWidth}
showMessage={showMessage}
redirectLink={redirectLink}
>
{children}
</Error>
);
}

export default Custom404Error;
32 changes: 32 additions & 0 deletions tools/obscuroscan_v3/frontend/pages/500.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ErrorType } from "@/src/types/interfaces";
import Error from "./_error";

function Custom500Error({
customPageTitle,
message,
showRedirectText,
redirectText,
err,
redirectLink,
children,
}: ErrorType) {
return (
<Error
heading={"Oops! Something went wrong."}
message={
message ||
"We're experiencing technical difficulties. Please try again later."
}
statusText={customPageTitle || `An Error occured`}
statusCode={500}
showRedirectText={showRedirectText || true}
redirectText={redirectText || "Home Page"}
err={err}
redirectLink={redirectLink}
>
{children}
</Error>
);
}

export default Custom500Error;
60 changes: 46 additions & 14 deletions tools/obscuroscan_v3/frontend/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { Toaster } from "@/src/components/ui/toaster";
import { useToast } from "@/src/components/ui/use-toast";
import { WalletConnectionProvider } from "@/src/components/providers/wallet-provider";
import { NetworkStatus } from "@/src/components/modules/common/network-status";
import HeadSeo from "@/src/components/head-seo";
import { siteMetadata } from "@/src/lib/siteMetadata";
import Script from "next/script";
import { GOOGLE_ANALYTICS_ID } from "@/src/lib/constants";

export default function App({ Component, pageProps }: AppProps) {
const { toast } = useToast();
Expand Down Expand Up @@ -47,20 +51,48 @@ export default function App({ Component, pageProps }: AppProps) {
);

return (
<QueryClientProvider client={queryClient}>
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
<>
<Script
strategy="lazyOnload"
src={`https://www.googletagmanager.com/gtag/js?id='${GOOGLE_ANALYTICS_ID}'`}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script URL contains extra quotes that may prevent the correct loading of the Google Analytics script.

- src={`https://www.googletagmanager.com/gtag/js?id='${GOOGLE_ANALYTICS_ID}'`}
+ src={`https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_ID}`}

Commitable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
src={`https://www.googletagmanager.com/gtag/js?id='${GOOGLE_ANALYTICS_ID}'`}
src={`https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_ID}`}

/>

<Script strategy="lazyOnload" id="google-analytics">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GOOGLE_ANALYTICS_ID}');
`}
</Script>

<HeadSeo
title={`${siteMetadata.companyName} `}
description={siteMetadata.description}
canonicalUrl={`${siteMetadata.siteUrl}`}
ogImageUrl={siteMetadata.siteLogo}
ogTwitterImage={siteMetadata.siteLogo}
ogType={"website"}
>
<WalletConnectionProvider>
<Component {...pageProps} />
<Toaster />
<NetworkStatus />
<ReactQueryDevtools initialIsOpen={false} />
</WalletConnectionProvider>
</ThemeProvider>
</QueryClientProvider>
<link rel="icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" />
<link rel="manifest" href="/manifest.json" />
</HeadSeo>
<QueryClientProvider client={queryClient}>
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
<WalletConnectionProvider>
<Component {...pageProps} />
<Toaster />
<NetworkStatus />
<ReactQueryDevtools initialIsOpen={false} />
</WalletConnectionProvider>
</ThemeProvider>
</QueryClientProvider>
</>
);
}
91 changes: 91 additions & 0 deletions tools/obscuroscan_v3/frontend/pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from "react";
import NextErrorComponent from "next/error";
import Link from "next/link";
import Image from "next/image";
import { ErrorType } from "@/src/types/interfaces";

function ErrorMessage({
statusText,
message,
showMessage,
showStatusText,
}: any) {
return (
<div className="error-message">
{showStatusText && <h3>{statusText}</h3>}
{message && showMessage && (
<p className="text-muted-foreground">{message}</p>
)}
</div>
);
}
Comment on lines +7 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ErrorMessage component should have a defined prop type for better type safety and to prevent potential bugs.

- function ErrorMessage({
-   statusText,
-   message,
-   showMessage,
-   showStatusText,
- }: any) {
+ interface ErrorMessageProps {
+   statusText: string;
+   message: string;
+   showMessage: boolean;
+   showStatusText: boolean;
+ }
+ function ErrorMessage({
+   statusText,
+   message,
+   showMessage,
+   showStatusText,
+ }: ErrorMessageProps) {

Commitable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
function ErrorMessage({
statusText,
message,
showMessage,
showStatusText,
}: any) {
return (
<div className="error-message">
{showStatusText && <h3>{statusText}</h3>}
{message && showMessage && (
<p className="text-muted-foreground">{message}</p>
)}
</div>
);
}
interface ErrorMessageProps {
statusText: string;
message: string;
showMessage: boolean;
showStatusText: boolean;
}
function ErrorMessage({
statusText,
message,
showMessage,
showStatusText,
}: ErrorMessageProps) {
return (
<div className="error-message">
{showStatusText && <h3>{statusText}</h3>}
{message && showMessage && (
<p className="text-muted-foreground">{message}</p>
)}
</div>
);
}


export function CustomError({
showRedirectText = true,
heading = "Oops! Something went wrong.",
statusText = "500",
message = "We're experiencing technical difficulties. Please try again later.",
redirectText = "Home Page",
isFullWidth,
err,
showMessage = true,
showStatusText,
statusCode,
isModal,
redirectLink = "/",
children,
...props
}: ErrorType) {
return (
<section
className="h-full flex flex-col justify-center items-center"
{...props}
>
<main className={isFullWidth ? "max-w-full" : ""}>
<div className="text-center">
<h1 className="text-4xl font-extrabold mb-6">{heading}</h1>
<div className={isFullWidth ? "w-full" : ""}>
<ErrorMessage
showStatusText={showStatusText}
showMessage={showMessage}
message={message}
statusText={statusText}
/>
</div>
{showRedirectText && (
<div>
Go to{" "}
<Link
href={redirectLink}
passHref
className="text-primary pointer underline"
>
{redirectText}
</Link>{" "}
{/* <div>
Looks like you&apos;re on the wrong side of town, buddy.
Let&apos;s get you back on the <Link href="/">right side</Link>.
</div> */}
</div>
)}
{children}
</div>
</main>
</section>
);
}

CustomError.getInitialProps = async ({ res, err }: any) => {
const statusCode = res ? res.statusCode : err?.statusCode || 404;
const errorInitialProps = await NextErrorComponent.getInitialProps({
res,
err,
} as any);
errorInitialProps.statusCode = statusCode;

return statusCode < 500
? errorInitialProps
: { ...errorInitialProps, statusCode };
Comment on lines +78 to +88
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getInitialProps method should use proper types for its parameters instead of any to ensure type safety.

- CustomError.getInitialProps = async ({ res, err }: any) => {
+ CustomError.getInitialProps = async ({ res, err }: { res?: NextApiResponse, err?: Error }) => {

Commitable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
CustomError.getInitialProps = async ({ res, err }: any) => {
const statusCode = res ? res.statusCode : err?.statusCode || 404;
const errorInitialProps = await NextErrorComponent.getInitialProps({
res,
err,
} as any);
errorInitialProps.statusCode = statusCode;
return statusCode < 500
? errorInitialProps
: { ...errorInitialProps, statusCode };
CustomError.getInitialProps = async ({ res, err }: { res?: NextApiResponse, err?: Error }) => {
const statusCode = res ? res.statusCode : err?.statusCode || 404;
const errorInitialProps = await NextErrorComponent.getInitialProps({
res,
err,
} as any);
errorInitialProps.statusCode = statusCode;
return statusCode < 500
? errorInitialProps
: { ...errorInitialProps, statusCode };

};

export default CustomError;
4 changes: 2 additions & 2 deletions tools/obscuroscan_v3/frontend/pages/batches/[hash].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchBatchByHash } from "@/api/batches";
import Layout from "@/src/components/layouts/default-layout";
import { BatchDetails } from "@/src/components/modules/batches/batch-details";
import { BatchDetailsComponent } from "@/src/components/modules/batches/batch-details";
import {
Card,
CardHeader,
Expand Down Expand Up @@ -36,7 +36,7 @@ export default function Batch() {
</CardDescription>
</CardHeader>
<CardContent>
<BatchDetails batchDetails={batchDetails} />
<BatchDetailsComponent batchDetails={batchDetails} />
</CardContent>
</Card>
) : (
Expand Down
24 changes: 20 additions & 4 deletions tools/obscuroscan_v3/frontend/pages/batches/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,35 @@ export const metadata: Metadata = {
};

export default function Batches() {
const { batches } = useBatchesService();
const { batches, refetchBatches, setNoPolling } = useBatchesService();
const { BatchesData, Total } = batches?.result || {
BatchesData: [],
Total: 0,
Jennievon marked this conversation as resolved.
Show resolved Hide resolved
};

React.useEffect(() => {
setNoPolling(true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<Layout>
<div className="h-full flex-1 flex-col space-y-8 md:flex">
<div className="flex items-center justify-between space-y-2">
<div>
<h2 className="text-2xl font-bold tracking-tight">Batches</h2>
<p className="text-muted-foreground">A table of Batches.</p>
<p className="text-sm text-muted-foreground">
{Total} Batches found.
</p>
</div>
</div>
{batches?.result?.BatchesData ? (
<DataTable columns={columns} data={batches?.result?.BatchesData} />
{BatchesData ? (
<DataTable
columns={columns}
data={BatchesData}
refetch={refetchBatches}
total={+Total}
/>
) : (
<p>Loading...</p>
Comment on lines 43 to 44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more robust loading indicator, such as a spinner or progress bar, to improve user experience.

)}
Expand Down
24 changes: 20 additions & 4 deletions tools/obscuroscan_v3/frontend/pages/blocks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,35 @@ export const metadata: Metadata = {
};

export default function Blocks() {
const { blocks } = useBlocksService();
const { blocks, setNoPolling, refetchBlocks } = useBlocksService();
const { BlocksData, Total } = blocks?.result || {
BlocksData: [],
Total: 0,
Jennievon marked this conversation as resolved.
Show resolved Hide resolved
};

React.useEffect(() => {
setNoPolling(true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Jennievon marked this conversation as resolved.
Show resolved Hide resolved

return (
<Layout>
<div className="h-full flex-1 flex-col space-y-8 md:flex">
<div className="flex items-center justify-between space-y-2">
<div>
<h2 className="text-2xl font-bold tracking-tight">Blocks</h2>
<p className="text-muted-foreground">A table of Blocks.</p>
<p className="text-sm text-muted-foreground">
{Total} Blocks found.
</p>
</div>
</div>
{blocks?.result?.BlocksData ? (
<DataTable columns={columns} data={blocks?.result?.BlocksData} />
{BlocksData ? (
Jennievon marked this conversation as resolved.
Show resolved Hide resolved
<DataTable
columns={columns}
data={BlocksData}
total={+Total}
refetch={refetchBlocks}
/>
) : (
<p>Loading...</p>
)}
Expand Down
Loading
Loading