Skip to content

Commit

Permalink
feat: Update smartts-sdk usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed Feb 7, 2022
1 parent a792cac commit dd409c2
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/blocks/base/contract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Blockly, { Block, FieldTextInput } from 'blockly';

import type { ILiteral } from '@tezwell/smartts-sdk/typings/literal';
import { Contract, EntryPoint } from '@tezwell/smartts-sdk/core';
import { Contract, EntryPoint } from '@tezwell/smartts-sdk';

import SmartML from 'src/blocks/generators/SmartML';
import BlockKind from '../enums/BlockKind';
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/base/entry_point.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Block, FieldTextInput, Procedures } from 'blockly';
import Blockly from 'blockly';
import { EntryPoint } from '@tezwell/smartts-sdk/core';
import { EntryPoint } from '@tezwell/smartts-sdk';

import SmartML from 'src/blocks/generators/SmartML';
import BlockKind from '../enums/BlockKind';
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/blockchain_operations/level.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Blockly from 'blockly';

import { TNat } from '@tezwell/smartts-sdk/core/type';
import { GetLevel } from '@tezwell/smartts-sdk/core';
import { GetLevel } from '@tezwell/smartts-sdk';
import SmartML from 'src/blocks/generators/SmartML';
import BlockKind from '../enums/BlockKind';

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/blockchain_operations/sender.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Blockly from 'blockly';

import { TAddress } from '@tezwell/smartts-sdk/core/type';
import { GetSender } from '@tezwell/smartts-sdk/core';
import { GetSender } from '@tezwell/smartts-sdk';
import SmartML from 'src/blocks/generators/SmartML';
import BlockKind from '../enums/BlockKind';

Expand Down
1 change: 1 addition & 0 deletions src/blocks/enums/BlockKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum BlockKind {
unit_literal = 'unit_literal',
number_literal = 'number_literal',
string_literal = 'string_literal',
bytes_literal = 'bytes_literal',
some_literal = 'some_literal',
none_literal = 'none_literal',
nat_literal = 'nat_literal',
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import './blockchain_operations';
import Blockly from 'blockly';
import type { Block, Workspace } from 'blockly';
import type { IType, IValue } from '@tezwell/michelson-sdk/typings';
import SmartMLSDK from '@tezwell/smartts-sdk/smartml';
// import { CompilerAPI } from '@tezwell/smartts-sdk';

import BlockKind from './enums/BlockKind';
import SmartML from './generators/SmartML';
Expand Down Expand Up @@ -73,7 +73,7 @@ export const compileBlock = (block: Block): Compilation | null => {
name: block.getFieldValue('NAME'),
storage: Michelson.translateValue(storageBlock),
storageXML: `<xml xmlns="http://www.w3.org/1999/xhtml">${storageXML}</xml>`,
code: JSON.stringify(SmartMLSDK.compileContract(code), null, 4),
code: 'JSON.stringify(CompilerAPI.default.compileContract(code), null, 4)',
},
};
case BlockKind.string_type:
Expand Down
50 changes: 50 additions & 0 deletions src/blocks/literals/Bytes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Block } from 'blockly';
import Blockly from 'blockly';

import MichelsonLiteral from '@tezwell/michelson-sdk/literal';
import MichelsonType from '@tezwell/michelson-sdk/type';
import SmartTSTypes from '@tezwell/smartts-sdk/core/type';
import SmartTSLiterals from '@tezwell/smartts-sdk/core/literal';
import SmartML from '../generators/SmartML';
import BlockKind from '../enums/BlockKind';
import Michelson from '../generators/Michelson';

const BytesBlock = {
type: BlockKind.bytes_literal,
message0: 'Bytes %1',
args0: [
{
type: 'field_input',
name: 'bytes',
text: '',
check: 'String',
},
],
output: ['Literal', 'Bytes'],
colour: 190,
};

Blockly.Blocks[BlockKind.bytes_literal] = {
init: function () {
this.jsonInit(BytesBlock);
this.setPreviousStatement(false);
this.setNextStatement(false);
},
};

SmartML.addBlock(BlockKind.string_literal, {
toType: () => {
return SmartTSTypes.TString;
},
toValue: (block: Block) => {
return SmartTSLiterals.Bytes(block.getFieldValue('bytes'));
},
});
Michelson.addBlock(BlockKind.string_literal, {
toType: () => {
return MichelsonType.TBytes();
},
toMichelson: (block: Block) => {
return MichelsonLiteral.Bytes(block.getFieldValue('bytes'));
},
});
2 changes: 1 addition & 1 deletion src/components/footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const Footer = () => (
</li>
<li className="mt-2 inline-block mr-2 md:block md:mr-0">
<a
href="https://twitter.com/hashtag/VisualTez"
href="https://twitter.com/VisualTez"
target="_blank"
className="flex hover:text-yellow-500"
>
Expand Down
44 changes: 17 additions & 27 deletions src/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,13 @@ import React from 'react';
import { Link, NavLink } from 'react-router-dom';

import ThemeSelection from 'src/components/theme/selection';
import { isDevelopment } from 'src/utils';
import { resolvePath } from 'src/utils/path';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface NavigationProps {}

const Navigation: React.FC<NavigationProps> = () => {
const devComponents = React.useMemo(() => {
if (process.env.NODE_ENV === 'development') {
return {
desktop: (
<li>
<NavLink className="inline-block py-2 px-4 font-bold no-underline" to="/editor">
Editor
</NavLink>
</li>
),
mobile: (
<Menu.Item>
<NavLink
className="inline-block w-full rounded font-bold no-underline p-2 bg-gray-200 dark:bg-gray-800"
to="/editor"
>
Editor
</NavLink>
</Menu.Item>
),
};
}
return {};
}, []);

return (
<nav id="header" className="w-full">
<div className="w-full container mx-auto flex flex-wrap items-center justify-between p-2">
Expand Down Expand Up @@ -64,7 +40,14 @@ const Navigation: React.FC<NavigationProps> = () => {
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items className="absolute right-0 w-56 mt-2 origin-top-right bg-white divide-y divide-gray-100 rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
{devComponents.mobile}
<Menu.Item>
<NavLink
className="inline-block w-full rounded font-bold no-underline p-2 bg-gray-200 dark:bg-gray-800"
to={isDevelopment() ? '/editor' : '/'}
>
Editor <p className="ml-2 text-yellow-500">(Coming Soon)</p>
</NavLink>
</Menu.Item>
</Menu.Items>
</Transition>
</Menu>
Expand All @@ -78,7 +61,14 @@ const Navigation: React.FC<NavigationProps> = () => {
id="nav-content"
>
<ul className="list-reset lg:flex justify-end flex-1 items-center">
{devComponents.desktop}
<li>
<NavLink
className="flex inline-block py-2 px-4 font-bold no-underline"
to={isDevelopment() ? '/editor' : '/'}
>
Editor <p className="ml-2 text-yellow-500">(Coming Soon)</p>
</NavLink>
</li>
<li className="h-10 border ml-3 mr-3 border-black dark:border-white" />
<li className="flex justify-end items-center">
<ThemeSelection />
Expand Down
1 change: 1 addition & 0 deletions src/pages/editor/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const EditorView: React.FC<EditorViewProps> = ({ workspaceRef, compile, onError
<Separator gap={40} />
<Block type={BlockKind.string_literal} />
<Block type={BlockKind.address_literal} />
<Block type={BlockKind.bytes_literal} />
<Separator gap={40} />
<Block type={BlockKind.boolean_literal} />
<Label text="-- Option --" web-class="defaultLabel" />
Expand Down
19 changes: 13 additions & 6 deletions src/pages/landing/view.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import RouterButton from 'src/components/common/RouterButton';
import { isDevelopment } from 'src/utils';
import { resolvePath } from 'src/utils/path';

const Landing: React.FC = () => (
Expand All @@ -11,12 +12,18 @@ const Landing: React.FC = () => (
<p className="leading-normal text-2xl mb-8">
A visual programming tool for writing smart contracts in the Tezos blockchain.
</p>
<RouterButton
to="/editor"
className="mx-auto lg:mx-0 hover:underline bg-black dark:bg-white text-white dark:text-black font-bold rounded-full my-6 py-4 px-8 shadow-lg focus:outline-none focus:shadow-outline transform transition hover:scale-105 duration-300 ease-in-out"
>
Open Editor
</RouterButton>
{isDevelopment() ? (
<RouterButton
to="/editor"
className="mx-auto lg:mx-0 hover:underline bg-black dark:bg-white text-white dark:text-black font-bold rounded-full my-6 py-4 px-8 shadow-lg focus:outline-none focus:shadow-outline transform transition hover:scale-105 duration-300 ease-in-out"
>
Open Editor
</RouterButton>
) : (
<button className="mx-auto lg:mx-0 bg-black dark:bg-white text-white dark:text-black font-bold rounded-full my-6 py-4 px-8 shadow-lg">
Coming Soon
</button>
)}
</div>
<div className="flex justify-center h-full w-full md:w-2/5 py-6 text-center">
<img className="h-full w-full" src={resolvePath('/assets/sample.svg')} />
Expand Down
3 changes: 2 additions & 1 deletion src/router/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PrivacyMarkdown from 'src/pages/markdown/privacy.md';
import ContactMarkdown from 'src/pages/markdown/contact.md';
import TermsMarkdown from 'src/pages/markdown/terms.md';
import MarkdownLayout from 'src/components/MarkdownLayout';
import { isDevelopment } from 'src/utils';

const EditorPage = React.lazy(() => import('src/pages/editor'));
const NodesPage = React.lazy(() => import('src/pages/nodes'));
Expand All @@ -33,7 +34,7 @@ export const routes = [
},
// Editor Page
{
disabled: process.env.NODE_ENV !== 'development',
disabled: !isDevelopment(),
title: 'VisualTez - Editor',
routeProps: {
key: 'editor',
Expand Down
2 changes: 2 additions & 0 deletions src/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"storage_prefix": "@VisualTez",
"networks": [
"mainnet",
"hangzhounet",
"ithacanet"
],
"node_monitor": {
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isDevelopment = () => process.env.NODE_ENV === 'development';

0 comments on commit dd409c2

Please sign in to comment.