update example.ts, generate-deploy-script.ts, and load-state.ts to support default generateDeployScript values for examples

This commit is contained in:
Jev Björsell 2020-05-25 18:47:50 +00:00
parent 8041ce5ddb
commit 7db2c24bd3
25 changed files with 2696 additions and 2281 deletions

View File

@ -15,6 +15,9 @@
evaluateFunction: evaluateFunction:
entrypoint: add entrypoint: add
parameters: 5, 6 parameters: 5, 6
generateDeployScript:
entrypoint: main
storage: 0
*_*) *_*)
type storage = int type storage = int

View File

@ -15,6 +15,9 @@
evaluateFunction: evaluateFunction:
entrypoint: add entrypoint: add
parameters: (5, 6) parameters: (5, 6)
generateDeployScript:
entrypoint: main
storage: 0
*_*) *_*)
// variant defining pseudo multi-entrypoint actions // variant defining pseudo multi-entrypoint actions
type action is type action is

View File

@ -15,6 +15,9 @@
evaluateFunction: evaluateFunction:
entrypoint: add entrypoint: add
parameters: (5, 6) parameters: (5, 6)
generateDeployScript:
entrypoint: main
storage: 0
*_*) *_*)
type storage = int; type storage = int;

View File

@ -16168,6 +16168,11 @@
} }
} }
}, },
"slugify": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.4.0.tgz",
"integrity": "sha512-FtLNsMGBSRB/0JOE2A0fxlqjI6fJsgHGS13iTuVT28kViI4JjUiNqp/vyis0ZXYcMnpR3fzGNkv+6vRlI2GwdQ=="
},
"snapdragon": { "snapdragon": {
"version": "0.8.2", "version": "0.8.2",
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",

View File

@ -7,7 +7,7 @@ import { DeployAction } from '../../redux/actions/deploy';
import { DryRunAction } from '../../redux/actions/dry-run'; import { DryRunAction } from '../../redux/actions/dry-run';
import { EvaluateFunctionAction } from '../../redux/actions/evaluate-function'; import { EvaluateFunctionAction } from '../../redux/actions/evaluate-function';
import { EvaluateValueAction } from '../../redux/actions/evaluate-value'; import { EvaluateValueAction } from '../../redux/actions/evaluate-value';
import { GenerateCommandAction } from '../../redux/actions/generate-command'; import { GenerateDeployScriptAction } from '../../redux/actions/generate-deploy-script';
import { AppState } from '../../redux/app'; import { AppState } from '../../redux/app';
import { ChangeDispatchedAction, ChangeSelectedAction, CommandState } from '../../redux/command'; import { ChangeDispatchedAction, ChangeSelectedAction, CommandState } from '../../redux/command';
import { Command } from '../../redux/types'; import { Command } from '../../redux/types';
@ -17,7 +17,7 @@ import { DeployPaneComponent } from './deploy-pane';
import { DryRunPaneComponent } from './dry-run-pane'; import { DryRunPaneComponent } from './dry-run-pane';
import { EvaluateFunctionPaneComponent } from './evaluate-function-pane'; import { EvaluateFunctionPaneComponent } from './evaluate-function-pane';
import { EvaluateValuePaneComponent } from './evaluate-value-pane'; import { EvaluateValuePaneComponent } from './evaluate-value-pane';
import { GenerateCommandPaneComponent } from './generate-command-pane'; import { GenerateDeployScriptPane } from './generate-deploy-script-pane';
const Container = styled.div<{ visible?: boolean }>` const Container = styled.div<{ visible?: boolean }>`
position: absolute; position: absolute;
@ -76,8 +76,8 @@ function createAction(command: Command) {
return new EvaluateValueAction(); return new EvaluateValueAction();
case Command.EvaluateFunction: case Command.EvaluateFunction:
return new EvaluateFunctionAction(); return new EvaluateFunctionAction();
case Command.GenerateCommand: case Command.GenerateDeployScript:
return new GenerateCommandAction(); return new GenerateDeployScriptAction();
default: default:
throw new Error('Unsupported command'); throw new Error('Unsupported command');
} }
@ -113,7 +113,7 @@ export const ConfigureTabComponent = (props: {
<Option value={Command.DryRun}>Dry Run</Option> <Option value={Command.DryRun}>Dry Run</Option>
<Option value={Command.EvaluateFunction}>Evaluate Function</Option> <Option value={Command.EvaluateFunction}>Evaluate Function</Option>
<Option value={Command.EvaluateValue}>Evaluate Value</Option> <Option value={Command.EvaluateValue}>Evaluate Value</Option>
<Option value={Command.GenerateCommand}>Generate Command</Option> <Option value={Command.GenerateDeployScript}>Generate Deploy Script</Option>
</SelectCommand> </SelectCommand>
<RunButton <RunButton
id="run" id="run"
@ -147,8 +147,8 @@ export const ConfigureTabComponent = (props: {
(command === Command.EvaluateValue && ( (command === Command.EvaluateValue && (
<EvaluateValuePaneComponent></EvaluateValuePaneComponent> <EvaluateValuePaneComponent></EvaluateValuePaneComponent>
)) || )) ||
(command === Command.GenerateCommand && ( (command === Command.GenerateDeployScript && (
<GenerateCommandPaneComponent></GenerateCommandPaneComponent> <GenerateDeployScriptPane></GenerateDeployScriptPane>
))} ))}
</Container> </Container>
); );

View File

@ -8,8 +8,8 @@ import {
ChangeEntrypointAction, ChangeEntrypointAction,
ChangeStorageAction, ChangeStorageAction,
ChangeToolAction, ChangeToolAction,
GenerateCommandState, GenerateDeployScriptState,
} from '../../redux/generate-command'; } from '../../redux/generate-deploy-script';
import { Tool, ToolCommand } from '../../redux/types'; import { Tool, ToolCommand } from '../../redux/types';
import { AccessFunctionLabel, Group, Input, Label, Textarea } from '../form/inputs'; import { AccessFunctionLabel, Group, Input, Label, Textarea } from '../form/inputs';
import { Option, Select } from '../form/select'; import { Option, Select } from '../form/select';
@ -18,23 +18,23 @@ const Container = styled.div`
overflow: auto; overflow: auto;
`; `;
export const GenerateCommandPaneComponent = () => { export const GenerateDeployScriptPane = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const tool = useSelector<AppState, GenerateCommandState['tool']>( const tool = useSelector<AppState, GenerateDeployScriptState['tool']>(
state => state.generateCommand.tool state => state.generateDeployScript.tool
); );
const command = useSelector<AppState, GenerateCommandState['command']>( const command = useSelector<AppState, GenerateDeployScriptState['command']>(
state => state.generateCommand.command state => state.generateDeployScript.command
); );
const entrypoint = useSelector<AppState, GenerateCommandState['entrypoint']>( const entrypoint = useSelector<AppState, GenerateDeployScriptState['entrypoint']>(
state => state.generateCommand.entrypoint state => state.generateDeployScript.entrypoint
); );
const storage = useSelector<AppState, GenerateCommandState['storage']>( const storage = useSelector<AppState, GenerateDeployScriptState['storage']>(
state => state.generateCommand.storage state => state.generateDeployScript.storage
); );
return ( return (

View File

@ -24,7 +24,7 @@ const Pre = styled.pre`
margin: 0; margin: 0;
`; `;
export const GenerateCommandOutputPane = () => { export const GenerateDeployScriptOutputPane = () => {
const output = useSelector<AppState, ResultState['output']>( const output = useSelector<AppState, ResultState['output']>(
state => state.result.output state => state.result.output
); );

View File

@ -8,7 +8,7 @@ import { ResultState } from '../../redux/result';
import { Command } from '../../redux/types'; import { Command } from '../../redux/types';
import { CompileOutputPane } from './compile-output-pane'; import { CompileOutputPane } from './compile-output-pane';
import { DeployOutputPane } from './deploy-output-pane'; import { DeployOutputPane } from './deploy-output-pane';
import { GenerateCommandOutputPane } from './generate-command-output-pane'; import { GenerateDeployScriptOutputPane } from './generate-deploy-script-output-pane';
import { Loading } from './loading'; import { Loading } from './loading';
import { OutputPane } from './output-pane'; import { OutputPane } from './output-pane';
@ -55,8 +55,8 @@ export const OutputTab = (props: {
return <CompileOutputPane></CompileOutputPane>; return <CompileOutputPane></CompileOutputPane>;
} else if (command === Command.Deploy) { } else if (command === Command.Deploy) {
return <DeployOutputPane></DeployOutputPane>; return <DeployOutputPane></DeployOutputPane>;
} else if (command === Command.GenerateCommand) { } else if (command === Command.GenerateDeployScript) {
return <GenerateCommandOutputPane></GenerateCommandOutputPane>; return <GenerateDeployScriptOutputPane></GenerateDeployScriptOutputPane>;
} }
return <OutputPane></OutputPane>; return <OutputPane></OutputPane>;

View File

@ -22,25 +22,25 @@ export async function fetchRandomPrivateKey(): Promise<string> {
return response.text(); return response.text();
} }
export class GenerateCommandAction extends CancellableAction { export class GenerateDeployScriptAction extends CancellableAction {
getAction() { getAction() {
return async (dispatch: Dispatch, getState: () => AppState) => { return async (dispatch: Dispatch, getState: () => AppState) => {
dispatch({ ...new UpdateLoadingAction('Compiling contract...') }); dispatch({ ...new UpdateLoadingAction('Compiling contract...') });
try { try {
const { editor, generateCommand } = getState(); const { editor, generateDeployScript } = getState();
const michelsonCodeJson = await compileContract( const michelsonCodeJson = await compileContract(
editor.language, editor.language,
editor.code, editor.code,
generateCommand.entrypoint, generateDeployScript.entrypoint,
MichelsonFormat.Json MichelsonFormat.Json
); );
const michelsonCode = await compileContract( const michelsonCode = await compileContract(
editor.language, editor.language,
editor.code, editor.code,
generateCommand.entrypoint generateDeployScript.entrypoint
); );
if (this.isCancelled()) { if (this.isCancelled()) {
@ -51,16 +51,16 @@ export class GenerateCommandAction extends CancellableAction {
const michelsonStorageJson = await compileStorage( const michelsonStorageJson = await compileStorage(
editor.language, editor.language,
editor.code, editor.code,
generateCommand.entrypoint, generateDeployScript.entrypoint,
generateCommand.storage, generateDeployScript.storage,
MichelsonFormat.Json MichelsonFormat.Json
); );
const michelsonStorage = await compileStorage( const michelsonStorage = await compileStorage(
editor.language, editor.language,
editor.code, editor.code,
generateCommand.entrypoint, generateDeployScript.entrypoint,
generateCommand.storage generateDeployScript.storage
); );
if (this.isCancelled()) { if (this.isCancelled()) {
@ -82,7 +82,7 @@ export class GenerateCommandAction extends CancellableAction {
const title = slugify(editor.title).toLowerCase() || 'untitled'; const title = slugify(editor.title).toLowerCase() || 'untitled';
const output = `tezos-client \\ const output = `tezos-client \\
${generateCommand.command} \\ ${generateDeployScript.command} \\
contract \\ contract \\
${title} \\ ${title} \\
transferring 0 \\ transferring 0 \\
@ -92,7 +92,7 @@ export class GenerateCommandAction extends CancellableAction {
--burn-cap ${estimate.burnFeeMutez / 1000000}`; --burn-cap ${estimate.burnFeeMutez / 1000000}`;
dispatch({ dispatch({
...new ChangeOutputAction(output, Command.GenerateCommand) ...new ChangeOutputAction(output, Command.GenerateDeployScript)
}); });
} catch (ex) { } catch (ex) {
if (this.isCancelled()) { if (this.isCancelled()) {
@ -101,7 +101,7 @@ export class GenerateCommandAction extends CancellableAction {
dispatch({ dispatch({
...new ChangeOutputAction( ...new ChangeOutputAction(
`Error: ${getErrorMessage(ex)}`, `Error: ${getErrorMessage(ex)}`,
Command.GenerateCommand Command.GenerateDeployScript
) )
}); });
} }

View File

@ -8,7 +8,7 @@ import editor, { EditorState } from './editor';
import evaluateFunction, { EvaluateFunctionState } from './evaluate-function'; import evaluateFunction, { EvaluateFunctionState } from './evaluate-function';
import evaluateValue, { EvaluateValueState } from './evaluate-value'; import evaluateValue, { EvaluateValueState } from './evaluate-value';
import examples, { ExamplesState } from './examples'; import examples, { ExamplesState } from './examples';
import generateCommand, { GenerateCommandState } from './generate-command'; import generateDeployScript, { GenerateDeployScriptState } from './generate-deploy-script';
import loading, { LoadingState } from './loading'; import loading, { LoadingState } from './loading';
import result, { ResultState } from './result'; import result, { ResultState } from './result';
import share, { ShareState } from './share'; import share, { ShareState } from './share';
@ -23,7 +23,7 @@ export interface AppState {
deploy: DeployState; deploy: DeployState;
evaluateFunction: EvaluateFunctionState; evaluateFunction: EvaluateFunctionState;
evaluateValue: EvaluateValueState; evaluateValue: EvaluateValueState;
generateCommand: GenerateCommandState; generateDeployScript: GenerateDeployScriptState;
result: ResultState; result: ResultState;
command: CommandState; command: CommandState;
examples: ExamplesState; examples: ExamplesState;
@ -38,7 +38,7 @@ export default combineReducers({
deploy, deploy,
evaluateFunction, evaluateFunction,
evaluateValue, evaluateValue,
generateCommand, generateDeployScript,
result, result,
command, command,
examples, examples,

View File

@ -4,6 +4,8 @@ import { DryRunState } from './dry-run';
import { EditorState } from './editor'; import { EditorState } from './editor';
import { EvaluateFunctionState } from './evaluate-function'; import { EvaluateFunctionState } from './evaluate-function';
import { EvaluateValueState } from './evaluate-value'; import { EvaluateValueState } from './evaluate-value';
import { GenerateDeployScriptState } from './generate-deploy-script';
export interface ExampleState { export interface ExampleState {
id: string; id: string;
@ -14,4 +16,5 @@ export interface ExampleState {
deploy: DeployState; deploy: DeployState;
evaluateFunction: EvaluateFunctionState; evaluateFunction: EvaluateFunctionState;
evaluateValue: EvaluateValueState; evaluateValue: EvaluateValueState;
generateDeployScript: GenerateDeployScriptState;
} }

View File

@ -1,13 +1,14 @@
import { ActionType as ExamplesActionType, ChangeSelectedAction as ChangeSelectedExampleAction } from './examples';
import { Tool, ToolCommand } from './types'; import { Tool, ToolCommand } from './types';
export enum ActionType { export enum ActionType {
ChangeTool = 'generate-command-change-tool', ChangeTool = 'generate-deploy-script-change-tool',
ChangeCommand = 'generate-command-change-command', ChangeCommand = 'generate-deploy-script-change-command',
ChangeEntrypoint = 'generate-command-change-entrypoint', ChangeEntrypoint = 'generate-deploy-script-change-entrypoint',
ChangeStorage = 'generate-command-change-storage' ChangeStorage = 'generate-deploy-script-change-storage'
} }
export interface GenerateCommandState { export interface GenerateDeployScriptState {
tool: Tool; tool: Tool;
command: ToolCommand; command: ToolCommand;
entrypoint: string; entrypoint: string;
@ -18,31 +19,32 @@ export interface GenerateCommandState {
export class ChangeToolAction { export class ChangeToolAction {
public readonly type = ActionType.ChangeTool; public readonly type = ActionType.ChangeTool;
constructor(public payload: GenerateCommandState['tool']) {} constructor(public payload: GenerateDeployScriptState['tool']) {}
} }
export class ChangeCommandAction { export class ChangeCommandAction {
public readonly type = ActionType.ChangeCommand; public readonly type = ActionType.ChangeCommand;
constructor(public payload: GenerateCommandState['command']) {} constructor(public payload: GenerateDeployScriptState['command']) {}
} }
export class ChangeEntrypointAction { export class ChangeEntrypointAction {
public readonly type = ActionType.ChangeEntrypoint; public readonly type = ActionType.ChangeEntrypoint;
constructor(public payload: GenerateCommandState['entrypoint']) {} constructor(public payload: GenerateDeployScriptState['entrypoint']) {}
} }
export class ChangeStorageAction { export class ChangeStorageAction {
public readonly type = ActionType.ChangeStorage; public readonly type = ActionType.ChangeStorage;
constructor(public payload: GenerateCommandState['storage']) {} constructor(public payload: GenerateDeployScriptState['storage']) {}
} }
type Action = type Action =
| ChangeToolAction | ChangeToolAction
| ChangeCommandAction | ChangeCommandAction
| ChangeEntrypointAction | ChangeEntrypointAction
| ChangeStorageAction; | ChangeStorageAction
| ChangeSelectedExampleAction;
const DEFAULT_STATE: GenerateCommandState = { const DEFAULT_STATE: GenerateDeployScriptState = {
tool: Tool.TezosClient, tool: Tool.TezosClient,
command: ToolCommand.Originate, command: ToolCommand.Originate,
entrypoint: '', entrypoint: '',
@ -54,8 +56,13 @@ const DEFAULT_STATE: GenerateCommandState = {
export default ( export default (
state = DEFAULT_STATE, state = DEFAULT_STATE,
action: Action action: Action
): GenerateCommandState => { ): GenerateDeployScriptState => {
switch (action.type) { switch (action.type) {
case ExamplesActionType.ChangeSelected:
return {
...state,
...(!action.payload ? DEFAULT_STATE : action.payload.generateDeployScript)
};
case ActionType.ChangeTool: case ActionType.ChangeTool:
return { return {
...state, ...state,

View File

@ -10,7 +10,7 @@ export enum Command {
EvaluateValue = 'evaluate-value', EvaluateValue = 'evaluate-value',
EvaluateFunction = 'evaluate-function', EvaluateFunction = 'evaluate-function',
Deploy = 'deploy', Deploy = 'deploy',
GenerateCommand = 'generate-command' GenerateDeployScript = 'generate-deploy-script'
} }
export enum Tool { export enum Tool {

View File

@ -3317,8 +3317,7 @@
"gensync": { "gensync": {
"version": "1.0.0-beta.1", "version": "1.0.0-beta.1",
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.1.tgz", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.1.tgz",
"integrity": "sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg==", "integrity": "sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg=="
"dev": true
}, },
"get-caller-file": { "get-caller-file": {
"version": "2.0.5", "version": "2.0.5",

View File

@ -11,16 +11,16 @@
}, },
"devDependencies": { "devDependencies": {
"@ts-tools/node": "^1.0.0", "@ts-tools/node": "^1.0.0",
"@types/cors": "^2.8.6",
"@types/express": "^4.17.1", "@types/express": "^4.17.1",
"@types/express-winston": "^3.0.4", "@types/express-winston": "^3.0.4",
"@types/hapi__joi": "^16.0.1", "@types/hapi__joi": "^16.0.1",
"@types/jest": "^24.0.23", "@types/jest": "^24.0.23",
"@types/joi": "^14.3.3", "@types/joi": "^14.3.3",
"@types/node": "10", "@types/node": "10",
"@types/node-fetch": "^2.5.4",
"@types/tmp": "^0.1.0", "@types/tmp": "^0.1.0",
"@types/winston": "^2.4.4", "@types/winston": "^2.4.4",
"@types/cors": "^2.8.6",
"@types/node-fetch": "^2.5.4",
"jest": "^24.9.0", "jest": "^24.9.0",
"nodemon": "^1.19.3", "nodemon": "^1.19.3",
"ts-jest": "^24.1.0", "ts-jest": "^24.1.0",
@ -40,6 +40,7 @@
"express": "^4.17.1", "express": "^4.17.1",
"express-prometheus-middleware": "^0.8.5", "express-prometheus-middleware": "^0.8.5",
"express-winston": "^4.0.1", "express-winston": "^4.0.1",
"gensync": "^1.0.0-beta.1",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",
"sanitize-html": "^1.20.1", "sanitize-html": "^1.20.1",
"tmp": "^0.1.0", "tmp": "^0.1.0",

View File

@ -11,7 +11,7 @@ interface CompileBody {
format?: string; format?: string;
} }
const validateRequest = (body: any): { value: CompileBody; error: any } => { const validateRequest = (body: any): { value: CompileBody; error?: any } => {
return joi return joi
.object({ .object({
syntax: joi.string().required(), syntax: joi.string().required(),

View File

@ -10,7 +10,7 @@ interface CompileBody {
format?: string; format?: string;
} }
const validateRequest = (body: any): { value: CompileBody; error: any } => { const validateRequest = (body: any): { value: CompileBody; error?: any } => {
return joi return joi
.object({ .object({
syntax: joi.string().required(), syntax: joi.string().required(),

View File

@ -12,7 +12,7 @@ interface CompileBody {
format?: string; format?: string;
} }
const validateRequest = (body: any): { value: CompileBody; error: any } => { const validateRequest = (body: any): { value: CompileBody; error?: any } => {
return joi return joi
.object({ .object({
syntax: joi.string().required(), syntax: joi.string().required(),

View File

@ -15,7 +15,7 @@ interface DeployBody {
Tezos.setProvider({ rpc: 'https://api.tez.ie/rpc/carthagenet' }); Tezos.setProvider({ rpc: 'https://api.tez.ie/rpc/carthagenet' });
const validateRequest = (body: any): { value: DeployBody; error: any } => { const validateRequest = (body: any): { value: DeployBody; error?: any } => {
return joi return joi
.object({ .object({
syntax: joi.string().required(), syntax: joi.string().required(),

View File

@ -12,7 +12,7 @@ interface DryRunBody {
storage: string; storage: string;
} }
const validateRequest = (body: any): { value: DryRunBody; error: any } => { const validateRequest = (body: any): { value: DryRunBody; error?: any } => {
return joi return joi
.object({ .object({
syntax: joi.string().required(), syntax: joi.string().required(),

View File

@ -12,7 +12,7 @@ interface EvaluateValueBody {
const validateRequest = ( const validateRequest = (
body: any body: any
): { value: EvaluateValueBody; error: any } => { ): { value: EvaluateValueBody; error?: any } => {
return joi return joi
.object({ .object({
syntax: joi.string().required(), syntax: joi.string().required(),

View File

@ -11,7 +11,7 @@ interface RunFunctionBody {
parameters: string; parameters: string;
} }
const validateRequest = (body: any): { value: RunFunctionBody; error: any } => { const validateRequest = (body: any): { value: RunFunctionBody; error?: any } => {
return joi return joi
.object({ .object({
syntax: joi.string().required(), syntax: joi.string().required(),

View File

@ -35,7 +35,7 @@ interface ShareBody {
}; };
} }
const validateRequest = (body: any): { value: ShareBody; error: any } => { const validateRequest = (body: any): { value: ShareBody; error?: any } => {
return joi return joi
.object({ .object({
editor: joi editor: joi

View File

@ -28,6 +28,7 @@ export async function loadDefaultState(appBundleDirectory: string) {
deploy: {}, deploy: {},
evaluateValue: {}, evaluateValue: {},
evaluateFunction: {}, evaluateFunction: {},
generateDeployScript: {},
editor: { editor: {
title: '' title: ''
}, },
@ -63,6 +64,10 @@ export async function loadDefaultState(appBundleDirectory: string) {
...defaultState.evaluateFunction, ...defaultState.evaluateFunction,
...defaultExample.evaluateFunction ...defaultExample.evaluateFunction
}; };
defaultState.generateDeployScript = {
...defaultState.generateDeployScript,
...defaultExample.generateDeployScript
};
defaultState.editor = { defaultState.editor = {
...defaultState.editor, ...defaultState.editor,
...defaultExample.editor, ...defaultExample.editor,

File diff suppressed because it is too large Load Diff