intermediate commiy

pull/2265/head
aniket-engg 3 years ago committed by yann300
parent 099b4a0053
commit 5703f65322
  1. 34
      apps/solidity-compiler/src/app/compiler-api.ts
  2. 1
      apps/solidity-compiler/webpack.config.js
  3. 1
      libs/remix-lib/src/types/ICompilerApi.ts
  4. 31
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  5. 35
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  6. 6
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  7. 1
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts
  8. 1231
      package-lock.json
  9. 2
      package.json

@ -1,6 +1,11 @@
import React from 'react';
import { compile, helper } from '@remix-project/remix-solidity'
import { CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line
import type { ConfigurationSettings } from '@remix-project/remix-lib-ts'
import Schema from "@truffle/contract-schema"
import Config from '@truffle/config'
import { Compile } from "@truffle/compile-solidity"
import { Shims } from "@truffle/compile-common"
export const CompilerApiMixin = (Base) => class extends Base {
currentFile: string
@ -100,6 +105,35 @@ export const CompilerApiMixin = (Base) => class extends Base {
return this.call('hardhat', 'compile', configFile)
}
async compileWithTruffle (fileName, CompConfig) {
console.log('fileName-in compileWithTruffle-->', fileName)
console.log('config-in compileWithTruffle-->', CompConfig)
const sources = {
Example: await this.call('fileManager', 'getFile', fileName)
}
let config = Config.default().with(CompConfig)
console.log('config---->', config)
console.log('sources---->', sources)
// Compile first
const { compilations } = await Compile.sources({
sources,
options: config
});
console.log('compilations----->', compilations)
const { contracts } = compilations[0];
// use forEach
const exampleContract = contracts.find(
contract => contract.contractName === "Owner"
);
const compiled = Schema.normalize(
Shims.NewToLegacy.forContract(exampleContract)
);
if(!compiled.updatedAt) compiled.updatedAt = new Date().toISOString()
console.log('compiled----->', compiled)
return "done"
}
logToTerminal (content) {
return this.call('terminal', 'log', content)
}

@ -7,6 +7,7 @@ module.exports = config => {
...nxWebpackConfig,
node: {
fs: 'empty',
path: 'empty',
tls: 'empty',
readline: 'empty',
net: 'empty',

@ -41,6 +41,7 @@ export interface ICompilerApi {
logToTerminal: (log: terminalLog) => void
compileWithHardhat: (configPath: string) => Promise<string>
compileWithTruffle: (file: string, config: Record<string, any>) => Promise<string>
statusChanged: (data: { key: string, title?: string, type?: string }) => void,
emit?: (key: string, ...payload: any) => void
}

@ -20,7 +20,7 @@ declare global {
const _paq = window._paq = window._paq || [] //eslint-disable-line
export const CompilerContainer = (props: CompilerContainerProps) => {
const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject } = props // eslint-disable-line
const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject } = props // eslint-disable-line
const [state, setState] = useState({
hideWarnings: false,
autoCompile: false,
@ -42,6 +42,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const compileIcon = useRef(null)
const promptMessageInput = useRef(null)
const [hhCompilation, sethhCompilation] = useState(false)
const [truffleCompilation, setTruffleCompilation] = useState(false)
const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState)
useEffect(() => {
@ -325,7 +326,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
if (!isSolFileSelected()) return
_setCompilerVersionFromPragma(currentFile)
compileTabLogic.runCompiler(hhCompilation)
let externalCompType
if (hhCompilation) externalCompType = 'hardhat'
else if (truffleCompilation) externalCompType = 'truffle'
compileTabLogic.runCompiler(externalCompType)
}
const _updateVersionSelector = (version, customUrl = '') => {
@ -500,6 +504,13 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
api.setAppParameter('hardhat-compilation', checked)
}
const updateTruffleCompilation = (event) => {
const checked = event.target.checked
setTruffleCompilation(checked)
api.setAppParameter('truffle-compilation', checked)
}
/*
The following functions map with the above event handlers.
They are an external API for modifying the compiler configuration.
@ -594,6 +605,22 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
</a>
</div>
}
{
isTruffleProject &&
<div className="mt-3 remixui_compilerConfig custom-control custom-checkbox">
<input className="remixui_autocompile custom-control-input" onChange={updateTruffleCompilation} id="enableTruffle" type="checkbox" title="Enable Truffle Compilation" checked={truffleCompilation} />
<label className="form-check-label custom-control-label" htmlFor="enableTruffle">Enable Truffle Compilation</label>
<a className="mt-1 text-nowrap" href='https://remix-ide.readthedocs.io/en/latest/' target={'_blank'}>
<OverlayTrigger placement={'right'} overlay={
<Tooltip className="text-nowrap" id="overlay-tooltip">
<span className="p-1 pr-3" style={{ backgroundColor: 'black', minWidth: '230px' }}>Learn how to use Truffle Compilation</span>
</Tooltip>
}>
<i style={{ fontSize: 'medium' }} className={'ml-2 fal fa-info-circle'} aria-hidden="true"></i>
</OverlayTrigger>
</a>
</div>
}
<button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block remixui_disabled mt-3" title="Compile" onClick={compile} disabled={disableCompileButton}>
<span>
{ <i ref={compileIcon} className="fas fa-sync remixui_iconbtn" aria-hidden="true"></i> }

@ -109,9 +109,16 @@ export class CompileTabLogic {
} else return false
}
runCompiler (hhCompilation) {
async isTruffleProject () {
return true
// if (this.api.getFileManagerMode() === 'localhost') {
// return await this.api.fileExists('truffle.config.js')
// } else return false
}
runCompiler (externalCompType) {
try {
if (this.api.getFileManagerMode() === 'localhost' && hhCompilation) {
if (this.api.getFileManagerMode() === 'localhost' && externalCompType === 'hardhat') {
const { currentVersion, optimize, runs } = this.compiler.state
if (currentVersion) {
const fileContent = `module.exports = {
@ -133,6 +140,30 @@ export class CompileTabLogic {
this.api.logToTerminal({ type: 'error', value: error })
})
}
} else if (externalCompType === 'truffle') {
const fileName = this.api.currentFile
const { currentVersion, optimize, runs, evmVersion} = this.compiler.state
if (currentVersion) {
const compConfig = {
compilers: {
solc: {
version: `'${currentVersion.substring(0, currentVersion.indexOf('+commit'))}'`,
settings: {
optimizer: {
enabled: optimize,
runs: runs
},
evmVersion: evmVersion
}
}
}
}
this.api.compileWithTruffle(fileName, compConfig).then((result) => {
this.api.logToTerminal({ type: 'info', value: result })
}).catch((error) => {
this.api.logToTerminal({ type: 'error', value: error })
})
}
}
// TODO readd saving current file
this.api.saveCurrentFile()

@ -12,6 +12,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const { api, api: { currentFile, compileTabLogic, configurationSettings } } = props
const [state, setState] = useState({
isHardhatProject: false,
isTruffleProject: false,
currentFile,
loading: false,
compileTabLogic: null,
@ -64,8 +65,9 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
api.onSetWorkspace = async (isLocalhost: boolean) => {
const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
const isTruffle = await compileTabLogic.isTruffleProject()
setState(prevState => {
return { ...prevState, currentFile, isHardhatProject: isHardhat }
return { ...prevState, currentFile, isHardhatProject: isHardhat, isTruffleProject: isTruffle }
})
}
@ -148,7 +150,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
return (
<>
<div id="compileTabView">
<CompilerContainer api={api} isHardhatProject={state.isHardhatProject} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} />
<CompilerContainer api={api} isHardhatProject={state.isHardhatProject} isTruffleProject={state.isTruffleProject} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} />
{ contractsFile[currentFile] && contractsFile[currentFile].contractsDetails && <ContractSelection api={api} contractsDetails={contractsFile[currentFile].contractsDetails} contractList={contractsFile[currentFile].contractList} modal={modal} /> }
{ compileErrors[currentFile] &&
<div className="remixui_errorBlobs p-4" data-id="compiledErrors">

@ -10,6 +10,7 @@ export interface CompilerContainerProps {
api: ICompilerApi,
compileTabLogic: CompileTabLogic,
isHardhatProject: boolean,
isTruffleProject: boolean,
tooltip: (message: string | JSX.Element) => void,
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,
compiledFileName: string,

1231
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -159,6 +159,8 @@
"@remixproject/plugin-utils": "^0.3.28",
"@remixproject/plugin-webview": "^0.3.28",
"@remixproject/plugin-ws": "^0.3.28",
"@truffle/compile-solidity": "^6.0.17",
"@truffle/contract-schema": "^3.4.6",
"ansi-gray": "^0.1.1",
"async": "^2.6.2",
"axios": ">=0.26.0",

Loading…
Cancel
Save