pull/3542/head
Defi Boy 5 years ago committed by Joseph Izang
parent ef8eed76ec
commit 01b51a1bf3
  1. 2
      src/App.tsx
  2. 7
      src/AppContext.tsx
  3. 15
      src/utils/template.ts
  4. 113
      src/utils/utils.test.ts
  5. 17
      src/utils/utils.ts
  6. 5
      src/views/ErrorView.tsx

@ -47,7 +47,7 @@ const App = () => {
await client.onload(); await client.onload();
setClientInstance(client); setClientInstance(client);
console.log("Remix EthDoc Plugin has been loaded"); console.log("Remix EthDoc Plugin has been loaded");
await client.call('manager' as any, 'activatePlugin', "ethdoc-viewer") await client.call("manager" as any, "activatePlugin", "ethdoc-viewer");
client.solidity.on( client.solidity.on(
"compilationFinished", "compilationFinished",
( (

@ -1,10 +1,5 @@
import React from "react"; import React from "react";
import { import { PluginApi, IRemixApi, Api, PluginClient } from "@remixproject/plugin";
PluginApi,
IRemixApi,
Api,
PluginClient
} from "@remixproject/plugin";
import { ContractName, Documentation, PublishedSite } from "./types"; import { ContractName, Documentation, PublishedSite } from "./types";

@ -23,7 +23,7 @@ export const htmlTemplate = (content: HTMLContent) => {
${content} ${content}
</body> </body>
</html> </html>
` `;
}; };
export const template = ( export const template = (
@ -82,7 +82,7 @@ const devMethodDocTemplate: Partial<TemplateDoc<MethodDoc>> = {
author: (author: string) => `<p>Created By ${author}</p>`, author: (author: string) => `<p>Created By ${author}</p>`,
details: (details: string) => `<p>${details}</p>`, details: (details: string) => `<p>${details}</p>`,
return: (value: string) => `<p>Return : ${value}</p>`, return: (value: string) => `<p>Return : ${value}</p>`,
notice: (notice: string) => notice ? `<p>${notice}</p>` : '', notice: (notice: string) => (notice ? `<p>${notice}</p>` : ""),
// returns: () => '', // Implemented by getParams() // returns: () => '', // Implemented by getParams()
params: () => "", // Implemented by getParams() params: () => "", // Implemented by getParams()
}; };
@ -93,7 +93,7 @@ export const renderHeader = (
) => ` ) => `
<h3>${name} ${ <h3>${name} ${
contractDoc.title ? `<small>: ${contractDoc.title}</small>` : "" contractDoc.title ? `<small>: ${contractDoc.title}</small>` : ""
}</h3> }</h3>
${contractDoc.notice ? `<p class="lead">${contractDoc.notice}</p>` : ""} ${contractDoc.notice ? `<p class="lead">${contractDoc.notice}</p>` : ""}
@ -104,7 +104,8 @@ export const renderHeader = (
export const renderParameterDocumentation = ( export const renderParameterDocumentation = (
parameters: ParameterDocumentation[] parameters: ParameterDocumentation[]
) => `${ ) =>
`${
parameters.length > 0 parameters.length > 0
? `<table class="table table-sm table-bordered table-striped"> ? `<table class="table table-sm table-bordered table-striped">
<thead> <thead>
@ -115,13 +116,15 @@ export const renderParameterDocumentation = (
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
${parameters.map( ${parameters
.map(
(output) => `<tr> (output) => `<tr>
<td>${output.name}</td> <td>${output.name}</td>
<td>${output.type}</td> <td>${output.type}</td>
<td>${output.description}</td> <td>${output.description}</td>
</tr>` </tr>`
).join("")} )
.join("")}
</tbody> </tbody>
</table>` </table>`
: "<p>No parameters</p>" : "<p>No parameters</p>"

@ -48,92 +48,89 @@ describe("Publisher tests", () => {
expect(template).toBeDefined(); expect(template).toBeDefined();
}); });
test('getContractDoc', () => { test("getContractDoc", () => {
const template = getContractDoc( const template = getContractDoc("Owner", {
'Owner',
{
...buildFakeArtifactWithComments(), ...buildFakeArtifactWithComments(),
abi: [ abi: [
{ {
"inputs": [], inputs: [],
"stateMutability": "nonpayable", stateMutability: "nonpayable",
"type": "constructor" type: "constructor",
}, },
{ {
"anonymous": false, anonymous: false,
"inputs": [ inputs: [
{ {
"indexed": true, indexed: true,
"internalType": "address", internalType: "address",
"name": "oldOwner", name: "oldOwner",
"type": "address" type: "address",
}, },
{ {
"indexed": true, indexed: true,
"internalType": "address", internalType: "address",
"name": "newOwner", name: "newOwner",
"type": "address" type: "address",
} },
], ],
"name": "OwnerSet", name: "OwnerSet",
"type": "event" type: "event",
}, },
{ {
"inputs": [ inputs: [
{ {
"internalType": "address", internalType: "address",
"name": "newOwner", name: "newOwner",
"type": "address" type: "address",
} },
], ],
"name": "changeOwner", name: "changeOwner",
"outputs": [], outputs: [],
"stateMutability": "nonpayable", stateMutability: "nonpayable",
"type": "function" type: "function",
}, },
{ {
"inputs": [], inputs: [],
"name": "getOwner", name: "getOwner",
"outputs": [ outputs: [
{ {
"internalType": "address", internalType: "address",
"name": "", name: "",
"type": "address" type: "address",
} },
], ],
"stateMutability": "view", stateMutability: "view",
"type": "function" type: "function",
} },
] as any, ] as any,
devdoc: { devdoc: {
"details": "Set & change owner", details: "Set & change owner",
"methods": { methods: {
"changeOwner(address)": { "changeOwner(address)": {
"details": "Change owner", details: "Change owner",
"params": { params: {
"newOwner": "address of new owner" newOwner: "address of new owner",
}
}, },
"constructor": { },
"details": "Set contract deployer as owner" constructor: {
details: "Set contract deployer as owner",
}, },
"getOwner()": { "getOwner()": {
"details": "Return owner address ", details: "Return owner address ",
"returns": { returns: {
"_0": "address of owner" _0: "address of owner",
} },
}
}, },
"title": "Owner" },
title: "Owner",
} as any, } as any,
userdoc: { userdoc: {
"methods": {} methods: {},
} as any } as any,
} });
)
expect(template).toBeDefined(); expect(template).toBeDefined();
}) });
}); });
describe("getFunctionDocumentation", () => { describe("getFunctionDocumentation", () => {

@ -3,14 +3,10 @@ import {
CompiledContract, CompiledContract,
FunctionDescription, FunctionDescription,
ABIParameter, ABIParameter,
ABIDescription ABIDescription,
} from "@remixproject/plugin"; } from "@remixproject/plugin";
import { import { FileName, Documentation, ContractName } from "../types";
FileName,
Documentation,
ContractName,
} from "../types";
import { template } from "./template"; import { template } from "./template";
import { import {
ContractDocumentation, ContractDocumentation,
@ -42,8 +38,8 @@ export const getContractDoc = (name: string, contract: CompiledContract) => {
const contractDoc: ContractDocumentation = getContractDocumentation(contract); const contractDoc: ContractDocumentation = getContractDocumentation(contract);
const onlyFunctions = contract.abi.filter((item) => { const onlyFunctions = contract.abi.filter((item) => {
return item.type !== "event" return item.type !== "event";
}) });
const functionsDocumentation = onlyFunctions.map((def: ABIDescription) => { const functionsDocumentation = onlyFunctions.map((def: ABIDescription) => {
if (def.type === "constructor") { if (def.type === "constructor") {
@ -51,7 +47,10 @@ export const getContractDoc = (name: string, contract: CompiledContract) => {
// because "constructor" is a string and not a { notice } object for userdoc we need to do that // because "constructor" is a string and not a { notice } object for userdoc we need to do that
const methodDoc = { const methodDoc = {
...(contract.devdoc.methods.constructor || {}), ...(contract.devdoc.methods.constructor || {}),
notice: Object.keys(contract.userdoc.methods['constructor']).length > 0 ? contract.userdoc.methods['constructor'] as string : "", notice:
Object.keys(contract.userdoc.methods.constructor).length > 0
? (contract.userdoc.methods.constructor as string)
: "",
}; };
return getFunctionDocumentation(def, methodDoc); return getFunctionDocumentation(def, methodDoc);
} else { } else {

@ -19,7 +19,10 @@ export const ErrorView: React.FC = () => {
<h5>Sorry, something unexpected happened. </h5> <h5>Sorry, something unexpected happened. </h5>
<h5> <h5>
Please raise an issue:{" "} Please raise an issue:{" "}
<a style={{ color: "red" }} href="https://github.com/Machinalabs/remix-ethdoc-plugin/issues"> <a
style={{ color: "red" }}
href="https://github.com/Machinalabs/remix-ethdoc-plugin/issues"
>
Here Here
</a> </a>
</h5> </h5>

Loading…
Cancel
Save