Compare commits
5 Commits
fix/split-
...
feat/updat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f3ad14a92 | ||
|
|
eacdc89d1e | ||
|
|
24169cf282 | ||
|
|
9c7c703dde | ||
|
|
fa98ede123 |
@@ -116,16 +116,9 @@ export const AccountDialog = ({
|
||||
<Text
|
||||
css={{
|
||||
fontFamily: "$monospace",
|
||||
a: { "&:hover": { textDecoration: "underline" } },
|
||||
}}
|
||||
>
|
||||
<a
|
||||
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${activeAccount?.address}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{activeAccount?.address}
|
||||
</a>
|
||||
{activeAccount?.address}
|
||||
</Text>
|
||||
</Flex>
|
||||
<Flex css={{ marginLeft: "auto", color: "$mauve12" }}>
|
||||
@@ -222,11 +215,7 @@ export const AccountDialog = ({
|
||||
</Button>
|
||||
</Text>
|
||||
</Flex>
|
||||
<Flex
|
||||
css={{
|
||||
marginLeft: "auto",
|
||||
}}
|
||||
>
|
||||
<Flex css={{ marginLeft: "auto" }}>
|
||||
<a
|
||||
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${activeAccount?.address}`}
|
||||
target="_blank"
|
||||
@@ -248,22 +237,10 @@ export const AccountDialog = ({
|
||||
<Text
|
||||
css={{
|
||||
fontFamily: "$monospace",
|
||||
a: { "&:hover": { textDecoration: "underline" } },
|
||||
}}
|
||||
>
|
||||
{activeAccount && activeAccount.hooks.length > 0
|
||||
? 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>
|
||||
);
|
||||
})
|
||||
? activeAccount.hooks.map((i) => truncate(i, 12)).join(",")
|
||||
: "–"}
|
||||
</Text>
|
||||
</Flex>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { useEffect } from "react";
|
||||
import ReconnectingWebSocket, { CloseEvent } from "reconnecting-websocket";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { proxy, ref, useSnapshot } from "valtio";
|
||||
import { subscribeKey } from "valtio/utils";
|
||||
import { Select } from ".";
|
||||
import state, { ILog, transactionsState } from "../state";
|
||||
import { extractJSON } from "../utils/json";
|
||||
@@ -17,7 +15,7 @@ export interface IStreamState {
|
||||
status: "idle" | "opened" | "closed";
|
||||
statusChangeTimestamp?: number;
|
||||
logs: ILog[];
|
||||
socket?: ReconnectingWebSocket;
|
||||
socket?: WebSocket;
|
||||
}
|
||||
|
||||
export const streamState = proxy<IStreamState>({
|
||||
@@ -26,85 +24,12 @@ export const streamState = proxy<IStreamState>({
|
||||
logs: [] as ILog[],
|
||||
});
|
||||
|
||||
const onOpen = (account: ISelect | null) => {
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
// streamState.logs = [];
|
||||
streamState.status = "opened";
|
||||
streamState.statusChangeTimestamp = Date.now();
|
||||
|
||||
pushLog(`Debug stream opened for account ${account?.value}`, {
|
||||
type: "success",
|
||||
});
|
||||
};
|
||||
const onError = () => {
|
||||
pushLog("Something went wrong! Check your connection and try again.", {
|
||||
type: "error",
|
||||
});
|
||||
};
|
||||
const onClose = (e: CloseEvent) => {
|
||||
// 999 = closed websocket connection by switching account
|
||||
if (e.code !== 4999) {
|
||||
pushLog(`Connection was closed. [code: ${e.code}]`, {
|
||||
type: "error",
|
||||
});
|
||||
}
|
||||
streamState.status = "closed";
|
||||
streamState.statusChangeTimestamp = Date.now();
|
||||
};
|
||||
const onMessage = (event: any) => {
|
||||
// Ping returns just account address, if we get that
|
||||
// response we don't need to log anything
|
||||
if (event.data !== streamState.selectedAccount?.value) {
|
||||
pushLog(event.data);
|
||||
}
|
||||
};
|
||||
|
||||
let interval: NodeJS.Timer | null = null;
|
||||
|
||||
const addListeners = (account: ISelect | null) => {
|
||||
if (account?.value && streamState.socket?.url.endsWith(account?.value)) {
|
||||
return;
|
||||
}
|
||||
streamState.logs = [];
|
||||
if (account?.value) {
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
if (streamState.socket) {
|
||||
streamState.socket?.removeEventListener("open", () => onOpen(account));
|
||||
streamState.socket?.removeEventListener("close", onClose);
|
||||
streamState.socket?.removeEventListener("error", onError);
|
||||
streamState.socket?.removeEventListener("message", onMessage);
|
||||
}
|
||||
|
||||
streamState.socket = ref(
|
||||
new ReconnectingWebSocket(
|
||||
`wss://${process.env.NEXT_PUBLIC_DEBUG_STREAM_URL}/${account?.value}`
|
||||
)
|
||||
);
|
||||
if (streamState.socket) {
|
||||
interval = setInterval(() => {
|
||||
streamState.socket?.send("");
|
||||
}, 45000);
|
||||
}
|
||||
|
||||
streamState.socket.addEventListener("open", () => onOpen(account));
|
||||
streamState.socket.addEventListener("close", onClose);
|
||||
streamState.socket.addEventListener("error", onError);
|
||||
streamState.socket.addEventListener("message", onMessage);
|
||||
}
|
||||
};
|
||||
|
||||
subscribeKey(streamState, "selectedAccount", addListeners);
|
||||
|
||||
const DebugStream = () => {
|
||||
const { selectedAccount, logs } = useSnapshot(streamState);
|
||||
const { selectedAccount, logs, socket } = useSnapshot(streamState);
|
||||
const { activeHeader: activeTxTab } = useSnapshot(transactionsState);
|
||||
const { accounts } = useSnapshot(state);
|
||||
|
||||
const accountOptions = accounts.map((acc) => ({
|
||||
const accountOptions = accounts.map(acc => ({
|
||||
label: acc.name,
|
||||
value: acc.address,
|
||||
}));
|
||||
@@ -117,21 +42,117 @@ const DebugStream = () => {
|
||||
options={accountOptions}
|
||||
hideSelectedOptions
|
||||
value={selectedAccount}
|
||||
onChange={(acc) => {
|
||||
streamState.socket?.close(
|
||||
4999,
|
||||
"Old connection closed because user switched account"
|
||||
);
|
||||
streamState.selectedAccount = acc as any;
|
||||
}}
|
||||
onChange={acc => (streamState.selectedAccount = acc as any)}
|
||||
css={{ width: "100%" }}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const account = selectedAccount?.value;
|
||||
if (account && (!socket || !socket.url.endsWith(account))) {
|
||||
socket?.close();
|
||||
streamState.socket = ref(
|
||||
new WebSocket(
|
||||
`wss://${process.env.NEXT_PUBLIC_DEBUG_STREAM_URL}/${account}`
|
||||
)
|
||||
);
|
||||
} else if (!account && socket) {
|
||||
socket.close();
|
||||
streamState.socket = undefined;
|
||||
}
|
||||
}, [selectedAccount?.value, socket]);
|
||||
|
||||
const onMount = useCallback(async () => {
|
||||
// deliberately using `proxy` values and not the `useSnapshot` ones to have no dep list
|
||||
const acc = streamState.selectedAccount;
|
||||
const status = streamState.status;
|
||||
|
||||
if (status === "opened" && acc) {
|
||||
// fetch the missing ones
|
||||
try {
|
||||
const url = `https://${process.env.NEXT_PUBLIC_DEBUG_STREAM_URL}/recent/${acc?.value}`;
|
||||
|
||||
// TODO Remove after api sets cors properly
|
||||
const res = await fetch("/api/proxy", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ url }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) return;
|
||||
|
||||
const body = await res.json();
|
||||
|
||||
if (!body?.logs) return;
|
||||
|
||||
const start = streamState.statusChangeTimestamp || 0;
|
||||
streamState.logs = [];
|
||||
pushLog(`Debug stream opened for account ${acc.value}`, {
|
||||
type: "success",
|
||||
});
|
||||
|
||||
const logs = Object.entries(body.logs).filter(([tm]) => +tm >= start);
|
||||
|
||||
logs.forEach(([tm, log]) => pushLog(log));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
onMount();
|
||||
}, [onMount]);
|
||||
|
||||
useEffect(() => {
|
||||
const account = selectedAccount?.value;
|
||||
const socket = streamState.socket;
|
||||
if (!socket) return;
|
||||
|
||||
const onOpen = () => {
|
||||
streamState.logs = [];
|
||||
streamState.status = "opened";
|
||||
streamState.statusChangeTimestamp = Date.now();
|
||||
pushLog(`Debug stream opened for account ${account}`, {
|
||||
type: "success",
|
||||
});
|
||||
};
|
||||
const onError = () => {
|
||||
pushLog("Something went wrong! Check your connection and try again.", {
|
||||
type: "error",
|
||||
});
|
||||
};
|
||||
const onClose = (e: CloseEvent) => {
|
||||
pushLog(`Connection was closed. [code: ${e.code}]`, {
|
||||
type: "error",
|
||||
});
|
||||
streamState.selectedAccount = null;
|
||||
streamState.status = "closed";
|
||||
streamState.statusChangeTimestamp = Date.now();
|
||||
};
|
||||
const onMessage = (event: any) => {
|
||||
pushLog(event.data);
|
||||
};
|
||||
|
||||
socket.addEventListener("open", onOpen);
|
||||
socket.addEventListener("close", onClose);
|
||||
socket.addEventListener("error", onError);
|
||||
socket.addEventListener("message", onMessage);
|
||||
|
||||
return () => {
|
||||
socket.removeEventListener("open", onOpen);
|
||||
socket.removeEventListener("close", onClose);
|
||||
socket.removeEventListener("message", onMessage);
|
||||
socket.removeEventListener("error", onError);
|
||||
};
|
||||
}, [selectedAccount?.value, socket]);
|
||||
|
||||
useEffect(() => {
|
||||
const account = transactionsState.transactions.find(
|
||||
(tx) => tx.header === activeTxTab
|
||||
tx => tx.header === activeTxTab
|
||||
)?.state.selectedAccount;
|
||||
|
||||
if (account && account.value !== streamState.selectedAccount?.value)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useCallback, useRef } from "react";
|
||||
import React, { useState, useEffect, useCallback } from "react";
|
||||
import {
|
||||
Plus,
|
||||
Share,
|
||||
@@ -101,7 +101,7 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
||||
if (!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." };
|
||||
}
|
||||
|
||||
@@ -132,55 +132,22 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
||||
createNewFile(filename);
|
||||
setFilename("");
|
||||
}, [filename, setIsNewfileDialogOpen, setFilename, validateFilename]);
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const files = snap.files;
|
||||
return (
|
||||
<Flex css={{ flexShrink: 0, gap: "$0" }}>
|
||||
<Flex
|
||||
id="kissa"
|
||||
ref={scrollRef}
|
||||
css={{
|
||||
overflowX: "scroll",
|
||||
overflowY: "hidden",
|
||||
py: "$3",
|
||||
pb: "$0",
|
||||
flex: 1,
|
||||
"&::-webkit-scrollbar": {
|
||||
height: "0.3em",
|
||||
background: "rgba(0,0,0,.0)",
|
||||
height: 0,
|
||||
background: "transparent",
|
||||
},
|
||||
"&::-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 }} ref={containerRef}>
|
||||
<Container css={{ flex: 1 }}>
|
||||
<Stack
|
||||
css={{
|
||||
gap: "$3",
|
||||
@@ -266,8 +233,8 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
||||
<Label>Filename</Label>
|
||||
<Input
|
||||
value={filename}
|
||||
onChange={(e) => setFilename(e.target.value)}
|
||||
onKeyPress={(e) => {
|
||||
onChange={e => setFilename(e.target.value)}
|
||||
onKeyPress={e => {
|
||||
if (e.key === "Enter") {
|
||||
handleConfirm();
|
||||
}
|
||||
@@ -542,8 +509,8 @@ const EditorNavigation = ({ showWat }: { showWat?: boolean }) => {
|
||||
type="number"
|
||||
min="1"
|
||||
value={editorSettings.tabSize}
|
||||
onChange={(e) =>
|
||||
setEditorSettings((curr) => ({
|
||||
onChange={e =>
|
||||
setEditorSettings(curr => ({
|
||||
...curr,
|
||||
tabSize: Number(e.target.value),
|
||||
}))
|
||||
|
||||
@@ -164,15 +164,21 @@ const HooksEditor = () => {
|
||||
onConnection: (connection) => {
|
||||
// create and start the language client
|
||||
const languageClient = createLanguageClient(connection);
|
||||
const disposable = languageClient.start();
|
||||
|
||||
connection.onClose(() => {
|
||||
try {
|
||||
disposable.dispose();
|
||||
} catch (err) {
|
||||
console.log("err", err);
|
||||
}
|
||||
});
|
||||
languageClient.start();
|
||||
// connection.onDispose((d) => {
|
||||
// console.log("disposed: ", d);
|
||||
// });
|
||||
// connection.onError((ee) => {
|
||||
// console.log(ee =)
|
||||
// })
|
||||
// connection.onClose(() => {
|
||||
// try {
|
||||
// // disposable.stop();
|
||||
// disposable.dispose();
|
||||
// } catch (err) {
|
||||
// console.log("err", err);
|
||||
// }
|
||||
// });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -340,8 +340,6 @@ const Navigation = () => {
|
||||
height: 0,
|
||||
background: "transparent",
|
||||
},
|
||||
scrollbarColor: "transparent",
|
||||
scrollbarWidth: "none",
|
||||
}}
|
||||
>
|
||||
<Stack
|
||||
|
||||
@@ -22,12 +22,12 @@ import {
|
||||
import { TTS, tts } from "../utils/hookOnCalculator";
|
||||
import { deployHook } from "../state/actions";
|
||||
import { useSnapshot } from "valtio";
|
||||
import state, { SelectOption } from "../state";
|
||||
import state from "../state";
|
||||
import toast from "react-hot-toast";
|
||||
import { prepareDeployHookTx, sha256 } from "../state/actions/deployHook";
|
||||
import estimateFee from "../utils/estimateFee";
|
||||
|
||||
const transactionOptions = Object.keys(tts).map(key => ({
|
||||
const transactionOptions = Object.keys(tts).map((key) => ({
|
||||
label: key,
|
||||
value: key as keyof TTS,
|
||||
}));
|
||||
@@ -56,22 +56,9 @@ export type SetHookData = {
|
||||
export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
({ accountAddress }) => {
|
||||
const snap = useSnapshot(state);
|
||||
const activeFile = snap.files[snap.active]?.compiledContent
|
||||
? snap.files[snap.active]
|
||||
: snap.files.filter(file => file.compiledContent)[0];
|
||||
const account = snap.accounts.find((acc) => acc.address === accountAddress);
|
||||
|
||||
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 {
|
||||
register,
|
||||
handleSubmit,
|
||||
@@ -81,13 +68,11 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useForm<SetHookData>({
|
||||
defaultValues: snap.deployValues?.[activeFile?.name]
|
||||
? snap.deployValues[activeFile?.name]
|
||||
: {
|
||||
HookNamespace:
|
||||
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "",
|
||||
Invoke: transactionOptions.filter(to => to.label === "ttPAYMENT"),
|
||||
},
|
||||
defaultValues: {
|
||||
HookNamespace:
|
||||
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "",
|
||||
Invoke: transactionOptions.filter((to) => to.label === "ttPAYMENT"),
|
||||
},
|
||||
});
|
||||
const { fields, append, remove } = useFieldArray({
|
||||
control,
|
||||
@@ -96,21 +81,14 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
const [formInitialized, setFormInitialized] = useState(false);
|
||||
const [estimateLoading, setEstimateLoading] = useState(false);
|
||||
const watchedFee = watch("Fee");
|
||||
|
||||
// Update value if activeWat changes
|
||||
useEffect(() => {
|
||||
const defaultValue = snap.deployValues?.[activeFile?.name]
|
||||
? snap.deployValues?.[activeFile?.name].HookNamespace
|
||||
: snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "";
|
||||
setValue("HookNamespace", defaultValue);
|
||||
setValue(
|
||||
"HookNamespace",
|
||||
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
|
||||
);
|
||||
setFormInitialized(true);
|
||||
}, [
|
||||
snap.activeWat,
|
||||
snap.files,
|
||||
setValue,
|
||||
activeFile?.name,
|
||||
snap.deployValues,
|
||||
]);
|
||||
}, [snap.activeWat, snap.files, setValue]);
|
||||
useEffect(() => {
|
||||
if (
|
||||
watchedFee &&
|
||||
@@ -130,9 +108,7 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
const [hashedNamespace, setHashedNamespace] = useState("");
|
||||
const namespace = watch(
|
||||
"HookNamespace",
|
||||
snap.deployValues?.[activeFile?.name]
|
||||
? snap.deployValues?.[activeFile?.name].HookNamespace
|
||||
: snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
|
||||
snap.files?.[snap.active]?.name?.split(".")?.[0] || ""
|
||||
);
|
||||
const calculateHashedValue = useCallback(async () => {
|
||||
const hashedVal = await sha256(namespace);
|
||||
@@ -160,10 +136,14 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [formInitialized]);
|
||||
|
||||
if (!account) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const tooLargeFile = () => {
|
||||
const activeFile = snap.files[snap.active].compiledContent
|
||||
? snap.files[snap.active]
|
||||
: snap.files.filter(file => file.compiledContent)[0];
|
||||
: snap.files.filter((file) => file.compiledContent)[0];
|
||||
return Boolean(
|
||||
activeFile?.compiledContent?.byteLength &&
|
||||
activeFile?.compiledContent?.byteLength >= 64000
|
||||
@@ -172,9 +152,8 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
|
||||
const onSubmit: SubmitHandler<SetHookData> = async (data) => {
|
||||
const currAccount = state.accounts.find(
|
||||
(acc) => acc.address === account?.address
|
||||
(acc) => acc.address === account.address
|
||||
);
|
||||
if (!account) return;
|
||||
if (currAccount) currAccount.isLoading = true;
|
||||
const res = await deployHook(account, data);
|
||||
if (currAccount) currAccount.isLoading = false;
|
||||
@@ -194,9 +173,8 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
uppercase
|
||||
variant={"secondary"}
|
||||
disabled={
|
||||
!account ||
|
||||
account.isLoading ||
|
||||
!snap.files.filter(file => file.compiledWatContent).length ||
|
||||
!snap.files.filter((file) => file.compiledWatContent).length ||
|
||||
tooLargeFile()
|
||||
}
|
||||
>
|
||||
@@ -208,22 +186,14 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
<DialogTitle>Deploy configuration</DialogTitle>
|
||||
<DialogDescription as="div">
|
||||
<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%" }}>
|
||||
<Label>Invoke on transactions</Label>
|
||||
<Controller
|
||||
name="Invoke"
|
||||
control={control}
|
||||
defaultValue={transactionOptions.filter(
|
||||
(to) => to.label === "ttPAYMENT"
|
||||
)}
|
||||
render={({ field }) => (
|
||||
<Select
|
||||
{...field}
|
||||
@@ -240,6 +210,9 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
<Input
|
||||
{...register("HookNamespace", { required: true })}
|
||||
autoComplete={"off"}
|
||||
defaultValue={
|
||||
snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
|
||||
}
|
||||
/>
|
||||
{errors.HookNamespace?.type === "required" && (
|
||||
<Box css={{ display: "inline", color: "$red11" }}>
|
||||
@@ -302,7 +275,7 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
type="number"
|
||||
{...register("Fee", { required: true })}
|
||||
autoComplete={"off"}
|
||||
onKeyPress={e => {
|
||||
onKeyPress={(e) => {
|
||||
if (e.key === "." || e.key === ",") {
|
||||
e.preventDefault();
|
||||
}
|
||||
@@ -334,9 +307,8 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
alignContent: "center",
|
||||
display: "flex",
|
||||
}}
|
||||
onClick={async e => {
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
if (!account) return;
|
||||
setEstimateLoading(true);
|
||||
const formValues = getValues();
|
||||
try {
|
||||
@@ -435,7 +407,7 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||
<Button
|
||||
variant="primary"
|
||||
type="submit"
|
||||
isLoading={account?.isLoading}
|
||||
isLoading={account.isLoading}
|
||||
>
|
||||
Set Hook
|
||||
</Button>
|
||||
|
||||
@@ -31,15 +31,13 @@ interface TabProps {
|
||||
|
||||
// TODO customise messages shown
|
||||
interface Props {
|
||||
label?: string;
|
||||
activeIndex?: number;
|
||||
activeHeader?: string;
|
||||
headless?: boolean;
|
||||
children: ReactElement<TabProps>[];
|
||||
keepAllAlive?: boolean;
|
||||
defaultExtension?: string;
|
||||
appendDefaultExtension?: boolean;
|
||||
allowedExtensions?: string[];
|
||||
forceDefaultExtension?: boolean;
|
||||
onCreateNewTab?: (name: string) => any;
|
||||
onCloseTab?: (index: number, header?: string) => any;
|
||||
onChangeActive?: (index: number, header?: string) => any;
|
||||
@@ -48,7 +46,6 @@ interface Props {
|
||||
export const Tab = (props: TabProps) => null;
|
||||
|
||||
export const Tabs = ({
|
||||
label = "Tab",
|
||||
children,
|
||||
activeIndex,
|
||||
activeHeader,
|
||||
@@ -58,8 +55,7 @@ export const Tabs = ({
|
||||
onCloseTab,
|
||||
onChangeActive,
|
||||
defaultExtension = "",
|
||||
appendDefaultExtension = false,
|
||||
allowedExtensions,
|
||||
forceDefaultExtension,
|
||||
}: Props) => {
|
||||
const [active, setActive] = useState(activeIndex || 0);
|
||||
const tabs: TabProps[] = children.map(elem => elem.props);
|
||||
@@ -90,13 +86,9 @@ export const Tabs = ({
|
||||
if (tabs.find(tab => tab.header === tabname)) {
|
||||
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 };
|
||||
},
|
||||
[allowedExtensions, tabs]
|
||||
[tabs]
|
||||
);
|
||||
|
||||
const handleActiveChange = useCallback(
|
||||
@@ -109,11 +101,9 @@ export const Tabs = ({
|
||||
|
||||
const handleCreateTab = useCallback(() => {
|
||||
// add default extension in case omitted
|
||||
let _tabname = tabname.includes(".")
|
||||
? tabname
|
||||
: `${tabname}.${defaultExtension}`;
|
||||
if (appendDefaultExtension && !_tabname.endsWith(defaultExtension)) {
|
||||
_tabname = `${_tabname}.${defaultExtension}`;
|
||||
let _tabname = tabname.includes(".") ? tabname : tabname + defaultExtension;
|
||||
if (forceDefaultExtension && !_tabname.endsWith(defaultExtension)) {
|
||||
_tabname = _tabname + defaultExtension;
|
||||
}
|
||||
|
||||
const chk = validateTabname(_tabname);
|
||||
@@ -132,7 +122,7 @@ export const Tabs = ({
|
||||
}, [
|
||||
tabname,
|
||||
defaultExtension,
|
||||
appendDefaultExtension,
|
||||
forceDefaultExtension,
|
||||
validateTabname,
|
||||
onCreateNewTab,
|
||||
handleActiveChange,
|
||||
@@ -216,13 +206,13 @@ export const Tabs = ({
|
||||
size="sm"
|
||||
css={{ alignItems: "center", px: "$2", mr: "$3" }}
|
||||
>
|
||||
<Plus size="16px" /> {tabs.length === 0 && `Add new ${label.toLocaleLowerCase()}`}
|
||||
<Plus size="16px" /> {tabs.length === 0 && "Add new tab"}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogTitle>Create new {label.toLocaleLowerCase()}</DialogTitle>
|
||||
<DialogTitle>Create new tab</DialogTitle>
|
||||
<DialogDescription>
|
||||
<Label>{label} name</Label>
|
||||
<Label>Tabname</Label>
|
||||
<Input
|
||||
value={tabname}
|
||||
onChange={e => setTabname(e.target.value)}
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
"monaco-editor": "^0.33.0",
|
||||
"next": "^12.0.4",
|
||||
"next-auth": "^4.0.0-beta.5",
|
||||
"next-plausible": "^3.2.0",
|
||||
"next-themes": "^0.1.1",
|
||||
"normalize-url": "^7.0.2",
|
||||
"octokit": "^1.7.0",
|
||||
|
||||
@@ -7,7 +7,6 @@ import { ThemeProvider } from "next-themes";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
import { useRouter } from "next/router";
|
||||
import { IdProvider } from "@radix-ui/react-id";
|
||||
import PlausibleProvider from "next-plausible";
|
||||
|
||||
import { darkTheme, css } from "../stitches.config";
|
||||
import Navigation from "../components/Navigation";
|
||||
@@ -18,8 +17,6 @@ import TimeAgo from "javascript-time-ago";
|
||||
import en from "javascript-time-ago/locale/en.json";
|
||||
import { useSnapshot } from "valtio";
|
||||
import Alert from "../components/AlertDialog";
|
||||
import { Button, Flex } from "../components";
|
||||
import { ChatCircleText } from "phosphor-react";
|
||||
|
||||
TimeAgo.setDefaultLocale(en.locale);
|
||||
TimeAgo.addLocale(en);
|
||||
@@ -40,7 +37,7 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
|
||||
if (
|
||||
!gistId &&
|
||||
router.isReady &&
|
||||
router.pathname.includes("/develop") &&
|
||||
!router.pathname.includes("/sign-in") &&
|
||||
!snap.files.length &&
|
||||
!snap.mainModalShowed
|
||||
) {
|
||||
@@ -117,7 +114,6 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
|
||||
media="(prefers-color-scheme: light)"
|
||||
/>
|
||||
</Head>
|
||||
|
||||
<IdProvider>
|
||||
<SessionProvider session={session}>
|
||||
<ThemeProvider
|
||||
@@ -129,40 +125,23 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
|
||||
dark: darkTheme.className,
|
||||
}}
|
||||
>
|
||||
<PlausibleProvider
|
||||
domain="hooks-builder.xrpl.org"
|
||||
trackOutboundLinks
|
||||
>
|
||||
<Navigation />
|
||||
<Component {...pageProps} />
|
||||
<Toaster
|
||||
toastOptions={{
|
||||
className: css({
|
||||
backgroundColor: "$mauve1",
|
||||
color: "$mauve10",
|
||||
fontSize: "$sm",
|
||||
zIndex: 9999,
|
||||
".dark &": {
|
||||
backgroundColor: "$mauve4",
|
||||
color: "$mauve12",
|
||||
},
|
||||
})(),
|
||||
}}
|
||||
/>
|
||||
<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>
|
||||
<Navigation />
|
||||
<Component {...pageProps} />
|
||||
<Toaster
|
||||
toastOptions={{
|
||||
className: css({
|
||||
backgroundColor: "$mauve1",
|
||||
color: "$mauve10",
|
||||
fontSize: "$sm",
|
||||
zIndex: 9999,
|
||||
".dark &": {
|
||||
backgroundColor: "$mauve4",
|
||||
color: "$mauve12",
|
||||
},
|
||||
})(),
|
||||
}}
|
||||
/>
|
||||
<Alert />
|
||||
</ThemeProvider>
|
||||
</SessionProvider>
|
||||
</IdProvider>
|
||||
|
||||
@@ -45,7 +45,7 @@ const Test = () => {
|
||||
? [50, 20, 30]
|
||||
: hasScripts
|
||||
? [50, 20, 50]
|
||||
: [50, 50, 0]
|
||||
: [50, 50]
|
||||
}
|
||||
gutterSize={4}
|
||||
gutterAlign="center"
|
||||
@@ -76,15 +76,14 @@ const Test = () => {
|
||||
>
|
||||
<Box css={{ width: "55%", px: "$2" }}>
|
||||
<Tabs
|
||||
label='Transaction'
|
||||
activeHeader={activeHeader}
|
||||
// TODO make header a required field
|
||||
onChangeActive={(idx, header) => {
|
||||
if (header) transactionsState.activeHeader = header;
|
||||
}}
|
||||
keepAllAlive
|
||||
defaultExtension="json"
|
||||
allowedExtensions={['json']}
|
||||
forceDefaultExtension
|
||||
defaultExtension=".json"
|
||||
onCreateNewTab={(header) => modifyTransaction(header, {})}
|
||||
onCloseTab={(idx, header) =>
|
||||
header && modifyTransaction(header, undefined)
|
||||
|
||||
@@ -126,10 +126,6 @@ export const deployHook = async (
|
||||
data: SetHookData
|
||||
) => {
|
||||
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);
|
||||
if (!tx) {
|
||||
return;
|
||||
|
||||
@@ -52,8 +52,6 @@ export interface ILog {
|
||||
defaultCollapsed?: boolean
|
||||
}
|
||||
|
||||
export type DeployValue = Record<IFile['name'], any>;
|
||||
|
||||
export interface IState {
|
||||
files: IFile[];
|
||||
gistId?: string | null;
|
||||
@@ -84,8 +82,7 @@ export interface IState {
|
||||
compileOptions: {
|
||||
optimizationLevel: '-O0' | '-O1' | '-O2' | '-O3' | '-O4' | '-Os';
|
||||
strip: boolean
|
||||
},
|
||||
deployValues: DeployValue
|
||||
}
|
||||
}
|
||||
|
||||
// let localStorageState: null | string = null;
|
||||
@@ -119,8 +116,7 @@ let initialState: IState = {
|
||||
compileOptions: {
|
||||
optimizationLevel: '-O2',
|
||||
strip: true
|
||||
},
|
||||
deployValues: {}
|
||||
}
|
||||
};
|
||||
|
||||
let localStorageAccounts: string | null = null;
|
||||
|
||||
@@ -2981,11 +2981,6 @@ next-auth@^4.0.0-beta.5:
|
||||
preact-render-to-string "^5.1.19"
|
||||
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:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.1.1.tgz#122113a458bf1d1be5ffed66778ab924c106f82a"
|
||||
@@ -3480,7 +3475,7 @@ react-select@^5.2.1:
|
||||
|
||||
react-split@^2.0.14:
|
||||
version "2.0.14"
|
||||
resolved "https://registry.yarnpkg.com/react-split/-/react-split-2.0.14.tgz#ef198259bf43264d605f792fb3384f15f5b34432"
|
||||
resolved "https://registry.npmjs.org/react-split/-/react-split-2.0.14.tgz"
|
||||
integrity sha512-bKWydgMgaKTg/2JGQnaJPg51T6dmumTWZppFgEbbY0Fbme0F5TuatAScCLaqommbGQQf/ZT1zaejuPDriscISA==
|
||||
dependencies:
|
||||
prop-types "^15.5.7"
|
||||
|
||||
Reference in New Issue
Block a user