add required artifacts to have app work. remove redundancies

pull/5370/head
Joseph Izang 2 years ago committed by Aniket
parent 382085d054
commit b4ef69c810
  1. 7
      apps/remixdocgen/project.json
  2. 38
      apps/remixdocgen/src/app/App.tsx
  3. 11
      apps/remixdocgen/src/app/routes.tsx
  4. 203
      apps/remixdocgen/src/app/views/HomeView.tsx
  5. 3
      apps/remixdocgen/src/app/views/index.ts
  6. 82
      apps/remixdocgen/webpack.config.js

@ -1,5 +1,5 @@
{
"name": "etherscan",
"name": "remixdocgen",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/remixdocgen/src",
"projectType": "application",
@ -18,10 +18,9 @@
"main": "apps/remixdocgen/src/main.tsx",
"tsConfig": "apps/remixdocgen/tsconfig.app.json",
"assets": [
"apps/remixdocgen/src/favicon.ico",
"apps/remixdocgen/src/assets"
"apps/remixdocgen/src/favicon.ico"
],
"styles": ["apps/remixdocgen/src/styles.css"],
"styles": [],
"scripts": [],
"webpackConfig": "apps/remixdocgen/webpack.config.js"
},

@ -11,7 +11,7 @@ import { Status } from "@remixproject/plugin-utils";
import { AppContext } from "./AppContext";
import { Routes } from "./routes";
import { useLocalStorage } from "./hooks/useLocalStorage";
import { createDocumentation } from "../utils/utils";
import "./App.css";
import { ContractName, Documentation } from "../types";
@ -59,13 +59,8 @@ const App = () => {
console.log("New compilation received");
const existingMap = contractsRef.current;
const newContractsMapWithDocumentation = createDocumentation(
fileName,
data
);
const newMap = new Map([
...existingMap,
...newContractsMapWithDocumentation,
]);
const status: Status = {
@ -74,7 +69,7 @@ const App = () => {
title: "New documentation ready",
};
clientInstanceRef.current.emit("statusChanged", status);
setContracts(newMap);
setContracts(new Map());
}
);
@ -93,19 +88,22 @@ const App = () => {
}, []);
return (
<AppContext.Provider
value={{
clientInstance,
contracts,
setContracts,
sites,
setSites,
themeType,
}}
>
<Routes />
</AppContext.Provider>
);
// <AppContext.Provider
// value={{
// clientInstance,
// contracts,
// setContracts,
// sites,
// setSites,
// themeType,
// }}
// >
// <Routes />
// </AppContext.Provider>
<div>
<h1>Testing</h1>
</div>
)
};
export default App;

@ -1,12 +1,11 @@
import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
RouteProps,
} from "react-router-dom";
import { ErrorView, HomeView } from "./views";
interface Props extends RouteProps {
component: any; // TODO: new (props: any) => React.Component
@ -15,17 +14,11 @@ interface Props extends RouteProps {
const CustomRoute = ({ component: Component, ...rest }: Props) => {
return (
<Route {...rest} render={(matchProps) => <Component {...matchProps} />} />
<></>
);
};
export const Routes = () => (
<Router>
<Switch>
<CustomRoute exact path="/" component={HomeView} from="/" />
<Route path="/error">
<ErrorView />
</Route>
</Switch>
</Router>
);

@ -1,203 +0,0 @@
import React, { useState, useEffect, useRef } from "react";
import { AppContext } from "../AppContext";
import { ContractName, Documentation } from "../../types";
import { publish } from "../../utils";
import { htmlTemplate } from "../../utils/template";
export const HomeView: React.FC = () => {
const [activeItem, setActiveItem] = useState("");
const [isPublishing, setIsPublishing] = useState(false);
const [htmlDocumentation, setHtmlDocumentation] = useState("");
const [hasErrorOnPublishing, setHasErrorOnPublishing] = useState(false);
const [publishedURL, setPublishedURL] = useState("");
const clearMessageFuncRef = useRef(undefined as any);
useEffect(() => {
const maxNumberOfRetries = 1;
let retries = 0;
const publishDocumentation = async () => {
try {
if (clearMessageFuncRef.current) {
clearTimeout(clearMessageFuncRef.current);
}
const hash = await publish(htmlDocumentation);
console.log("Hash", hash);
setIsPublishing(false);
const url = `https://ipfs.io/ipfs/${hash}`;
window.open(url);
setPublishedURL(url);
} catch (error) {
if (retries < maxNumberOfRetries) {
console.log("Retrying...");
retries++;
publishDocumentation();
} else {
setIsPublishing(false);
setHasErrorOnPublishing(true);
clearMessageFuncRef.current = setTimeout(() => {
setHasErrorOnPublishing(false);
}, 5000);
}
}
};
if (isPublishing) {
setHasErrorOnPublishing(false);
publishDocumentation();
}
}, [isPublishing, htmlDocumentation]);
const displayDocumentation = (
client: any,
contractName: ContractName,
documentation: Documentation
) => {
console.log("Display Documentation", contractName, documentation);
client.emit("documentation-generated", documentation);
};
return (
<AppContext.Consumer>
{({ clientInstance, contracts, setContracts, themeType }) => (
<div
id="ethdoc"
style={{ color: themeType === "dark" ? "white" : "black" }}
>
{[...contracts.keys()].length === 0 && (
<p>Compile a contract with Solidity Compiler</p>
)}
{[...contracts.keys()].length > 0 && (
<div>
<div className="list-group">
{[...contracts.keys()].map((item) => {
const documentation = contracts.get(item) as string;
return (
<button
key={item}
className={
activeItem === item
? "list-group-item list-group-item-action active"
: "list-group-item list-group-item-action"
}
aria-pressed="false"
onClick={() => {
setPublishedURL("");
setActiveItem(item);
displayDocumentation(
clientInstance,
item,
documentation
);
const documentationAsHtml = htmlTemplate(documentation);
setHtmlDocumentation(documentationAsHtml);
}}
>
{item} Documentation
</button>
);
})}
</div>
<div style={{ float: "right" }}>
<button
type="button"
className="btn btn-sm btn-link"
onClick={() => {
setContracts(new Map());
displayDocumentation(clientInstance, "", "");
setPublishedURL("");
}}
>
Clear
</button>
</div>
<div>
{activeItem !== "" && (
<PublishButton
isPublishing={isPublishing}
item={activeItem}
onClick={() => {
console.log("Is publishing");
setIsPublishing(true);
}}
/>
)}
</div>
{!isPublishing && publishedURL !== "" && (
<>
<div className="small mt-1">
<a rel="noreferrer" href={publishedURL} target="_blank">
{publishedURL}
</a>
</div>
</>
)}
{hasErrorOnPublishing && (
<div>
<label>Something unexpected happen, Please try again</label>
</div>
)}
</div>
)}
</div>
)}
</AppContext.Consumer>
);
};
interface PublishButtonProps {
isPublishing: boolean;
onClick: any;
item: string;
}
export const PublishButton: React.FC<PublishButtonProps> = ({
isPublishing,
onClick,
item,
}) => {
return (
<button
style={{ marginTop: "1em" }}
className="btn btn-secondary btn-sm btn-block"
disabled={isPublishing}
onClick={onClick}
>
{!isPublishing && <span>Publish {item}</span>}
{isPublishing && (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<span
className="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"
style={{ marginRight: "0.5em" }}
/>
<p style={{ margin: "0" }}>Publishing...Please wait</p>
</div>
)}
</button>
);
};
// <label class="btn btn-secondary active">
// <input type="radio" name="options" id="option1" checked> Active
// </label>
// <label class="btn btn-secondary">
// <input type="radio" name="options" id="option2"> Radio
// </label>
// <label class="btn btn-secondary">
// <input type="radio" name="options" id="option3"> Radio
// </label>

@ -1,2 +1 @@
export { HomeView } from "./HomeView";
export { ErrorView } from "./ErrorView";

@ -0,0 +1,82 @@
const { composePlugins, withNx } = require('@nrwl/webpack')
const webpack = require('webpack')
const TerserPlugin = require("terser-webpack-plugin")
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
// Nx plugins for webpack.
module.exports = composePlugins(withNx(), (config) => {
// Update the webpack config as needed here.
// e.g. `config.plugins.push(new MyPlugin())`
// add fallback for node modules
config.resolve.fallback = {
...config.resolve.fallback,
"crypto": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"path": require.resolve("path-browserify"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"constants": require.resolve("constants-browserify"),
"os": false, //require.resolve("os-browserify/browser"),
"timers": false, // require.resolve("timers-browserify"),
"zlib": require.resolve("browserify-zlib"),
"fs": false,
"module": false,
"tls": false,
"net": false,
"readline": false,
"child_process": false,
"buffer": require.resolve("buffer/"),
"vm": require.resolve('vm-browserify'),
}
// add externals
config.externals = {
...config.externals,
solc: 'solc',
}
// add public path
config.output.publicPath = '/'
// add copy & provide plugin
config.plugins.push(
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
url: ['url', 'URL'],
process: 'process/browser',
})
)
// souce-map loader
config.module.rules.push({
test: /\.js$/,
use: ["source-map-loader"],
enforce: "pre"
})
config.ignoreWarnings = [/Failed to parse source map/] // ignore source-map-loader warnings
// set minimizer
config.optimization.minimizer = [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 2015,
compress: false,
mangle: false,
format: {
comments: false,
},
},
extractComments: false,
}),
new CssMinimizerPlugin(),
];
return config;
});
Loading…
Cancel
Save