Compare commits
39 Commits
feat/debug
...
feat/jsdoc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4373bb970 | ||
|
|
cfb791092a | ||
|
|
c40b272ce8 | ||
|
|
860ff66a8a | ||
|
|
f4f700bea1 | ||
|
|
789bc00ac3 | ||
|
|
6a0aabdeda | ||
|
|
175b6266e8 | ||
|
|
621482e2ee | ||
|
|
e55f48bc83 | ||
|
|
3e9e26a46a | ||
|
|
f0e730bb9b | ||
|
|
6ce4828fc6 | ||
|
|
bb0a246ae5 | ||
|
|
0289d64f5e | ||
|
|
868a0bcf78 | ||
|
|
aab2476a05 | ||
|
|
cb25986d72 | ||
|
|
309ad57173 | ||
|
|
25c5b9c015 | ||
|
|
407e3946ce | ||
|
|
dc5b0d71eb | ||
|
|
3fd6c3f50e | ||
|
|
ec8bfc5eee | ||
|
|
b4a0bcb90d | ||
|
|
2c729e2aa4 | ||
|
|
1cb2542170 | ||
|
|
00b309df34 | ||
|
|
a6fc730de6 | ||
|
|
2245c5a221 | ||
|
|
60c33661ad | ||
|
|
ea21c85038 | ||
|
|
5478f43609 | ||
|
|
a9b64abb85 | ||
|
|
c6ced424d8 | ||
|
|
3a1159cffc | ||
|
|
3136de1bd1 | ||
|
|
67ffd3f1b4 | ||
|
|
8508cb69c4 |
@@ -116,9 +116,16 @@ export const AccountDialog = ({
|
|||||||
<Text
|
<Text
|
||||||
css={{
|
css={{
|
||||||
fontFamily: "$monospace",
|
fontFamily: "$monospace",
|
||||||
|
a: { "&:hover": { textDecoration: "underline" } },
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{activeAccount?.address}
|
<a
|
||||||
|
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${activeAccount?.address}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{activeAccount?.address}
|
||||||
|
</a>
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex css={{ marginLeft: "auto", color: "$mauve12" }}>
|
<Flex css={{ marginLeft: "auto", color: "$mauve12" }}>
|
||||||
@@ -215,7 +222,11 @@ export const AccountDialog = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex css={{ marginLeft: "auto" }}>
|
<Flex
|
||||||
|
css={{
|
||||||
|
marginLeft: "auto",
|
||||||
|
}}
|
||||||
|
>
|
||||||
<a
|
<a
|
||||||
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${activeAccount?.address}`}
|
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${activeAccount?.address}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -237,10 +248,22 @@ export const AccountDialog = ({
|
|||||||
<Text
|
<Text
|
||||||
css={{
|
css={{
|
||||||
fontFamily: "$monospace",
|
fontFamily: "$monospace",
|
||||||
|
a: { "&:hover": { textDecoration: "underline" } },
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{activeAccount && activeAccount.hooks.length > 0
|
{activeAccount && activeAccount.hooks.length > 0
|
||||||
? activeAccount.hooks.map((i) => truncate(i, 12)).join(",")
|
? activeAccount.hooks.map((i) => {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
key={i}
|
||||||
|
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${i}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{truncate(i, 12)}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
})
|
||||||
: "–"}
|
: "–"}
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useCallback } from "react";
|
import React, { useState, useEffect, useCallback, useRef } from "react";
|
||||||
import {
|
import {
|
||||||
Plus,
|
Plus,
|
||||||
Share,
|
Share,
|
||||||
@@ -101,7 +101,7 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
|||||||
if (!filename) {
|
if (!filename) {
|
||||||
return { error: "You need to add filename" };
|
return { error: "You need to add filename" };
|
||||||
}
|
}
|
||||||
if (snap.files.find(file => file.name === filename)) {
|
if (snap.files.find((file) => file.name === filename)) {
|
||||||
return { error: "Filename already exists." };
|
return { error: "Filename already exists." };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,22 +132,55 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
|||||||
createNewFile(filename);
|
createNewFile(filename);
|
||||||
setFilename("");
|
setFilename("");
|
||||||
}, [filename, setIsNewfileDialogOpen, setFilename, validateFilename]);
|
}, [filename, setIsNewfileDialogOpen, setFilename, validateFilename]);
|
||||||
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const files = snap.files;
|
const files = snap.files;
|
||||||
return (
|
return (
|
||||||
<Flex css={{ flexShrink: 0, gap: "$0" }}>
|
<Flex css={{ flexShrink: 0, gap: "$0" }}>
|
||||||
<Flex
|
<Flex
|
||||||
|
id="kissa"
|
||||||
|
ref={scrollRef}
|
||||||
css={{
|
css={{
|
||||||
overflowX: "scroll",
|
overflowX: "scroll",
|
||||||
|
overflowY: "hidden",
|
||||||
py: "$3",
|
py: "$3",
|
||||||
|
pb: "$0",
|
||||||
flex: 1,
|
flex: 1,
|
||||||
"&::-webkit-scrollbar": {
|
"&::-webkit-scrollbar": {
|
||||||
height: 0,
|
height: "0.3em",
|
||||||
background: "transparent",
|
background: "rgba(0,0,0,.0)",
|
||||||
|
},
|
||||||
|
"&::-webkit-scrollbar-gutter": "stable",
|
||||||
|
"&::-webkit-scrollbar-thumb": {
|
||||||
|
backgroundColor: "rgba(0,0,0,.2)",
|
||||||
|
outline: "0px",
|
||||||
|
borderRadius: "9999px",
|
||||||
|
},
|
||||||
|
scrollbarColor: "rgba(0,0,0,.2) rgba(0,0,0,0)",
|
||||||
|
scrollbarGutter: "stable",
|
||||||
|
scrollbarWidth: "thin",
|
||||||
|
".dark &": {
|
||||||
|
"&::-webkit-scrollbar": {
|
||||||
|
background: "rgba(0,0,0,.0)",
|
||||||
|
},
|
||||||
|
"&::-webkit-scrollbar-gutter": "stable",
|
||||||
|
"&::-webkit-scrollbar-thumb": {
|
||||||
|
backgroundColor: "rgba(255,255,255,.2)",
|
||||||
|
outline: "0px",
|
||||||
|
borderRadius: "9999px",
|
||||||
|
},
|
||||||
|
scrollbarColor: "rgba(255,255,255,.2) rgba(0,0,0,0)",
|
||||||
|
scrollbarGutter: "stable",
|
||||||
|
scrollbarWidth: "thin",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
onWheelCapture={(e) => {
|
||||||
|
if (scrollRef.current) {
|
||||||
|
scrollRef.current.scrollLeft += e.deltaY;
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Container css={{ flex: 1 }}>
|
<Container css={{ flex: 1 }} ref={containerRef}>
|
||||||
<Stack
|
<Stack
|
||||||
css={{
|
css={{
|
||||||
gap: "$3",
|
gap: "$3",
|
||||||
@@ -233,8 +266,8 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
|||||||
<Label>Filename</Label>
|
<Label>Filename</Label>
|
||||||
<Input
|
<Input
|
||||||
value={filename}
|
value={filename}
|
||||||
onChange={e => setFilename(e.target.value)}
|
onChange={(e) => setFilename(e.target.value)}
|
||||||
onKeyPress={e => {
|
onKeyPress={(e) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
handleConfirm();
|
handleConfirm();
|
||||||
}
|
}
|
||||||
@@ -509,8 +542,8 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
|||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
value={editorSettings.tabSize}
|
value={editorSettings.tabSize}
|
||||||
onChange={e =>
|
onChange={(e) =>
|
||||||
setEditorSettings(curr => ({
|
setEditorSettings((curr) => ({
|
||||||
...curr,
|
...curr,
|
||||||
tabSize: Number(e.target.value),
|
tabSize: Number(e.target.value),
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
useCallback,
|
useCallback,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { Notepad, Prohibit } from "phosphor-react";
|
import { IconProps, Notepad, Prohibit } from "phosphor-react";
|
||||||
import useStayScrolled from "react-stay-scrolled";
|
import useStayScrolled from "react-stay-scrolled";
|
||||||
import NextLink from "next/link";
|
import NextLink from "next/link";
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ interface ILogBox {
|
|||||||
logs: ILog[];
|
logs: ILog[];
|
||||||
renderNav?: () => ReactNode;
|
renderNav?: () => ReactNode;
|
||||||
enhanced?: boolean;
|
enhanced?: boolean;
|
||||||
|
Icon?: FC<IconProps>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LogBox: FC<ILogBox> = ({
|
const LogBox: FC<ILogBox> = ({
|
||||||
@@ -33,6 +34,7 @@ const LogBox: FC<ILogBox> = ({
|
|||||||
children,
|
children,
|
||||||
renderNav,
|
renderNav,
|
||||||
enhanced,
|
enhanced,
|
||||||
|
Icon = Notepad,
|
||||||
}) => {
|
}) => {
|
||||||
const logRef = useRef<HTMLPreElement>(null);
|
const logRef = useRef<HTMLPreElement>(null);
|
||||||
const { stayScrolled /*, scrollBottom*/ } = useStayScrolled(logRef);
|
const { stayScrolled /*, scrollBottom*/ } = useStayScrolled(logRef);
|
||||||
@@ -82,14 +84,14 @@ const LogBox: FC<ILogBox> = ({
|
|||||||
gap: "$3",
|
gap: "$3",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Notepad size="15px" /> <Text css={{ lineHeight: 1 }}>{title}</Text>
|
<Icon size="15px" /> <Text css={{ lineHeight: 1 }}>{title}</Text>
|
||||||
</Heading>
|
</Heading>
|
||||||
<Flex
|
<Flex
|
||||||
row
|
row
|
||||||
align="center"
|
align="center"
|
||||||
css={{
|
// css={{
|
||||||
width: "50%", // TODO make it max without breaking layout!
|
// maxWidth: "100%", // TODO make it max without breaking layout!
|
||||||
}}
|
// }}
|
||||||
>
|
>
|
||||||
{renderNav?.()}
|
{renderNav?.()}
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -162,11 +164,11 @@ export const Log: FC<ILog> = ({
|
|||||||
(str?: string): ReactNode => {
|
(str?: string): ReactNode => {
|
||||||
if (!str || !accounts.length) return null;
|
if (!str || !accounts.length) return null;
|
||||||
|
|
||||||
const pattern = `(${accounts.map((acc) => acc.address).join("|")})`;
|
const pattern = `(${accounts.map(acc => acc.address).join("|")})`;
|
||||||
const res = regexifyString({
|
const res = regexifyString({
|
||||||
pattern: new RegExp(pattern, "gim"),
|
pattern: new RegExp(pattern, "gim"),
|
||||||
decorator: (match, idx) => {
|
decorator: (match, idx) => {
|
||||||
const name = accounts.find((acc) => acc.address === match)?.name;
|
const name = accounts.find(acc => acc.address === match)?.name;
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
key={match + idx}
|
key={match + idx}
|
||||||
@@ -188,13 +190,13 @@ export const Log: FC<ILog> = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
let message: ReactNode;
|
let message: ReactNode;
|
||||||
|
|
||||||
if (typeof _message === 'string') {
|
if (typeof _message === "string") {
|
||||||
_message = _message.trim().replace(/\n /gi, "\n");
|
_message = _message.trim().replace(/\n /gi, "\n");
|
||||||
message = enrichAccounts(_message)
|
if (_message) message = enrichAccounts(_message);
|
||||||
}
|
else message = <Text muted>{'""'}</Text>
|
||||||
else {
|
} else {
|
||||||
message = _message
|
message = _message;
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonData = enrichAccounts(_jsonData);
|
const jsonData = enrichAccounts(_jsonData);
|
||||||
|
|||||||
@@ -1,234 +0,0 @@
|
|||||||
import {
|
|
||||||
useRef,
|
|
||||||
useLayoutEffect,
|
|
||||||
ReactNode,
|
|
||||||
FC,
|
|
||||||
useState,
|
|
||||||
useCallback,
|
|
||||||
} from "react";
|
|
||||||
import { FileJs, Prohibit } from "phosphor-react";
|
|
||||||
import useStayScrolled from "react-stay-scrolled";
|
|
||||||
import NextLink from "next/link";
|
|
||||||
|
|
||||||
import Container from "./Container";
|
|
||||||
import LogText from "./LogText";
|
|
||||||
import state, { ILog } from "../state";
|
|
||||||
import { Pre, Link, Heading, Button, Text, Flex, Box } from ".";
|
|
||||||
import regexifyString from "regexify-string";
|
|
||||||
import { useSnapshot } from "valtio";
|
|
||||||
import { AccountDialog } from "./Accounts";
|
|
||||||
import RunScript from "./RunScript";
|
|
||||||
|
|
||||||
interface ILogBox {
|
|
||||||
title: string;
|
|
||||||
clearLog?: () => void;
|
|
||||||
logs: ILog[];
|
|
||||||
renderNav?: () => ReactNode;
|
|
||||||
enhanced?: boolean;
|
|
||||||
showButtons?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const LogBox: FC<ILogBox> = ({
|
|
||||||
title,
|
|
||||||
clearLog,
|
|
||||||
logs,
|
|
||||||
children,
|
|
||||||
renderNav,
|
|
||||||
enhanced,
|
|
||||||
showButtons = true,
|
|
||||||
}) => {
|
|
||||||
const logRef = useRef<HTMLPreElement>(null);
|
|
||||||
const { stayScrolled /*, scrollBottom*/ } = useStayScrolled(logRef);
|
|
||||||
const snap = useSnapshot(state);
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
stayScrolled();
|
|
||||||
}, [stayScrolled, logs]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex
|
|
||||||
as="div"
|
|
||||||
css={{
|
|
||||||
display: "flex",
|
|
||||||
borderTop: "1px solid $mauve6",
|
|
||||||
background: "$mauve1",
|
|
||||||
position: "relative",
|
|
||||||
flex: 1,
|
|
||||||
height: "100%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Container
|
|
||||||
css={{
|
|
||||||
px: 0,
|
|
||||||
height: "100%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Flex
|
|
||||||
fluid
|
|
||||||
css={{
|
|
||||||
height: "48px",
|
|
||||||
alignItems: "center",
|
|
||||||
fontSize: "$sm",
|
|
||||||
fontWeight: 300,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Heading
|
|
||||||
as="h3"
|
|
||||||
css={{
|
|
||||||
fontWeight: 300,
|
|
||||||
m: 0,
|
|
||||||
fontSize: "11px",
|
|
||||||
color: "$mauve12",
|
|
||||||
px: "$3",
|
|
||||||
textTransform: "uppercase",
|
|
||||||
alignItems: "center",
|
|
||||||
display: "inline-flex",
|
|
||||||
gap: "$3",
|
|
||||||
mr: "$3",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<FileJs size="15px" /> <Text css={{ lineHeight: 1 }}>{title}</Text>
|
|
||||||
</Heading>
|
|
||||||
{showButtons && (
|
|
||||||
<Flex css={{ gap: "$3" }}>
|
|
||||||
{snap.files
|
|
||||||
.filter((f) => f.name.endsWith(".js"))
|
|
||||||
.map((file) => (
|
|
||||||
<RunScript file={file} key={file.name} />
|
|
||||||
))}
|
|
||||||
</Flex>
|
|
||||||
)}
|
|
||||||
<Flex css={{ ml: "auto", gap: "$3", marginRight: "$3" }}>
|
|
||||||
{clearLog && (
|
|
||||||
<Button ghost size="xs" onClick={clearLog}>
|
|
||||||
<Prohibit size="14px" />
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Flex>
|
|
||||||
</Flex>
|
|
||||||
<Box
|
|
||||||
as="pre"
|
|
||||||
ref={logRef}
|
|
||||||
css={{
|
|
||||||
margin: 0,
|
|
||||||
// display: "inline-block",
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
width: "100%",
|
|
||||||
height: "calc(100% - 48px)", // 100% minus the logbox header height
|
|
||||||
overflowY: "auto",
|
|
||||||
fontSize: "13px",
|
|
||||||
fontWeight: "$body",
|
|
||||||
fontFamily: "$monospace",
|
|
||||||
px: "$3",
|
|
||||||
pb: "$2",
|
|
||||||
whiteSpace: "normal",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{logs?.map((log, index) => (
|
|
||||||
<Box
|
|
||||||
as="span"
|
|
||||||
key={log.type + index}
|
|
||||||
css={{
|
|
||||||
"@hover": {
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor: enhanced ? "$backgroundAlt" : undefined,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
p: enhanced ? "$1" : undefined,
|
|
||||||
my: enhanced ? "$1" : undefined,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Log {...log} />
|
|
||||||
</Box>
|
|
||||||
))}
|
|
||||||
{children}
|
|
||||||
</Box>
|
|
||||||
</Container>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Log: FC<ILog> = ({
|
|
||||||
type,
|
|
||||||
timestring,
|
|
||||||
message: _message,
|
|
||||||
link,
|
|
||||||
linkText,
|
|
||||||
defaultCollapsed,
|
|
||||||
jsonData: _jsonData,
|
|
||||||
}) => {
|
|
||||||
const [expanded, setExpanded] = useState(!defaultCollapsed);
|
|
||||||
const { accounts } = useSnapshot(state);
|
|
||||||
const [dialogAccount, setDialogAccount] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const enrichAccounts = useCallback(
|
|
||||||
(str?: string): ReactNode => {
|
|
||||||
if (!str || !accounts.length) return null;
|
|
||||||
|
|
||||||
const pattern = `(${accounts.map((acc) => acc.address).join("|")})`;
|
|
||||||
const res = regexifyString({
|
|
||||||
pattern: new RegExp(pattern, "gim"),
|
|
||||||
decorator: (match, idx) => {
|
|
||||||
const name = accounts.find((acc) => acc.address === match)?.name;
|
|
||||||
return (
|
|
||||||
<Link
|
|
||||||
key={match + idx}
|
|
||||||
as="a"
|
|
||||||
onClick={() => setDialogAccount(match)}
|
|
||||||
title={match}
|
|
||||||
highlighted
|
|
||||||
>
|
|
||||||
{name || match}
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
input: str,
|
|
||||||
});
|
|
||||||
|
|
||||||
return <>{res}</>;
|
|
||||||
},
|
|
||||||
[accounts]
|
|
||||||
);
|
|
||||||
|
|
||||||
let message: ReactNode;
|
|
||||||
|
|
||||||
if (typeof _message === "string") {
|
|
||||||
_message = _message.trim().replace(/\n /gi, "\n");
|
|
||||||
message = enrichAccounts(_message);
|
|
||||||
} else {
|
|
||||||
message = _message;
|
|
||||||
}
|
|
||||||
|
|
||||||
const jsonData = enrichAccounts(_jsonData);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<AccountDialog
|
|
||||||
setActiveAccountAddress={setDialogAccount}
|
|
||||||
activeAccountAddress={dialogAccount}
|
|
||||||
/>
|
|
||||||
<LogText variant={type}>
|
|
||||||
{timestring && (
|
|
||||||
<Text muted monospace>
|
|
||||||
{timestring}{" "}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
<Pre>{message} </Pre>
|
|
||||||
{link && (
|
|
||||||
<NextLink href={link} shallow passHref>
|
|
||||||
<Link as="a">{linkText}</Link>
|
|
||||||
</NextLink>
|
|
||||||
)}
|
|
||||||
{jsonData && (
|
|
||||||
<Link onClick={() => setExpanded(!expanded)} as="a">
|
|
||||||
{expanded ? "Collapse" : "Expand"}
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
{expanded && jsonData && <Pre block>{jsonData}</Pre>}
|
|
||||||
</LogText>
|
|
||||||
<br />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LogBox;
|
|
||||||
@@ -340,6 +340,8 @@ const Navigation = () => {
|
|||||||
height: 0,
|
height: 0,
|
||||||
background: "transparent",
|
background: "transparent",
|
||||||
},
|
},
|
||||||
|
scrollbarColor: "transparent",
|
||||||
|
scrollbarWidth: "none",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack
|
<Stack
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import * as Handlebars from "handlebars";
|
|
||||||
import { Play, X } from "phosphor-react";
|
import { Play, X } from "phosphor-react";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import {
|
||||||
import state, { IFile, ILog } from "../../state";
|
HTMLInputTypeAttribute,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
|
import state, { IAccount, IFile, ILog } from "../../state";
|
||||||
import Button from "../Button";
|
import Button from "../Button";
|
||||||
import Box from "../Box";
|
import Box from "../Box";
|
||||||
import Input from "../Input";
|
import Input, { Label } from "../Input";
|
||||||
import Stack from "../Stack";
|
import Stack from "../Stack";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -17,16 +21,21 @@ import {
|
|||||||
import Flex from "../Flex";
|
import Flex from "../Flex";
|
||||||
import { useSnapshot } from "valtio";
|
import { useSnapshot } from "valtio";
|
||||||
import Select from "../Select";
|
import Select from "../Select";
|
||||||
|
import Text from "../Text";
|
||||||
import { saveFile } from "../../state/actions/saveFile";
|
import { saveFile } from "../../state/actions/saveFile";
|
||||||
|
import { getErrors, getTags } from "../../utils/comment-parser";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
Handlebars.registerHelper(
|
const generateHtmlTemplate = (code: string, data?: Record<string, any>) => {
|
||||||
"customize_input",
|
let processString: string | undefined;
|
||||||
function (/* dynamic arguments */) {
|
const process = { env: { NODE_ENV: "production" } } as any;
|
||||||
return new Handlebars.SafeString(arguments[0]);
|
if (data) {
|
||||||
|
Object.keys(data).forEach(key => {
|
||||||
|
process.env[key] = data[key];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
processString = JSON.stringify(process);
|
||||||
|
|
||||||
const generateHtmlTemplate = (code: string) => {
|
|
||||||
return `
|
return `
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@@ -55,8 +64,21 @@ const generateHtmlTemplate = (code: string) => {
|
|||||||
parent.window.postMessage({ type: 'warning', args: args || [] }, '*');
|
parent.window.postMessage({ type: 'warning', args: args || [] }, '*');
|
||||||
warnLog.apply(console, args);
|
warnLog.apply(console, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var process = '${processString || "{}"}';
|
||||||
|
process = JSON.parse(process);
|
||||||
|
window.process = process
|
||||||
|
|
||||||
|
function windowErrorHandler(event) {
|
||||||
|
event.preventDefault() // to prevent automatically logging to console
|
||||||
|
console.error(event.error?.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('error', windowErrorHandler);
|
||||||
</script>
|
</script>
|
||||||
<script type="module">
|
|
||||||
|
<script type="module">
|
||||||
${code}
|
${code}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
@@ -69,72 +91,57 @@ const generateHtmlTemplate = (code: string) => {
|
|||||||
type Fields = Record<
|
type Fields = Record<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
key: string;
|
name: string;
|
||||||
value: string;
|
value: string;
|
||||||
label?: string;
|
type?: "Account" | `Account.${keyof IAccount}` | HTMLInputTypeAttribute;
|
||||||
type?: string;
|
description?: string;
|
||||||
attach?: "account_secret" | "account_address" | string;
|
required?: boolean;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
||||||
const snap = useSnapshot(state);
|
const snap = useSnapshot(state);
|
||||||
const [templateError, setTemplateError] = useState("");
|
const [templateError, setTemplateError] = useState("");
|
||||||
const getFieldValues = useCallback(() => {
|
|
||||||
try {
|
|
||||||
const parsed = Handlebars.parse(content);
|
|
||||||
const names = parsed.body
|
|
||||||
.filter((i) => i.type === "MustacheStatement")
|
|
||||||
.map((block) => {
|
|
||||||
// @ts-expect-error
|
|
||||||
const type = block.hash?.pairs?.find((i) => i.key == "type");
|
|
||||||
// @ts-expect-error
|
|
||||||
const attach = block.hash?.pairs?.find((i) => i.key == "attach");
|
|
||||||
// @ts-expect-error
|
|
||||||
const label = block.hash?.pairs?.find((i) => i.key == "label");
|
|
||||||
const key =
|
|
||||||
// @ts-expect-error
|
|
||||||
block?.path?.original === "customize_input"
|
|
||||||
? // @ts-expect-error
|
|
||||||
block?.params?.[0].original
|
|
||||||
: // @ts-expect-error
|
|
||||||
block?.path?.original;
|
|
||||||
return {
|
|
||||||
key,
|
|
||||||
label: label?.value?.original || key,
|
|
||||||
attach: attach?.value?.original,
|
|
||||||
type: type?.value?.original,
|
|
||||||
value: "",
|
|
||||||
};
|
|
||||||
});
|
|
||||||
const defaultState: Fields = {};
|
|
||||||
|
|
||||||
if (names) {
|
|
||||||
names.forEach((field) => (defaultState[field.key] = field));
|
|
||||||
}
|
|
||||||
setTemplateError("");
|
|
||||||
return defaultState;
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
setTemplateError("Could not parse template");
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}, [content]);
|
|
||||||
|
|
||||||
// const defaultFieldValues = getFieldValues();
|
|
||||||
|
|
||||||
const [fields, setFields] = useState<Fields>({});
|
const [fields, setFields] = useState<Fields>({});
|
||||||
const [iFrameCode, setIframeCode] = useState("");
|
const [iFrameCode, setIframeCode] = useState("");
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
const runScript = () => {
|
|
||||||
const fieldsToSend: Record<string, string> = {};
|
const getFields = useCallback(() => {
|
||||||
Object.entries(fields).map(([key, obj]) => {
|
const inputTags = ["input", "param", "arg", "argument"];
|
||||||
fieldsToSend[key] = obj.value;
|
const tags = getTags(content)
|
||||||
});
|
.filter(tag => inputTags.includes(tag.tag))
|
||||||
const template = Handlebars.compile(content, { strict: false });
|
.filter(tag => !!tag.name);
|
||||||
|
|
||||||
|
let _fields = tags.map(tag => ({
|
||||||
|
name: tag.name,
|
||||||
|
value: tag.default || "",
|
||||||
|
type: tag.type,
|
||||||
|
description: tag.description,
|
||||||
|
required: !tag.optional,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const fields: Fields = _fields.reduce((acc, field) => {
|
||||||
|
acc[field.name] = field;
|
||||||
|
return acc;
|
||||||
|
}, {} as Fields);
|
||||||
|
|
||||||
|
const error = getErrors(content);
|
||||||
|
if (error) setTemplateError(error.message);
|
||||||
|
else setTemplateError("");
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}, [content]);
|
||||||
|
|
||||||
|
const runScript = useCallback(() => {
|
||||||
try {
|
try {
|
||||||
const code = template(fieldsToSend);
|
let data: any = {};
|
||||||
setIframeCode(generateHtmlTemplate(code));
|
Object.keys(fields).forEach(key => {
|
||||||
|
data[key] = fields[key].value;
|
||||||
|
});
|
||||||
|
const template = generateHtmlTemplate(content, data);
|
||||||
|
|
||||||
|
setIframeCode(template);
|
||||||
|
|
||||||
state.scriptLogs = [
|
state.scriptLogs = [
|
||||||
...snap.scriptLogs,
|
...snap.scriptLogs,
|
||||||
{ type: "success", message: "Started running..." },
|
{ type: "success", message: "Started running..." },
|
||||||
@@ -146,7 +153,7 @@ const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
|||||||
{ type: "error", message: err?.message || "Could not parse template" },
|
{ type: "error", message: err?.message || "Could not parse template" },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
};
|
}, [content, fields, snap.scriptLogs]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleEvent = (e: any) => {
|
const handleEvent = (e: any) => {
|
||||||
@@ -163,17 +170,29 @@ const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
|||||||
}, [snap.scriptLogs]);
|
}, [snap.scriptLogs]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newDefaultState = getFieldValues();
|
const defaultFields = getFields() || {};
|
||||||
setFields(newDefaultState || {});
|
setFields(defaultFields);
|
||||||
}, [content, setFields, getFieldValues]);
|
}, [content, setFields, getFields]);
|
||||||
|
|
||||||
const options = snap.accounts?.map((acc) => ({
|
const accOptions = snap.accounts?.map(acc => ({
|
||||||
|
...acc,
|
||||||
label: acc.name,
|
label: acc.name,
|
||||||
secret: acc.secret,
|
|
||||||
address: acc.address,
|
|
||||||
value: acc.address,
|
value: acc.address,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const isDisabled = Object.values(fields).some(
|
||||||
|
field => field.required && !field.value
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleRun = useCallback(() => {
|
||||||
|
if (isDisabled)
|
||||||
|
return toast.error("Please fill in all the required fields.");
|
||||||
|
|
||||||
|
state.scriptLogs = [];
|
||||||
|
runScript();
|
||||||
|
setIsDialogOpen(false);
|
||||||
|
}, [isDisabled, runScript]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
||||||
@@ -191,74 +210,87 @@ const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
|||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogTitle>Run {name} script</DialogTitle>
|
<DialogTitle>Run {name} script</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
You are about to run scripts provided by the developer of the hook,
|
<Box>
|
||||||
make sure you know what you are doing.
|
You are about to run scripts provided by the developer of the
|
||||||
<br />
|
hook, make sure you trust the author before you continue.
|
||||||
|
</Box>
|
||||||
{templateError && (
|
{templateError && (
|
||||||
<Box
|
<Box
|
||||||
as="span"
|
as="span"
|
||||||
css={{ display: "block", color: "$error", mt: "$3" }}
|
css={{
|
||||||
|
display: "block",
|
||||||
|
color: "$error",
|
||||||
|
mt: "$3",
|
||||||
|
whiteSpace: "pre",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Error occured while parsing template, modify script and try
|
{templateError}
|
||||||
again!
|
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
<br />
|
{Object.keys(fields).length > 0 && (
|
||||||
{Object.keys(fields).length > 0
|
<Box css={{ mt: "$4", mb: 0 }}>
|
||||||
? `You also need to fill in following parameters to run the script`
|
Fill in the following parameters to run the script.
|
||||||
: ""}
|
|
||||||
</DialogDescription>
|
|
||||||
<Stack css={{ width: "100%" }}>
|
|
||||||
{Object.keys(fields).map((key) => (
|
|
||||||
<Box key={key} css={{ width: "100%" }}>
|
|
||||||
<label>
|
|
||||||
{fields[key]?.label || key}{" "}
|
|
||||||
{fields[key].attach === "account_secret" &&
|
|
||||||
`(Script uses account secret)`}
|
|
||||||
</label>
|
|
||||||
{fields[key].attach === "account_secret" ||
|
|
||||||
fields[key].attach === "account_address" ? (
|
|
||||||
<Select
|
|
||||||
css={{ mt: "$1" }}
|
|
||||||
options={options}
|
|
||||||
onChange={(val: any) => {
|
|
||||||
setFields({
|
|
||||||
...fields,
|
|
||||||
[key]: {
|
|
||||||
...fields[key],
|
|
||||||
value:
|
|
||||||
fields[key].attach === "account_secret"
|
|
||||||
? val.secret
|
|
||||||
: val.address,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
value={options.find(
|
|
||||||
(opt) =>
|
|
||||||
opt.address === fields[key].value ||
|
|
||||||
opt.secret === fields[key].value
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Input
|
|
||||||
type={fields[key].type || "text"}
|
|
||||||
value={
|
|
||||||
typeof fields[key].value !== "string"
|
|
||||||
? // @ts-expect-error
|
|
||||||
fields[key].value.value
|
|
||||||
: fields[key].value
|
|
||||||
}
|
|
||||||
css={{ mt: "$1" }}
|
|
||||||
onChange={(e) => {
|
|
||||||
setFields({
|
|
||||||
...fields,
|
|
||||||
[key]: { ...fields[key], value: e.target.value },
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
))}
|
)}
|
||||||
|
</DialogDescription>
|
||||||
|
|
||||||
|
<Stack css={{ width: "100%" }}>
|
||||||
|
{Object.keys(fields).map(key => {
|
||||||
|
const { name, value, type, description, required } = fields[key];
|
||||||
|
|
||||||
|
const isAccount = type?.startsWith("Account");
|
||||||
|
const isAccountSecret = type === "Account.secret";
|
||||||
|
|
||||||
|
const accountField =
|
||||||
|
(isAccount && type?.split(".")[1]) || "address";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box key={name} css={{ width: "100%" }}>
|
||||||
|
<Label
|
||||||
|
css={{ display: "flex", justifyContent: "space-between" }}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
{description || name} {required && <Text error>*</Text>}
|
||||||
|
</span>
|
||||||
|
{isAccountSecret && (
|
||||||
|
<Text error small css={{ alignSelf: "end" }}>
|
||||||
|
can access account secret key
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Label>
|
||||||
|
{isAccount ? (
|
||||||
|
<Select
|
||||||
|
css={{ mt: "$1" }}
|
||||||
|
options={accOptions}
|
||||||
|
onChange={(val: any) => {
|
||||||
|
setFields({
|
||||||
|
...fields,
|
||||||
|
[key]: {
|
||||||
|
...fields[key],
|
||||||
|
value: val[accountField],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
value={accOptions.find(
|
||||||
|
(acc: any) => acc[accountField] === value
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Input
|
||||||
|
type={type || "text"}
|
||||||
|
value={value}
|
||||||
|
css={{ mt: "$1" }}
|
||||||
|
onChange={e => {
|
||||||
|
setFields({
|
||||||
|
...fields,
|
||||||
|
[key]: { ...fields[key], value: e.target.value },
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
})}
|
||||||
<Flex
|
<Flex
|
||||||
css={{ justifyContent: "flex-end", width: "100%", gap: "$3" }}
|
css={{ justifyContent: "flex-end", width: "100%", gap: "$3" }}
|
||||||
>
|
>
|
||||||
@@ -267,16 +299,8 @@ const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
|||||||
</DialogClose>
|
</DialogClose>
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
isDisabled={
|
isDisabled={isDisabled}
|
||||||
(Object.entries(fields).length > 0 &&
|
onClick={handleRun}
|
||||||
Object.entries(fields).some(([key, obj]) => !obj.value)) ||
|
|
||||||
Boolean(templateError)
|
|
||||||
}
|
|
||||||
onClick={() => {
|
|
||||||
state.scriptLogs = [];
|
|
||||||
runScript();
|
|
||||||
setIsDialogOpen(false);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Run script
|
Run script
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ import {
|
|||||||
import { TTS, tts } from "../utils/hookOnCalculator";
|
import { TTS, tts } from "../utils/hookOnCalculator";
|
||||||
import { deployHook } from "../state/actions";
|
import { deployHook } from "../state/actions";
|
||||||
import { useSnapshot } from "valtio";
|
import { useSnapshot } from "valtio";
|
||||||
import state from "../state";
|
import state, { SelectOption } from "../state";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { prepareDeployHookTx, sha256 } from "../state/actions/deployHook";
|
import { prepareDeployHookTx, sha256 } from "../state/actions/deployHook";
|
||||||
import estimateFee from "../utils/estimateFee";
|
import estimateFee from "../utils/estimateFee";
|
||||||
|
|
||||||
const transactionOptions = Object.keys(tts).map((key) => ({
|
const transactionOptions = Object.keys(tts).map(key => ({
|
||||||
label: key,
|
label: key,
|
||||||
value: key as keyof TTS,
|
value: key as keyof TTS,
|
||||||
}));
|
}));
|
||||||
@@ -56,9 +56,22 @@ export type SetHookData = {
|
|||||||
export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||||
({ accountAddress }) => {
|
({ accountAddress }) => {
|
||||||
const snap = useSnapshot(state);
|
const snap = useSnapshot(state);
|
||||||
const account = snap.accounts.find((acc) => acc.address === accountAddress);
|
const activeFile = snap.files[snap.active]?.compiledContent
|
||||||
|
? snap.files[snap.active]
|
||||||
|
: snap.files.filter(file => file.compiledContent)[0];
|
||||||
const [isSetHookDialogOpen, setIsSetHookDialogOpen] = useState(false);
|
const [isSetHookDialogOpen, setIsSetHookDialogOpen] = useState(false);
|
||||||
|
|
||||||
|
const accountOptions: SelectOption[] = snap.accounts.map(acc => ({
|
||||||
|
label: acc.name,
|
||||||
|
value: acc.address,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const [selectedAccount, setSelectedAccount] = useState(
|
||||||
|
accountOptions.find(acc => acc.value === accountAddress)
|
||||||
|
);
|
||||||
|
const account = snap.accounts.find(
|
||||||
|
acc => acc.address === selectedAccount?.value
|
||||||
|
);
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@@ -68,11 +81,13 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
getValues,
|
getValues,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<SetHookData>({
|
} = useForm<SetHookData>({
|
||||||
defaultValues: {
|
defaultValues: snap.deployValues?.[activeFile?.name]
|
||||||
HookNamespace:
|
? snap.deployValues[activeFile?.name]
|
||||||
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "",
|
: {
|
||||||
Invoke: transactionOptions.filter((to) => to.label === "ttPAYMENT"),
|
HookNamespace:
|
||||||
},
|
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "",
|
||||||
|
Invoke: transactionOptions.filter(to => to.label === "ttPAYMENT"),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const { fields, append, remove } = useFieldArray({
|
const { fields, append, remove } = useFieldArray({
|
||||||
control,
|
control,
|
||||||
@@ -81,14 +96,21 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
const [formInitialized, setFormInitialized] = useState(false);
|
const [formInitialized, setFormInitialized] = useState(false);
|
||||||
const [estimateLoading, setEstimateLoading] = useState(false);
|
const [estimateLoading, setEstimateLoading] = useState(false);
|
||||||
const watchedFee = watch("Fee");
|
const watchedFee = watch("Fee");
|
||||||
|
|
||||||
// Update value if activeWat changes
|
// Update value if activeWat changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue(
|
const defaultValue = snap.deployValues?.[activeFile?.name]
|
||||||
"HookNamespace",
|
? snap.deployValues?.[activeFile?.name].HookNamespace
|
||||||
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
|
: snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "";
|
||||||
);
|
setValue("HookNamespace", defaultValue);
|
||||||
setFormInitialized(true);
|
setFormInitialized(true);
|
||||||
}, [snap.activeWat, snap.files, setValue]);
|
}, [
|
||||||
|
snap.activeWat,
|
||||||
|
snap.files,
|
||||||
|
setValue,
|
||||||
|
activeFile?.name,
|
||||||
|
snap.deployValues,
|
||||||
|
]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
watchedFee &&
|
watchedFee &&
|
||||||
@@ -108,7 +130,9 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
const [hashedNamespace, setHashedNamespace] = useState("");
|
const [hashedNamespace, setHashedNamespace] = useState("");
|
||||||
const namespace = watch(
|
const namespace = watch(
|
||||||
"HookNamespace",
|
"HookNamespace",
|
||||||
snap.files?.[snap.active]?.name?.split(".")?.[0] || ""
|
snap.deployValues?.[activeFile?.name]
|
||||||
|
? snap.deployValues?.[activeFile?.name].HookNamespace
|
||||||
|
: snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
|
||||||
);
|
);
|
||||||
const calculateHashedValue = useCallback(async () => {
|
const calculateHashedValue = useCallback(async () => {
|
||||||
const hashedVal = await sha256(namespace);
|
const hashedVal = await sha256(namespace);
|
||||||
@@ -136,14 +160,10 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [formInitialized]);
|
}, [formInitialized]);
|
||||||
|
|
||||||
if (!account) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tooLargeFile = () => {
|
const tooLargeFile = () => {
|
||||||
const activeFile = snap.files[snap.active].compiledContent
|
const activeFile = snap.files[snap.active].compiledContent
|
||||||
? snap.files[snap.active]
|
? snap.files[snap.active]
|
||||||
: snap.files.filter((file) => file.compiledContent)[0];
|
: snap.files.filter(file => file.compiledContent)[0];
|
||||||
return Boolean(
|
return Boolean(
|
||||||
activeFile?.compiledContent?.byteLength &&
|
activeFile?.compiledContent?.byteLength &&
|
||||||
activeFile?.compiledContent?.byteLength >= 64000
|
activeFile?.compiledContent?.byteLength >= 64000
|
||||||
@@ -152,8 +172,9 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
|
|
||||||
const onSubmit: SubmitHandler<SetHookData> = async (data) => {
|
const onSubmit: SubmitHandler<SetHookData> = async (data) => {
|
||||||
const currAccount = state.accounts.find(
|
const currAccount = state.accounts.find(
|
||||||
(acc) => acc.address === account.address
|
(acc) => acc.address === account?.address
|
||||||
);
|
);
|
||||||
|
if (!account) return;
|
||||||
if (currAccount) currAccount.isLoading = true;
|
if (currAccount) currAccount.isLoading = true;
|
||||||
const res = await deployHook(account, data);
|
const res = await deployHook(account, data);
|
||||||
if (currAccount) currAccount.isLoading = false;
|
if (currAccount) currAccount.isLoading = false;
|
||||||
@@ -173,8 +194,9 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
uppercase
|
uppercase
|
||||||
variant={"secondary"}
|
variant={"secondary"}
|
||||||
disabled={
|
disabled={
|
||||||
|
!account ||
|
||||||
account.isLoading ||
|
account.isLoading ||
|
||||||
!snap.files.filter((file) => file.compiledWatContent).length ||
|
!snap.files.filter(file => file.compiledWatContent).length ||
|
||||||
tooLargeFile()
|
tooLargeFile()
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -186,14 +208,22 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
<DialogTitle>Deploy configuration</DialogTitle>
|
<DialogTitle>Deploy configuration</DialogTitle>
|
||||||
<DialogDescription as="div">
|
<DialogDescription as="div">
|
||||||
<Stack css={{ width: "100%", flex: 1 }}>
|
<Stack css={{ width: "100%", flex: 1 }}>
|
||||||
|
<Box css={{ width: "100%" }}>
|
||||||
|
<Label>Account</Label>
|
||||||
|
<Select
|
||||||
|
instanceId="deploy-account"
|
||||||
|
placeholder="Select account"
|
||||||
|
hideSelectedOptions
|
||||||
|
options={accountOptions}
|
||||||
|
value={selectedAccount}
|
||||||
|
onChange={(acc: any) => setSelectedAccount(acc)}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
<Box css={{ width: "100%" }}>
|
<Box css={{ width: "100%" }}>
|
||||||
<Label>Invoke on transactions</Label>
|
<Label>Invoke on transactions</Label>
|
||||||
<Controller
|
<Controller
|
||||||
name="Invoke"
|
name="Invoke"
|
||||||
control={control}
|
control={control}
|
||||||
defaultValue={transactionOptions.filter(
|
|
||||||
(to) => to.label === "ttPAYMENT"
|
|
||||||
)}
|
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Select
|
<Select
|
||||||
{...field}
|
{...field}
|
||||||
@@ -210,9 +240,6 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
<Input
|
<Input
|
||||||
{...register("HookNamespace", { required: true })}
|
{...register("HookNamespace", { required: true })}
|
||||||
autoComplete={"off"}
|
autoComplete={"off"}
|
||||||
defaultValue={
|
|
||||||
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
{errors.HookNamespace?.type === "required" && (
|
{errors.HookNamespace?.type === "required" && (
|
||||||
<Box css={{ display: "inline", color: "$red11" }}>
|
<Box css={{ display: "inline", color: "$red11" }}>
|
||||||
@@ -275,7 +302,7 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
type="number"
|
type="number"
|
||||||
{...register("Fee", { required: true })}
|
{...register("Fee", { required: true })}
|
||||||
autoComplete={"off"}
|
autoComplete={"off"}
|
||||||
onKeyPress={(e) => {
|
onKeyPress={e => {
|
||||||
if (e.key === "." || e.key === ",") {
|
if (e.key === "." || e.key === ",") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
@@ -307,8 +334,9 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
alignContent: "center",
|
alignContent: "center",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
}}
|
}}
|
||||||
onClick={async (e) => {
|
onClick={async e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if (!account) return;
|
||||||
setEstimateLoading(true);
|
setEstimateLoading(true);
|
||||||
const formValues = getValues();
|
const formValues = getValues();
|
||||||
try {
|
try {
|
||||||
@@ -407,7 +435,7 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
type="submit"
|
type="submit"
|
||||||
isLoading={account.isLoading}
|
isLoading={account?.isLoading}
|
||||||
>
|
>
|
||||||
Set Hook
|
Set Hook
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -31,13 +31,15 @@ interface TabProps {
|
|||||||
|
|
||||||
// TODO customise messages shown
|
// TODO customise messages shown
|
||||||
interface Props {
|
interface Props {
|
||||||
|
label?: string;
|
||||||
activeIndex?: number;
|
activeIndex?: number;
|
||||||
activeHeader?: string;
|
activeHeader?: string;
|
||||||
headless?: boolean;
|
headless?: boolean;
|
||||||
children: ReactElement<TabProps>[];
|
children: ReactElement<TabProps>[];
|
||||||
keepAllAlive?: boolean;
|
keepAllAlive?: boolean;
|
||||||
defaultExtension?: string;
|
defaultExtension?: string;
|
||||||
forceDefaultExtension?: boolean;
|
appendDefaultExtension?: boolean;
|
||||||
|
allowedExtensions?: string[];
|
||||||
onCreateNewTab?: (name: string) => any;
|
onCreateNewTab?: (name: string) => any;
|
||||||
onCloseTab?: (index: number, header?: string) => any;
|
onCloseTab?: (index: number, header?: string) => any;
|
||||||
onChangeActive?: (index: number, header?: string) => any;
|
onChangeActive?: (index: number, header?: string) => any;
|
||||||
@@ -46,6 +48,7 @@ interface Props {
|
|||||||
export const Tab = (props: TabProps) => null;
|
export const Tab = (props: TabProps) => null;
|
||||||
|
|
||||||
export const Tabs = ({
|
export const Tabs = ({
|
||||||
|
label = "Tab",
|
||||||
children,
|
children,
|
||||||
activeIndex,
|
activeIndex,
|
||||||
activeHeader,
|
activeHeader,
|
||||||
@@ -55,7 +58,8 @@ export const Tabs = ({
|
|||||||
onCloseTab,
|
onCloseTab,
|
||||||
onChangeActive,
|
onChangeActive,
|
||||||
defaultExtension = "",
|
defaultExtension = "",
|
||||||
forceDefaultExtension,
|
appendDefaultExtension = false,
|
||||||
|
allowedExtensions,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [active, setActive] = useState(activeIndex || 0);
|
const [active, setActive] = useState(activeIndex || 0);
|
||||||
const tabs: TabProps[] = children.map(elem => elem.props);
|
const tabs: TabProps[] = children.map(elem => elem.props);
|
||||||
@@ -86,9 +90,13 @@ export const Tabs = ({
|
|||||||
if (tabs.find(tab => tab.header === tabname)) {
|
if (tabs.find(tab => tab.header === tabname)) {
|
||||||
return { error: "Name already exists." };
|
return { error: "Name already exists." };
|
||||||
}
|
}
|
||||||
|
const ext = tabname.split(".").pop() || "";
|
||||||
|
if (allowedExtensions && !allowedExtensions.includes(ext)) {
|
||||||
|
return { error: "This file extension is not allowed!" };
|
||||||
|
}
|
||||||
return { error: null };
|
return { error: null };
|
||||||
},
|
},
|
||||||
[tabs]
|
[allowedExtensions, tabs]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleActiveChange = useCallback(
|
const handleActiveChange = useCallback(
|
||||||
@@ -101,9 +109,11 @@ export const Tabs = ({
|
|||||||
|
|
||||||
const handleCreateTab = useCallback(() => {
|
const handleCreateTab = useCallback(() => {
|
||||||
// add default extension in case omitted
|
// add default extension in case omitted
|
||||||
let _tabname = tabname.includes(".") ? tabname : tabname + defaultExtension;
|
let _tabname = tabname.includes(".")
|
||||||
if (forceDefaultExtension && !_tabname.endsWith(defaultExtension)) {
|
? tabname
|
||||||
_tabname = _tabname + defaultExtension;
|
: `${tabname}.${defaultExtension}`;
|
||||||
|
if (appendDefaultExtension && !_tabname.endsWith(defaultExtension)) {
|
||||||
|
_tabname = `${_tabname}.${defaultExtension}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chk = validateTabname(_tabname);
|
const chk = validateTabname(_tabname);
|
||||||
@@ -122,7 +132,7 @@ export const Tabs = ({
|
|||||||
}, [
|
}, [
|
||||||
tabname,
|
tabname,
|
||||||
defaultExtension,
|
defaultExtension,
|
||||||
forceDefaultExtension,
|
appendDefaultExtension,
|
||||||
validateTabname,
|
validateTabname,
|
||||||
onCreateNewTab,
|
onCreateNewTab,
|
||||||
handleActiveChange,
|
handleActiveChange,
|
||||||
@@ -206,13 +216,13 @@ export const Tabs = ({
|
|||||||
size="sm"
|
size="sm"
|
||||||
css={{ alignItems: "center", px: "$2", mr: "$3" }}
|
css={{ alignItems: "center", px: "$2", mr: "$3" }}
|
||||||
>
|
>
|
||||||
<Plus size="16px" /> {tabs.length === 0 && "Add new tab"}
|
<Plus size="16px" /> {tabs.length === 0 && `Add new ${label.toLocaleLowerCase()}`}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogTitle>Create new tab</DialogTitle>
|
<DialogTitle>Create new {label.toLocaleLowerCase()}</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
<Label>Tabname</Label>
|
<Label>{label} name</Label>
|
||||||
<Input
|
<Input
|
||||||
value={tabname}
|
value={tabname}
|
||||||
onChange={e => setTabname(e.target.value)}
|
onChange={e => setTabname(e.target.value)}
|
||||||
|
|||||||
@@ -7,20 +7,30 @@ const Text = styled("span", {
|
|||||||
variants: {
|
variants: {
|
||||||
small: {
|
small: {
|
||||||
true: {
|
true: {
|
||||||
fontSize: '$xs'
|
fontSize: "$xs",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
muted: {
|
muted: {
|
||||||
true: {
|
true: {
|
||||||
color: '$mauve9'
|
color: "$mauve9",
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
true: {
|
||||||
|
color: "$error",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
monospace: {
|
monospace: {
|
||||||
true: {
|
true: {
|
||||||
fontFamily: '$monospace'
|
fontFamily: "$monospace",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
block: {
|
||||||
|
true: {
|
||||||
|
display: "block",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Text;
|
export default Text;
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ module.exports = {
|
|||||||
config.resolve.alias["vscode"] = require.resolve(
|
config.resolve.alias["vscode"] = require.resolve(
|
||||||
"@codingame/monaco-languageclient/lib/vscode-compatibility"
|
"@codingame/monaco-languageclient/lib/vscode-compatibility"
|
||||||
);
|
);
|
||||||
config.resolve.alias["handlebars"] = require.resolve(
|
|
||||||
"handlebars/dist/handlebars.js"
|
|
||||||
);
|
|
||||||
if (!isServer) {
|
if (!isServer) {
|
||||||
config.resolve.fallback.fs = false;
|
config.resolve.fallback.fs = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,10 @@
|
|||||||
"@radix-ui/react-tooltip": "^0.1.7",
|
"@radix-ui/react-tooltip": "^0.1.7",
|
||||||
"@stitches/react": "^1.2.8",
|
"@stitches/react": "^1.2.8",
|
||||||
"base64-js": "^1.5.1",
|
"base64-js": "^1.5.1",
|
||||||
|
"comment-parser": "^1.3.1",
|
||||||
"dinero.js": "^1.9.1",
|
"dinero.js": "^1.9.1",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"filesize": "^8.0.7",
|
"filesize": "^8.0.7",
|
||||||
"handlebars": "^4.7.7",
|
|
||||||
"javascript-time-ago": "^2.3.11",
|
"javascript-time-ago": "^2.3.11",
|
||||||
"jszip": "^3.7.1",
|
"jszip": "^3.7.1",
|
||||||
"lodash.uniqby": "^4.7.0",
|
"lodash.uniqby": "^4.7.0",
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
"monaco-editor": "^0.33.0",
|
"monaco-editor": "^0.33.0",
|
||||||
"next": "^12.0.4",
|
"next": "^12.0.4",
|
||||||
"next-auth": "^4.0.0-beta.5",
|
"next-auth": "^4.0.0-beta.5",
|
||||||
|
"next-plausible": "^3.2.0",
|
||||||
"next-themes": "^0.1.1",
|
"next-themes": "^0.1.1",
|
||||||
"normalize-url": "^7.0.2",
|
"normalize-url": "^7.0.2",
|
||||||
"octokit": "^1.7.0",
|
"octokit": "^1.7.0",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { ThemeProvider } from "next-themes";
|
|||||||
import { Toaster } from "react-hot-toast";
|
import { Toaster } from "react-hot-toast";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { IdProvider } from "@radix-ui/react-id";
|
import { IdProvider } from "@radix-ui/react-id";
|
||||||
|
import PlausibleProvider from "next-plausible";
|
||||||
|
|
||||||
import { darkTheme, css } from "../stitches.config";
|
import { darkTheme, css } from "../stitches.config";
|
||||||
import Navigation from "../components/Navigation";
|
import Navigation from "../components/Navigation";
|
||||||
@@ -17,6 +18,8 @@ import TimeAgo from "javascript-time-ago";
|
|||||||
import en from "javascript-time-ago/locale/en.json";
|
import en from "javascript-time-ago/locale/en.json";
|
||||||
import { useSnapshot } from "valtio";
|
import { useSnapshot } from "valtio";
|
||||||
import Alert from "../components/AlertDialog";
|
import Alert from "../components/AlertDialog";
|
||||||
|
import { Button, Flex } from "../components";
|
||||||
|
import { ChatCircleText } from "phosphor-react";
|
||||||
|
|
||||||
TimeAgo.setDefaultLocale(en.locale);
|
TimeAgo.setDefaultLocale(en.locale);
|
||||||
TimeAgo.addLocale(en);
|
TimeAgo.addLocale(en);
|
||||||
@@ -37,7 +40,7 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
|
|||||||
if (
|
if (
|
||||||
!gistId &&
|
!gistId &&
|
||||||
router.isReady &&
|
router.isReady &&
|
||||||
!router.pathname.includes("/sign-in") &&
|
router.pathname.includes("/develop") &&
|
||||||
!snap.files.length &&
|
!snap.files.length &&
|
||||||
!snap.mainModalShowed
|
!snap.mainModalShowed
|
||||||
) {
|
) {
|
||||||
@@ -114,6 +117,7 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
|
|||||||
media="(prefers-color-scheme: light)"
|
media="(prefers-color-scheme: light)"
|
||||||
/>
|
/>
|
||||||
</Head>
|
</Head>
|
||||||
|
|
||||||
<IdProvider>
|
<IdProvider>
|
||||||
<SessionProvider session={session}>
|
<SessionProvider session={session}>
|
||||||
<ThemeProvider
|
<ThemeProvider
|
||||||
@@ -125,23 +129,40 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
|
|||||||
dark: darkTheme.className,
|
dark: darkTheme.className,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Navigation />
|
<PlausibleProvider
|
||||||
<Component {...pageProps} />
|
domain="hooks-builder.xrpl.org"
|
||||||
<Toaster
|
trackOutboundLinks
|
||||||
toastOptions={{
|
>
|
||||||
className: css({
|
<Navigation />
|
||||||
backgroundColor: "$mauve1",
|
<Component {...pageProps} />
|
||||||
color: "$mauve10",
|
<Toaster
|
||||||
fontSize: "$sm",
|
toastOptions={{
|
||||||
zIndex: 9999,
|
className: css({
|
||||||
".dark &": {
|
backgroundColor: "$mauve1",
|
||||||
backgroundColor: "$mauve4",
|
color: "$mauve10",
|
||||||
color: "$mauve12",
|
fontSize: "$sm",
|
||||||
},
|
zIndex: 9999,
|
||||||
})(),
|
".dark &": {
|
||||||
}}
|
backgroundColor: "$mauve4",
|
||||||
/>
|
color: "$mauve12",
|
||||||
<Alert />
|
},
|
||||||
|
})(),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Alert />
|
||||||
|
<Flex
|
||||||
|
as="a"
|
||||||
|
href="https://github.com/XRPLF/Hooks/discussions"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
css={{ position: "fixed", right: "$4", bottom: "$4" }}
|
||||||
|
>
|
||||||
|
<Button size="sm" variant="primary" outline>
|
||||||
|
<ChatCircleText size={14} style={{ marginRight: "0px" }} />
|
||||||
|
Bugs & Discussions
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</PlausibleProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</SessionProvider>
|
</SessionProvider>
|
||||||
</IdProvider>
|
</IdProvider>
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import { Label } from "@radix-ui/react-label";
|
import { Label } from "@radix-ui/react-label";
|
||||||
import type { NextPage } from "next";
|
import type { NextPage } from "next";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { Gear, Play } from "phosphor-react";
|
import { FileJs, Gear, Play } from "phosphor-react";
|
||||||
import Hotkeys from "react-hot-keys";
|
import Hotkeys from "react-hot-keys";
|
||||||
import Split from "react-split";
|
import Split from "react-split";
|
||||||
import { useSnapshot } from "valtio";
|
import { useSnapshot } from "valtio";
|
||||||
import { ButtonGroup, Flex } from "../../components";
|
import { ButtonGroup, Flex } from "../../components";
|
||||||
import Box from "../../components/Box";
|
import Box from "../../components/Box";
|
||||||
import Button from "../../components/Button";
|
import Button from "../../components/Button";
|
||||||
import LogBoxForScripts from "../../components/LogBoxForScripts";
|
|
||||||
import Popover from "../../components/Popover";
|
import Popover from "../../components/Popover";
|
||||||
import RunScript from "../../components/RunScript";
|
import RunScript from "../../components/RunScript";
|
||||||
import state from "../../state";
|
import state from "../../state";
|
||||||
@@ -244,8 +243,8 @@ const Home: NextPage = () => {
|
|||||||
flex: 1,
|
flex: 1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LogBoxForScripts
|
<LogBox
|
||||||
showButtons={false}
|
Icon={FileJs}
|
||||||
title="Script Log"
|
title="Script Log"
|
||||||
logs={snap.scriptLogs}
|
logs={snap.scriptLogs}
|
||||||
clearLog={() => (state.scriptLogs = [])}
|
clearLog={() => (state.scriptLogs = [])}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import Transaction from "../../components/Transaction";
|
|||||||
import state from "../../state";
|
import state from "../../state";
|
||||||
import { getSplit, saveSplit } from "../../state/actions/persistSplits";
|
import { getSplit, saveSplit } from "../../state/actions/persistSplits";
|
||||||
import { transactionsState, modifyTransaction } from "../../state";
|
import { transactionsState, modifyTransaction } from "../../state";
|
||||||
import LogBoxForScripts from "../../components/LogBoxForScripts";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { FileJs } from "phosphor-react";
|
||||||
|
import RunScript from '../../components/RunScript';
|
||||||
|
|
||||||
const DebugStream = dynamic(() => import("../../components/DebugStream"), {
|
const DebugStream = dynamic(() => import("../../components/DebugStream"), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@@ -33,7 +34,17 @@ const Test = () => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const hasScripts = Boolean(
|
const hasScripts = Boolean(
|
||||||
snap.files.filter((f) => f.name.toLowerCase()?.endsWith(".js")).length
|
snap.files.filter(f => f.name.toLowerCase()?.endsWith(".js")).length
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderNav = () => (
|
||||||
|
<Flex css={{ gap: "$3" }}>
|
||||||
|
{snap.files
|
||||||
|
.filter(f => f.name.endsWith(".js"))
|
||||||
|
.map(file => (
|
||||||
|
<RunScript file={file} key={file.name} />
|
||||||
|
))}
|
||||||
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -50,7 +61,7 @@ const Test = () => {
|
|||||||
gutterSize={4}
|
gutterSize={4}
|
||||||
gutterAlign="center"
|
gutterAlign="center"
|
||||||
style={{ height: "calc(100vh - 60px)" }}
|
style={{ height: "calc(100vh - 60px)" }}
|
||||||
onDragEnd={(e) => saveSplit("testVertical", e)}
|
onDragEnd={e => saveSplit("testVertical", e)}
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
row
|
row
|
||||||
@@ -72,19 +83,20 @@ const Test = () => {
|
|||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
}}
|
}}
|
||||||
onDragEnd={(e) => saveSplit("testHorizontal", e)}
|
onDragEnd={e => saveSplit("testHorizontal", e)}
|
||||||
>
|
>
|
||||||
<Box css={{ width: "55%", px: "$2" }}>
|
<Box css={{ width: "55%", px: "$2" }}>
|
||||||
<Tabs
|
<Tabs
|
||||||
|
label="Transaction"
|
||||||
activeHeader={activeHeader}
|
activeHeader={activeHeader}
|
||||||
// TODO make header a required field
|
// TODO make header a required field
|
||||||
onChangeActive={(idx, header) => {
|
onChangeActive={(idx, header) => {
|
||||||
if (header) transactionsState.activeHeader = header;
|
if (header) transactionsState.activeHeader = header;
|
||||||
}}
|
}}
|
||||||
keepAllAlive
|
keepAllAlive
|
||||||
forceDefaultExtension
|
defaultExtension="json"
|
||||||
defaultExtension=".json"
|
allowedExtensions={["json"]}
|
||||||
onCreateNewTab={(header) => modifyTransaction(header, {})}
|
onCreateNewTab={header => modifyTransaction(header, {})}
|
||||||
onCloseTab={(idx, header) =>
|
onCloseTab={(idx, header) =>
|
||||||
header && modifyTransaction(header, undefined)
|
header && modifyTransaction(header, undefined)
|
||||||
}
|
}
|
||||||
@@ -110,10 +122,12 @@ const Test = () => {
|
|||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LogBoxForScripts
|
<LogBox
|
||||||
|
Icon={FileJs}
|
||||||
title="Helper scripts"
|
title="Helper scripts"
|
||||||
logs={snap.scriptLogs}
|
logs={snap.scriptLogs}
|
||||||
clearLog={() => (state.scriptLogs = [])}
|
clearLog={() => (state.scriptLogs = [])}
|
||||||
|
renderNav={renderNav}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ export const deployHook = async (
|
|||||||
data: SetHookData
|
data: SetHookData
|
||||||
) => {
|
) => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
|
const activeFile = state.files[state.active]?.compiledContent
|
||||||
|
? state.files[state.active]
|
||||||
|
: state.files.filter((file) => file.compiledContent)[0];
|
||||||
|
state.deployValues[activeFile.name] = data;
|
||||||
const tx = await prepareDeployHookTx(account, data);
|
const tx = await prepareDeployHookTx(account, data);
|
||||||
if (!tx) {
|
if (!tx) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ export const templateFileIds = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
'firewall': {
|
'firewall': {
|
||||||
id: '741816f53eddac862ef1ba400e1b9b84',
|
id: '1cc30f39c8a0b9c55b88c312669ca45e', // Forked
|
||||||
name: 'Firewall',
|
name: 'Firewall',
|
||||||
description: 'This Hook essentially checks a blacklist of accounts',
|
description: 'This Hook essentially checks a blacklist of accounts',
|
||||||
icon: Firewall
|
icon: Firewall
|
||||||
},
|
},
|
||||||
'notary': {
|
'notary': {
|
||||||
id: '0dfe12adb0aa75cff24c3c19497fb95a',
|
id: '87b6f5a8c2f5038fb0f20b8b510efa10', // Forked
|
||||||
name: 'Notary',
|
name: 'Notary',
|
||||||
description: 'Collecting signatures for multi-sign transactions',
|
description: 'Collecting signatures for multi-sign transactions',
|
||||||
icon: Notary
|
icon: Notary
|
||||||
@@ -31,7 +31,7 @@ export const templateFileIds = {
|
|||||||
icon: Carbon
|
icon: Carbon
|
||||||
},
|
},
|
||||||
'peggy': {
|
'peggy': {
|
||||||
id: '52e61c02e777c44c913808981a4ca61f',
|
id: '049784a83fa068faf7912f663f7b6471', // Forked
|
||||||
name: 'Peggy',
|
name: 'Peggy',
|
||||||
description: 'An oracle based stable coin hook',
|
description: 'An oracle based stable coin hook',
|
||||||
icon: Peggy
|
icon: Peggy
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ export interface ILog {
|
|||||||
defaultCollapsed?: boolean
|
defaultCollapsed?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DeployValue = Record<IFile['name'], any>;
|
||||||
|
|
||||||
export interface IState {
|
export interface IState {
|
||||||
files: IFile[];
|
files: IFile[];
|
||||||
gistId?: string | null;
|
gistId?: string | null;
|
||||||
@@ -82,7 +84,8 @@ export interface IState {
|
|||||||
compileOptions: {
|
compileOptions: {
|
||||||
optimizationLevel: '-O0' | '-O1' | '-O2' | '-O3' | '-O4' | '-Os';
|
optimizationLevel: '-O0' | '-O1' | '-O2' | '-O3' | '-O4' | '-Os';
|
||||||
strip: boolean
|
strip: boolean
|
||||||
}
|
},
|
||||||
|
deployValues: DeployValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// let localStorageState: null | string = null;
|
// let localStorageState: null | string = null;
|
||||||
@@ -116,7 +119,8 @@ let initialState: IState = {
|
|||||||
compileOptions: {
|
compileOptions: {
|
||||||
optimizationLevel: '-O2',
|
optimizationLevel: '-O2',
|
||||||
strip: true
|
strip: true
|
||||||
}
|
},
|
||||||
|
deployValues: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let localStorageAccounts: string | null = null;
|
let localStorageAccounts: string | null = null;
|
||||||
|
|||||||
24
utils/comment-parser.ts
Normal file
24
utils/comment-parser.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Spec, parse, Problem } from "comment-parser"
|
||||||
|
|
||||||
|
export const getTags = (source?: string): Spec[] => {
|
||||||
|
if (!source) return []
|
||||||
|
const blocks = parse(source)
|
||||||
|
const tags = blocks.reduce(
|
||||||
|
(acc, block) => acc.concat(block.tags),
|
||||||
|
[] as Spec[]
|
||||||
|
);
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getErrors = (source?: string): Error | undefined => {
|
||||||
|
if (!source) return undefined
|
||||||
|
const blocks = parse(source)
|
||||||
|
const probs = blocks.reduce(
|
||||||
|
(acc, block) => acc.concat(block.problems),
|
||||||
|
[] as Problem[]
|
||||||
|
);
|
||||||
|
if (!probs.length) return undefined
|
||||||
|
const errors = probs.map(prob => `[${prob.code}] on line ${prob.line}: ${prob.message}`)
|
||||||
|
const error = new Error(`The following error(s) occured while parsing JSDOC: \n${errors.join('\n')}`)
|
||||||
|
return error
|
||||||
|
}
|
||||||
42
yarn.lock
42
yarn.lock
@@ -1525,6 +1525,11 @@ color-name@~1.1.4:
|
|||||||
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz"
|
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz"
|
||||||
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
|
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
|
||||||
|
|
||||||
|
comment-parser@^1.3.1:
|
||||||
|
version "1.3.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-1.3.1.tgz#3d7ea3adaf9345594aedee6563f422348f165c1b"
|
||||||
|
integrity sha512-B52sN2VNghyq5ofvUsqZjmk6YkihBX5vMSChmSK9v4ShjKf3Vk5Xcmgpw4o+iIgtrnM/u5FiMpz9VKb8lpBveA==
|
||||||
|
|
||||||
concat-map@0.0.1:
|
concat-map@0.0.1:
|
||||||
version "0.0.1"
|
version "0.0.1"
|
||||||
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz"
|
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz"
|
||||||
@@ -2281,18 +2286,6 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
|
|||||||
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz"
|
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz"
|
||||||
integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==
|
integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==
|
||||||
|
|
||||||
handlebars@^4.7.7:
|
|
||||||
version "4.7.7"
|
|
||||||
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1"
|
|
||||||
integrity sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==
|
|
||||||
dependencies:
|
|
||||||
minimist "^1.2.5"
|
|
||||||
neo-async "^2.6.0"
|
|
||||||
source-map "^0.6.1"
|
|
||||||
wordwrap "^1.0.0"
|
|
||||||
optionalDependencies:
|
|
||||||
uglify-js "^3.1.4"
|
|
||||||
|
|
||||||
has-bigints@^1.0.1:
|
has-bigints@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.1.tgz"
|
resolved "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.1.tgz"
|
||||||
@@ -2961,11 +2954,6 @@ natural-compare@^1.4.0:
|
|||||||
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
|
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
|
||||||
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
||||||
|
|
||||||
neo-async@^2.6.0:
|
|
||||||
version "2.6.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
|
|
||||||
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
|
|
||||||
|
|
||||||
next-auth@^4.0.0-beta.5:
|
next-auth@^4.0.0-beta.5:
|
||||||
version "4.2.1"
|
version "4.2.1"
|
||||||
resolved "https://registry.npmjs.org/next-auth/-/next-auth-4.2.1.tgz"
|
resolved "https://registry.npmjs.org/next-auth/-/next-auth-4.2.1.tgz"
|
||||||
@@ -2981,6 +2969,11 @@ next-auth@^4.0.0-beta.5:
|
|||||||
preact-render-to-string "^5.1.19"
|
preact-render-to-string "^5.1.19"
|
||||||
uuid "^8.3.2"
|
uuid "^8.3.2"
|
||||||
|
|
||||||
|
next-plausible@^3.2.0:
|
||||||
|
version "3.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/next-plausible/-/next-plausible-3.2.0.tgz#d801346253e0c1cf64a02b9fc3a42050455cbc47"
|
||||||
|
integrity sha512-OlYcLXBG3kKd/fKMpm8SZ5IkUKSFm1/8t7cv6e5bewIqlpdZpdWuSrjbdJpbmutb2KPLXHzilKp09zmDGjy9KQ==
|
||||||
|
|
||||||
next-themes@^0.1.1:
|
next-themes@^0.1.1:
|
||||||
version "0.1.1"
|
version "0.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.1.1.tgz#122113a458bf1d1be5ffed66778ab924c106f82a"
|
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.1.1.tgz#122113a458bf1d1be5ffed66778ab924c106f82a"
|
||||||
@@ -3875,11 +3868,6 @@ source-map@^0.5.7:
|
|||||||
resolved "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz"
|
resolved "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz"
|
||||||
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
|
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
|
||||||
|
|
||||||
source-map@^0.6.1:
|
|
||||||
version "0.6.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
|
||||||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
|
||||||
|
|
||||||
split.js@^1.6.0:
|
split.js@^1.6.0:
|
||||||
version "1.6.5"
|
version "1.6.5"
|
||||||
resolved "https://registry.npmjs.org/split.js/-/split.js-1.6.5.tgz"
|
resolved "https://registry.npmjs.org/split.js/-/split.js-1.6.5.tgz"
|
||||||
@@ -4111,11 +4099,6 @@ typescript@4.4.4:
|
|||||||
resolved "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz"
|
resolved "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz"
|
||||||
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==
|
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==
|
||||||
|
|
||||||
uglify-js@^3.1.4:
|
|
||||||
version "3.16.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.16.0.tgz#b778ba0831ca102c1d8ecbdec2d2bdfcc7353190"
|
|
||||||
integrity sha512-FEikl6bR30n0T3amyBh3LoiBdqHRy/f4H80+My34HOesOKyHfOsxAPAxOoqC0JUnC1amnO0IwkYC3sko51caSw==
|
|
||||||
|
|
||||||
unbox-primitive@^1.0.1:
|
unbox-primitive@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz"
|
resolved "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz"
|
||||||
@@ -4335,11 +4318,6 @@ word-wrap@^1.2.3:
|
|||||||
resolved "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz"
|
resolved "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz"
|
||||||
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==
|
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==
|
||||||
|
|
||||||
wordwrap@^1.0.0:
|
|
||||||
version "1.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
|
|
||||||
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
|
|
||||||
|
|
||||||
wrappy@1:
|
wrappy@1:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz"
|
resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz"
|
||||||
|
|||||||
Reference in New Issue
Block a user