Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke enhance #38

Merged
merged 7 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
561 changes: 551 additions & 10 deletions app/package-lock.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
"@types/react-dom": "^18.2.6",
"bootstrap": "^5.3.0",
"bootstrap-icons": "^1.10.5",
"highlight.js": "^11.8.0",
"@monaco-editor/react": "^4.5.1",
"node-fetch": "2.6.1",
"octokit": "^3.1.0",
"react": "^18.2.0",
"react-bootstrap": "^2.8.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1",
"highlight.js": "^11.8.0",
"react-highlight": "^0.15.0",
"react-monaco-editor": "^0.54.0",
"react-router-dom": "^6.14.1",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
Expand Down Expand Up @@ -61,8 +65,11 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-promise": "^6.1.1",
"prettier": "^2.8.8",
"@types/react-highlight": "^0.12.5"
"@types/node-fetch": "^2.6.4",
"prettier": "^2.8.8"
},
"browser": {
"fs": false
},
"homepage": "https://eigerco.github.io/nebula/"
}
8 changes: 8 additions & 0 deletions app/src/Editor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.console {
background-color: #0d1117;
padding: 1rem;
}

.codelens-decoration {
--vscode-editorCodeLens-fontSize: 13px;
}
157 changes: 138 additions & 19 deletions app/src/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,140 @@
import React from 'react'
import Highlight from 'react-highlight'
import 'highlight.js/styles/github-dark.css'

export function Editor({
contractTrait,
codeGen,
contractName,
author,
license,
}: any) {
codeGen.generateHeader(author, license)
codeGen.generateContractCode(contractTrait, contractName)
const contractCode = codeGen.getCode()

return (
<div className="Editor">
<Highlight className="language-rust">{contractCode}</Highlight>
</div>
)
import Button from 'react-bootstrap/Button'
import Modal from 'react-bootstrap/Modal'
import MonacoEditor from '@monaco-editor/react'
import './Editor.css'
import { ContractService } from './contractsources/contractservice'

interface Props {
contractTrait: any
codeGen: any
contractName: any
author: any
license: any
}

export class Editor extends React.Component<Props> {
state = {
showInvokeModal: false,
}

modalBody = ''
contractCode = ''
monaco: any
editor: any

contractService = new ContractService()

editorDidMount = (ed: any, mon: any) => {
this.contractService
.readContracts()
.then(() => {
// force redraw editor
this.forceUpdate()
})
.catch(e => {
console.error(e)
})

this.monaco = mon
this.editor = ed
ed.focus()
this.updateInvokes(this)
}

private updateInvokes(outerThis: any) {
const commandId = (method: string, params: string) => {
return this.editor.addCommand(
0,
function () {
const contractName: string = outerThis.props.contractName
// services available in `ctx`
outerThis.modalBody = `soroban contract invoke \\
--wasm ${contractName}.wasm \\
--id 1 \\
-- \\
${method} \\
${params}`
outerThis.setState({ showInvokeModal: true })
},
''
)
}
this.monaco.languages.registerCodeLensProvider('rust', {
provideCodeLenses: function (model: any, token: any) {
return outerThis.props.codeGen.getInvokes(commandId)
},
resolveCodeLens: function (model: any, codeLens: any, token: any) {
return codeLens
},
})
}

private handleInvokeModalClose(outerThis: any) {
outerThis.setState({ showInvokeModal: false })
}

generateContractCode() {
this.props.codeGen.generateHeader(this.props.author, this.props.license)
const traitLowerCase: string = this.props.contractTrait.toLowerCase()
const originalCode = this.contractService.getContractCode(traitLowerCase)
this.props.codeGen.generateContractCode(
originalCode,
this.props.contractName
)
this.contractCode = this.props.codeGen.getCode()
}

render() {
const options = {
selectOnLineNumbers: true,
readOnly: true,
}
this.generateContractCode()

return (
<div className="Editor">
<div
className="modal show"
style={{ display: 'block', position: 'initial' }}
>
<Modal
show={this.state.showInvokeModal}
onHide={() => {
this.handleInvokeModalClose(this)
}}
>
<Modal.Header closeButton>
<Modal.Title>Invoke command example</Modal.Title>
</Modal.Header>
<Modal.Body>
<pre className="console">
<code>{this.modalBody}</code>
</pre>
</Modal.Body>
<Modal.Footer>
<Button
variant="secondary"
onClick={() => {
this.handleInvokeModalClose(this)
}}
>
<i className="bi bi-x-circle"></i>
Close
</Button>
</Modal.Footer>
</Modal>
</div>
<MonacoEditor
width="100%"
height="90vh"
language="rust"
theme="vs-dark"
value={this.contractCode}
options={options}
onMount={this.editorDidMount}
/>
</div>
)
}
}
16 changes: 5 additions & 11 deletions app/src/Toolbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

.buttons {
margin-top: 10px;
margin-bottom: 10px;
}

.contract-menu {
Expand All @@ -26,22 +27,15 @@
margin-top: 10px;
}

.input-group-text {
min-width: 100px;
}

.buttons button {
margin-bottom: 5px;
width: 160px;
}

.contract-params {
border: 1px solid #4e4e4e;
margin-bottom: 1em;
margin-top: 1em;
padding: 1em;
}

.contract-params span {
min-width: 150px;
}

.bi {
margin-right: 5px;
}
68 changes: 23 additions & 45 deletions app/src/Toolbox.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React from 'react'
import Form from 'react-bootstrap/Form'
import { ContractParams } from './contractparams/ContractParams'
import './Toolbox.css'

export function Toolbox({
contractName,
onContractNameChanged,
contractTrait,
onContractTraitChanged,
updateParams,
author,
onAuthorChanged,
license,
Expand Down Expand Up @@ -45,7 +42,29 @@ export function Toolbox({
{/* <option disabled>NFT</option> */}
</Form.Select>
</div>
<div>
<div className="input-group mb-2">
<span className="input-group-text">Author</span>
<input
type="text"
className="form-control"
aria-label="License"
aria-describedby="basic-addon1"
value={author}
onChange={e => onAuthorChanged(e.target.value)}
/>
</div>
<div className="input-group mb-2">
<span className="input-group-text">License</span>
<input
type="text"
className="form-control"
aria-label="License"
aria-describedby="basic-addon1"
value={license}
onChange={e => onLicenseChanged(e.target.value)}
/>
</div>
<div className="buttons">
<div className="row mt-1">
<div className="col">
<button
Expand All @@ -57,18 +76,6 @@ export function Toolbox({
<i className="bi bi-clipboard"></i>Copy
</button>
</div>
<div className="col">
<button
type="button"
className="btn btn-secondary w-100"
onClick={e => handleClick('Invoke')}
title="Invoke"
>
<i className="bi bi-gear"></i>Invoke
</button>
</div>
</div>
<div className="row mt-1">
<div className="col">
<button
type="button"
Expand All @@ -81,35 +88,6 @@ export function Toolbox({
</div>
</div>
</div>
<label className="params">Init params:</label>
<div className="contract-params">
<ContractParams
contractTrait={contractTrait}
updateParams={updateParams}
/>
</div>
<div className="input-group mb-2">
<span className="input-group-text">Author</span>
<input
type="text"
className="form-control"
aria-label="License"
aria-describedby="basic-addon1"
value={author}
onChange={e => onAuthorChanged(e.target.value)}
/>
</div>
<div className="input-group mb-2">
<span className="input-group-text">License</span>
<input
type="text"
className="form-control"
aria-label="License"
aria-describedby="basic-addon1"
value={license}
onChange={e => onLicenseChanged(e.target.value)}
/>
</div>
</div>
)
}
Loading