ligo/tools/webide/packages/client/src/redux/actions/compile.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Dispatch } from 'redux';
import { compileContract, getErrorMessage } from '../../services/api';
import { AppState } from '../app';
import { DoneLoadingAction, UpdateLoadingAction } from '../loading';
import { ChangeOutputAction } from '../result';
2020-02-28 00:22:43 +04:00
import { Command } from '../types';
import { CancellableAction } from './cancellable';
export class CompileAction extends CancellableAction {
getAction() {
return async (dispatch: Dispatch, getState: () => AppState) => {
dispatch({ ...new UpdateLoadingAction('Compiling contract...') });
try {
const { editor, compile: compileState } = getState();
const michelsonCode = await compileContract(
editor.language,
editor.code,
2020-02-14 05:18:23 +04:00
compileState.entrypoint,
compileState.michelsonFormat
);
if (this.isCancelled()) {
return;
}
2020-02-28 00:22:43 +04:00
dispatch({
...new ChangeOutputAction(michelsonCode.result, Command.Compile)
});
} catch (ex) {
if (this.isCancelled()) {
return;
}
dispatch({
2020-02-28 00:22:43 +04:00
...new ChangeOutputAction(
`Error: ${getErrorMessage(ex)}`,
Command.Compile
)
});
}
dispatch({ ...new DoneLoadingAction() });
};
}
}