refactorqueryParams

pull/1487/head
yann300 3 years ago
parent 0e6c04194a
commit bea98e0a1f
  1. 10
      apps/remix-ide/src/app/tabs/compile-tab.js
  2. 10
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  3. 20
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  4. 4
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  5. 3
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -52,7 +52,7 @@ class CompileTab extends ViewPlugin {
eventHandlers: {}, eventHandlers: {},
loading: false loading: false
} }
this.compileTabLogic = new CompileTabLogic( this.compileTabLogic = new CompileTabLogic(this,
this.queryParams, this.queryParams,
this.fileManager, this.fileManager,
this.config, this.config,
@ -277,6 +277,14 @@ class CompileTab extends ViewPlugin {
, this.el) , this.el)
} }
getParameters () {
return this.queryParams.get()
}
setParameters (params) {
this.queryParams.update(params)
}
onActivation () { onActivation () {
this.call('manager', 'activatePlugin', 'solidity-logic') this.call('manager', 'activatePlugin', 'solidity-logic')
this.listenToEvents() this.listenToEvents()

@ -18,7 +18,7 @@ declare global {
const _paq = window._paq = window._paq || [] //eslint-disable-line const _paq = window._paq = window._paq || [] //eslint-disable-line
export const CompilerContainer = (props: CompilerContainerProps) => { export const CompilerContainer = (props: CompilerContainerProps) => {
const { config, queryParams, compileTabLogic, tooltip, modal, compiledFileName, setHardHatCompilation, updateCurrentVersion, isHardHatProject, configurationSettings } = props // eslint-disable-line const { api, config, compileTabLogic, tooltip, modal, compiledFileName, setHardHatCompilation, updateCurrentVersion, isHardHatProject, configurationSettings } = props // eslint-disable-line
const [state, setState] = useState({ const [state, setState] = useState({
hideWarnings: false, hideWarnings: false,
autoCompile: false, autoCompile: false,
@ -65,7 +65,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
useEffect(() => { useEffect(() => {
if (compileTabLogic && compileTabLogic.compiler) { if (compileTabLogic && compileTabLogic.compiler) {
setState(prevState => { setState(prevState => {
const params = queryParams.get() const params = api.getParameters()
const optimize = params.optimize === 'false' ? false : params.optimize === 'true' ? true : null const optimize = params.optimize === 'false' ? false : params.optimize === 'true' ? true : null
const runs = params.runs const runs = params.runs
const evmVersion = params.evmVersion const evmVersion = params.evmVersion
@ -152,7 +152,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
allVersions = [...allVersions, ...versions] allVersions = [...allVersions, ...versions]
selectedVersion = state.defaultVersion selectedVersion = state.defaultVersion
if (queryParams.get().version) selectedVersion = queryParams.get().version if (api.getParameters().version) selectedVersion = api.getParameters().version
// Check if version is a URL and corresponding filename starts with 'soljson' // Check if version is a URL and corresponding filename starts with 'soljson'
if (selectedVersion.startsWith('https://')) { if (selectedVersion.startsWith('https://')) {
const urlArr = selectedVersion.split('/') const urlArr = selectedVersion.split('/')
@ -321,7 +321,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}) })
} }
updateCurrentVersion(selectedVersion) updateCurrentVersion(selectedVersion)
queryParams.update({ version: selectedVersion }) api.setParameters({ version: selectedVersion })
let url let url
if (customUrl !== '') { if (customUrl !== '') {
@ -331,7 +331,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}) })
updateCurrentVersion(selectedVersion) updateCurrentVersion(selectedVersion)
url = customUrl url = customUrl
queryParams.update({ version: selectedVersion }) api.setParameters({ version: selectedVersion })
} else if (selectedVersion === 'builtin') { } else if (selectedVersion === 'builtin') {
let location: string | Location = window.document.location let location: string | Location = window.document.location
let path = location.pathname let path = location.pathname

@ -18,46 +18,46 @@ export class CompileTab extends Plugin {
public compilerImport public compilerImport
public event public event
constructor (public queryParams, public fileManager, public config, public fileProvider, public contentImport) { constructor (public api, public fileManager, public config, public fileProvider, public contentImport) {
super(profile) super(profile)
this.event = new EventEmitter() this.event = new EventEmitter()
this.compiler = new Compiler((url, cb) => this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))) this.compiler = new Compiler((url, cb) => this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message)))
} }
init () { init () {
this.optimize = this.queryParams.get().optimize this.optimize = this.api.getParameters().optimize
this.optimize = this.optimize === 'true' this.optimize = this.optimize === 'true'
this.queryParams.update({ optimize: this.optimize }) this.api.setParameters({ optimize: this.optimize })
this.compiler.set('optimize', this.optimize) this.compiler.set('optimize', this.optimize)
this.runs = this.queryParams.get().runs this.runs = this.api.getParameters().runs
this.runs = this.runs && this.runs !== 'undefined' ? this.runs : 200 this.runs = this.runs && this.runs !== 'undefined' ? this.runs : 200
this.queryParams.update({ runs: this.runs }) this.api.setParameters({ runs: this.runs })
this.compiler.set('runs', this.runs) this.compiler.set('runs', this.runs)
this.evmVersion = this.queryParams.get().evmVersion this.evmVersion = this.api.getParameters().evmVersion
if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) { if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) {
this.evmVersion = null this.evmVersion = null
} }
this.queryParams.update({ evmVersion: this.evmVersion }) this.api.setParameters({ evmVersion: this.evmVersion })
this.compiler.set('evmVersion', this.evmVersion) this.compiler.set('evmVersion', this.evmVersion)
} }
setOptimize (newOptimizeValue) { setOptimize (newOptimizeValue) {
this.optimize = newOptimizeValue this.optimize = newOptimizeValue
this.queryParams.update({ optimize: this.optimize }) this.api.setParameters({ optimize: this.optimize })
this.compiler.set('optimize', this.optimize) this.compiler.set('optimize', this.optimize)
} }
setRuns (runs) { setRuns (runs) {
this.runs = runs this.runs = runs
this.queryParams.update({ runs: this.runs }) this.api.setParameters({ runs: this.runs })
this.compiler.set('runs', this.runs) this.compiler.set('runs', this.runs)
} }
setEvmVersion (newEvmVersion) { setEvmVersion (newEvmVersion) {
this.evmVersion = newEvmVersion this.evmVersion = newEvmVersion
this.queryParams.update({ evmVersion: this.evmVersion }) this.api.setParameters({ evmVersion: this.evmVersion })
this.compiler.set('evmVersion', this.evmVersion) this.compiler.set('evmVersion', this.evmVersion)
} }

@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line
import './css/style.css' import './css/style.css'
export const SolidityCompiler = (props: SolidityCompilerProps) => { export const SolidityCompiler = (props: SolidityCompilerProps) => {
const { plugin, plugin: { config, queryParams, compileTabLogic, currentFile, fileProvider, fileManager, contractsDetails, contractMap, compileErrors, isHardHatProject, setHardHatCompilation, configurationSettings } } = props const { plugin, plugin: { config, compileTabLogic, currentFile, fileProvider, fileManager, contractsDetails, contractMap, compileErrors, isHardHatProject, setHardHatCompilation, configurationSettings } } = props
const [state, setState] = useState({ const [state, setState] = useState({
contractsDetails: {}, contractsDetails: {},
eventHandlers: {}, eventHandlers: {},
@ -78,7 +78,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
return ( return (
<> <>
<div id="compileTabView"> <div id="compileTabView">
<CompilerContainer config={config} queryParams={queryParams} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} setHardHatCompilation={setHardHatCompilation.bind(plugin)} updateCurrentVersion={updateCurrentVersion} isHardHatProject={isHardHatProject} configurationSettings={configurationSettings} /> <CompilerContainer api={plugin} config={config} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} setHardHatCompilation={setHardHatCompilation.bind(plugin)} updateCurrentVersion={updateCurrentVersion} isHardHatProject={isHardHatProject} configurationSettings={configurationSettings} />
<ContractSelection contractMap={contractMap} fileProvider={fileProvider} fileManager={fileManager} contractsDetails={contractsDetails} modal={modal} /> <ContractSelection contractMap={contractMap} fileProvider={fileProvider} fileManager={fileManager} contractsDetails={contractsDetails} modal={modal} />
<div className="remixui_errorBlobs p-4" data-id="compiledErrors"> <div className="remixui_errorBlobs p-4" data-id="compiledErrors">
<span data-id={`compilationFinishedWith_${currentVersion}`}></span> <span data-id={`compilationFinishedWith_${currentVersion}`}></span>

@ -5,7 +5,6 @@ export interface SolidityCompilerProps {
} | Record<string, any> } | Record<string, any>
compileErrors: any, compileErrors: any,
isHardHatProject: boolean, isHardHatProject: boolean,
queryParams: any,
compileTabLogic: any, compileTabLogic: any,
currentFile: string, currentFile: string,
contractsDetails: Record<string, any>, contractsDetails: Record<string, any>,
@ -22,8 +21,8 @@ export interface SolidityCompilerProps {
} }
export interface CompilerContainerProps { export interface CompilerContainerProps {
api: any,
config: any, config: any,
queryParams: any,
compileTabLogic: any, compileTabLogic: any,
tooltip: (message: string | JSX.Element) => void, tooltip: (message: string | JSX.Element) => void,
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,

Loading…
Cancel
Save