diff --git a/src/components/App.tsx b/src/components/App.tsx index ef4ec74..db6fc57 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -19,6 +19,22 @@ function App() { const [contract, setContract] = useState(undefined) const [utxos, setUtxos] = useState(undefined) const [balance, setBalance] = useState(undefined) + const [code, setCode] = useState( +`pragma cashscript >= 0.8.0; + +contract TransferWithTimeout(pubkey sender, pubkey recipient, int timeout) { + // Require recipient's signature to match + function transfer(sig recipientSig) { + require(checkSig(recipientSig, recipient)); + } + + // Require timeout time to be reached and sender's signature to match + function timeout(sig senderSig) { + require(checkSig(senderSig, sender)); + require(tx.time >= timeout); + } +} +`); async function updateUtxosContract () { if (!contract) return @@ -37,7 +53,7 @@ function App() { style={{ display: "inline-flex", marginLeft: "calc(100vw - 1100px)" }} > -
+
diff --git a/src/components/ArtifactsInfo.tsx b/src/components/ArtifactsInfo.tsx index 2923db1..c33006a 100644 --- a/src/components/ArtifactsInfo.tsx +++ b/src/components/ArtifactsInfo.tsx @@ -1,12 +1,14 @@ import React from 'react' import { Artifact } from 'cashscript' +import { Button } from 'react-bootstrap' interface Props { + setCode: (code: string) => void artifacts?: Artifact[] setArtifacts: (artifacts: Artifact[] | undefined) => void } -const ContractInfo: React.FC = ({ artifacts, setArtifacts }) => { +const ContractInfo: React.FC = ({ setCode, artifacts, setArtifacts }) => { const downloadArtifact = (artifact: Artifact) => { const element = document.createElement('a'); @@ -24,6 +26,11 @@ const ContractInfo: React.FC = ({ artifacts, setArtifacts }) => { setArtifacts(newArtifacts) } + const loadArtifact = (artifact: Artifact) => { + console.log(artifact.source) + setCode(artifact.source) + } + return (
= ({ artifacts, setArtifacts }) => { download JSON file

+ Load Contract to Editor +
))} diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx index 0ffaea0..5ef89c3 100644 --- a/src/components/Editor.tsx +++ b/src/components/Editor.tsx @@ -26,7 +26,7 @@ const Editor: React.FC = ({ code, setCode, compile, needRecompile }) => { language="sol" value={code} theme="light" - onChange={(ev: any, code?: string) => code && setCode(code)} + onChange={(ev: any, code?: string) => setCode(code?? "") } editorDidMount={handleEditorDidMount} />