Skip to content

Commit 863f395

Browse files
committed
update state
1 parent d59fb9b commit 863f395

File tree

4 files changed

+268
-544
lines changed

4 files changed

+268
-544
lines changed

libs/remix-ui/solidity-compiler/src/lib/api/compiler-api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
152152
* @param {object} settings {evmVersion, optimize, runs, version, language}
153153
*/
154154
async compileWithParameters (compilationTargets: Source, settings: CompilerInputOptions) {
155-
const compilerState = this.getCompilerState()
155+
const compilerState = await this.getCompilerState()
156156
const version = settings.version || compilerState.currentVersion
157157
const settingsCompile: CompilerInput = JSON.parse(compilerInputFactory(null, settings))
158158
const res = await compile(
@@ -165,8 +165,8 @@ export const CompilerApiMixin = (Base) => class extends Base {
165165
}
166166

167167
// This function is used for passing the compiler configuration to 'remix-tests'
168-
getCurrentCompilerConfig () {
169-
const compilerState = this.getCompilerState()
168+
async getCurrentCompilerConfig () {
169+
const compilerState = await this.getCompilerState()
170170
const compilerDetails: any = {
171171
currentVersion: compilerState.currentVersion,
172172
evmVersion: compilerState.evmVersion,

libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class CompileTabLogic {
5656
if (this.language != null) {
5757
this.compiler.set('language', this.language)
5858
}
59+
5960
}
6061

6162
setOptimize (newOptimizeValue: boolean) {
@@ -64,9 +65,11 @@ export class CompileTabLogic {
6465
this.compiler.set('optimize', this.optimize)
6566
}
6667

67-
setUseFileConfiguration (useFileConfiguration: boolean) {
68+
async setUseFileConfiguration (useFileConfiguration: boolean) {
6869
this.useFileConfiguration = useFileConfiguration
70+
console.log('setUseFileConfiguration', useFileConfiguration)
6971
this.compiler.set('useFileConfiguration', useFileConfiguration)
72+
await this.setCompilerConfigContent()
7073
}
7174

7275
setConfigFilePath (path) {
@@ -85,7 +88,10 @@ export class CompileTabLogic {
8588
this.compiler.set('evmVersion', this.evmVersion)
8689
}
8790

88-
getCompilerState () {
91+
async getCompilerState () {
92+
await this.setCompilerMappings()
93+
await this.setCompilerConfigContent()
94+
console.log('getCompilerState', this.compiler)
8995
return this.compiler.state
9096
}
9197

@@ -99,6 +105,23 @@ export class CompileTabLogic {
99105
this.compiler.set('language', lang)
100106
}
101107

108+
async setCompilerMappings () {
109+
if (await this.api.fileExists('remappings.txt')) {
110+
this.api.readFile('remappings.txt').then(remappings => {
111+
this.compiler.set('remappings', remappings.split('\n').filter(Boolean))
112+
})
113+
} else this.compiler.set('remappings', [])
114+
}
115+
116+
async setCompilerConfigContent () {
117+
if (this.configFilePath && this.useFileConfiguration) {
118+
this.api.readFile(this.configFilePath).then(content => {
119+
this.compiler.set('configFileContent', content)
120+
})
121+
}
122+
}
123+
124+
102125
/**
103126
* Compile a specific file of the file manager
104127
* @param {string} target the path to the file to compile
@@ -110,16 +133,8 @@ export class CompileTabLogic {
110133
const sources = { [target]: { content } }
111134
this.event.emit('removeAnnotations')
112135
this.event.emit('startingCompilation')
113-
if (await this.api.fileExists('remappings.txt')) {
114-
this.api.readFile('remappings.txt').then(remappings => {
115-
this.compiler.set('remappings', remappings.split('\n').filter(Boolean))
116-
})
117-
} else this.compiler.set('remappings', [])
118-
if (this.configFilePath) {
119-
this.api.readFile(this.configFilePath).then( contentConfig => {
120-
this.compiler.set('configFileContent', contentConfig)
121-
})
122-
}
136+
await this.setCompilerMappings()
137+
await this.setCompilerConfigContent()
123138
// setTimeout fix the animation on chrome... (animation triggered by 'staringCompilation')
124139
setTimeout(() => { this.compiler.compile(sources, target); resolve(true) }, 100)
125140
}).catch((error) => {

libs/remix-ui/solidity-compiler/src/lib/reducers/compiler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const compilerInitialState = {
1414
}
1515

1616
export const compilerReducer = (state = compilerInitialState, action: Action) => {
17+
console.log('compilerReducer', action)
1718
switch (action.type) {
1819
case 'SET_COMPILER_MODE': {
1920
return {

0 commit comments

Comments
 (0)