handle noFileSelected case

pull/2756/head
yann300 2 years ago
parent e9ed7cb9fb
commit b73c984708
  1. 3
      apps/vyper/src/app/app.tsx
  2. 18
      apps/vyper/src/app/components/CompilerButton.tsx
  3. 4
      apps/vyper/src/app/utils/compiler.tsx
  4. 8
      apps/vyper/src/app/utils/remix-client.tsx

@ -38,7 +38,8 @@ const App: React.FC = () => {
async function start() {
try {
await remixClient.loaded()
remixClient.onFileChange(name => setContract(name))
remixClient.onFileChange(name => setContract(name))
remixClient.onNoFileSelected(() => setContract(''))
const name = await remixClient.getContractName()
setContract(name)
} catch (err) {

@ -31,8 +31,8 @@ function CompilerButton({ contract, setOutput, compilerUrl }: Props) {
let _contract
try {
_contract = await remixClient.getContract()
} catch (e) {
setOutput('', { status: 'failed', message: err.message})
} catch (e: any) {
setOutput('', { status: 'failed', message: e.message})
return
}
remixClient.changeStatus({
@ -43,19 +43,21 @@ function CompilerButton({ contract, setOutput, compilerUrl }: Props) {
let output
try {
output = await compile(compilerUrl, _contract)
} catch (e) {
setOutput(_contract.name, { status: 'failed', message: err.message})
} catch (e: any) {
setOutput(_contract.name, { status: 'failed', message: e.message})
return
}
setOutput(_contract.name, output)
// ERROR
if (isCompilationError(output)) {
const line = output.line
const lineColumnPos = {
start: { line: line - 1 },
end: { line: line - 1 }
if (line) {
const lineColumnPos = {
start: { line: line - 1 },
end: { line: line - 1 }
}
remixClient.highlight(lineColumnPos as any, _contract.name, '#e0b4b4')
}
remixClient.highlight(lineColumnPos as any, _contract.name, '#e0b4b4')
throw new Error(output.message)
}
// SUCCESS

@ -18,8 +18,8 @@ export interface VyperCompilationResult {
export interface VyperCompilationError {
status: 'failed'
column: number
line: number
column?: number
line?: number
message: string
}

@ -14,11 +14,17 @@ export class RemixClient extends PluginClient {
/** Emit an event when file changed */
async onFileChange(cb: (contract: string) => any) {
this.client.on('fileManager', 'currentFileChanged', async (name: string) => {
if (!name) return
cb(name)
})
}
/** Emit an event when file changed */
async onNoFileSelected(cb: () => any) {
this.client.on('fileManager', 'noFileSelected', async () => {
cb()
})
}
/** Load Ballot contract example into the file manager */
async loadContract({name, content}: Contract) {
try {

Loading…
Cancel
Save