Compare commits
	
		
			40 Commits
		
	
	
		
			fix/change
			...
			feat/remov
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					c7e4cd7c92 | ||
| 
						 | 
					b09d029931 | ||
| 
						 | 
					b2dc49754f | ||
| 
						 | 
					6f636645f7 | ||
| 
						 | 
					377c963c7a | ||
| 
						 | 
					ae038f17ff | ||
| 
						 | 
					0d8f2c31e7 | ||
| 
						 | 
					da9986eb66 | ||
| 
						 | 
					a21350770e | ||
| 
						 | 
					49dfd43220 | ||
| 
						 | 
					4472957f5c | ||
| 
						 | 
					ca46707bb5 | ||
| 
						 | 
					704ebe4b92 | ||
| 
						 | 
					9a6ef2c393 | ||
| 
						 | 
					56203ce9c6 | ||
| 
						 | 
					933bdb5968 | ||
| 
						 | 
					864711697b | ||
| 
						 | 
					e5eaf09721 | ||
| 
						 | 
					d0dde56c67 | ||
| 
						 | 
					45c6927e72 | ||
| 
						 | 
					6014b6e79f | ||
| 
						 | 
					04a99227df | ||
| 
						 | 
					0965a1e898 | ||
| 
						 | 
					32445dbebf | ||
| 
						 | 
					1a1d4901aa | ||
| 
						 | 
					8b646c56dc | ||
| 
						 | 
					ac38bbc72c | ||
| 
						 | 
					bf1182351a | ||
| 
						 | 
					55e48a943b | ||
| 
						 | 
					faf417be69 | ||
| 
						 | 
					c2eb57211f | ||
| 
						 | 
					0e97df3c8e | ||
| 
						 | 
					5dd0dfdc18 | ||
| 
						 | 
					ef48bac8f6 | ||
| 
						 | 
					3a3d984098 | ||
| 
						 | 
					2300c201f8 | ||
| 
						 | 
					329dc4a355 | ||
| 
						 | 
					cd6a5b23d4 | ||
| 
						 | 
					4dd7cbe2ca | ||
| 
						 | 
					260de7c838 | 
@@ -1,6 +1,8 @@
 | 
			
		||||
# XRPL Hooks IDE
 | 
			
		||||
# XRPL Hooks Builder
 | 
			
		||||
 | 
			
		||||
This is the repository for XRPL Hooks IDE. This project is built with Next.JS
 | 
			
		||||
https://hooks-builder.xrpl.org/
 | 
			
		||||
 | 
			
		||||
This is the repository for XRPL Hooks Builder. This project is built with Next.JS
 | 
			
		||||
 | 
			
		||||
## General
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -304,6 +304,18 @@ const Accounts: FC<AccountProps> = (props) => {
 | 
			
		||||
          if (accountToUpdate) {
 | 
			
		||||
            accountToUpdate.xrp = balance;
 | 
			
		||||
            accountToUpdate.sequence = sequence;
 | 
			
		||||
            accountToUpdate.error = null;
 | 
			
		||||
          } else {
 | 
			
		||||
            const oldAccount = state.accounts.find(
 | 
			
		||||
              (acc) => acc.address === res?.account
 | 
			
		||||
            );
 | 
			
		||||
            if (oldAccount) {
 | 
			
		||||
              oldAccount.xrp = "0";
 | 
			
		||||
              oldAccount.error = {
 | 
			
		||||
                code: res?.error,
 | 
			
		||||
                message: res?.error_message,
 | 
			
		||||
              };
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
        const objectRequests = snap.accounts.map((acc) => {
 | 
			
		||||
@@ -343,7 +355,7 @@ const Accounts: FC<AccountProps> = (props) => {
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
    // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
			
		||||
  }, [snap.accounts, snap.clientStatus]);
 | 
			
		||||
  }, [snap.accounts.length, snap.clientStatus]);
 | 
			
		||||
  return (
 | 
			
		||||
    <Box
 | 
			
		||||
      as="div"
 | 
			
		||||
@@ -431,18 +443,23 @@ const Accounts: FC<AccountProps> = (props) => {
 | 
			
		||||
                      wordBreak: "break-word",
 | 
			
		||||
                    }}
 | 
			
		||||
                  >
 | 
			
		||||
                    {account.address} (
 | 
			
		||||
                    {Dinero({
 | 
			
		||||
                      amount: Number(account?.xrp || "0"),
 | 
			
		||||
                      precision: 6,
 | 
			
		||||
                    })
 | 
			
		||||
                      .toUnit()
 | 
			
		||||
                      .toLocaleString(undefined, {
 | 
			
		||||
                        style: "currency",
 | 
			
		||||
                        currency: "XRP",
 | 
			
		||||
                        currencyDisplay: "name",
 | 
			
		||||
                      })}
 | 
			
		||||
                    )
 | 
			
		||||
                    {account.address}{" "}
 | 
			
		||||
                    {!account?.error ? (
 | 
			
		||||
                      `(${Dinero({
 | 
			
		||||
                        amount: Number(account?.xrp || "0"),
 | 
			
		||||
                        precision: 6,
 | 
			
		||||
                      })
 | 
			
		||||
                        .toUnit()
 | 
			
		||||
                        .toLocaleString(undefined, {
 | 
			
		||||
                          style: "currency",
 | 
			
		||||
                          currency: "XRP",
 | 
			
		||||
                          currencyDisplay: "name",
 | 
			
		||||
                        })})`
 | 
			
		||||
                    ) : (
 | 
			
		||||
                      <Box css={{ color: "$red11" }}>
 | 
			
		||||
                        (Account not found, request funds to activate account)
 | 
			
		||||
                      </Box>
 | 
			
		||||
                    )}
 | 
			
		||||
                  </Text>
 | 
			
		||||
                </Box>
 | 
			
		||||
                {!props.hideDeployBtn && (
 | 
			
		||||
@@ -452,7 +469,7 @@ const Accounts: FC<AccountProps> = (props) => {
 | 
			
		||||
                      e.stopPropagation();
 | 
			
		||||
                    }}
 | 
			
		||||
                  >
 | 
			
		||||
                    <SetHookDialog account={account} />
 | 
			
		||||
                    <SetHookDialog accountAddress={account.address} />
 | 
			
		||||
                  </div>
 | 
			
		||||
                )}
 | 
			
		||||
              </Flex>
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,7 @@ const StyledContent = styled(DialogPrimitive.Content, {
 | 
			
		||||
  color: "$mauve12",
 | 
			
		||||
  borderRadius: "$md",
 | 
			
		||||
  position: "relative",
 | 
			
		||||
  mb: "15%",
 | 
			
		||||
  boxShadow:
 | 
			
		||||
    "0px 10px 38px -5px rgba(22, 23, 24, 0.25), 0px 10px 20px -5px rgba(22, 23, 24, 0.2)",
 | 
			
		||||
  width: "90vw",
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,28 @@ import {
 | 
			
		||||
} from "./Dialog";
 | 
			
		||||
import PanelBox from "./PanelBox";
 | 
			
		||||
import { templateFileIds } from "../state/constants";
 | 
			
		||||
import { styled } from "../stitches.config";
 | 
			
		||||
 | 
			
		||||
import Starter from "../components/icons/Starter";
 | 
			
		||||
import Firewall from "../components/icons/Firewall";
 | 
			
		||||
import Notary from "../components/icons/Notary";
 | 
			
		||||
import Carbon from "../components/icons/Carbon";
 | 
			
		||||
import Peggy from "../components/icons/Peggy";
 | 
			
		||||
 | 
			
		||||
const ImageWrapper = styled(Flex, {
 | 
			
		||||
  position: "relative",
 | 
			
		||||
  mt: "$2",
 | 
			
		||||
  mb: "$10",
 | 
			
		||||
  svg: {
 | 
			
		||||
    // fill: "red",
 | 
			
		||||
    ".angle": {
 | 
			
		||||
      fill: "$text",
 | 
			
		||||
    },
 | 
			
		||||
    ":not(.angle)": {
 | 
			
		||||
      stroke: "$text",
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const Navigation = () => {
 | 
			
		||||
  const router = useRouter();
 | 
			
		||||
@@ -91,7 +113,7 @@ const Navigation = () => {
 | 
			
		||||
                <Text
 | 
			
		||||
                  css={{ fontSize: "$xs", color: "$mauve10", lineHeight: 1 }}
 | 
			
		||||
                >
 | 
			
		||||
                  {snap.files.length > 0 ? "Gist: " : "Playground"}
 | 
			
		||||
                  {snap.files.length > 0 ? "Gist: " : "Builder"}
 | 
			
		||||
                  {snap.files.length > 0 && (
 | 
			
		||||
                    <Link
 | 
			
		||||
                      href={`https://gist.github.com/${snap.gistOwner || ""}/${
 | 
			
		||||
@@ -128,19 +150,20 @@ const Navigation = () => {
 | 
			
		||||
                </DialogTrigger>
 | 
			
		||||
                <DialogContent
 | 
			
		||||
                  css={{
 | 
			
		||||
                    display: "flex",
 | 
			
		||||
                    maxWidth: "1080px",
 | 
			
		||||
                    width: "80vw",
 | 
			
		||||
                    height: "80%",
 | 
			
		||||
                    maxHeight: "80%",
 | 
			
		||||
                    backgroundColor: "$mauve1 !important",
 | 
			
		||||
                    overflowY: "auto",
 | 
			
		||||
                    background: "black",
 | 
			
		||||
                    p: 0,
 | 
			
		||||
                  }}
 | 
			
		||||
                >
 | 
			
		||||
                  <Flex
 | 
			
		||||
                    css={{
 | 
			
		||||
                      flexDirection: "column",
 | 
			
		||||
                      flex: 1,
 | 
			
		||||
                      height: "auto",
 | 
			
		||||
                      height: "100%",
 | 
			
		||||
                      "@md": {
 | 
			
		||||
                        flexDirection: "row",
 | 
			
		||||
                        height: "100%",
 | 
			
		||||
@@ -151,15 +174,15 @@ const Navigation = () => {
 | 
			
		||||
                      css={{
 | 
			
		||||
                        borderBottom: "1px solid $colors$mauve5",
 | 
			
		||||
                        width: "100%",
 | 
			
		||||
                        minWidth: "240px",
 | 
			
		||||
                        flexDirection: "column",
 | 
			
		||||
                        p: "$7",
 | 
			
		||||
                        height: "100%",
 | 
			
		||||
                        backgroundColor: "$mauve2",
 | 
			
		||||
                        "@md": {
 | 
			
		||||
                          width: "30%",
 | 
			
		||||
                          maxWidth: "300px",
 | 
			
		||||
                          borderBottom: "0px",
 | 
			
		||||
                          borderRight: "1px solid $colors$mauve6",
 | 
			
		||||
                          borderRight: "1px solid $colors$mauve5",
 | 
			
		||||
                        },
 | 
			
		||||
                      }}
 | 
			
		||||
                    >
 | 
			
		||||
@@ -196,9 +219,9 @@ const Navigation = () => {
 | 
			
		||||
                              display: "inline-flex",
 | 
			
		||||
                              alignItems: "center",
 | 
			
		||||
                              gap: "$3",
 | 
			
		||||
                              color: "$purple10",
 | 
			
		||||
                              color: "$purple11",
 | 
			
		||||
                              "&:hover": {
 | 
			
		||||
                                color: "$purple11",
 | 
			
		||||
                                color: "$purple12",
 | 
			
		||||
                              },
 | 
			
		||||
                              "&:focus": {
 | 
			
		||||
                                outline: 0,
 | 
			
		||||
@@ -217,9 +240,9 @@ const Navigation = () => {
 | 
			
		||||
                              display: "inline-flex",
 | 
			
		||||
                              alignItems: "center",
 | 
			
		||||
                              gap: "$3",
 | 
			
		||||
                              color: "$purple10",
 | 
			
		||||
                              color: "$purple11",
 | 
			
		||||
                              "&:hover": {
 | 
			
		||||
                                color: "$purple11",
 | 
			
		||||
                                color: "$purple12",
 | 
			
		||||
                              },
 | 
			
		||||
                              "&:focus": {
 | 
			
		||||
                                outline: 0,
 | 
			
		||||
@@ -237,9 +260,9 @@ const Navigation = () => {
 | 
			
		||||
                              display: "inline-flex",
 | 
			
		||||
                              alignItems: "center",
 | 
			
		||||
                              gap: "$3",
 | 
			
		||||
                              color: "$purple10",
 | 
			
		||||
                              color: "$purple11",
 | 
			
		||||
                              "&:hover": {
 | 
			
		||||
                                color: "$purple11",
 | 
			
		||||
                                color: "$purple12",
 | 
			
		||||
                              },
 | 
			
		||||
                              "&:focus": {
 | 
			
		||||
                                outline: 0,
 | 
			
		||||
@@ -255,67 +278,90 @@ const Navigation = () => {
 | 
			
		||||
                        </Flex>
 | 
			
		||||
                      </DialogDescription>
 | 
			
		||||
                    </Flex>
 | 
			
		||||
                    <div>
 | 
			
		||||
                      <Flex
 | 
			
		||||
                        css={{
 | 
			
		||||
                          display: "grid",
 | 
			
		||||
                          gridTemplateColumns: "1fr",
 | 
			
		||||
 | 
			
		||||
                    <Flex
 | 
			
		||||
                      css={{
 | 
			
		||||
                        display: "grid",
 | 
			
		||||
                        gridTemplateColumns: "1fr",
 | 
			
		||||
                        gridTemplateRows: "max-content",
 | 
			
		||||
                        flex: 1,
 | 
			
		||||
                        p: "$7",
 | 
			
		||||
                        pb: "$16",
 | 
			
		||||
                        gap: "$3",
 | 
			
		||||
                        alignItems: "normal",
 | 
			
		||||
                        flexWrap: "wrap",
 | 
			
		||||
                        backgroundColor: "$mauve1",
 | 
			
		||||
                        "@md": {
 | 
			
		||||
                          gridTemplateColumns: "1fr 1fr",
 | 
			
		||||
                          gridTemplateRows: "max-content",
 | 
			
		||||
                          flex: 1,
 | 
			
		||||
                          p: "$7",
 | 
			
		||||
                          gap: "$3",
 | 
			
		||||
                          alignItems: "normal",
 | 
			
		||||
                          flexWrap: "wrap",
 | 
			
		||||
                          backgroundColor: "$mauve1",
 | 
			
		||||
                          "@md": {
 | 
			
		||||
                            gridTemplateColumns: "1fr 1fr 1fr",
 | 
			
		||||
                            gridTemplateRows: "max-content",
 | 
			
		||||
                          },
 | 
			
		||||
                        }}
 | 
			
		||||
                        },
 | 
			
		||||
                        "@lg": {
 | 
			
		||||
                          gridTemplateColumns: "1fr 1fr 1fr",
 | 
			
		||||
                          gridTemplateRows: "max-content",
 | 
			
		||||
                        },
 | 
			
		||||
                      }}
 | 
			
		||||
                    >
 | 
			
		||||
                      <PanelBox
 | 
			
		||||
                        as="a"
 | 
			
		||||
                        href={`/develop/${templateFileIds.starter}`}
 | 
			
		||||
                      >
 | 
			
		||||
                        <PanelBox
 | 
			
		||||
                          as="a"
 | 
			
		||||
                          href={`/develop/${templateFileIds.starter}`}
 | 
			
		||||
                        >
 | 
			
		||||
                          <Heading>Starter</Heading>
 | 
			
		||||
                          <Text>
 | 
			
		||||
                            Just a basic starter with essential imports
 | 
			
		||||
                          </Text>
 | 
			
		||||
                        </PanelBox>
 | 
			
		||||
                        <PanelBox
 | 
			
		||||
                          as="a"
 | 
			
		||||
                          href={`/develop/${templateFileIds.firewall}`}
 | 
			
		||||
                        >
 | 
			
		||||
                          <Heading>Firewall</Heading>
 | 
			
		||||
                          <Text>
 | 
			
		||||
                            This Hook essentially checks a blacklist of accounts
 | 
			
		||||
                          </Text>
 | 
			
		||||
                        </PanelBox>
 | 
			
		||||
                        <PanelBox
 | 
			
		||||
                          as="a"
 | 
			
		||||
                          href={`/develop/${templateFileIds.notary}`}
 | 
			
		||||
                        >
 | 
			
		||||
                          <Heading>Notary</Heading>
 | 
			
		||||
                          <Text>
 | 
			
		||||
                            Collecting signatures for multi-sign transactions
 | 
			
		||||
                          </Text>
 | 
			
		||||
                        </PanelBox>
 | 
			
		||||
                        <PanelBox
 | 
			
		||||
                          as="a"
 | 
			
		||||
                          href={`/develop/${templateFileIds.carbon}`}
 | 
			
		||||
                        >
 | 
			
		||||
                          <Heading>Carbon</Heading>
 | 
			
		||||
                          <Text>Send a percentage of sum to an address</Text>
 | 
			
		||||
                        </PanelBox>
 | 
			
		||||
                        <PanelBox
 | 
			
		||||
                          as="a"
 | 
			
		||||
                          href={`/develop/${templateFileIds.peggy}`}
 | 
			
		||||
                        >
 | 
			
		||||
                          <Heading>Peggy</Heading>
 | 
			
		||||
                          <Text>An oracle based stable coin hook</Text>
 | 
			
		||||
                        </PanelBox>
 | 
			
		||||
                      </Flex>
 | 
			
		||||
                    </div>
 | 
			
		||||
                        <ImageWrapper>
 | 
			
		||||
                          <Starter />
 | 
			
		||||
                        </ImageWrapper>
 | 
			
		||||
                        <Heading>Starter</Heading>
 | 
			
		||||
 | 
			
		||||
                        <Text>
 | 
			
		||||
                          Just a basic starter with essential imports, just
 | 
			
		||||
                          accepts any transaction coming through
 | 
			
		||||
                        </Text>
 | 
			
		||||
                      </PanelBox>
 | 
			
		||||
 | 
			
		||||
                      <PanelBox
 | 
			
		||||
                        as="a"
 | 
			
		||||
                        href={`/develop/${templateFileIds.firewall}`}
 | 
			
		||||
                        css={{ alignItems: "flex-start" }}
 | 
			
		||||
                      >
 | 
			
		||||
                        <ImageWrapper>
 | 
			
		||||
                          <Firewall />
 | 
			
		||||
                        </ImageWrapper>
 | 
			
		||||
                        <Heading>Firewall</Heading>
 | 
			
		||||
                        <Text>
 | 
			
		||||
                          This Hook essentially checks a blacklist of accounts
 | 
			
		||||
                        </Text>
 | 
			
		||||
                      </PanelBox>
 | 
			
		||||
                      <PanelBox
 | 
			
		||||
                        as="a"
 | 
			
		||||
                        href={`/develop/${templateFileIds.notary}`}
 | 
			
		||||
                      >
 | 
			
		||||
                        <ImageWrapper>
 | 
			
		||||
                          <Notary />
 | 
			
		||||
                        </ImageWrapper>
 | 
			
		||||
                        <Heading>Notary</Heading>
 | 
			
		||||
                        <Text>
 | 
			
		||||
                          Collecting signatures for multi-sign transactions
 | 
			
		||||
                        </Text>
 | 
			
		||||
                      </PanelBox>
 | 
			
		||||
                      <PanelBox
 | 
			
		||||
                        as="a"
 | 
			
		||||
                        href={`/develop/${templateFileIds.carbon}`}
 | 
			
		||||
                      >
 | 
			
		||||
                        <ImageWrapper>
 | 
			
		||||
                          <Carbon />
 | 
			
		||||
                        </ImageWrapper>
 | 
			
		||||
                        <Heading>Carbon</Heading>
 | 
			
		||||
                        <Text>Send a percentage of sum to an address</Text>
 | 
			
		||||
                      </PanelBox>
 | 
			
		||||
                      <PanelBox
 | 
			
		||||
                        as="a"
 | 
			
		||||
                        href={`/develop/${templateFileIds.peggy}`}
 | 
			
		||||
                      >
 | 
			
		||||
                        <ImageWrapper>
 | 
			
		||||
                          <Peggy />
 | 
			
		||||
                        </ImageWrapper>
 | 
			
		||||
                        <Heading>Peggy</Heading>
 | 
			
		||||
                        <Text>An oracle based stable coin hook</Text>
 | 
			
		||||
                      </PanelBox>
 | 
			
		||||
                    </Flex>
 | 
			
		||||
                  </Flex>
 | 
			
		||||
                  <DialogClose asChild>
 | 
			
		||||
                    <Box
 | 
			
		||||
 
 | 
			
		||||
@@ -21,11 +21,11 @@ import {
 | 
			
		||||
 | 
			
		||||
import { TTS, tts } from "../utils/hookOnCalculator";
 | 
			
		||||
import { deployHook } from "../state/actions";
 | 
			
		||||
import type { IAccount } from "../state";
 | 
			
		||||
import { useSnapshot } from "valtio";
 | 
			
		||||
import state from "../state";
 | 
			
		||||
import toast from "react-hot-toast";
 | 
			
		||||
import { sha256 } from "../state/actions/deployHook";
 | 
			
		||||
import { prepareDeployHookTx, sha256 } from "../state/actions/deployHook";
 | 
			
		||||
import estimateFee from "../utils/estimateFee";
 | 
			
		||||
 | 
			
		||||
const transactionOptions = Object.keys(tts).map((key) => ({
 | 
			
		||||
  label: key,
 | 
			
		||||
@@ -37,6 +37,7 @@ export type SetHookData = {
 | 
			
		||||
    value: keyof TTS;
 | 
			
		||||
    label: string;
 | 
			
		||||
  }[];
 | 
			
		||||
  Fee: string;
 | 
			
		||||
  HookNamespace: string;
 | 
			
		||||
  HookParameters: {
 | 
			
		||||
    HookParameter: {
 | 
			
		||||
@@ -52,176 +53,266 @@ export type SetHookData = {
 | 
			
		||||
  // }[];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const SetHookDialog: React.FC<{ account: IAccount }> = ({ account }) => {
 | 
			
		||||
  const snap = useSnapshot(state);
 | 
			
		||||
  const [isSetHookDialogOpen, setIsSetHookDialogOpen] = useState(false);
 | 
			
		||||
  const {
 | 
			
		||||
    register,
 | 
			
		||||
    handleSubmit,
 | 
			
		||||
    control,
 | 
			
		||||
    watch,
 | 
			
		||||
    setValue,
 | 
			
		||||
    formState: { errors },
 | 
			
		||||
  } = useForm<SetHookData>({
 | 
			
		||||
    defaultValues: {
 | 
			
		||||
      HookNamespace: snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "",
 | 
			
		||||
    },
 | 
			
		||||
  });
 | 
			
		||||
  const { fields, append, remove } = useFieldArray({
 | 
			
		||||
    control,
 | 
			
		||||
    name: "HookParameters", // unique name for your Field Array
 | 
			
		||||
  });
 | 
			
		||||
export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
 | 
			
		||||
  ({ accountAddress }) => {
 | 
			
		||||
    const snap = useSnapshot(state);
 | 
			
		||||
    const account = snap.accounts.find((acc) => acc.address === accountAddress);
 | 
			
		||||
 | 
			
		||||
  // Update value if activeWat changes
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    setValue(
 | 
			
		||||
    const [isSetHookDialogOpen, setIsSetHookDialogOpen] = useState(false);
 | 
			
		||||
    const {
 | 
			
		||||
      register,
 | 
			
		||||
      handleSubmit,
 | 
			
		||||
      control,
 | 
			
		||||
      watch,
 | 
			
		||||
      setValue,
 | 
			
		||||
      getValues,
 | 
			
		||||
      formState: { errors },
 | 
			
		||||
    } = useForm<SetHookData>({
 | 
			
		||||
      defaultValues: {
 | 
			
		||||
        HookNamespace:
 | 
			
		||||
          snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || "",
 | 
			
		||||
        Invoke: transactionOptions.filter((to) => to.label === "ttPAYMENT"),
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
    const { fields, append, remove } = useFieldArray({
 | 
			
		||||
      control,
 | 
			
		||||
      name: "HookParameters", // unique name for your Field Array
 | 
			
		||||
    });
 | 
			
		||||
    const [formInitialized, setFormInitialized] = useState(false);
 | 
			
		||||
    const [estimateLoading, setEstimateLoading] = useState(false);
 | 
			
		||||
 | 
			
		||||
    // Update value if activeWat changes
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
      setValue(
 | 
			
		||||
        "HookNamespace",
 | 
			
		||||
        snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
 | 
			
		||||
      );
 | 
			
		||||
      setFormInitialized(true);
 | 
			
		||||
    }, [snap.activeWat, snap.files, setValue]);
 | 
			
		||||
    // const {
 | 
			
		||||
    //   fields: grantFields,
 | 
			
		||||
    //   append: grantAppend,
 | 
			
		||||
    //   remove: grantRemove,
 | 
			
		||||
    // } = useFieldArray({
 | 
			
		||||
    //   control,
 | 
			
		||||
    //   name: "HookGrants", // unique name for your Field Array
 | 
			
		||||
    // });
 | 
			
		||||
    const [hashedNamespace, setHashedNamespace] = useState("");
 | 
			
		||||
    const namespace = watch(
 | 
			
		||||
      "HookNamespace",
 | 
			
		||||
      snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
 | 
			
		||||
      snap.files?.[snap.active]?.name?.split(".")?.[0] || ""
 | 
			
		||||
    );
 | 
			
		||||
  }, [snap.activeWat, snap.files, setValue]);
 | 
			
		||||
  // const {
 | 
			
		||||
  //   fields: grantFields,
 | 
			
		||||
  //   append: grantAppend,
 | 
			
		||||
  //   remove: grantRemove,
 | 
			
		||||
  // } = useFieldArray({
 | 
			
		||||
  //   control,
 | 
			
		||||
  //   name: "HookGrants", // unique name for your Field Array
 | 
			
		||||
  // });
 | 
			
		||||
  const [hashedNamespace, setHashedNamespace] = useState("");
 | 
			
		||||
  const namespace = watch(
 | 
			
		||||
    "HookNamespace",
 | 
			
		||||
    snap.files?.[snap.active]?.name?.split(".")?.[0] || ""
 | 
			
		||||
  );
 | 
			
		||||
  const calculateHashedValue = useCallback(async () => {
 | 
			
		||||
    const hashedVal = await sha256(namespace);
 | 
			
		||||
    setHashedNamespace(hashedVal.toUpperCase());
 | 
			
		||||
  }, [namespace]);
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    calculateHashedValue();
 | 
			
		||||
  }, [namespace, calculateHashedValue]);
 | 
			
		||||
    const calculateHashedValue = useCallback(async () => {
 | 
			
		||||
      const hashedVal = await sha256(namespace);
 | 
			
		||||
      setHashedNamespace(hashedVal.toUpperCase());
 | 
			
		||||
    }, [namespace]);
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
      calculateHashedValue();
 | 
			
		||||
    }, [namespace, calculateHashedValue]);
 | 
			
		||||
 | 
			
		||||
  if (!account) {
 | 
			
		||||
    return null;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const onSubmit: SubmitHandler<SetHookData> = async (data) => {
 | 
			
		||||
    const currAccount = state.accounts.find(
 | 
			
		||||
      (acc) => acc.address === account.address
 | 
			
		||||
    );
 | 
			
		||||
    if (currAccount) currAccount.isLoading = true;
 | 
			
		||||
    const res = await deployHook(account, data);
 | 
			
		||||
    if (currAccount) currAccount.isLoading = false;
 | 
			
		||||
 | 
			
		||||
    if (res && res.engine_result === "tesSUCCESS") {
 | 
			
		||||
      toast.success("Transaction succeeded!");
 | 
			
		||||
      return setIsSetHookDialogOpen(false);
 | 
			
		||||
    }
 | 
			
		||||
    toast.error(`Transaction failed! (${res?.engine_result_message})`);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Dialog open={isSetHookDialogOpen} onOpenChange={setIsSetHookDialogOpen}>
 | 
			
		||||
      <DialogTrigger asChild>
 | 
			
		||||
        <Button
 | 
			
		||||
          ghost
 | 
			
		||||
          size="xs"
 | 
			
		||||
          uppercase
 | 
			
		||||
          variant={"secondary"}
 | 
			
		||||
          disabled={
 | 
			
		||||
            account.isLoading ||
 | 
			
		||||
            !snap.files.filter((file) => file.compiledWatContent).length
 | 
			
		||||
    // Calcucate initial fee estimate when modal opens
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
      if (formInitialized && account) {
 | 
			
		||||
        (async () => {
 | 
			
		||||
          const formValues = getValues();
 | 
			
		||||
          const tx = await prepareDeployHookTx(account, formValues);
 | 
			
		||||
          if (!tx) {
 | 
			
		||||
            return;
 | 
			
		||||
          }
 | 
			
		||||
        >
 | 
			
		||||
          Set Hook
 | 
			
		||||
        </Button>
 | 
			
		||||
      </DialogTrigger>
 | 
			
		||||
      <DialogContent>
 | 
			
		||||
        <form onSubmit={handleSubmit(onSubmit)}>
 | 
			
		||||
          <DialogTitle>Deploy configuration</DialogTitle>
 | 
			
		||||
          <DialogDescription as="div">
 | 
			
		||||
            <Stack css={{ width: "100%", flex: 1 }}>
 | 
			
		||||
              <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}
 | 
			
		||||
                      closeMenuOnSelect={false}
 | 
			
		||||
                      isMulti
 | 
			
		||||
                      menuPosition="fixed"
 | 
			
		||||
                      options={transactionOptions}
 | 
			
		||||
                    />
 | 
			
		||||
                  )}
 | 
			
		||||
                />
 | 
			
		||||
              </Box>
 | 
			
		||||
              <Box css={{ width: "100%" }}>
 | 
			
		||||
                <Label>Hook Namespace Seed</Label>
 | 
			
		||||
                <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" }}>
 | 
			
		||||
                    Namespace is required
 | 
			
		||||
                  </Box>
 | 
			
		||||
                )}
 | 
			
		||||
                <Box css={{ mt: "$3" }}>
 | 
			
		||||
                  <Label>Hook Namespace (sha256)</Label>
 | 
			
		||||
                  <Input readOnly value={hashedNamespace} />
 | 
			
		||||
          const res = await estimateFee(tx, account);
 | 
			
		||||
          if (res && res.base_fee) {
 | 
			
		||||
            setValue("Fee", res.base_fee);
 | 
			
		||||
          }
 | 
			
		||||
        })();
 | 
			
		||||
      }
 | 
			
		||||
      // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
			
		||||
    }, [formInitialized]);
 | 
			
		||||
 | 
			
		||||
    if (!account) {
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const onSubmit: SubmitHandler<SetHookData> = async (data) => {
 | 
			
		||||
      const currAccount = state.accounts.find(
 | 
			
		||||
        (acc) => acc.address === account.address
 | 
			
		||||
      );
 | 
			
		||||
      if (currAccount) currAccount.isLoading = true;
 | 
			
		||||
      const res = await deployHook(account, data);
 | 
			
		||||
      if (currAccount) currAccount.isLoading = false;
 | 
			
		||||
 | 
			
		||||
      if (res && res.engine_result === "tesSUCCESS") {
 | 
			
		||||
        toast.success("Transaction succeeded!");
 | 
			
		||||
        return setIsSetHookDialogOpen(false);
 | 
			
		||||
      }
 | 
			
		||||
      toast.error(`Transaction failed! (${res?.engine_result_message})`);
 | 
			
		||||
    };
 | 
			
		||||
    return (
 | 
			
		||||
      <Dialog open={isSetHookDialogOpen} onOpenChange={setIsSetHookDialogOpen}>
 | 
			
		||||
        <DialogTrigger asChild>
 | 
			
		||||
          <Button
 | 
			
		||||
            ghost
 | 
			
		||||
            size="xs"
 | 
			
		||||
            uppercase
 | 
			
		||||
            variant={"secondary"}
 | 
			
		||||
            disabled={
 | 
			
		||||
              account.isLoading ||
 | 
			
		||||
              !snap.files.filter((file) => file.compiledWatContent).length
 | 
			
		||||
            }
 | 
			
		||||
          >
 | 
			
		||||
            Set Hook
 | 
			
		||||
          </Button>
 | 
			
		||||
        </DialogTrigger>
 | 
			
		||||
        <DialogContent>
 | 
			
		||||
          <form onSubmit={handleSubmit(onSubmit)}>
 | 
			
		||||
            <DialogTitle>Deploy configuration</DialogTitle>
 | 
			
		||||
            <DialogDescription as="div">
 | 
			
		||||
              <Stack css={{ width: "100%", flex: 1 }}>
 | 
			
		||||
                <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}
 | 
			
		||||
                        closeMenuOnSelect={false}
 | 
			
		||||
                        isMulti
 | 
			
		||||
                        menuPosition="fixed"
 | 
			
		||||
                        options={transactionOptions}
 | 
			
		||||
                      />
 | 
			
		||||
                    )}
 | 
			
		||||
                  />
 | 
			
		||||
                </Box>
 | 
			
		||||
              </Box>
 | 
			
		||||
              <Box css={{ width: "100%" }}>
 | 
			
		||||
                <Label style={{ marginBottom: "10px", display: "block" }}>
 | 
			
		||||
                  Hook parameters
 | 
			
		||||
                </Label>
 | 
			
		||||
                <Stack>
 | 
			
		||||
                  {fields.map((field, index) => (
 | 
			
		||||
                    <Stack key={field.id}>
 | 
			
		||||
                      <Input
 | 
			
		||||
                        // important to include key with field's id
 | 
			
		||||
                        placeholder="Parameter name"
 | 
			
		||||
                        {...register(
 | 
			
		||||
                          `HookParameters.${index}.HookParameter.HookParameterName`
 | 
			
		||||
                        )}
 | 
			
		||||
                      />
 | 
			
		||||
                      <Input
 | 
			
		||||
                        placeholder="Value (hex-quoted)"
 | 
			
		||||
                        {...register(
 | 
			
		||||
                          `HookParameters.${index}.HookParameter.HookParameterValue`
 | 
			
		||||
                        )}
 | 
			
		||||
                      />
 | 
			
		||||
                      <Button onClick={() => remove(index)} variant="destroy">
 | 
			
		||||
                        <Trash weight="regular" size="16px" />
 | 
			
		||||
                      </Button>
 | 
			
		||||
                    </Stack>
 | 
			
		||||
                  ))}
 | 
			
		||||
                  <Button
 | 
			
		||||
                    outline
 | 
			
		||||
                    fullWidth
 | 
			
		||||
                    type="button"
 | 
			
		||||
                    onClick={() =>
 | 
			
		||||
                      append({
 | 
			
		||||
                        HookParameter: {
 | 
			
		||||
                          HookParameterName: "",
 | 
			
		||||
                          HookParameterValue: "",
 | 
			
		||||
                        },
 | 
			
		||||
                      })
 | 
			
		||||
                <Box css={{ width: "100%" }}>
 | 
			
		||||
                  <Label>Hook Namespace Seed</Label>
 | 
			
		||||
                  <Input
 | 
			
		||||
                    {...register("HookNamespace", { required: true })}
 | 
			
		||||
                    autoComplete={"off"}
 | 
			
		||||
                    defaultValue={
 | 
			
		||||
                      snap.files?.[snap.activeWat]?.name?.split(".")?.[0] || ""
 | 
			
		||||
                    }
 | 
			
		||||
                  >
 | 
			
		||||
                    <Plus size="16px" />
 | 
			
		||||
                    Add Hook Parameter
 | 
			
		||||
                  </Button>
 | 
			
		||||
                </Stack>
 | 
			
		||||
              </Box>
 | 
			
		||||
              {/* <Box css={{ width: "100%" }}>
 | 
			
		||||
                  />
 | 
			
		||||
                  {errors.HookNamespace?.type === "required" && (
 | 
			
		||||
                    <Box css={{ display: "inline", color: "$red11" }}>
 | 
			
		||||
                      Namespace is required
 | 
			
		||||
                    </Box>
 | 
			
		||||
                  )}
 | 
			
		||||
                  <Box css={{ mt: "$3" }}>
 | 
			
		||||
                    <Label>Hook Namespace (sha256)</Label>
 | 
			
		||||
                    <Input readOnly value={hashedNamespace} />
 | 
			
		||||
                  </Box>
 | 
			
		||||
                </Box>
 | 
			
		||||
 | 
			
		||||
                <Box css={{ width: "100%" }}>
 | 
			
		||||
                  <Label style={{ marginBottom: "10px", display: "block" }}>
 | 
			
		||||
                    Hook parameters
 | 
			
		||||
                  </Label>
 | 
			
		||||
                  <Stack>
 | 
			
		||||
                    {fields.map((field, index) => (
 | 
			
		||||
                      <Stack key={field.id}>
 | 
			
		||||
                        <Input
 | 
			
		||||
                          // important to include key with field's id
 | 
			
		||||
                          placeholder="Parameter name"
 | 
			
		||||
                          {...register(
 | 
			
		||||
                            `HookParameters.${index}.HookParameter.HookParameterName`
 | 
			
		||||
                          )}
 | 
			
		||||
                        />
 | 
			
		||||
                        <Input
 | 
			
		||||
                          placeholder="Value (hex-quoted)"
 | 
			
		||||
                          {...register(
 | 
			
		||||
                            `HookParameters.${index}.HookParameter.HookParameterValue`
 | 
			
		||||
                          )}
 | 
			
		||||
                        />
 | 
			
		||||
                        <Button onClick={() => remove(index)} variant="destroy">
 | 
			
		||||
                          <Trash weight="regular" size="16px" />
 | 
			
		||||
                        </Button>
 | 
			
		||||
                      </Stack>
 | 
			
		||||
                    ))}
 | 
			
		||||
                    <Button
 | 
			
		||||
                      outline
 | 
			
		||||
                      fullWidth
 | 
			
		||||
                      type="button"
 | 
			
		||||
                      onClick={() =>
 | 
			
		||||
                        append({
 | 
			
		||||
                          HookParameter: {
 | 
			
		||||
                            HookParameterName: "",
 | 
			
		||||
                            HookParameterValue: "",
 | 
			
		||||
                          },
 | 
			
		||||
                        })
 | 
			
		||||
                      }
 | 
			
		||||
                    >
 | 
			
		||||
                      <Plus size="16px" />
 | 
			
		||||
                      Add Hook Parameter
 | 
			
		||||
                    </Button>
 | 
			
		||||
                  </Stack>
 | 
			
		||||
                </Box>
 | 
			
		||||
                <Box css={{ width: "100%", position: "relative" }}>
 | 
			
		||||
                  <Label>Fee</Label>
 | 
			
		||||
                  <Box css={{ display: "flex", alignItems: "center" }}>
 | 
			
		||||
                    <Input
 | 
			
		||||
                      type="number"
 | 
			
		||||
                      {...register("Fee", { required: true })}
 | 
			
		||||
                      autoComplete={"off"}
 | 
			
		||||
                      defaultValue={10000}
 | 
			
		||||
                      css={{
 | 
			
		||||
                        "-moz-appearance": "textfield",
 | 
			
		||||
                        "&::-webkit-outer-spin-button": {
 | 
			
		||||
                          "-webkit-appearance": "none",
 | 
			
		||||
                          margin: 0,
 | 
			
		||||
                        },
 | 
			
		||||
                        "&::-webkit-inner-spin-button ": {
 | 
			
		||||
                          "-webkit-appearance": "none",
 | 
			
		||||
                          margin: 0,
 | 
			
		||||
                        },
 | 
			
		||||
                      }}
 | 
			
		||||
                    />
 | 
			
		||||
                    <Button
 | 
			
		||||
                      size="xs"
 | 
			
		||||
                      variant="primary"
 | 
			
		||||
                      outline
 | 
			
		||||
                      isLoading={estimateLoading}
 | 
			
		||||
                      css={{
 | 
			
		||||
                        position: "absolute",
 | 
			
		||||
                        right: "$2",
 | 
			
		||||
                        fontSize: "$xs",
 | 
			
		||||
                        cursor: "pointer",
 | 
			
		||||
                        alignContent: "center",
 | 
			
		||||
                        display: "flex",
 | 
			
		||||
                      }}
 | 
			
		||||
                      onClick={async (e) => {
 | 
			
		||||
                        e.preventDefault();
 | 
			
		||||
                        setEstimateLoading(true);
 | 
			
		||||
                        const formValues = getValues();
 | 
			
		||||
                        try {
 | 
			
		||||
                          const tx = await prepareDeployHookTx(
 | 
			
		||||
                            account,
 | 
			
		||||
                            formValues
 | 
			
		||||
                          );
 | 
			
		||||
                          if (tx) {
 | 
			
		||||
                            const res = await estimateFee(tx, account);
 | 
			
		||||
 | 
			
		||||
                            if (res && res.base_fee) {
 | 
			
		||||
                              setValue("Fee", res.base_fee);
 | 
			
		||||
                            }
 | 
			
		||||
                          }
 | 
			
		||||
                        } catch (err) {}
 | 
			
		||||
 | 
			
		||||
                        setEstimateLoading(false);
 | 
			
		||||
                      }}
 | 
			
		||||
                    >
 | 
			
		||||
                      Suggest
 | 
			
		||||
                    </Button>
 | 
			
		||||
                  </Box>
 | 
			
		||||
                  {errors.Fee?.type === "required" && (
 | 
			
		||||
                    <Box css={{ display: "inline", color: "$red11" }}>
 | 
			
		||||
                      Fee is required
 | 
			
		||||
                    </Box>
 | 
			
		||||
                  )}
 | 
			
		||||
                </Box>
 | 
			
		||||
                {/* <Box css={{ width: "100%" }}>
 | 
			
		||||
                <label style={{ marginBottom: "10px", display: "block" }}>
 | 
			
		||||
                  Hook Grants
 | 
			
		||||
                </label>
 | 
			
		||||
@@ -269,38 +360,41 @@ export const SetHookDialog: React.FC<{ account: IAccount }> = ({ account }) => {
 | 
			
		||||
                  </Button>
 | 
			
		||||
                </Stack>
 | 
			
		||||
              </Box> */}
 | 
			
		||||
            </Stack>
 | 
			
		||||
          </DialogDescription>
 | 
			
		||||
              </Stack>
 | 
			
		||||
            </DialogDescription>
 | 
			
		||||
 | 
			
		||||
          <Flex
 | 
			
		||||
            css={{
 | 
			
		||||
              marginTop: 25,
 | 
			
		||||
              justifyContent: "flex-end",
 | 
			
		||||
              gap: "$3",
 | 
			
		||||
            }}
 | 
			
		||||
          >
 | 
			
		||||
            <DialogClose asChild>
 | 
			
		||||
              <Button outline>Cancel</Button>
 | 
			
		||||
            </DialogClose>
 | 
			
		||||
            {/* <DialogClose asChild> */}
 | 
			
		||||
            <Button
 | 
			
		||||
              variant="primary"
 | 
			
		||||
              type="submit"
 | 
			
		||||
              isLoading={account.isLoading}
 | 
			
		||||
            <Flex
 | 
			
		||||
              css={{
 | 
			
		||||
                marginTop: 25,
 | 
			
		||||
                justifyContent: "flex-end",
 | 
			
		||||
                gap: "$3",
 | 
			
		||||
              }}
 | 
			
		||||
            >
 | 
			
		||||
              Set Hook
 | 
			
		||||
            </Button>
 | 
			
		||||
            {/* </DialogClose> */}
 | 
			
		||||
          </Flex>
 | 
			
		||||
          <DialogClose asChild>
 | 
			
		||||
            <Box css={{ position: "absolute", top: "$3", right: "$3" }}>
 | 
			
		||||
              <X size="20px" />
 | 
			
		||||
            </Box>
 | 
			
		||||
          </DialogClose>
 | 
			
		||||
        </form>
 | 
			
		||||
      </DialogContent>
 | 
			
		||||
    </Dialog>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
              <DialogClose asChild>
 | 
			
		||||
                <Button outline>Cancel</Button>
 | 
			
		||||
              </DialogClose>
 | 
			
		||||
              {/* <DialogClose asChild> */}
 | 
			
		||||
              <Button
 | 
			
		||||
                variant="primary"
 | 
			
		||||
                type="submit"
 | 
			
		||||
                isLoading={account.isLoading}
 | 
			
		||||
              >
 | 
			
		||||
                Set Hook
 | 
			
		||||
              </Button>
 | 
			
		||||
              {/* </DialogClose> */}
 | 
			
		||||
            </Flex>
 | 
			
		||||
            <DialogClose asChild>
 | 
			
		||||
              <Box css={{ position: "absolute", top: "$3", right: "$3" }}>
 | 
			
		||||
                <X size="20px" />
 | 
			
		||||
              </Box>
 | 
			
		||||
            </DialogClose>
 | 
			
		||||
          </form>
 | 
			
		||||
        </DialogContent>
 | 
			
		||||
      </Dialog>
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
SetHookDialog.displayName = "SetHookDialog";
 | 
			
		||||
 | 
			
		||||
export default SetHookDialog;
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,8 @@ import Button from "../Button";
 | 
			
		||||
import Flex from "../Flex";
 | 
			
		||||
import { TxJson } from "./json";
 | 
			
		||||
import { TxUI } from "./ui";
 | 
			
		||||
import { default as _estimateFee } from "../../utils/estimateFee";
 | 
			
		||||
import toast from 'react-hot-toast';
 | 
			
		||||
 | 
			
		||||
export interface TransactionProps {
 | 
			
		||||
  header: string;
 | 
			
		||||
@@ -76,13 +78,19 @@ const Transaction: FC<TransactionProps> = ({
 | 
			
		||||
    } else {
 | 
			
		||||
      setState({ txIsDisabled: false });
 | 
			
		||||
    }
 | 
			
		||||
  }, [selectedAccount?.value, selectedTransaction?.value, setState, txIsLoading]);
 | 
			
		||||
  }, [
 | 
			
		||||
    selectedAccount?.value,
 | 
			
		||||
    selectedTransaction?.value,
 | 
			
		||||
    setState,
 | 
			
		||||
    txIsLoading,
 | 
			
		||||
  ]);
 | 
			
		||||
 | 
			
		||||
  const submitTest = useCallback(async () => {
 | 
			
		||||
    let st: TransactionState | undefined;
 | 
			
		||||
    const tt = txState.selectedTransaction?.value;
 | 
			
		||||
    if (viewType === "json") {
 | 
			
		||||
      // save the editor state first
 | 
			
		||||
      const pst = prepareState(editorValue || '', txState);
 | 
			
		||||
      const pst = prepareState(editorValue || "", tt);
 | 
			
		||||
      if (!pst) return;
 | 
			
		||||
 | 
			
		||||
      st = setState(pst);
 | 
			
		||||
@@ -102,7 +110,7 @@ const Transaction: FC<TransactionProps> = ({
 | 
			
		||||
      const options = prepareOptions(st);
 | 
			
		||||
 | 
			
		||||
      if (options.Destination === null) {
 | 
			
		||||
        throw Error("Destination account cannot be null")
 | 
			
		||||
        throw Error("Destination account cannot be null");
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      await sendTransaction(account, options, { logPrefix });
 | 
			
		||||
@@ -116,7 +124,17 @@ const Transaction: FC<TransactionProps> = ({
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    setState({ txIsLoading: false });
 | 
			
		||||
  }, [viewType, accounts, txIsDisabled, setState, header, editorValue, txState, selectedAccount?.value, prepareOptions]);
 | 
			
		||||
  }, [
 | 
			
		||||
    viewType,
 | 
			
		||||
    accounts,
 | 
			
		||||
    txIsDisabled,
 | 
			
		||||
    setState,
 | 
			
		||||
    header,
 | 
			
		||||
    editorValue,
 | 
			
		||||
    txState,
 | 
			
		||||
    selectedAccount?.value,
 | 
			
		||||
    prepareOptions,
 | 
			
		||||
  ]);
 | 
			
		||||
 | 
			
		||||
  const resetState = useCallback(() => {
 | 
			
		||||
    modifyTransaction(header, { viewType }, { replaceState: true });
 | 
			
		||||
@@ -129,6 +147,31 @@ const Transaction: FC<TransactionProps> = ({
 | 
			
		||||
    [editorSavedValue, editorSettings.tabSize, prepareOptions]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const estimateFee = useCallback(
 | 
			
		||||
    async (st?: TransactionState, opts?: { silent?: boolean }) => {
 | 
			
		||||
      const state = st || txState;
 | 
			
		||||
      const ptx = prepareOptions(state);
 | 
			
		||||
      const account = accounts.find(
 | 
			
		||||
        acc => acc.address === state.selectedAccount?.value
 | 
			
		||||
      );
 | 
			
		||||
      if (!account) {
 | 
			
		||||
        if (!opts?.silent) {
 | 
			
		||||
          toast.error("Please select account from the list.")
 | 
			
		||||
        }
 | 
			
		||||
        return
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      ptx.Account = account.address;
 | 
			
		||||
      ptx.Sequence = account.sequence;
 | 
			
		||||
 | 
			
		||||
      const res = await _estimateFee(ptx, account, opts);
 | 
			
		||||
      const fee = res?.base_fee;
 | 
			
		||||
      setState({ estimatedFee: fee });
 | 
			
		||||
      return fee;
 | 
			
		||||
    },
 | 
			
		||||
    [accounts, prepareOptions, setState, txState]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Box css={{ position: "relative", height: "calc(100% - 28px)" }} {...props}>
 | 
			
		||||
      {viewType === "json" ? (
 | 
			
		||||
@@ -137,9 +180,10 @@ const Transaction: FC<TransactionProps> = ({
 | 
			
		||||
          header={header}
 | 
			
		||||
          state={txState}
 | 
			
		||||
          setState={setState}
 | 
			
		||||
          estimateFee={estimateFee}
 | 
			
		||||
        />
 | 
			
		||||
      ) : (
 | 
			
		||||
        <TxUI state={txState} setState={setState} />
 | 
			
		||||
        <TxUI state={txState} setState={setState} estimateFee={estimateFee} />
 | 
			
		||||
      )}
 | 
			
		||||
      <Flex
 | 
			
		||||
        row
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,7 @@ interface JsonProps {
 | 
			
		||||
  header?: string;
 | 
			
		||||
  setState: (pTx?: Partial<TransactionState> | undefined) => void;
 | 
			
		||||
  state: TransactionState;
 | 
			
		||||
  estimateFee?: () => Promise<string | undefined>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
@@ -38,22 +39,37 @@ export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
  setState,
 | 
			
		||||
}) => {
 | 
			
		||||
  const { editorSettings, accounts } = useSnapshot(state);
 | 
			
		||||
  const { editorValue = value, selectedTransaction } = txState;
 | 
			
		||||
  const { editorValue = value, estimatedFee } = txState;
 | 
			
		||||
  const { theme } = useTheme();
 | 
			
		||||
  const [hasUnsaved, setHasUnsaved] = useState(false);
 | 
			
		||||
  const [currTxType, setCurrTxType] = useState<string | undefined>(
 | 
			
		||||
    txState.selectedTransaction?.value
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    setState({ editorValue: value });
 | 
			
		||||
    // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
			
		||||
  }, [value]);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const parsed = parseJSON(editorValue);
 | 
			
		||||
    if (!parsed) return;
 | 
			
		||||
 | 
			
		||||
    const tt = parsed.TransactionType;
 | 
			
		||||
    const tx = transactionsData.find(t => t.TransactionType === tt);
 | 
			
		||||
    if (tx) setCurrTxType(tx.TransactionType);
 | 
			
		||||
    else {
 | 
			
		||||
      setCurrTxType(undefined);
 | 
			
		||||
    }
 | 
			
		||||
  }, [editorValue]);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    if (editorValue === value) setHasUnsaved(false);
 | 
			
		||||
    else setHasUnsaved(true);
 | 
			
		||||
  }, [editorValue, value]);
 | 
			
		||||
 | 
			
		||||
  const saveState = (value: string, txState: TransactionState) => {
 | 
			
		||||
    const tx = prepareState(value, txState);
 | 
			
		||||
  const saveState = (value: string, transactionType?: string) => {
 | 
			
		||||
    const tx = prepareState(value, transactionType);
 | 
			
		||||
    if (tx) setState(tx);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
@@ -68,7 +84,7 @@ export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
  const onExit = (value: string) => {
 | 
			
		||||
    const options = parseJSON(value);
 | 
			
		||||
    if (options) {
 | 
			
		||||
      saveState(value, txState);
 | 
			
		||||
      saveState(value, currTxType);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    showAlert("Error!", {
 | 
			
		||||
@@ -82,9 +98,10 @@ export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
  const path = `file:///${header}`;
 | 
			
		||||
  const monaco = useMonaco();
 | 
			
		||||
 | 
			
		||||
  const getSchemas = useCallback((): any[] => {
 | 
			
		||||
    const tt = selectedTransaction?.value;
 | 
			
		||||
    const txObj = transactionsData.find(td => td.TransactionType === tt);
 | 
			
		||||
  const getSchemas = useCallback(async (): Promise<any[]> => {
 | 
			
		||||
    const txObj = transactionsData.find(
 | 
			
		||||
      td => td.TransactionType === currTxType
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    let genericSchemaProps: any;
 | 
			
		||||
    if (txObj) {
 | 
			
		||||
@@ -98,7 +115,6 @@ export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
        {}
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return [
 | 
			
		||||
      {
 | 
			
		||||
        uri: "file:///main-schema.json", // id of the first schema
 | 
			
		||||
@@ -130,6 +146,9 @@ export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
            Amount: {
 | 
			
		||||
              $ref: "file:///amount-schema.json",
 | 
			
		||||
            },
 | 
			
		||||
            Fee: {
 | 
			
		||||
              $ref: "file:///fee-schema.json",
 | 
			
		||||
            },
 | 
			
		||||
          },
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
@@ -141,17 +160,30 @@ export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
          enum: accounts.map(acc => acc.address),
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        uri: "file:///fee-schema.json",
 | 
			
		||||
        schema: {
 | 
			
		||||
          type: "string",
 | 
			
		||||
          title: "Fee type",
 | 
			
		||||
          const: estimatedFee,
 | 
			
		||||
          description: estimatedFee
 | 
			
		||||
            ? "Above mentioned value is recommended base fee"
 | 
			
		||||
            : undefined,
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        ...amountSchema,
 | 
			
		||||
      },
 | 
			
		||||
    ];
 | 
			
		||||
  }, [accounts, header, selectedTransaction?.value]);
 | 
			
		||||
  }, [accounts, currTxType, estimatedFee, header]);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    if (!monaco) return;
 | 
			
		||||
    monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
 | 
			
		||||
      validate: true,
 | 
			
		||||
      schemas: getSchemas(),
 | 
			
		||||
    getSchemas().then(schemas => {
 | 
			
		||||
      monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
 | 
			
		||||
        validate: true,
 | 
			
		||||
        schemas,
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  }, [getSchemas, monaco]);
 | 
			
		||||
 | 
			
		||||
@@ -184,19 +216,13 @@ export const TxJson: FC<JsonProps> = ({
 | 
			
		||||
          // register onExit cb
 | 
			
		||||
          const model = editor.getModel();
 | 
			
		||||
          model?.onWillDispose(() => onExit(model.getValue()));
 | 
			
		||||
 | 
			
		||||
          // set json defaults
 | 
			
		||||
          monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
 | 
			
		||||
            validate: true,
 | 
			
		||||
            schemas: getSchemas(),
 | 
			
		||||
          });
 | 
			
		||||
        }}
 | 
			
		||||
        theme={theme === "dark" ? "dark" : "light"}
 | 
			
		||||
      />
 | 
			
		||||
      {hasUnsaved && (
 | 
			
		||||
        <Text muted small css={{ position: "absolute", bottom: 0, right: 0 }}>
 | 
			
		||||
          This file has unsaved changes.{" "}
 | 
			
		||||
          <Link onClick={() => saveState(editorValue, txState)}>save</Link>{" "}
 | 
			
		||||
          <Link onClick={() => saveState(editorValue, currTxType)}>save</Link>{" "}
 | 
			
		||||
          <Link onClick={discardChanges}>discard</Link>
 | 
			
		||||
        </Text>
 | 
			
		||||
      )}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
import { FC } from "react";
 | 
			
		||||
import { FC, useCallback, useState } from "react";
 | 
			
		||||
import Container from "../Container";
 | 
			
		||||
import Flex from "../Flex";
 | 
			
		||||
import Input from "../Input";
 | 
			
		||||
@@ -9,17 +9,26 @@ import {
 | 
			
		||||
  TransactionState,
 | 
			
		||||
  transactionsData,
 | 
			
		||||
  TxFields,
 | 
			
		||||
  getTxFields,
 | 
			
		||||
} from "../../state/transactions";
 | 
			
		||||
import { useSnapshot } from "valtio";
 | 
			
		||||
import state from "../../state";
 | 
			
		||||
import { streamState } from "../DebugStream";
 | 
			
		||||
import { Button } from "..";
 | 
			
		||||
 | 
			
		||||
interface UIProps {
 | 
			
		||||
  setState: (pTx?: Partial<TransactionState> | undefined) => void;
 | 
			
		||||
  setState: (
 | 
			
		||||
    pTx?: Partial<TransactionState> | undefined
 | 
			
		||||
  ) => TransactionState | undefined;
 | 
			
		||||
  state: TransactionState;
 | 
			
		||||
  estimateFee?: (...arg: any) => Promise<string | undefined>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const TxUI: FC<UIProps> = ({ state: txState, setState }) => {
 | 
			
		||||
export const TxUI: FC<UIProps> = ({
 | 
			
		||||
  state: txState,
 | 
			
		||||
  setState,
 | 
			
		||||
  estimateFee,
 | 
			
		||||
}) => {
 | 
			
		||||
  const { accounts } = useSnapshot(state);
 | 
			
		||||
  const {
 | 
			
		||||
    selectedAccount,
 | 
			
		||||
@@ -45,32 +54,54 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState }) => {
 | 
			
		||||
    }))
 | 
			
		||||
    .filter(acc => acc.value !== selectedAccount?.value);
 | 
			
		||||
 | 
			
		||||
  const resetOptions = (tt: string) => {
 | 
			
		||||
    const txFields: TxFields | undefined = transactionsData.find(
 | 
			
		||||
      tx => tx.TransactionType === tt
 | 
			
		||||
    );
 | 
			
		||||
  const [feeLoading, setFeeLoading] = useState(false);
 | 
			
		||||
 | 
			
		||||
    if (!txFields) return setState({ txFields: {} });
 | 
			
		||||
 | 
			
		||||
    const _txFields = Object.keys(txFields)
 | 
			
		||||
      .filter(key => !["TransactionType", "Account", "Sequence"].includes(key))
 | 
			
		||||
      .reduce<TxFields>(
 | 
			
		||||
        (tf, key) => ((tf[key as keyof TxFields] = (txFields as any)[key]), tf),
 | 
			
		||||
        {}
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
    if (!_txFields.Destination) setState({ selectedDestAccount: null });
 | 
			
		||||
    setState({ txFields: _txFields });
 | 
			
		||||
  };
 | 
			
		||||
  const resetOptions = useCallback(
 | 
			
		||||
    (tt: string) => {
 | 
			
		||||
      const fields = getTxFields(tt);
 | 
			
		||||
      if (!fields.Destination) setState({ selectedDestAccount: null });
 | 
			
		||||
      return setState({ txFields: fields });
 | 
			
		||||
    },
 | 
			
		||||
    [setState]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const handleSetAccount = (acc: SelectOption) => {
 | 
			
		||||
    setState({ selectedAccount: acc });
 | 
			
		||||
    streamState.selectedAccount = acc;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const handleSetField = useCallback(
 | 
			
		||||
    (field: keyof TxFields, value: string, opFields?: TxFields) => {
 | 
			
		||||
      const fields = opFields || txFields;
 | 
			
		||||
      const obj = fields[field];
 | 
			
		||||
      setState({
 | 
			
		||||
        txFields: {
 | 
			
		||||
          ...fields,
 | 
			
		||||
          [field]: typeof obj === "object" ? { ...obj, $value: value } : value,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
    [setState, txFields]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const handleEstimateFee = useCallback(
 | 
			
		||||
    async (state?: TransactionState, silent?: boolean) => {
 | 
			
		||||
      setFeeLoading(true);
 | 
			
		||||
 | 
			
		||||
      const fee = await estimateFee?.(state, { silent });
 | 
			
		||||
      if (fee) handleSetField("Fee", fee, state?.txFields);
 | 
			
		||||
 | 
			
		||||
      setFeeLoading(false);
 | 
			
		||||
    },
 | 
			
		||||
    [estimateFee, handleSetField]
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const handleChangeTxType = (tt: SelectOption) => {
 | 
			
		||||
    setState({ selectedTransaction: tt });
 | 
			
		||||
    resetOptions(tt.value);
 | 
			
		||||
 | 
			
		||||
    const newState = resetOptions(tt.value);
 | 
			
		||||
 | 
			
		||||
    handleEstimateFee(newState, true);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const specialFields = ["TransactionType", "Account", "Destination"];
 | 
			
		||||
@@ -87,7 +118,7 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState }) => {
 | 
			
		||||
        height: "calc(100% - 45px)",
 | 
			
		||||
      }}
 | 
			
		||||
    >
 | 
			
		||||
      <Flex column fluid css={{ height: "100%", overflowY: "auto" }}>
 | 
			
		||||
      <Flex column fluid css={{ height: "100%", overflowY: "auto", pr: "$1" }}>
 | 
			
		||||
        <Flex
 | 
			
		||||
          row
 | 
			
		||||
          fluid
 | 
			
		||||
@@ -174,36 +205,49 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState }) => {
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          let isXrp = typeof _value === "object" && _value.$type === "xrp";
 | 
			
		||||
 | 
			
		||||
          const isFee = field === "Fee";
 | 
			
		||||
          return (
 | 
			
		||||
            <Flex
 | 
			
		||||
              key={field}
 | 
			
		||||
              row
 | 
			
		||||
              fluid
 | 
			
		||||
              css={{
 | 
			
		||||
                justifyContent: "flex-end",
 | 
			
		||||
                alignItems: "center",
 | 
			
		||||
                mb: "$3",
 | 
			
		||||
                pr: "1px",
 | 
			
		||||
              }}
 | 
			
		||||
            >
 | 
			
		||||
              <Text muted css={{ mr: "$3" }}>
 | 
			
		||||
                {field + (isXrp ? " (XRP)" : "")}:{" "}
 | 
			
		||||
              </Text>
 | 
			
		||||
              <Input
 | 
			
		||||
                value={value}
 | 
			
		||||
                onChange={e => {
 | 
			
		||||
                  setState({
 | 
			
		||||
                    txFields: {
 | 
			
		||||
                      ...txFields,
 | 
			
		||||
                      [field]:
 | 
			
		||||
                        typeof _value === "object"
 | 
			
		||||
                          ? { ..._value, $value: e.target.value }
 | 
			
		||||
                          : e.target.value,
 | 
			
		||||
                    },
 | 
			
		||||
                  });
 | 
			
		||||
            <Flex column key={field} css={{ mb: "$2", pr: "1px" }}>
 | 
			
		||||
              <Flex
 | 
			
		||||
                row
 | 
			
		||||
                fluid
 | 
			
		||||
                css={{
 | 
			
		||||
                  justifyContent: "flex-end",
 | 
			
		||||
                  alignItems: "center",
 | 
			
		||||
                  position: "relative",
 | 
			
		||||
                }}
 | 
			
		||||
                css={{ width: "70%", flex: "inherit" }}
 | 
			
		||||
              />
 | 
			
		||||
              >
 | 
			
		||||
                <Text muted css={{ mr: "$3" }}>
 | 
			
		||||
                  {field + (isXrp ? " (XRP)" : "")}:{" "}
 | 
			
		||||
                </Text>
 | 
			
		||||
                <Input
 | 
			
		||||
                  value={value}
 | 
			
		||||
                  onChange={e => {
 | 
			
		||||
                    handleSetField(field, e.target.value);
 | 
			
		||||
                  }}
 | 
			
		||||
                  css={{ width: "70%", flex: "inherit" }}
 | 
			
		||||
                />
 | 
			
		||||
                {isFee && (
 | 
			
		||||
                  <Button
 | 
			
		||||
                    size="xs"
 | 
			
		||||
                    variant="primary"
 | 
			
		||||
                    outline
 | 
			
		||||
                    isLoading={feeLoading}
 | 
			
		||||
                    css={{
 | 
			
		||||
                      position: "absolute",
 | 
			
		||||
                      right: "$2",
 | 
			
		||||
                      fontSize: "$xs",
 | 
			
		||||
                      cursor: "pointer",
 | 
			
		||||
                      alignContent: "center",
 | 
			
		||||
                      display: "flex",
 | 
			
		||||
                    }}
 | 
			
		||||
                    onClick={() => handleEstimateFee()}
 | 
			
		||||
                  >
 | 
			
		||||
                    Suggest
 | 
			
		||||
                  </Button>
 | 
			
		||||
                )}
 | 
			
		||||
              </Flex>
 | 
			
		||||
            </Flex>
 | 
			
		||||
          );
 | 
			
		||||
        })}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										40
									
								
								components/icons/Carbon.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								components/icons/Carbon.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
const Carbon = () => (
 | 
			
		||||
  <svg
 | 
			
		||||
    width="66"
 | 
			
		||||
    height="32"
 | 
			
		||||
    viewBox="0 0 66 32"
 | 
			
		||||
    fill="none"
 | 
			
		||||
    xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
  >
 | 
			
		||||
    <path
 | 
			
		||||
      d="M33 2L23 15H28L21 24H45L38 15H43L33 2Z"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M33 24V30"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M-1.14441e-05 4L8.94099 15.0625L4.00543e-05 26.125H2.27587L10.5015 15.9475H16.5938V14.1775H10.5015L2.27582 4H-1.14441e-05Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M66 4L57.059 15.0625L66 26.125H63.7241L55.4985 15.9475H49.4062V14.1775H55.4985L63.7242 4H66Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
  </svg>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export default Carbon;
 | 
			
		||||
							
								
								
									
										75
									
								
								components/icons/Firewall.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								components/icons/Firewall.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
			
		||||
const Firewall = () => (
 | 
			
		||||
  <svg
 | 
			
		||||
    width="66"
 | 
			
		||||
    height="32"
 | 
			
		||||
    viewBox="0 0 66 32"
 | 
			
		||||
    fill="none"
 | 
			
		||||
    xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
  >
 | 
			
		||||
    <path
 | 
			
		||||
      d="M33 13V7"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M27 19V13"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M39 19V13"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M33 25V19"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M21 13H45"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M21 19H45"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M45 7H21V25H45V7Z"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M-1.14441e-05 4.875L8.94099 15.9375L4.00543e-05 27H2.27587L10.5015 16.8225H16.5938V15.0525H10.5015L2.27582 4.875H-1.14441e-05Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M66 4.875L57.059 15.9375L66 27H63.7241L55.4985 16.8225H49.4062V15.0525H55.4985L63.7242 4.875H66Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
  </svg>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export default Firewall;
 | 
			
		||||
							
								
								
									
										40
									
								
								components/icons/Notary.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								components/icons/Notary.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
const Notary = () => (
 | 
			
		||||
  <svg
 | 
			
		||||
    width="66"
 | 
			
		||||
    height="32"
 | 
			
		||||
    viewBox="0 0 66 32"
 | 
			
		||||
    fill="none"
 | 
			
		||||
    xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
  >
 | 
			
		||||
    <path
 | 
			
		||||
      d="M37.5 10.5L26.5 21.5L21 16.0002"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M49 10.5L38 21.5L35.0784 18.5785"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M-1.14441e-05 5L8.94099 16.0625L4.00543e-05 27.125H2.27587L10.5015 16.9475H16.5938V15.1775H10.5015L2.27582 5H-1.14441e-05Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M66 5L57.059 16.0625L66 27.125H63.7241L55.4985 16.9475H49.4062V15.1775H55.4985L63.7242 5H66Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
  </svg>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export default Notary;
 | 
			
		||||
							
								
								
									
										61
									
								
								components/icons/Peggy.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								components/icons/Peggy.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
const Peggy = () => (
 | 
			
		||||
  <svg
 | 
			
		||||
    width="66"
 | 
			
		||||
    height="32"
 | 
			
		||||
    viewBox="0 0 66 32"
 | 
			
		||||
    fill="none"
 | 
			
		||||
    xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
  >
 | 
			
		||||
    <path
 | 
			
		||||
      d="M33 19C40.1797 19 46 16.3137 46 13C46 9.68629 40.1797 7 33 7C25.8203 7 20 9.68629 20 13C20 16.3137 25.8203 19 33 19Z"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M33 19V25"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M20 13V19C20 22 25 25 33 25C41 25 46 22 46 19V13"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M41 17.7633V23.7634"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M25 17.7633V23.7634"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M-1.14441e-05 4L8.94099 15.0625L4.00543e-05 26.125H2.27587L10.5015 15.9475H16.5938V14.1775H10.5015L2.27582 4H-1.14441e-05Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M66 4L57.059 15.0625L66 26.125H63.7241L55.4985 15.9475H49.4062V14.1775H55.4985L63.7242 4H66Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
  </svg>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export default Peggy;
 | 
			
		||||
							
								
								
									
										40
									
								
								components/icons/Starter.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								components/icons/Starter.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
const Starter = () => (
 | 
			
		||||
  <svg
 | 
			
		||||
    width="66"
 | 
			
		||||
    height="32"
 | 
			
		||||
    viewBox="0 0 66 32"
 | 
			
		||||
    fill="none"
 | 
			
		||||
    xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
  >
 | 
			
		||||
    <path
 | 
			
		||||
      d="M42 28H24C23.7347 28 23.4804 27.8946 23.2929 27.7071C23.1053 27.5196 23 27.2652 23 27V5C23 4.73479 23.1053 4.48044 23.2929 4.2929C23.4804 4.10537 23.7347 4.00001 24 4H36.0003L43 11V27C43 27.2652 42.8947 27.5196 42.7071 27.7071C42.5196 27.8946 42.2653 28 42 28V28Z"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      d="M36 4V11H43.001"
 | 
			
		||||
      stroke="#EDEDEF"
 | 
			
		||||
      strokeWidth="1.5"
 | 
			
		||||
      strokeLinecap="round"
 | 
			
		||||
      strokeLinejoin="round"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M-1.14441e-05 4.875L8.94099 15.9375L4.00543e-05 27H2.27587L10.5015 16.8225H16.5938V15.0525H10.5015L2.27582 4.875H-1.14441e-05Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
    <path
 | 
			
		||||
      className="angle"
 | 
			
		||||
      fillRule="evenodd"
 | 
			
		||||
      clipRule="evenodd"
 | 
			
		||||
      d="M66 4.875L57.059 15.9375L66 27H63.7241L55.4985 16.8225H49.4062V15.0525H55.4985L63.7242 4.875H66Z"
 | 
			
		||||
      fill="#EDEDEF"
 | 
			
		||||
    />
 | 
			
		||||
  </svg>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export default Starter;
 | 
			
		||||
							
								
								
									
										12057
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										12057
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -16,7 +16,7 @@ import state from "../state";
 | 
			
		||||
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 Alert from "../components/AlertDialog";
 | 
			
		||||
 | 
			
		||||
TimeAgo.setDefaultLocale(en.locale);
 | 
			
		||||
TimeAgo.addLocale(en);
 | 
			
		||||
@@ -61,22 +61,22 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
 | 
			
		||||
        <meta name="format-detection" content="telephone=no" />
 | 
			
		||||
        <meta property="og:url" content={`${origin}${router.asPath}`} />
 | 
			
		||||
 | 
			
		||||
        <title>XRPL Hooks Editor</title>
 | 
			
		||||
        <meta property="og:title" content="XRPL Hooks Editor" />
 | 
			
		||||
        <meta name="twitter:title" content="XRPL Hooks Editor" />
 | 
			
		||||
        <title>XRPL Hooks Builder</title>
 | 
			
		||||
        <meta property="og:title" content="XRPL Hooks Builder" />
 | 
			
		||||
        <meta name="twitter:title" content="XRPL Hooks Builder" />
 | 
			
		||||
        <meta name="twitter:card" content="summary_large_image" />
 | 
			
		||||
        <meta name="twitter:site" content="@xrpllabs" />
 | 
			
		||||
        <meta name="twitter:site" content="@XRPLF" />
 | 
			
		||||
        <meta
 | 
			
		||||
          name="description"
 | 
			
		||||
          content="Playground for buildings Hooks, that add smart contract functionality to the XRP Ledger."
 | 
			
		||||
          content="Hooks Builder, add smart contract functionality to the XRP Ledger."
 | 
			
		||||
        />
 | 
			
		||||
        <meta
 | 
			
		||||
          property="og:description"
 | 
			
		||||
          content="Playground for buildings Hooks, that add smart contract functionality to the XRP Ledger."
 | 
			
		||||
          content="Hooks Builder, add smart contract functionality to the XRP Ledger."
 | 
			
		||||
        />
 | 
			
		||||
        <meta
 | 
			
		||||
          name="twitter:description"
 | 
			
		||||
          content="Playground for buildings Hooks, that add smart contract functionality to the XRP Ledger.."
 | 
			
		||||
          content="Hooks Builder, add smart contract functionality to the XRP Ledger."
 | 
			
		||||
        />
 | 
			
		||||
        <meta property="og:image" content={`${origin}${shareImg}`} />
 | 
			
		||||
        <meta property="og:image:width" content="1200" />
 | 
			
		||||
@@ -101,7 +101,7 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
 | 
			
		||||
        />
 | 
			
		||||
        <link rel="manifest" href="/site.webmanifest" />
 | 
			
		||||
        <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#161618" />
 | 
			
		||||
        <meta name="application-name" content="XRPL Hooks Editor" />
 | 
			
		||||
        <meta name="application-name" content="XRPL Hooks Builder" />
 | 
			
		||||
        <meta name="msapplication-TileColor" content="#c10ad0" />
 | 
			
		||||
        <meta
 | 
			
		||||
          name="theme-color"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
import { Label } from "@radix-ui/react-label";
 | 
			
		||||
import { Switch, SwitchThumb } from "../../components/Switch";
 | 
			
		||||
import type { NextPage } from "next";
 | 
			
		||||
import dynamic from "next/dynamic";
 | 
			
		||||
import { Gear, Play } from "phosphor-react";
 | 
			
		||||
@@ -141,59 +140,6 @@ const CompilerSettings = () => {
 | 
			
		||||
          </Button>
 | 
			
		||||
        </ButtonGroup>
 | 
			
		||||
      </Box>
 | 
			
		||||
      <Box css={{ flexDirection: "column" }}>
 | 
			
		||||
        <Label
 | 
			
		||||
          style={{
 | 
			
		||||
            flexDirection: "row",
 | 
			
		||||
            display: "flex",
 | 
			
		||||
          }}
 | 
			
		||||
        >
 | 
			
		||||
          Clean WASM (experimental){" "}
 | 
			
		||||
          <Popover
 | 
			
		||||
            css={{
 | 
			
		||||
              maxWidth: "240px",
 | 
			
		||||
              lineHeight: "1.3",
 | 
			
		||||
              a: {
 | 
			
		||||
                color: "$purple11",
 | 
			
		||||
              },
 | 
			
		||||
              ".dark &": {
 | 
			
		||||
                backgroundColor: "$black !important",
 | 
			
		||||
 | 
			
		||||
                ".arrow": {
 | 
			
		||||
                  fill: "$colors$black",
 | 
			
		||||
                },
 | 
			
		||||
              },
 | 
			
		||||
            }}
 | 
			
		||||
            content="Cleaner removes unwanted compiler-provided exports and functions from a wasm binary to make it (more) suitable for being used as a Hook"
 | 
			
		||||
          >
 | 
			
		||||
            <Flex
 | 
			
		||||
              css={{
 | 
			
		||||
                position: "relative",
 | 
			
		||||
                top: "-1px",
 | 
			
		||||
                mx: "$1",
 | 
			
		||||
                backgroundColor: "$mauve8",
 | 
			
		||||
                borderRadius: "$full",
 | 
			
		||||
                cursor: "pointer",
 | 
			
		||||
                width: "16px",
 | 
			
		||||
                height: "16px",
 | 
			
		||||
                alignItems: "center",
 | 
			
		||||
                justifyContent: "center",
 | 
			
		||||
              }}
 | 
			
		||||
            >
 | 
			
		||||
              ?
 | 
			
		||||
            </Flex>
 | 
			
		||||
          </Popover>
 | 
			
		||||
        </Label>
 | 
			
		||||
        <Switch
 | 
			
		||||
          css={{ mt: "$2" }}
 | 
			
		||||
          checked={snap.compileOptions.strip}
 | 
			
		||||
          onCheckedChange={(checked) => {
 | 
			
		||||
            state.compileOptions.strip = checked;
 | 
			
		||||
          }}
 | 
			
		||||
        >
 | 
			
		||||
          <SwitchThumb />
 | 
			
		||||
        </Switch>
 | 
			
		||||
      </Box>
 | 
			
		||||
    </Flex>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -6,13 +6,14 @@ import calculateHookOn, { TTS } from "../../utils/hookOnCalculator";
 | 
			
		||||
import { SetHookData } from "../../components/SetHookDialog";
 | 
			
		||||
import { Link } from "../../components";
 | 
			
		||||
import { ref } from "valtio";
 | 
			
		||||
import estimateFee from "../../utils/estimateFee";
 | 
			
		||||
 | 
			
		||||
export const sha256 = async (string: string) => {
 | 
			
		||||
  const utf8 = new TextEncoder().encode(string);
 | 
			
		||||
  const hashBuffer = await crypto.subtle.digest("SHA-256", utf8);
 | 
			
		||||
  const hashArray = Array.from(new Uint8Array(hashBuffer));
 | 
			
		||||
  const hashHex = hashArray
 | 
			
		||||
    .map(bytes => bytes.toString(16).padStart(2, "0"))
 | 
			
		||||
    .map((bytes) => bytes.toString(16).padStart(2, "0"))
 | 
			
		||||
    .join("");
 | 
			
		||||
  return hashHex;
 | 
			
		||||
};
 | 
			
		||||
@@ -49,11 +50,7 @@ function arrayBufferToHex(arrayBuffer?: ArrayBuffer | null) {
 | 
			
		||||
  return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* deployHook function turns the wasm binary into
 | 
			
		||||
 * hex string, signs the transaction and deploys it to
 | 
			
		||||
 * Hooks testnet.
 | 
			
		||||
 */
 | 
			
		||||
export const deployHook = async (
 | 
			
		||||
export const prepareDeployHookTx = async (
 | 
			
		||||
  account: IAccount & { name?: string },
 | 
			
		||||
  data: SetHookData
 | 
			
		||||
) => {
 | 
			
		||||
@@ -72,12 +69,12 @@ export const deployHook = async (
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  const HookNamespace = (await sha256(data.HookNamespace)).toUpperCase();
 | 
			
		||||
  const hookOnValues: (keyof TTS)[] = data.Invoke.map(tt => tt.value);
 | 
			
		||||
  const hookOnValues: (keyof TTS)[] = data.Invoke.map((tt) => tt.value);
 | 
			
		||||
  const { HookParameters } = data;
 | 
			
		||||
  const filteredHookParameters = HookParameters.filter(
 | 
			
		||||
    hp =>
 | 
			
		||||
    (hp) =>
 | 
			
		||||
      hp.HookParameter.HookParameterName && hp.HookParameter.HookParameterValue
 | 
			
		||||
  )?.map(aa => ({
 | 
			
		||||
  )?.map((aa) => ({
 | 
			
		||||
    HookParameter: {
 | 
			
		||||
      HookParameterName: toHex(aa.HookParameter.HookParameterName || ""),
 | 
			
		||||
      HookParameterValue: aa.HookParameter.HookParameterValue || "",
 | 
			
		||||
@@ -92,13 +89,12 @@ export const deployHook = async (
 | 
			
		||||
  //     }
 | 
			
		||||
  //   }
 | 
			
		||||
  // });
 | 
			
		||||
 | 
			
		||||
  if (typeof window !== "undefined") {
 | 
			
		||||
    const tx = {
 | 
			
		||||
      Account: account.address,
 | 
			
		||||
      TransactionType: "SetHook",
 | 
			
		||||
      Sequence: account.sequence,
 | 
			
		||||
      Fee: "100000",
 | 
			
		||||
      Fee: data.Fee,
 | 
			
		||||
      Hooks: [
 | 
			
		||||
        {
 | 
			
		||||
          Hook: {
 | 
			
		||||
@@ -117,18 +113,39 @@ export const deployHook = async (
 | 
			
		||||
        },
 | 
			
		||||
      ],
 | 
			
		||||
    };
 | 
			
		||||
    return tx;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* deployHook function turns the wasm binary into
 | 
			
		||||
 * hex string, signs the transaction and deploys it to
 | 
			
		||||
 * Hooks testnet.
 | 
			
		||||
 */
 | 
			
		||||
export const deployHook = async (
 | 
			
		||||
  account: IAccount & { name?: string },
 | 
			
		||||
  data: SetHookData
 | 
			
		||||
) => {
 | 
			
		||||
  if (typeof window !== "undefined") {
 | 
			
		||||
    const tx = await prepareDeployHookTx(account, data);
 | 
			
		||||
    if (!tx) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    if (!state.client) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    const keypair = derive.familySeed(account.secret);
 | 
			
		||||
 | 
			
		||||
    const { signedTransaction } = sign(tx, keypair);
 | 
			
		||||
    const currentAccount = state.accounts.find(
 | 
			
		||||
      acc => acc.address === account.address
 | 
			
		||||
      (acc) => acc.address === account.address
 | 
			
		||||
    );
 | 
			
		||||
    if (currentAccount) {
 | 
			
		||||
      currentAccount.isLoading = true;
 | 
			
		||||
    }
 | 
			
		||||
    let submitRes;
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      submitRes = await state.client.send({
 | 
			
		||||
      submitRes = await state.client?.send({
 | 
			
		||||
        command: "submit",
 | 
			
		||||
        tx_blob: signedTransaction,
 | 
			
		||||
      });
 | 
			
		||||
@@ -143,14 +160,14 @@ export const deployHook = async (
 | 
			
		||||
          message: ref(
 | 
			
		||||
            <>
 | 
			
		||||
              [{submitRes.engine_result}] {submitRes.engine_result_message}{" "}
 | 
			
		||||
              Validated ledger index:{" "}
 | 
			
		||||
              Transaction hash:{" "}
 | 
			
		||||
              <Link
 | 
			
		||||
                as="a"
 | 
			
		||||
                href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${submitRes.validated_ledger_index}`}
 | 
			
		||||
                href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${submitRes.tx_json?.hash}`}
 | 
			
		||||
                target="_blank"
 | 
			
		||||
                rel="noopener noreferrer"
 | 
			
		||||
              >
 | 
			
		||||
                {submitRes.validated_ledger_index}
 | 
			
		||||
                {submitRes.tx_json?.hash}
 | 
			
		||||
              </Link>
 | 
			
		||||
            </>
 | 
			
		||||
          ),
 | 
			
		||||
@@ -183,7 +200,7 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  const currentAccount = state.accounts.find(
 | 
			
		||||
    acc => acc.address === account.address
 | 
			
		||||
    (acc) => acc.address === account.address
 | 
			
		||||
  );
 | 
			
		||||
  if (currentAccount?.isLoading || !currentAccount?.hooks.length) {
 | 
			
		||||
    return;
 | 
			
		||||
@@ -205,6 +222,14 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const keypair = derive.familySeed(account.secret);
 | 
			
		||||
    try {
 | 
			
		||||
      // Update tx Fee value with network estimation
 | 
			
		||||
      const res = await estimateFee(tx, account);
 | 
			
		||||
      tx["Fee"] = res?.base_fee ? res?.base_fee : "1000";
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
      // use default value what you defined earlier
 | 
			
		||||
      console.log(err);
 | 
			
		||||
    }
 | 
			
		||||
    const { signedTransaction } = sign(tx, keypair);
 | 
			
		||||
 | 
			
		||||
    if (currentAccount) {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,14 +20,11 @@ export const sendTransaction = async (account: IAccount, txOptions: TransactionO
 | 
			
		||||
    const { Fee = "1000", ...opts } = txOptions
 | 
			
		||||
    const tx: TransactionOptions = {
 | 
			
		||||
        Account: account.address,
 | 
			
		||||
        Sequence: account.sequence, // TODO auto-fillable
 | 
			
		||||
        Fee,  // TODO auto-fillable
 | 
			
		||||
        Sequence: account.sequence,
 | 
			
		||||
        Fee,  // TODO auto-fillable default
 | 
			
		||||
        ...opts
 | 
			
		||||
    };
 | 
			
		||||
    const currAcc = state.accounts.find(acc => acc.address === account.address);
 | 
			
		||||
    if (currAcc) {
 | 
			
		||||
        currAcc.sequence = account.sequence + 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const { logPrefix = '' } = options || {}
 | 
			
		||||
    try {
 | 
			
		||||
        const signedAccount = derive.familySeed(account.secret);
 | 
			
		||||
@@ -47,6 +44,10 @@ export const sendTransaction = async (account: IAccount, txOptions: TransactionO
 | 
			
		||||
                message: `${logPrefix}[${response.error || response.engine_result}] ${response.error_exception || response.engine_result_message}`,
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        const currAcc = state.accounts.find(acc => acc.address === account.address);
 | 
			
		||||
        if (currAcc && response.account_sequence_next) {
 | 
			
		||||
            currAcc.sequence = response.account_sequence_next;
 | 
			
		||||
        }
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
        console.error(err);
 | 
			
		||||
        state.transactionLogs.push({
 | 
			
		||||
 
 | 
			
		||||
@@ -35,6 +35,10 @@ export interface IAccount {
 | 
			
		||||
  hooks: string[];
 | 
			
		||||
  isLoading: boolean;
 | 
			
		||||
  version?: string;
 | 
			
		||||
  error?: {
 | 
			
		||||
    message: string;
 | 
			
		||||
    code: string;
 | 
			
		||||
  } | null;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ILog {
 | 
			
		||||
@@ -109,7 +113,7 @@ let initialState: IState = {
 | 
			
		||||
  accounts: [],
 | 
			
		||||
  compileOptions: {
 | 
			
		||||
    optimizationLevel: '-O0',
 | 
			
		||||
    strip: false
 | 
			
		||||
    strip: true
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,8 @@ export interface TransactionState {
 | 
			
		||||
    txFields: TxFields;
 | 
			
		||||
    viewType: 'json' | 'ui',
 | 
			
		||||
    editorSavedValue: null | string,
 | 
			
		||||
    editorValue?: string
 | 
			
		||||
    editorValue?: string,
 | 
			
		||||
    estimatedFee?: string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -93,7 +94,7 @@ export const modifyTransaction = (
 | 
			
		||||
    Object.keys(partialTx).forEach(k => {
 | 
			
		||||
        // Typescript mess here, but is definetly safe!
 | 
			
		||||
        const s = tx.state as any;
 | 
			
		||||
        const p = partialTx as any;
 | 
			
		||||
        const p = partialTx as any; // ? Make copy
 | 
			
		||||
        if (!deepEqual(s[k], p[k])) s[k] = p[k];
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@@ -140,7 +141,7 @@ export const prepareTransaction = (data: any) => {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// editor value to state
 | 
			
		||||
export const prepareState = (value: string, txState: TransactionState) => {
 | 
			
		||||
export const prepareState = (value: string, transactionType?: string) => {
 | 
			
		||||
    const options = parseJSON(value);
 | 
			
		||||
    if (!options) {
 | 
			
		||||
        showAlert("Error!", {
 | 
			
		||||
@@ -151,7 +152,7 @@ export const prepareState = (value: string, txState: TransactionState) => {
 | 
			
		||||
 | 
			
		||||
    const { Account, TransactionType, Destination, ...rest } = options;
 | 
			
		||||
    let tx: Partial<TransactionState> = {};
 | 
			
		||||
    const { txFields } = txState
 | 
			
		||||
    const txFields = getTxFields(transactionType)
 | 
			
		||||
 | 
			
		||||
    if (Account) {
 | 
			
		||||
        const acc = state.accounts.find(acc => acc.address === Account);
 | 
			
		||||
@@ -206,7 +207,7 @@ export const prepareState = (value: string, txState: TransactionState) => {
 | 
			
		||||
        if (isXrp) {
 | 
			
		||||
            rest[field] = {
 | 
			
		||||
                $type: "xrp",
 | 
			
		||||
                $value: +value / 1000000, // TODO maybe use bigint?
 | 
			
		||||
                $value: +value / 1000000, // ! maybe use bigint?
 | 
			
		||||
            };
 | 
			
		||||
        } else if (typeof value === "object") {
 | 
			
		||||
            rest[field] = {
 | 
			
		||||
@@ -222,4 +223,24 @@ export const prepareState = (value: string, txState: TransactionState) => {
 | 
			
		||||
    return tx
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const getTxFields = (tt?: string) => {
 | 
			
		||||
    const txFields: TxFields | undefined = transactionsData.find(
 | 
			
		||||
        tx => tx.TransactionType === tt
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (!txFields) return {}
 | 
			
		||||
 | 
			
		||||
    let _txFields = Object.keys(txFields)
 | 
			
		||||
        .filter(
 | 
			
		||||
            key => !["TransactionType", "Account", "Sequence"].includes(key)
 | 
			
		||||
        )
 | 
			
		||||
        .reduce<TxFields>(
 | 
			
		||||
            (tf, key) => (
 | 
			
		||||
                (tf[key as keyof TxFields] = (txFields as any)[key]), tf
 | 
			
		||||
            ),
 | 
			
		||||
            {}
 | 
			
		||||
        );
 | 
			
		||||
    return _txFields
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { transactionsData }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										30
									
								
								utils/estimateFee.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								utils/estimateFee.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
import toast from 'react-hot-toast';
 | 
			
		||||
import { derive, sign } from "xrpl-accountlib"
 | 
			
		||||
import state, { IAccount } from "../state"
 | 
			
		||||
 | 
			
		||||
const estimateFee = async (tx: Record<string, unknown>, account: IAccount, opts: { silent?: boolean } = {}): Promise<null | { base_fee: string, median_fee: string; minimum_fee: string; open_ledger_fee: string; }> => {
 | 
			
		||||
  try {
 | 
			
		||||
    const copyTx = JSON.parse(JSON.stringify(tx))
 | 
			
		||||
    delete copyTx['SigningPubKey']
 | 
			
		||||
    if (!copyTx.Fee) {
 | 
			
		||||
      copyTx.Fee = '1000'
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    const keypair = derive.familySeed(account.secret)
 | 
			
		||||
    const { signedTransaction } = sign(copyTx, keypair);
 | 
			
		||||
 | 
			
		||||
    const res = await state.client?.send({ command: 'fee', tx_blob: signedTransaction })
 | 
			
		||||
    if (res && res.drops) {
 | 
			
		||||
      return res.drops;
 | 
			
		||||
    }
 | 
			
		||||
    return null
 | 
			
		||||
  } catch (err) {
 | 
			
		||||
    if (!opts.silent) {
 | 
			
		||||
      console.error(err)
 | 
			
		||||
      toast.error("Cannot estimate fee.") // ? Some better msg
 | 
			
		||||
    }
 | 
			
		||||
    return null
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default estimateFee
 | 
			
		||||
@@ -41,6 +41,7 @@ import hooksSkipHashBufLen from "./md/hooks-skip-hash-buf-len.md";
 | 
			
		||||
import hooksStateBufLen from "./md/hooks-state-buf-len.md";
 | 
			
		||||
import hooksTransactionHashBufLen from "./md/hooks-transaction-hash-buf-len.md";
 | 
			
		||||
import hooksTransactionSlotLimit from "./md/hooks-transaction-slot-limit.md";
 | 
			
		||||
import hooksTrivialCbak from "./md/hooks-trivial-cbak.md";
 | 
			
		||||
import hooksValidateBufLen from "./md/hooks-validate-buf-len.md";
 | 
			
		||||
import hooksVerifyBufLen from "./md/hooks-verify-buf-len.md";
 | 
			
		||||
 | 
			
		||||
@@ -90,6 +91,7 @@ const docs: { [key: string]: string; } = {
 | 
			
		||||
  "hooks-state-buf-len": hooksStateBufLen,
 | 
			
		||||
  "hooks-transaction-hash-buf-len": hooksTransactionHashBufLen,
 | 
			
		||||
  "hooks-transaction-slot-limit": hooksTransactionSlotLimit,
 | 
			
		||||
  "hooks-trivial-cbak": hooksTrivialCbak,
 | 
			
		||||
  "hooks-validate-buf-len": hooksValidateBufLen,
 | 
			
		||||
  "hooks-verify-buf-len": hooksVerifyBufLen,
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
# hooks-entry-points
 | 
			
		||||
 | 
			
		||||
A Hook always implements and exports exactly two functions: [cbak](https://xrpl-hooks.readme.io/v2.0/reference/cbak) and [hook](https://xrpl-hooks.readme.io/v2.0/reference/hook).
 | 
			
		||||
A Hook always implements and exports a [hook](https://xrpl-hooks.readme.io/v2.0/reference/hook) function.
 | 
			
		||||
 | 
			
		||||
This check shows error on translation units that do not have them.
 | 
			
		||||
This check shows error on translation units that do not have it.
 | 
			
		||||
 | 
			
		||||
[Read more](https://xrpl-hooks.readme.io/v2.0/docs/compiling-hooks)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
# hooks-hash-buf-len
 | 
			
		||||
 | 
			
		||||
Functions [util_sha512h](https://xrpl-hooks.readme.io/v2.0/reference/util_sha512h), [hook_hash](https://xrpl-hooks.readme.io/v2.0/reference/hook_hash), [ledger_last_hash](https://xrpl-hooks.readme.io/v2.0/reference/ledger_last_hash) and [nonce](https://xrpl-hooks.readme.io/v2.0/reference/nonce) have fixed-size hash output.
 | 
			
		||||
Functions [util_sha512h](https://xrpl-hooks.readme.io/v2.0/reference/util_sha512h), [hook_hash](https://xrpl-hooks.readme.io/v2.0/reference/hook_hash), [ledger_last_hash](https://xrpl-hooks.readme.io/v2.0/reference/ledger_last_hash), [etxn_nonce](https://xrpl-hooks.readme.io/v2.0/reference/etxn_nonce) and [ledger_nonce](https://xrpl-hooks.readme.io/v2.0/reference/ledger_nonce) have fixed-size hash output.
 | 
			
		||||
 | 
			
		||||
This check warns about too-small size of their output buffer (if it's specified by a constant - variable parameter is ignored).
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								xrpl-hooks-docs/md/hooks-trivial-cbak.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								xrpl-hooks-docs/md/hooks-trivial-cbak.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
# hooks-trivial-cbak
 | 
			
		||||
 | 
			
		||||
A Hook may implement and export a [cbak](https://xrpl-hooks.readme.io/v2.0/reference/cbak) function.
 | 
			
		||||
 | 
			
		||||
But the function is optional, and defining it so that it doesn't do anything besides returning a constant value is unnecessary (except for some debugging scenarios) and just increases the hook size. This check warns about such implementations.
 | 
			
		||||
 | 
			
		||||
[Read more](https://xrpl-hooks.readme.io/v2.0/docs/compiling-hooks)
 | 
			
		||||
		Reference in New Issue
	
	Block a user