Compare commits

..

20 Commits

Author SHA1 Message Date
muzam1l
db0ffe999e fix line wrap and timestamp font 2022-03-08 19:18:51 +05:30
muzam1l
ce91182c7b fix and segrregate debug stream state. 2022-03-07 17:14:53 +05:30
muzam1l
2e3a0e557e Some vertical margin in enhanced logs 2022-03-04 20:37:07 +05:30
muzam1l
6b9a9ef978 better socket error mesage 2022-03-04 15:36:48 +05:30
muzam1l
bc5bb5be39 Fix timesatmp in logs 2022-03-04 15:22:05 +05:30
muzam1l
0fe83811b9 Clickable accounts in logs and formatting fixes 2022-03-04 15:13:56 +05:30
muzam1l
c6359aa853 Add error code to close event message 2022-03-04 14:19:23 +05:30
muzam1l
c9c818c8f3 json data is now collapsible! 2022-03-03 21:03:28 +05:30
muzam1l
c521246393 debug stream state as full global 2022-03-03 16:36:42 +05:30
muzam1l
8936b34361 separate messages for debug stream error and close evensts 2022-03-03 16:16:00 +05:30
muzam1l
5993d2762f Separately format time, json and message of debug stream log. 2022-03-01 21:36:24 +05:30
muzamil
0a44b5b5d1 Merge pull request #94 from eqlabs/feat/wasm-stats
Compiled wasm file stats
2022-03-01 15:14:14 +05:30
Vaclav Barta
cc83924c27 Merge pull request #98 from eqlabs/bugfix/typos
fix for #97
2022-02-15 08:49:38 +01:00
Vaclav Barta
e3e964f72a fix for #97 2022-02-11 13:54:52 +01:00
muzam
0def1d30a6 compiled wasm file stats 2022-02-09 19:06:29 +05:30
Joni Juup
bdb2c0cf8f Merge pull request #93 from eqlabs/bugfix/monaco-popups
Fix monaco popup issues
2022-02-09 15:10:28 +02:00
muzamil
3e8dbc9793 Merge pull request #91 from eqlabs/fixes
Clearing some issues
2022-02-09 18:32:47 +05:30
Joni Juup
eddf228283 more specific rule for the box itself 2022-02-09 13:14:17 +02:00
Joni Juup
f9d617efdc more specific css rule for hr 2022-02-09 13:09:36 +02:00
Joni Juup
43796021da fix monaco editor issues with popups 2022-02-09 13:04:41 +02:00
23 changed files with 486 additions and 162 deletions

View File

@@ -27,7 +27,7 @@ const labelStyle = css({
mb: "$0.5", mb: "$0.5",
}); });
const AccountDialog = ({ export const AccountDialog = ({
activeAccountAddress, activeAccountAddress,
setActiveAccountAddress, setActiveAccountAddress,
}: { }: {
@@ -364,7 +364,7 @@ const Accounts: FC<AccountProps> = props => {
<Text>{account.name} </Text> <Text>{account.name} </Text>
<Text <Text
css={{ css={{
color: "$mauve9", color: "$textMuted",
wordBreak: "break-word", wordBreak: "break-word",
}} }}
> >

View File

@@ -66,6 +66,12 @@ export const StyledButton = styled("button", {
}, },
}, },
variant: { variant: {
link: {
textDecoration: "underline",
fontSize: "inherit",
color: "$textMuted",
textUnderlineOffset: "2px",
},
default: { default: {
backgroundColor: "$mauve12", backgroundColor: "$mauve12",
boxShadow: "inset 0 0 0 1px $colors$mauve12", boxShadow: "inset 0 0 0 1px $colors$mauve12",
@@ -81,8 +87,7 @@ export const StyledButton = styled("button", {
boxShadow: "inset 0 0 0 1px $colors$mauve11", boxShadow: "inset 0 0 0 1px $colors$mauve11",
}, },
"&:focus": { "&:focus": {
boxShadow: boxShadow: "inset 0 0 0 1px $colors$mauve12, inset 0 0 0 2px $colors$mauve12",
"inset 0 0 0 1px $colors$mauve12, inset 0 0 0 2px $colors$mauve12",
}, },
'&[data-radix-popover-trigger][data-state="open"], &[data-radix-dropdown-menu-trigger][data-state="open"]': '&[data-radix-popover-trigger][data-state="open"], &[data-radix-dropdown-menu-trigger][data-state="open"]':
{ {
@@ -137,7 +142,11 @@ export const StyledButton = styled("button", {
}, },
}, },
}, },
muted: {
true: {
color: "$textMuted",
},
},
outline: { outline: {
true: { true: {
backgroundColor: "transparent", backgroundColor: "transparent",
@@ -227,21 +236,16 @@ export const StyledButton = styled("button", {
}, },
}); });
const CustomButton: React.FC< const CustomButton: React.FC<React.ComponentProps<typeof StyledButton> & { as?: string }> =
React.ComponentProps<typeof StyledButton> & { as?: string } React.forwardRef(({ children, as = "button", ...rest }, ref) => (
> = React.forwardRef(({ children, as = "button", ...rest }, ref) => ( // @ts-expect-error
// @ts-expect-error <StyledButton {...rest} ref={ref} as={as}>
<StyledButton {...rest} ref={ref} as={as}> <Flex as="span" css={{ gap: "$2", alignItems: "center" }} className="button-content">
<Flex {children}
as="span" </Flex>
css={{ gap: "$2", alignItems: "center" }} {rest.isLoading && <Spinner css={{ position: "absolute" }} />}
className="button-content" </StyledButton>
> ));
{children}
</Flex>
{rest.isLoading && <Spinner css={{ position: "absolute" }} />}
</StyledButton>
));
CustomButton.displayName = "CustomButton"; CustomButton.displayName = "CustomButton";

View File

@@ -1,84 +1,136 @@
import { useEffect, useState } from "react"; import { useCallback, useEffect } from "react";
import { useSnapshot } from "valtio"; import { proxy, ref, useSnapshot } from "valtio";
import { Select } from "."; import { Select } from ".";
import state from "../state"; import state, { ILog } from "../state";
import { extractJSON } from "../utils/json";
import LogBox from "./LogBox"; import LogBox from "./LogBox";
import Text from "./Text";
interface ISelect<T = string> {
label: string;
value: T;
}
const streamState = proxy({
selectedAccount: null as ISelect | null,
logs: [] as ILog[],
socket: undefined as WebSocket | undefined,
});
const DebugStream = () => { const DebugStream = () => {
const snap = useSnapshot(state); const { selectedAccount, logs, socket } = useSnapshot(streamState);
const { accounts } = useSnapshot(state);
const accountOptions = snap.accounts.map(acc => ({ const accountOptions = accounts.map(acc => ({
label: acc.name, label: acc.name,
value: acc.address, value: acc.address,
})); }));
const [selectedAccount, setSelectedAccount] = useState<typeof accountOptions[0] | null>(null);
const renderNav = () => ( const renderNav = () => (
<> <>
<Text css={{ mx: "$2", fontSize: "inherit" }}>Account: </Text>
<Select <Select
instanceId="debugStreamAccount" instanceId="DSAccount"
placeholder="Select account" placeholder="Select account"
options={accountOptions} options={accountOptions}
hideSelectedOptions hideSelectedOptions
value={selectedAccount} value={selectedAccount}
onChange={acc => setSelectedAccount(acc as any)} onChange={acc => (streamState.selectedAccount = acc as any)}
css={{ width: "30%" }} css={{ width: "100%" }}
/> />
</> </>
); );
const prepareLog = useCallback((str: any): ILog => {
if (typeof str !== "string") throw Error("Unrecognized debug log stream!");
const match = str.match(/([\s\S]+(?:UTC|ISO|GMT[+|-]\d+))\ ?([\s\S]*)/m);
const [_, tm, msg] = match || [];
const extracted = extractJSON(msg);
const timestamp = isNaN(Date.parse(tm || ""))
? tm
: new Date(tm).toLocaleTimeString();
const message = !extracted
? msg
: msg.slice(0, extracted.start) + msg.slice(extracted.end + 1);
const jsonData = extracted
? JSON.stringify(extracted.result, null, 2)
: undefined;
return {
type: "log",
message,
timestamp,
jsonData,
defaultCollapsed: true,
};
}, []);
useEffect(() => { useEffect(() => {
const account = selectedAccount?.value; const account = selectedAccount?.value;
if (!account) { if (account && (!socket || !socket.url.endsWith(account))) {
return; socket?.close();
streamState.socket = ref(
new WebSocket(
`wss://hooks-testnet-debugstream.xrpl-labs.com/${account}`
)
);
} else if (!account && socket) {
socket.close();
streamState.socket = undefined;
} }
const socket = new WebSocket(`wss://hooks-testnet-debugstream.xrpl-labs.com/${account}`); }, [selectedAccount?.value, socket]);
useEffect(() => {
const account = selectedAccount?.value;
const socket = streamState.socket;
if (!socket) return;
const onOpen = () => { const onOpen = () => {
state.debugLogs = []; streamState.logs = [];
state.debugLogs.push({ streamState.logs.push({
type: "success", type: "success",
message: `Debug stream opened for account ${account}`, message: `Debug stream opened for account ${account}`,
}); });
}; };
const onError = () => { const onError = () => {
state.debugLogs.push({ streamState.logs.push({
type: "error", type: "error",
message: "Something went wrong in establishing connection!", message: "Something went wrong! Check your connection and try again.",
}); });
setSelectedAccount(null); };
const onClose = (e: CloseEvent) => {
streamState.logs.push({
type: "error",
message: `Connection was closed. [code: ${e.code}]`,
});
streamState.selectedAccount = null;
}; };
const onMessage = (event: any) => { const onMessage = (event: any) => {
if (!event.data) return; if (!event.data) return;
state.debugLogs.push({ streamState.logs.push(prepareLog(event.data));
type: "log",
message: event.data,
});
}; };
socket.addEventListener("open", onOpen); socket.addEventListener("open", onOpen);
socket.addEventListener("close", onError); socket.addEventListener("close", onClose);
socket.addEventListener("error", onError); socket.addEventListener("error", onError);
socket.addEventListener("message", onMessage); socket.addEventListener("message", onMessage);
return () => { return () => {
socket.removeEventListener("open", onOpen); socket.removeEventListener("open", onOpen);
socket.removeEventListener("close", onError); socket.removeEventListener("close", onClose);
socket.removeEventListener("message", onMessage); socket.removeEventListener("message", onMessage);
socket.removeEventListener("error", onError);
socket.close();
}; };
}, [selectedAccount]); }, [prepareLog, selectedAccount?.value, socket]);
return ( return (
<LogBox <LogBox
enhanced enhanced
renderNav={renderNav} renderNav={renderNav}
title="Debug stream" title="Debug stream"
logs={snap.debugLogs} logs={logs}
clearLog={() => (state.debugLogs = [])} clearLog={() => (streamState.logs = [])}
/> />
); );
}; };

View File

@@ -1,10 +1,12 @@
import React, { useRef } from "react"; import React, { useRef, useState } from "react";
import { useSnapshot, ref } from "valtio"; import { useSnapshot, ref } from "valtio";
import Editor, { loader } from "@monaco-editor/react"; import Editor, { loader } from "@monaco-editor/react";
import type monaco from "monaco-editor"; import type monaco from "monaco-editor";
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import NextLink from "next/link"; import NextLink from "next/link";
import ReactTimeAgo from "react-time-ago";
import filesize from "filesize";
import Box from "./Box"; import Box from "./Box";
import Container from "./Container"; import Container from "./Container";
@@ -13,8 +15,7 @@ import light from "../theme/editor/xcode_default.json";
import state from "../state"; import state from "../state";
import EditorNavigation from "./EditorNavigation"; import EditorNavigation from "./EditorNavigation";
import Text from "./Text"; import { Button, Text, Link, Flex } from ".";
import Link from "./Link";
loader.config({ loader.config({
paths: { paths: {
@@ -22,11 +23,65 @@ loader.config({
}, },
}); });
const FILESIZE_BREAKPOINTS: [number, number] = [2 * 1024, 5 * 1024];
const DeployEditor = () => { const DeployEditor = () => {
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(); const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>();
const snap = useSnapshot(state); const snap = useSnapshot(state);
const router = useRouter(); const router = useRouter();
const { theme } = useTheme(); const { theme } = useTheme();
const [showContent, setShowContent] = useState(false);
const activeFile = snap.files[snap.active];
const compiledSize = activeFile?.compiledContent?.byteLength || 0;
const color =
compiledSize > FILESIZE_BREAKPOINTS[1]
? "$error"
: compiledSize > FILESIZE_BREAKPOINTS[0]
? "$warning"
: "$success";
const CompiledStatView = activeFile && (
<Flex
column
align="center"
css={{
fontSize: "$sm",
fontFamily: "$monospace",
textAlign: "center",
}}
>
<Flex row align="center">
<Text css={{ mr: "$1" }}>Compiled {activeFile.name.split(".")[0] + ".wasm"}</Text>
{activeFile?.lastCompiled && <ReactTimeAgo date={activeFile.lastCompiled} locale="en-US" />}
{activeFile.compiledContent?.byteLength && (
<Text css={{ ml: "$2", color }}>({filesize(activeFile.compiledContent.byteLength)})</Text>
)}
</Flex>
<Button variant="link" onClick={() => setShowContent(true)}>
View as WAT-file
</Button>
</Flex>
);
const NoContentView = !snap.loading && router.isReady && (
<Text
css={{
mt: "-60px",
fontSize: "$sm",
fontFamily: "$monospace",
maxWidth: "300px",
textAlign: "center",
}}
>
{`You haven't compiled any files yet, compile files on `}
<NextLink shallow href={`/develop/${router.query.slug}`} passHref>
<Link as="a">develop view</Link>
</NextLink>
</Text>
);
const isContent =
snap.files?.filter(file => file.compiledWatContent).length > 0 && router.isReady;
return ( return (
<Box <Box
css={{ css={{
@@ -39,60 +94,45 @@ const DeployEditor = () => {
}} }}
> >
<EditorNavigation showWat /> <EditorNavigation showWat />
{snap.files?.filter((file) => file.compiledWatContent).length > 0 && <Container
router.isReady ? ( css={{
<Editor display: "flex",
className="hooks-editor" flex: 1,
// keepCurrentModel justifyContent: "center",
defaultLanguage={snap.files?.[snap.active]?.language} alignItems: "center",
language={snap.files?.[snap.active]?.language} }}
path={`file://tmp/c/${snap.files?.[snap.active]?.name}.wat`} >
value={snap.files?.[snap.active]?.compiledWatContent || ""} {!isContent ? (
beforeMount={(monaco) => { NoContentView
if (!state.editorCtx) { ) : !showContent ? (
state.editorCtx = ref(monaco.editor); CompiledStatView
// @ts-expect-error ) : (
monaco.editor.defineTheme("dark", dark); <Editor
// @ts-expect-error className="hooks-editor"
monaco.editor.defineTheme("light", light); defaultLanguage={snap.files?.[snap.active]?.language}
} language={snap.files?.[snap.active]?.language}
}} path={`file://tmp/c/${snap.files?.[snap.active]?.name}.wat`}
onMount={(editor, monaco) => { value={snap.files?.[snap.active]?.compiledWatContent || ""}
editorRef.current = editor; beforeMount={monaco => {
editor.updateOptions({ if (!state.editorCtx) {
glyphMargin: true, state.editorCtx = ref(monaco.editor);
readOnly: true, // @ts-expect-error
}); monaco.editor.defineTheme("dark", dark);
}} // @ts-expect-error
theme={theme === "dark" ? "dark" : "light"} monaco.editor.defineTheme("light", light);
/> }
) : ( }}
<Container onMount={(editor, monaco) => {
css={{ editorRef.current = editor;
display: "flex", editor.updateOptions({
flex: 1, glyphMargin: true,
justifyContent: "center", readOnly: true,
alignItems: "center", });
}} }}
> theme={theme === "dark" ? "dark" : "light"}
{!snap.loading && router.isReady && ( />
<Text )}
css={{ </Container>
mt: "-60px",
fontSize: "14px",
fontFamily: "$monospace",
maxWidth: "300px",
textAlign: "center",
}}
>
{`You haven't compiled any files yet, compile files on `}
<NextLink shallow href={`/develop/${router.query.slug}`} passHref>
<Link as="a">develop view</Link>
</NextLink>
</Text>
)}
</Container>
)}
</Box> </Box>
); );
}; };

View File

@@ -62,7 +62,7 @@ import { styled } from "../stitches.config";
const DEFAULT_EXTENSION = ".c"; const DEFAULT_EXTENSION = ".c";
const ErrorText = styled(Text, { const ErrorText = styled(Text, {
color: "$crimson9", color: "$error",
mt: "$1", mt: "$1",
display: "block", display: "block",
}); });

View File

@@ -16,9 +16,37 @@ const Flex = styled(Box, {
}, },
fluid: { fluid: {
true: { true: {
width: '100%' width: "100%",
} },
} },
align: {
start: {
alignItems: "start",
},
center: {
alignItems: "center",
},
end: {
alignItems: "end",
},
},
justify: {
start: {
justifyContent: "start",
},
center: {
justifyContent: "center",
},
end: {
justifyContent: "end",
},
"space-between": {
justifyContent: "space-between",
},
"space-around": {
justifyContent: "space-around",
},
},
}, },
}); });

View File

@@ -173,7 +173,7 @@ const HooksEditor = () => {
fontFamily: "$monospace", fontFamily: "$monospace",
}} }}
> >
Click the link above to create a your file Click the link above to create your file
</Text> </Text>
</Box> </Box>
</Box> </Box>

View File

@@ -3,6 +3,14 @@ import { styled } from "../stitches.config";
const StyledLink = styled("a", { const StyledLink = styled("a", {
color: "CurrentColor", color: "CurrentColor",
textDecoration: "underline", textDecoration: "underline",
cursor: 'pointer',
variants: {
highlighted: {
true: {
color: '$blue9'
}
}
}
}); });
export default StyledLink; export default StyledLink;

View File

@@ -1,17 +1,15 @@
import React, { useRef, useLayoutEffect, ReactNode } from "react"; import { useRef, useLayoutEffect, ReactNode, FC, useState, useCallback } from "react";
import { Notepad, Prohibit } from "phosphor-react"; import { 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";
import Container from "./Container"; import Container from "./Container";
import Box from "./Box";
import Flex from "./Flex";
import LogText from "./LogText"; import LogText from "./LogText";
import { ILog } from "../state"; import state, { ILog } from "../state";
import Text from "./Text"; import { Pre, Link, Heading, Button, Text, Flex, Box } from ".";
import Button from "./Button"; import regexifyString from "regexify-string";
import Heading from "./Heading"; import { useSnapshot } from "valtio";
import Link from "./Link"; import { AccountDialog } from "./Accounts";
interface ILogBox { interface ILogBox {
title: string; title: string;
@@ -21,14 +19,7 @@ interface ILogBox {
enhanced?: boolean; enhanced?: boolean;
} }
const LogBox: React.FC<ILogBox> = ({ const LogBox: FC<ILogBox> = ({ title, clearLog, logs, children, renderNav, enhanced }) => {
title,
clearLog,
logs,
children,
renderNav,
enhanced,
}) => {
const logRef = useRef<HTMLPreElement>(null); const logRef = useRef<HTMLPreElement>(null);
const { stayScrolled /*, scrollBottom*/ } = useStayScrolled(logRef); const { stayScrolled /*, scrollBottom*/ } = useStayScrolled(logRef);
@@ -55,6 +46,7 @@ const LogBox: React.FC<ILogBox> = ({
}} }}
> >
<Flex <Flex
fluid
css={{ css={{
height: "48px", height: "48px",
alignItems: "center", alignItems: "center",
@@ -78,7 +70,15 @@ const LogBox: React.FC<ILogBox> = ({
> >
<Notepad size="15px" /> <Text css={{ lineHeight: 1 }}>{title}</Text> <Notepad size="15px" /> <Text css={{ lineHeight: 1 }}>{title}</Text>
</Heading> </Heading>
{renderNav?.()} <Flex
row
align="center"
css={{
width: "50%", // TODO make it max without breaking layout!
}}
>
{renderNav?.()}
</Flex>
<Flex css={{ ml: "auto", gap: "$3", marginRight: "$3" }}> <Flex css={{ ml: "auto", gap: "$3", marginRight: "$3" }}>
{clearLog && ( {clearLog && (
<Button ghost size="xs" onClick={clearLog}> <Button ghost size="xs" onClick={clearLog}>
@@ -117,17 +117,11 @@ const LogBox: React.FC<ILogBox> = ({
backgroundColor: enhanced ? "$backgroundAlt" : undefined, backgroundColor: enhanced ? "$backgroundAlt" : undefined,
}, },
}, },
p: enhanced ? "$2 $1" : undefined, p: enhanced ? "$1" : undefined,
my: enhanced ? "$1" : undefined,
}} }}
> >
<LogText variant={log.type}> <Log {...log} />
{log.message}{" "}
{log.link && (
<NextLink href={log.link} shallow passHref>
<Link as="a">{log.linkText}</Link>
</NextLink>
)}
</LogText>
</Box> </Box>
))} ))}
{children} {children}
@@ -137,4 +131,74 @@ const LogBox: React.FC<ILogBox> = ({
); );
}; };
export const Log: FC<ILog> = ({
type,
timestamp: timestamp,
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]
);
_message = _message.trim().replace(/\n /gi, "\n");
const message = enrichAccounts(_message);
const jsonData = enrichAccounts(_jsonData);
return (
<>
<AccountDialog
setActiveAccountAddress={setDialogAccount}
activeAccountAddress={dialogAccount}
/>
<LogText variant={type}>
{timestamp && <Text muted monospace>{timestamp} </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>
</>
);
};
export default LogBox; export default LogBox;

View File

@@ -11,13 +11,13 @@ const Text = styled("span", {
color: "$text", color: "$text",
}, },
warning: { warning: {
color: "$amber11", color: "$warning",
}, },
error: { error: {
color: "$crimson11", color: "$error",
}, },
success: { success: {
color: "$grass11", color: "$success",
}, },
}, },
capitalize: { capitalize: {

View File

@@ -312,7 +312,7 @@ const Navigation = () => {
href={`/develop/${templateFileIds.peggy}`} href={`/develop/${templateFileIds.peggy}`}
> >
<Heading>Peggy</Heading> <Heading>Peggy</Heading>
<Text>An oracle based stabe coin hook</Text> <Text>An oracle based stable coin hook</Text>
</PanelBox> </PanelBox>
</Flex> </Flex>
</Flex> </Flex>

27
components/Pre.tsx Normal file
View File

@@ -0,0 +1,27 @@
import { styled } from "../stitches.config";
const Pre = styled("span", {
m: 0,
wordBreak: "break-all",
fontFamily: '$monospace',
whiteSpace: 'pre-wrap',
variants: {
fluid: {
true: {
width: "100%",
},
},
line: {
true: {
whiteSpace: 'pre-line'
}
},
block: {
true: {
display: 'block'
}
}
},
});
export default Pre;

View File

@@ -19,7 +19,7 @@ import { Plus, X } from "phosphor-react";
import { styled } from "../stitches.config"; import { styled } from "../stitches.config";
const ErrorText = styled(Text, { const ErrorText = styled(Text, {
color: "$crimson9", color: "$error",
mt: "$1", mt: "$1",
display: "block", display: "block",
}); });

View File

@@ -14,6 +14,11 @@ const Text = styled("span", {
true: { true: {
color: '$mauve9' color: '$mauve9'
} }
},
monospace: {
true: {
fontFamily: '$monospace'
}
} }
} }
}); });

View File

@@ -1,15 +1,17 @@
export { default as Flex } from './Flex' export { default as Flex } from "./Flex";
export { default as Container } from './Container' export { default as Link } from "./Link";
export { default as Heading } from './Heading' export { default as Container } from "./Container";
export { default as Stack } from './Stack' export { default as Heading } from "./Heading";
export { default as Text } from './Text' export { default as Stack } from "./Stack";
export { default as Input } from './Input' export { default as Text } from "./Text";
export { default as Select } from './Select' export { default as Input } from "./Input";
export * from './Tabs' export { default as Select } from "./Select";
export * from './AlertDialog' export * from "./Tabs";
export { default as Box } from './Box' export * from "./AlertDialog";
export { default as Button } from './Button' export { default as Box } from "./Box";
export { default as ButtonGroup } from './ButtonGroup' export { default as Button } from "./Button";
export { default as DeployFooter } from './DeployFooter' export { default as Pre } from "./Pre";
export * from './Dialog' export { default as ButtonGroup } from "./ButtonGroup";
export * from './DropdownMenu' export { default as DeployFooter } from "./DeployFooter";
export * from "./Dialog";
export * from "./DropdownMenu";

View File

@@ -23,6 +23,8 @@
"base64-js": "^1.5.1", "base64-js": "^1.5.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",
"javascript-time-ago": "^2.3.11",
"jszip": "^3.7.1", "jszip": "^3.7.1",
"monaco-editor": "^0.30.1", "monaco-editor": "^0.30.1",
"next": "^12.0.4", "next": "^12.0.4",
@@ -43,7 +45,9 @@
"react-select": "^5.2.1", "react-select": "^5.2.1",
"react-split": "^2.0.14", "react-split": "^2.0.14",
"react-stay-scrolled": "^7.4.0", "react-stay-scrolled": "^7.4.0",
"react-time-ago": "^7.1.9",
"reconnecting-websocket": "^4.4.0", "reconnecting-websocket": "^4.4.0",
"regexify-string": "^1.0.17",
"valtio": "^1.2.5", "valtio": "^1.2.5",
"vscode-languageserver": "^7.0.0", "vscode-languageserver": "^7.0.0",
"vscode-uri": "^3.0.2", "vscode-uri": "^3.0.2",
@@ -60,4 +64,4 @@
"eslint-config-next": "11.1.2", "eslint-config-next": "11.1.2",
"typescript": "4.4.4" "typescript": "4.4.4"
} }
} }

View File

@@ -13,6 +13,10 @@ import Navigation from "../components/Navigation";
import { fetchFiles } from "../state/actions"; import { fetchFiles } from "../state/actions";
import state from "../state"; import state from "../state";
import TimeAgo from "javascript-time-ago";
import en from "javascript-time-ago/locale/en.json";
TimeAgo.addDefaultLocale(en);
function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) { function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
const router = useRouter(); const router = useRouter();
const slug = router.query?.slug; const slug = router.query?.slug;

View File

@@ -66,6 +66,7 @@ export const compileCode = async (activeId: number) => {
// Decode base64 encoded wasm that is coming back from the endpoint // Decode base64 encoded wasm that is coming back from the endpoint
const bufferData = await decodeBinary(json.output); const bufferData = await decodeBinary(json.output);
state.files[state.active].compiledContent = ref(bufferData); state.files[state.active].compiledContent = ref(bufferData);
state.files[state.active].lastCompiled = new Date();
// Import wabt from and create human readable version of wasm file and // Import wabt from and create human readable version of wasm file and
// put it into state // put it into state
import("wabt").then((wabt) => { import("wabt").then((wabt) => {

View File

@@ -9,6 +9,7 @@ export interface IFile {
content: string; content: string;
compiledContent?: ArrayBuffer | null; compiledContent?: ArrayBuffer | null;
compiledWatContent?: string | null; compiledWatContent?: string | null;
lastCompiled?: Date
} }
export interface FaucetAccountRes { export interface FaucetAccountRes {
@@ -32,8 +33,11 @@ export interface IAccount {
export interface ILog { export interface ILog {
type: "error" | "warning" | "log" | "success"; type: "error" | "warning" | "log" | "success";
message: string; message: string;
jsonData?: any,
timestamp?: string;
link?: string; link?: string;
linkText?: string; linkText?: string;
defaultCollapsed?: boolean
} }
export interface IState { export interface IState {
@@ -50,7 +54,6 @@ export interface IState {
logs: ILog[]; logs: ILog[];
deployLogs: ILog[]; deployLogs: ILog[];
transactionLogs: ILog[]; transactionLogs: ILog[];
debugLogs: ILog[];
editorCtx?: typeof monaco.editor; editorCtx?: typeof monaco.editor;
editorSettings: { editorSettings: {
tabSize: number; tabSize: number;
@@ -73,7 +76,6 @@ let initialState: IState = {
logs: [], logs: [],
deployLogs: [], deployLogs: [],
transactionLogs: [], transactionLogs: [],
debugLogs: [],
editorCtx: undefined, editorCtx: undefined,
gistId: undefined, gistId: undefined,
gistOwner: undefined, gistOwner: undefined,

View File

@@ -19,6 +19,8 @@ import {
mauveDark, mauveDark,
amberDark, amberDark,
purpleDark, purpleDark,
red,
redDark,
} from "@radix-ui/colors"; } from "@radix-ui/colors";
export const { export const {
@@ -41,11 +43,16 @@ export const {
...mauve, ...mauve,
...amber, ...amber,
...purple, ...purple,
...red,
accent: "#9D2DFF", accent: "#9D2DFF",
background: "$gray1", background: "$gray1",
backgroundAlt: "$gray4", backgroundAlt: "$gray4",
text: "$gray12", text: "$gray12",
textMuted: "$gray10",
primary: "$plum", primary: "$plum",
error: '$red9',
warning: '$amber11',
success: "$grass11",
white: "white", white: "white",
black: "black", black: "black",
deep: "rgb(244, 244, 244)", deep: "rgb(244, 244, 244)",
@@ -348,6 +355,7 @@ export const darkTheme = createTheme("dark", {
...mauveDark, ...mauveDark,
...amberDark, ...amberDark,
...purpleDark, ...purpleDark,
...redDark,
deep: "rgb(10, 10, 10)", deep: "rgb(10, 10, 10)",
// backgroundA: transparentize(0.1, grayDark.gray1), // backgroundA: transparentize(0.1, grayDark.gray1),
}, },

View File

@@ -39,3 +39,14 @@ html.light .gutter-vertical:hover {
html.light .gutter-horizontal:hover { html.light .gutter-horizontal:hover {
background-color: rgba(0, 0, 0, 0.25); background-color: rgba(0, 0, 0, 0.25);
} }
/* Adjust Monaco tooltip stylings */
.markdown-hover h3 {
margin: 0;
}
.monaco-editor .monaco-hover hr {
margin: 8px 0;
}
.monaco-editor .monaco-hover {
z-index: 9999;
}

21
utils/json.ts Normal file
View File

@@ -0,0 +1,21 @@
export const extractJSON = (str?: string) => {
if (!str) return
let firstOpen = 0, firstClose = 0, candidate = '';
firstOpen = str.indexOf('{', firstOpen + 1);
do {
firstClose = str.lastIndexOf('}');
if (firstClose <= firstOpen) {
return;
}
do {
candidate = str.substring(firstOpen, firstClose + 1);
try {
let result = JSON.parse(candidate);
return { result, start: firstOpen < 0 ? 0 : firstOpen, end: firstClose }
}
catch (e) { }
firstClose = str.substring(0, firstClose).lastIndexOf('}');
} while (firstClose > firstOpen);
firstOpen = str.indexOf('{', firstOpen + 1);
} while (firstOpen != -1);
}

View File

@@ -2273,6 +2273,11 @@ file-uri-to-path@1.0.0:
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
filesize@^8.0.7:
version "8.0.7"
resolved "https://registry.yarnpkg.com/filesize/-/filesize-8.0.7.tgz#695e70d80f4e47012c132d57a059e80c6b580bd8"
integrity sha512-pjmC+bkIF8XI7fWaH8KxHcZL3DPybs1roSKP4rKDvy20tAWwIObE4+JIseG2byfGKhud5ZnM4YSGKBz7Sh0ndQ==
fill-range@^7.0.1: fill-range@^7.0.1:
version "7.0.1" version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
@@ -2833,6 +2838,13 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
javascript-time-ago@^2.3.11:
version "2.3.11"
resolved "https://registry.yarnpkg.com/javascript-time-ago/-/javascript-time-ago-2.3.11.tgz#b488ae765b7f42ff003f3830977a92411ef1fe92"
integrity sha512-R6Ux0IGv7RmAZ7vB04r/gevGaLDJeZY7+6jTYyYsPAF5x4PSv6up+dW2hLK99+OUY8xwdeXPItZFiUppIRUaoQ==
dependencies:
relative-time-format "^1.0.6"
jest-worker@27.0.0-next.5: jest-worker@27.0.0-next.5:
version "27.0.0-next.5" version "27.0.0-next.5"
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.0.0-next.5.tgz#5985ee29b12a4e191f4aae4bb73b97971d86ec28" resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.0.0-next.5.tgz#5985ee29b12a4e191f4aae4bb73b97971d86ec28"
@@ -3608,6 +3620,11 @@ pbkdf2@^3.0.3, pbkdf2@^3.0.9:
safe-buffer "^5.0.1" safe-buffer "^5.0.1"
sha.js "^2.4.8" sha.js "^2.4.8"
performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
phosphor-react@^1.3.1: phosphor-react@^1.3.1:
version "1.3.1" version "1.3.1"
resolved "https://registry.yarnpkg.com/phosphor-react/-/phosphor-react-1.3.1.tgz#96e33f44370d83cda15b60cccc17087ad0060684" resolved "https://registry.yarnpkg.com/phosphor-react/-/phosphor-react-1.3.1.tgz#96e33f44370d83cda15b60cccc17087ad0060684"
@@ -3754,6 +3771,13 @@ queue@6.0.2:
dependencies: dependencies:
inherits "~2.0.3" inherits "~2.0.3"
raf@^3.4.1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/raf/-/raf-3.4.1.tgz#0742e99a4a6552f445d73e3ee0328af0ff1ede39"
integrity sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==
dependencies:
performance-now "^2.1.0"
randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5: randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a"
@@ -3889,6 +3913,15 @@ react-style-singleton@^2.1.0:
invariant "^2.2.4" invariant "^2.2.4"
tslib "^1.0.0" tslib "^1.0.0"
react-time-ago@^7.1.9:
version "7.1.9"
resolved "https://registry.yarnpkg.com/react-time-ago/-/react-time-ago-7.1.9.tgz#df3999f1184b71ab09aaf1d05dda2a19b76e0bb8"
integrity sha512-jN4EsEgqm3a5eLJV0ZrRpom3iG+w4bullS2NHc2htIucGUIr2FbgHXjU0wIkuN9uWM87aFvIfkUDpS/ju7Mazg==
dependencies:
memoize-one "^6.0.0"
prop-types "^15.7.2"
raf "^3.4.1"
react-transition-group@^4.3.0: react-transition-group@^4.3.0:
version "4.4.2" version "4.4.2"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.4.2.tgz#8b59a56f09ced7b55cbd53c36768b922890d5470" resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.4.2.tgz#8b59a56f09ced7b55cbd53c36768b922890d5470"
@@ -3956,6 +3989,11 @@ regenerator-runtime@^0.13.4:
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA== integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==
regexify-string@^1.0.17:
version "1.0.17"
resolved "https://registry.yarnpkg.com/regexify-string/-/regexify-string-1.0.17.tgz#b9e571b51c8ec566eb82b7121744dae0d8e829de"
integrity sha512-mmD0AUNaY/piGW2AyACWdQOjIAwNuWz+KIvxfBZPDdCBAexiROeQxdxTaYAWcIxwtUAOwojdTta6CMMil84jXw==
regexp.prototype.flags@^1.3.1: regexp.prototype.flags@^1.3.1:
version "1.3.1" version "1.3.1"
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.1.tgz#7ef352ae8d159e758c0eadca6f8fcb4eef07be26" resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.1.tgz#7ef352ae8d159e758c0eadca6f8fcb4eef07be26"
@@ -3969,6 +4007,11 @@ regexpp@^3.1.0:
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg== integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==
relative-time-format@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/relative-time-format/-/relative-time-format-1.0.6.tgz#4956f6aa161f63cbab8a7f2d8b2e92d7b6a888a3"
integrity sha512-voemOJLxlKun4P1fAo4PEg2WXNGjhqfE/G8Xen4gcy24Hyu/djn5bT5axmhx4MnjynoZ8f0HCOjk3RZpsY6X/g==
require-from-string@^2.0.2: require-from-string@^2.0.2:
version "2.0.2" version "2.0.2"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"