parent
eb7991a36d
commit
c1dd4d748e
@ -1,17 +1,23 @@ |
|||||||
import React from "react" |
import React from "react"; |
||||||
import { PluginApi, IRemixApi, Api, PluginClient, CompilationResult } from "@remixproject/plugin" |
import { |
||||||
|
PluginApi, |
||||||
|
IRemixApi, |
||||||
|
Api, |
||||||
|
PluginClient, |
||||||
|
CompilationResult, |
||||||
|
} from "@remixproject/plugin"; |
||||||
|
|
||||||
import { ContractName, Documentation, PublishedSite } from "./types" |
import { ContractName, Documentation, PublishedSite } from "./types"; |
||||||
|
|
||||||
export const AppContext = React.createContext({ |
export const AppContext = React.createContext({ |
||||||
clientInstance: {} as PluginApi<Readonly<IRemixApi>> & |
clientInstance: {} as PluginApi<Readonly<IRemixApi>> & |
||||||
PluginClient<Api, Readonly<IRemixApi>>, |
PluginClient<Api, Readonly<IRemixApi>>, |
||||||
contracts: new Map<ContractName, Documentation>(), |
contracts: new Map<ContractName, Documentation>(), |
||||||
setContracts: (contracts: Map<ContractName, Documentation>) => { |
setContracts: (contracts: Map<ContractName, Documentation>) => { |
||||||
console.log("Calling Set Contract Names") |
console.log("Calling Set Contract Names"); |
||||||
}, |
}, |
||||||
sites: [], |
sites: [], |
||||||
setSites: (sites: PublishedSite[]) => { |
setSites: (sites: PublishedSite[]) => { |
||||||
console.log("Calling Set Sites") |
console.log("Calling Set Sites"); |
||||||
} |
}, |
||||||
}) |
}); |
||||||
|
@ -1,11 +1,11 @@ |
|||||||
import React from 'react'; |
import React from "react"; |
||||||
import ReactDOM from 'react-dom'; |
import ReactDOM from "react-dom"; |
||||||
import App from './App'; |
import App from "./App"; |
||||||
import { Routes } from './routes' |
import { Routes } from "./routes"; |
||||||
|
|
||||||
ReactDOM.render( |
ReactDOM.render( |
||||||
<React.StrictMode> |
<React.StrictMode> |
||||||
<App /> |
<App /> |
||||||
</React.StrictMode>, |
</React.StrictMode>, |
||||||
document.getElementById('root') |
document.getElementById("root") |
||||||
); |
); |
@ -1,30 +1,30 @@ |
|||||||
import { CompiledContract, ABIParameter } from '@remixproject/plugin' |
import { CompiledContract, ABIParameter } from "@remixproject/plugin"; |
||||||
|
|
||||||
import sampleData from './sample-data/sample-artifact.json' |
import sampleData from "./sample-data/sample-artifact.json"; |
||||||
import sampleDataWithComments from './sample-data/sample-artifact-with-comments.json' |
import sampleDataWithComments from "./sample-data/sample-artifact-with-comments.json"; |
||||||
|
|
||||||
export const buildFakeArtifact: () => CompiledContract = () => { |
export const buildFakeArtifact: () => CompiledContract = () => { |
||||||
const result = sampleData as never as CompiledContract |
const result = (sampleData as never) as CompiledContract; |
||||||
return result |
return result; |
||||||
} |
}; |
||||||
|
|
||||||
export const buildFakeArtifactWithComments: () => CompiledContract = () => { |
export const buildFakeArtifactWithComments: () => CompiledContract = () => { |
||||||
const result = sampleDataWithComments as never as CompiledContract |
const result = (sampleDataWithComments as never) as CompiledContract; |
||||||
return result |
return result; |
||||||
} |
}; |
||||||
|
|
||||||
export const buildFakeABIParameter: () => ABIParameter = () => { |
export const buildFakeABIParameter: () => ABIParameter = () => { |
||||||
return { |
return { |
||||||
internalType: "address", |
internalType: "address", |
||||||
name: "allocator", |
name: "allocator", |
||||||
type: "address" |
type: "address", |
||||||
} |
}; |
||||||
} |
}; |
||||||
|
|
||||||
export const buildFakeABIParameterWithDocumentation: () => ABIParameter = () => { |
export const buildFakeABIParameterWithDocumentation: () => ABIParameter = () => { |
||||||
return { |
return { |
||||||
internalType: "address", |
internalType: "address", |
||||||
name: "allocator", |
name: "allocator", |
||||||
type: "address" |
type: "address", |
||||||
} |
}; |
||||||
} |
}; |
||||||
|
@ -1,2 +1,2 @@ |
|||||||
export * from './utils' |
export * from "./utils"; |
||||||
export * from './publisher' |
export * from "./publisher"; |
||||||
|
@ -1,13 +1,18 @@ |
|||||||
import { HTMLContent } from "./types"; |
import { HTMLContent } from "./types"; |
||||||
|
|
||||||
const IpfsClient = require('ipfs-mini') |
// tslint:disable-next-line
|
||||||
|
const IpfsClient = require("ipfs-mini"); |
||||||
|
|
||||||
export const publish = async (content: HTMLContent) => { |
export const publish = async (content: HTMLContent) => { |
||||||
const ipfs = new IpfsClient({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' }); |
const ipfs = new IpfsClient({ |
||||||
|
host: "ipfs.infura.io", |
||||||
|
port: 5001, |
||||||
|
protocol: "https", |
||||||
|
}); |
||||||
|
|
||||||
const documentHash = await ipfs.add(content) |
const documentHash = await ipfs.add(content); |
||||||
|
|
||||||
console.log("Document hash", documentHash) |
console.log("Document hash", documentHash); |
||||||
|
|
||||||
return documentHash |
return documentHash; |
||||||
} |
}; |
||||||
|
@ -1,94 +1,130 @@ |
|||||||
import { CompilationResult, CompiledContract, FunctionDescription, ABIDescription, DevMethodDoc, UserMethodDoc, ABIParameter, DeveloperDocumentation, UserDocumentation } from "@remixproject/plugin" |
import { |
||||||
|
CompilationResult, |
||||||
import { EthDocumentation, FileName, Documentation, ContractName } from '../types' |
CompiledContract, |
||||||
import { template } from './template' |
FunctionDescription, |
||||||
import { ContractDocumentation, MethodDoc, FunctionDocumentation, ParameterDocumentation, MethodsDocumentation } from './types' |
ABIDescription, |
||||||
|
DevMethodDoc, |
||||||
export const createDocumentation = (fileName: FileName, compilationResult: CompilationResult) => { |
UserMethodDoc, |
||||||
console.log("Filename", fileName) |
ABIParameter, |
||||||
|
DeveloperDocumentation, |
||||||
|
UserDocumentation, |
||||||
|
} from "@remixproject/plugin"; |
||||||
|
|
||||||
|
import { |
||||||
|
EthDocumentation, |
||||||
|
FileName, |
||||||
|
Documentation, |
||||||
|
ContractName, |
||||||
|
} from "../types"; |
||||||
|
import { template } from "./template"; |
||||||
|
import { |
||||||
|
ContractDocumentation, |
||||||
|
MethodDoc, |
||||||
|
FunctionDocumentation, |
||||||
|
ParameterDocumentation, |
||||||
|
MethodsDocumentation, |
||||||
|
} from "./types"; |
||||||
|
|
||||||
|
export const createDocumentation = ( |
||||||
|
fileName: FileName, |
||||||
|
compilationResult: CompilationResult |
||||||
|
) => { |
||||||
|
console.log("Filename", fileName); |
||||||
const result = new Map<ContractName, Documentation>(); |
const result = new Map<ContractName, Documentation>(); |
||||||
|
|
||||||
const contracts = compilationResult.contracts[fileName] |
const contracts = compilationResult.contracts[fileName]; |
||||||
console.log("Contracts", contracts) |
console.log("Contracts", contracts); |
||||||
|
|
||||||
Object.keys(contracts).forEach((name) => { |
Object.keys(contracts).forEach((name) => { |
||||||
console.log("CompiledContract", JSON.stringify(contracts[name])) |
console.log("CompiledContract", JSON.stringify(contracts[name])); |
||||||
result.set(name, getContractDoc(name, contracts[name])) |
result.set(name, getContractDoc(name, contracts[name])); |
||||||
}) |
}); |
||||||
|
|
||||||
return result |
return result; |
||||||
} |
}; |
||||||
|
|
||||||
export const getContractDoc = (name: string, contract: CompiledContract) => { |
export const getContractDoc = (name: string, contract: CompiledContract) => { |
||||||
const contractDoc: ContractDocumentation = getContractDocumentation(contract) |
const contractDoc: ContractDocumentation = getContractDocumentation(contract); |
||||||
|
|
||||||
const functionsDocumentation = contract.abi |
const functionsDocumentation = contract.abi.map((def: ABIDescription) => { |
||||||
.map((def: ABIDescription) => { |
if (def.type === "constructor") { |
||||||
if (def.type === 'constructor') { |
def.name = "constructor"; |
||||||
def.name = 'constructor' |
|
||||||
// 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: contract.userdoc.methods.constructor as string |
notice: contract.userdoc.methods.constructor as string, |
||||||
} |
}; |
||||||
return getFunctionDocumentation(def, methodDoc) |
return getFunctionDocumentation(def, methodDoc); |
||||||
} else { |
} else { |
||||||
if (def.type === 'fallback') { |
if (def.type === "fallback") { |
||||||
def.name = 'fallback' |
def.name = "fallback"; |
||||||
} |
} |
||||||
const method = Object.keys(contractDoc.methods).find((key) => key.includes(def.name as string)) as string |
const method = Object.keys(contractDoc.methods).find((key) => |
||||||
const methodDoc = contractDoc.methods[method] |
key.includes(def.name as string) |
||||||
return getFunctionDocumentation(def as FunctionDescription, methodDoc) |
) as string; |
||||||
|
const methodDoc = contractDoc.methods[method]; |
||||||
|
return getFunctionDocumentation(def as FunctionDescription, methodDoc); |
||||||
} |
} |
||||||
}) |
}); |
||||||
|
|
||||||
return template(name, contractDoc, functionsDocumentation) |
return template(name, contractDoc, functionsDocumentation); |
||||||
} |
}; |
||||||
|
|
||||||
export const getContractDocumentation = (contract: CompiledContract) => { |
export const getContractDocumentation = (contract: CompiledContract) => { |
||||||
let methods: MethodsDocumentation = {}; |
const methods: MethodsDocumentation = {}; |
||||||
|
|
||||||
Object.keys(contract.userdoc.methods).map((item) => { |
Object.keys(contract.userdoc.methods).map((item) => { |
||||||
if (contract.devdoc.methods[item]) { |
if (contract.devdoc.methods[item]) { |
||||||
const finalResult = { |
const finalResult = { |
||||||
...contract.userdoc.methods[item], |
...contract.userdoc.methods[item], |
||||||
...contract.devdoc.methods[item] |
...contract.devdoc.methods[item], |
||||||
} |
}; |
||||||
methods[item] = finalResult |
methods[item] = finalResult; |
||||||
} else { |
} else { |
||||||
methods[item] = contract.userdoc.methods[item] |
methods[item] = contract.userdoc.methods[item]; |
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
const contractDoc = { ...contract.userdoc, ...contract.devdoc, methods } |
|
||||||
|
|
||||||
return contractDoc |
|
||||||
} |
} |
||||||
|
}); |
||||||
export const getFunctionDocumentation = (def: FunctionDescription, devdoc?: Partial<MethodDoc>) => { |
|
||||||
const doc = devdoc || {} |
const contractDoc = { ...contract.userdoc, ...contract.devdoc, methods }; |
||||||
const devparams = doc.params || {} |
|
||||||
const inputsWithDescription = mergeParametersWithDevdoc(def.inputs || [], devparams) |
return contractDoc; |
||||||
const outputsWithDescription = mergeParametersWithDevdoc(def.outputs || [], devparams) |
}; |
||||||
const type = def.constant ? 'view' : 'read' |
|
||||||
|
export const getFunctionDocumentation = ( |
||||||
|
def: FunctionDescription, |
||||||
|
devdoc?: Partial<MethodDoc> |
||||||
|
) => { |
||||||
|
const doc = devdoc || {}; |
||||||
|
const devparams = doc.params || {}; |
||||||
|
const inputsWithDescription = mergeParametersWithDevdoc( |
||||||
|
def.inputs || [], |
||||||
|
devparams |
||||||
|
); |
||||||
|
const outputsWithDescription = mergeParametersWithDevdoc( |
||||||
|
def.outputs || [], |
||||||
|
devparams |
||||||
|
); |
||||||
|
const type = def.constant ? "view" : "read"; |
||||||
|
|
||||||
return { |
return { |
||||||
name: def.name, |
name: def.name, |
||||||
type, |
type, |
||||||
devdoc: devdoc, |
devdoc, |
||||||
inputs: inputsWithDescription, |
inputs: inputsWithDescription, |
||||||
outputs: outputsWithDescription |
outputs: outputsWithDescription, |
||||||
} as FunctionDocumentation |
} as FunctionDocumentation; |
||||||
} |
}; |
||||||
|
|
||||||
export const mergeParametersWithDevdoc = (params: ABIParameter[], devparams: any) => { |
export const mergeParametersWithDevdoc = ( |
||||||
|
params: ABIParameter[], |
||||||
|
devparams: any |
||||||
|
) => { |
||||||
return params.map((input) => { |
return params.map((input) => { |
||||||
const description = devparams[input.name] || '' |
const description = devparams[input.name] || ""; |
||||||
return { |
return { |
||||||
name: input.name, |
name: input.name, |
||||||
type: input.type, |
type: input.type, |
||||||
description |
description, |
||||||
} as ParameterDocumentation |
} as ParameterDocumentation; |
||||||
}) |
}); |
||||||
} |
}; |
||||||
|
|
||||||
|
@ -1,2 +1,2 @@ |
|||||||
export { HomeView } from "./HomeView" |
export { HomeView } from "./HomeView"; |
||||||
export { ErrorView } from "./ErrorView" |
export { ErrorView } from "./ErrorView"; |
||||||
|
Loading…
Reference in new issue