Merge branch 'main' into feat/improved-logs
This commit is contained in:
		@@ -2,6 +2,7 @@ NEXTAUTH_URL=https://example.com
 | 
			
		||||
GITHUB_SECRET=""
 | 
			
		||||
GITHUB_ID=""
 | 
			
		||||
NEXT_PUBLIC_COMPILE_API_ENDPOINT="http://localhost:9000/api/build"
 | 
			
		||||
NEXT_PUBLIC_COMPILE_API_BASE_URL="http://localhost:9000"
 | 
			
		||||
NEXT_PUBLIC_LANGUAGE_SERVER_API_ENDPOINT="ws://localhost:9000/language-server/c"
 | 
			
		||||
NEXT_PUBLIC_TESTNET_URL="hooks-testnet-v2.xrpl-labs.com"
 | 
			
		||||
NEXT_PUBLIC_DEBUG_STREAM_URL="hooks-testnet-v2-debugstream.xrpl-labs.com"
 | 
			
		||||
 
 | 
			
		||||
@@ -226,6 +226,22 @@ const HooksEditor = () => {
 | 
			
		||||
              }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            // Hacky way to hide Peek menu
 | 
			
		||||
            editor.onContextMenu((e) => {
 | 
			
		||||
              const host =
 | 
			
		||||
                document.querySelector<HTMLElement>(".shadow-root-host");
 | 
			
		||||
 | 
			
		||||
              const contextMenuItems =
 | 
			
		||||
                host?.shadowRoot?.querySelectorAll("li.action-item");
 | 
			
		||||
              contextMenuItems?.forEach((k) => {
 | 
			
		||||
                // If menu item contains "Peek" lets hide it
 | 
			
		||||
                if (k.querySelector(".action-label")?.textContent === "Peek") {
 | 
			
		||||
                  // @ts-expect-error
 | 
			
		||||
                  k["style"].display = "none";
 | 
			
		||||
                }
 | 
			
		||||
              });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            validateWritability(editor);
 | 
			
		||||
          }}
 | 
			
		||||
          theme={theme === "dark" ? "dark" : "light"}
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,8 @@ export const Input = styled("input", {
 | 
			
		||||
  },
 | 
			
		||||
  "&:read-only": {
 | 
			
		||||
    backgroundColor: "$mauve2",
 | 
			
		||||
    color: "$text",
 | 
			
		||||
    opacity: 0.8,
 | 
			
		||||
    "&:focus": {
 | 
			
		||||
      boxShadow: "inset 0px 0px 0px 1px $colors$mauve7",
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
import React, { useState } from "react";
 | 
			
		||||
import React, { useCallback, useEffect, useState } from "react";
 | 
			
		||||
import { Plus, Trash, X } from "phosphor-react";
 | 
			
		||||
import Button from "./Button";
 | 
			
		||||
import Box from "./Box";
 | 
			
		||||
@@ -25,6 +25,7 @@ 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";
 | 
			
		||||
 | 
			
		||||
const transactionOptions = Object.keys(tts).map((key) => ({
 | 
			
		||||
  label: key,
 | 
			
		||||
@@ -36,6 +37,7 @@ export type SetHookData = {
 | 
			
		||||
    value: keyof TTS;
 | 
			
		||||
    label: string;
 | 
			
		||||
  }[];
 | 
			
		||||
  HookNamespace: string;
 | 
			
		||||
  HookParameters: {
 | 
			
		||||
    HookParameter: {
 | 
			
		||||
      HookParameterName: string;
 | 
			
		||||
@@ -57,8 +59,13 @@ export const SetHookDialog: React.FC<{ account: IAccount }> = ({ account }) => {
 | 
			
		||||
    register,
 | 
			
		||||
    handleSubmit,
 | 
			
		||||
    control,
 | 
			
		||||
    // formState: { errors },
 | 
			
		||||
  } = useForm<SetHookData>();
 | 
			
		||||
    watch,
 | 
			
		||||
    formState: { errors },
 | 
			
		||||
  } = useForm<SetHookData>({
 | 
			
		||||
    defaultValues: {
 | 
			
		||||
      HookNamespace: snap.files?.[snap.active]?.name?.split(".")?.[0] || "",
 | 
			
		||||
    },
 | 
			
		||||
  });
 | 
			
		||||
  const { fields, append, remove } = useFieldArray({
 | 
			
		||||
    control,
 | 
			
		||||
    name: "HookParameters", // unique name for your Field Array
 | 
			
		||||
@@ -71,6 +78,19 @@ export const SetHookDialog: React.FC<{ account: IAccount }> = ({ account }) => {
 | 
			
		||||
  //   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]);
 | 
			
		||||
 | 
			
		||||
  if (!account) {
 | 
			
		||||
    return null;
 | 
			
		||||
  }
 | 
			
		||||
@@ -89,6 +109,7 @@ export const SetHookDialog: React.FC<{ account: IAccount }> = ({ account }) => {
 | 
			
		||||
    }
 | 
			
		||||
    toast.error(`Transaction failed! (${res?.engine_result_message})`);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Dialog open={isSetHookDialogOpen} onOpenChange={setIsSetHookDialogOpen}>
 | 
			
		||||
      <DialogTrigger asChild>
 | 
			
		||||
@@ -130,7 +151,26 @@ export const SetHookDialog: React.FC<{ account: IAccount }> = ({ account }) => {
 | 
			
		||||
                />
 | 
			
		||||
              </Box>
 | 
			
		||||
              <Box css={{ width: "100%" }}>
 | 
			
		||||
                <Label css={{mb: '$2'}}>
 | 
			
		||||
                <Label>Hook Namespace Seed</Label>
 | 
			
		||||
                <Input
 | 
			
		||||
                  {...register("HookNamespace", { required: true })}
 | 
			
		||||
                  autoComplete={"off"}
 | 
			
		||||
                  defaultValue={
 | 
			
		||||
                    snap.files?.[snap.active]?.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} />
 | 
			
		||||
                </Box>
 | 
			
		||||
              </Box>
 | 
			
		||||
              <Box css={{ width: "100%" }}>
 | 
			
		||||
                <Label style={{ marginBottom: "10px", display: "block" }}>
 | 
			
		||||
                  Hook parameters
 | 
			
		||||
                </Label>
 | 
			
		||||
                <Stack>
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@codingame/monaco-jsonrpc": "^0.3.1",
 | 
			
		||||
    "@codingame/monaco-languageclient": "^0.17.0",
 | 
			
		||||
    "@monaco-editor/react": "^4.3.1",
 | 
			
		||||
    "@monaco-editor/react": "^4.4.1",
 | 
			
		||||
    "@octokit/core": "^3.5.1",
 | 
			
		||||
    "@radix-ui/colors": "^0.1.7",
 | 
			
		||||
    "@radix-ui/react-alert-dialog": "^0.1.1",
 | 
			
		||||
@@ -30,10 +30,10 @@
 | 
			
		||||
    "jszip": "^3.7.1",
 | 
			
		||||
    "lodash.uniqby": "^4.7.0",
 | 
			
		||||
    "lodash.xor": "^4.5.0",
 | 
			
		||||
    "monaco-editor": "^0.30.1",
 | 
			
		||||
    "monaco-editor": "^0.33.0",
 | 
			
		||||
    "next": "^12.0.4",
 | 
			
		||||
    "next-auth": "^4.0.0-beta.5",
 | 
			
		||||
    "next-themes": "^0.0.15",
 | 
			
		||||
    "next-themes": "^0.1.1",
 | 
			
		||||
    "normalize-url": "^7.0.2",
 | 
			
		||||
    "octokit": "^1.7.0",
 | 
			
		||||
    "pako": "^2.0.4",
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ import en from "javascript-time-ago/locale/en.json";
 | 
			
		||||
import { useSnapshot } from "valtio";
 | 
			
		||||
 | 
			
		||||
TimeAgo.setDefaultLocale(en.locale);
 | 
			
		||||
TimeAgo.addLocale(en)
 | 
			
		||||
TimeAgo.addLocale(en);
 | 
			
		||||
 | 
			
		||||
function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
 | 
			
		||||
  const router = useRouter();
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ import state, { IAccount } from "../index";
 | 
			
		||||
import calculateHookOn, { TTS } from "../../utils/hookOnCalculator";
 | 
			
		||||
import { SetHookData } from "../../components/SetHookDialog";
 | 
			
		||||
 | 
			
		||||
const hash = async (string: string) => {
 | 
			
		||||
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));
 | 
			
		||||
@@ -66,9 +66,7 @@ export const deployHook = async (account: IAccount & { name?: string }, data: Se
 | 
			
		||||
  if (!state.client) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  const HookNamespace = await hash(arrayBufferToHex(
 | 
			
		||||
    state.files?.[state.active]?.compiledContent
 | 
			
		||||
  ).toUpperCase());
 | 
			
		||||
  const HookNamespace = (await sha256(data.HookNamespace)).toUpperCase();
 | 
			
		||||
  const hookOnValues: (keyof TTS)[] = data.Invoke.map(tt => tt.value);
 | 
			
		||||
  const { HookParameters } = data;
 | 
			
		||||
  const filteredHookParameters = HookParameters.filter(hp => hp.HookParameter.HookParameterName && hp.HookParameter.HookParameterValue)?.map(aa => ({ HookParameter: { HookParameterName: toHex(aa.HookParameter.HookParameterName || ''), HookParameterValue: toHex(aa.HookParameter.HookParameterValue || '') } }));
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,6 @@ import { Octokit } from "@octokit/core";
 | 
			
		||||
import Router from "next/router";
 | 
			
		||||
import state from '../index';
 | 
			
		||||
import { templateFileIds } from '../constants';
 | 
			
		||||
import { hookapiH, hookmacroH, sfcodesH } from '../constants/headerTemplates';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const octokit = new Octokit();
 | 
			
		||||
 | 
			
		||||
@@ -20,18 +18,30 @@ export const fetchFiles = (gistId: string) => {
 | 
			
		||||
 | 
			
		||||
    octokit
 | 
			
		||||
      .request("GET /gists/{gist_id}", { gist_id: gistId })
 | 
			
		||||
      .then(res => {
 | 
			
		||||
      .then(async res => {
 | 
			
		||||
        if (!Object.values(templateFileIds).includes(gistId)) {
 | 
			
		||||
          return res
 | 
			
		||||
        }
 | 
			
		||||
        // in case of templates, fetch header file(s) and append to res
 | 
			
		||||
        const files = {
 | 
			
		||||
          ...res.data.files,
 | 
			
		||||
          'hookapi.h': res.data.files?.['hookapi.h'] || { filename: 'hookapi.h', content: hookapiH, language: 'C' },
 | 
			
		||||
          'hookmacro.h': res.data.files?.['hookmacro.h'] || { filename: 'hookmacro.h', content: hookmacroH, language: 'C' },
 | 
			
		||||
          'sfcodes.h': res.data.files?.['sfcodes.h'] || { filename: 'sfcodes.h', content: sfcodesH, language: 'C' },
 | 
			
		||||
        };
 | 
			
		||||
        res.data.files = files;
 | 
			
		||||
        let resHeaderJson;
 | 
			
		||||
        try {
 | 
			
		||||
          const resHeader = await fetch(`${process.env.NEXT_PUBLIC_COMPILE_API_BASE_URL}/api/header-files`);
 | 
			
		||||
          if (resHeader.ok) {
 | 
			
		||||
            resHeaderJson = await resHeader.json();
 | 
			
		||||
            const files = {
 | 
			
		||||
              ...res.data.files,
 | 
			
		||||
              'hookapi.h': res.data.files?.['hookapi.h'] || { filename: 'hookapi.h', content: resHeaderJson.hookapi, language: 'C' },
 | 
			
		||||
              'hookmacro.h': res.data.files?.['hookmacro.h'] || { filename: 'hookmacro.h', content: resHeaderJson.hookmacro, language: 'C' },
 | 
			
		||||
              'sfcodes.h': res.data.files?.['sfcodes.h'] || { filename: 'sfcodes.h', content: resHeaderJson.sfcodes, language: 'C' },
 | 
			
		||||
            };
 | 
			
		||||
            res.data.files = files;
 | 
			
		||||
          }
 | 
			
		||||
        } catch (err) {
 | 
			
		||||
          console.log(err)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        return res;
 | 
			
		||||
        // If you want to load templates from GIST instad, uncomment the code below and comment the code above.
 | 
			
		||||
        // return octokit.request("GET /gists/{gist_id}", { gist_id: templateFileIds.headers }).then(({ data: { files: headerFiles } }) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import toast from "react-hot-toast";
 | 
			
		||||
import { derive } from "xrpl-accountlib";
 | 
			
		||||
import { derive, XRPL_Account } from "xrpl-accountlib";
 | 
			
		||||
 | 
			
		||||
import state from '../index';
 | 
			
		||||
import { names } from './addFaucetAccount';
 | 
			
		||||
@@ -12,8 +12,18 @@ export const importAccount = (secret: string) => {
 | 
			
		||||
  if (state.accounts.find((acc) => acc.secret === secret)) {
 | 
			
		||||
    return toast.error("Account already added!");
 | 
			
		||||
  }
 | 
			
		||||
  const account = derive.familySeed(secret);
 | 
			
		||||
  if (!account.secret.familySeed) {
 | 
			
		||||
  let account: XRPL_Account | null = null;
 | 
			
		||||
  try {
 | 
			
		||||
    account = derive.familySeed(secret);
 | 
			
		||||
  } catch (err: any) {
 | 
			
		||||
    if (err?.message) {
 | 
			
		||||
      toast.error(err.message)
 | 
			
		||||
    } else {
 | 
			
		||||
      toast.error('Error occured while importing account')
 | 
			
		||||
    }
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (!account || !account.secret.familySeed) {
 | 
			
		||||
    return toast.error(`Couldn't create account!`);
 | 
			
		||||
  }
 | 
			
		||||
  state.accounts.push({
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										34
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								yarn.lock
									
									
									
									
									
								
							@@ -202,19 +202,19 @@
 | 
			
		||||
  resolved "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz"
 | 
			
		||||
  integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==
 | 
			
		||||
 | 
			
		||||
"@monaco-editor/loader@^1.2.0":
 | 
			
		||||
  version "1.2.0"
 | 
			
		||||
  resolved "https://registry.npmjs.org/@monaco-editor/loader/-/loader-1.2.0.tgz"
 | 
			
		||||
  integrity sha512-cJVCG/T/KxXgzYnjKqyAgsKDbH9mGLjcXxN6AmwumBwa2rVFkwvGcUj1RJtD0ko4XqLqJxwqsN/Z/KURB5f1OQ==
 | 
			
		||||
"@monaco-editor/loader@^1.3.0":
 | 
			
		||||
  version "1.3.0"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/@monaco-editor/loader/-/loader-1.3.0.tgz#659fbaf1d612ea67b2a0519a18612d1c4813e444"
 | 
			
		||||
  integrity sha512-N3mGq1ktC3zh7WUx3NGO+PSDdNq9Vspk/41rEmRdrCqV9vNbBTRzAOplmUpNQsi+hmTs++ERMBobMERb8Kb+3g==
 | 
			
		||||
  dependencies:
 | 
			
		||||
    state-local "^1.0.6"
 | 
			
		||||
 | 
			
		||||
"@monaco-editor/react@^4.3.1":
 | 
			
		||||
  version "4.3.1"
 | 
			
		||||
  resolved "https://registry.npmjs.org/@monaco-editor/react/-/react-4.3.1.tgz"
 | 
			
		||||
  integrity sha512-f+0BK1PP/W5I50hHHmwf11+Ea92E5H1VZXs+wvKplWUWOfyMa1VVwqkJrXjRvbcqHL+XdIGYWhWNdi4McEvnZg==
 | 
			
		||||
"@monaco-editor/react@^4.4.1":
 | 
			
		||||
  version "4.4.1"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/@monaco-editor/react/-/react-4.4.1.tgz#2e2b9b369f3082b0e14f47cdbe35658fd56c7c7d"
 | 
			
		||||
  integrity sha512-95E/XPC4dbm/7qdkhSsU/a1kRgcn2PYhRTVIc+/cixWCZrwRURW1DRPaIZ2lOawBJ6kAOLywxuD4A4UmbT0ZIw==
 | 
			
		||||
  dependencies:
 | 
			
		||||
    "@monaco-editor/loader" "^1.2.0"
 | 
			
		||||
    "@monaco-editor/loader" "^1.3.0"
 | 
			
		||||
    prop-types "^15.7.2"
 | 
			
		||||
 | 
			
		||||
"@next/env@12.1.0":
 | 
			
		||||
@@ -2878,10 +2878,10 @@ minimist@^1.2.0, minimist@^1.2.5:
 | 
			
		||||
  resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz"
 | 
			
		||||
  integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
 | 
			
		||||
 | 
			
		||||
monaco-editor@^0.30.1:
 | 
			
		||||
  version "0.30.1"
 | 
			
		||||
  resolved "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.30.1.tgz"
 | 
			
		||||
  integrity sha512-B/y4+b2O5G2gjuxIFtCE2EkM17R2NM7/3F8x0qcPsqy4V83bitJTIO4TIeZpYlzu/xy6INiY/+84BEm6+7Cmzg==
 | 
			
		||||
monaco-editor@^0.33.0:
 | 
			
		||||
  version "0.33.0"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.33.0.tgz#842e244f3750a2482f8a29c676b5684e75ff34af"
 | 
			
		||||
  integrity sha512-VcRWPSLIUEgQJQIE0pVT8FcGBIgFoxz7jtqctE+IiCxWugD0DwgyQBcZBhdSrdMC84eumoqMZsGl2GTreOzwqw==
 | 
			
		||||
 | 
			
		||||
ms@2.0.0:
 | 
			
		||||
  version "2.0.0"
 | 
			
		||||
@@ -2928,10 +2928,10 @@ next-auth@^4.0.0-beta.5:
 | 
			
		||||
    preact-render-to-string "^5.1.19"
 | 
			
		||||
    uuid "^8.3.2"
 | 
			
		||||
 | 
			
		||||
next-themes@^0.0.15:
 | 
			
		||||
  version "0.0.15"
 | 
			
		||||
  resolved "https://registry.npmjs.org/next-themes/-/next-themes-0.0.15.tgz"
 | 
			
		||||
  integrity sha512-LTmtqYi03c4gMTJmWwVK9XkHL7h0/+XrtR970Ujvtu3s0kZNeJN24aJsi4rkZOI8i19+qq6f8j+8Duwy5jqcrQ==
 | 
			
		||||
next-themes@^0.1.1:
 | 
			
		||||
  version "0.1.1"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.1.1.tgz#122113a458bf1d1be5ffed66778ab924c106f82a"
 | 
			
		||||
  integrity sha512-Iqxt6rhS/KfK/iHJ0tfFjTcdLEAI0AgwFuAFrMwLOPK5e+MI3I+fzyvBoS+VaOS+NldUiazurhgwYhrfV0VXsQ==
 | 
			
		||||
 | 
			
		||||
next-tick@^1.1.0:
 | 
			
		||||
  version "1.1.0"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user