diff --git a/components/LogBox.tsx b/components/LogBox.tsx index 1f75794..6dfe8fd 100644 --- a/components/LogBox.tsx +++ b/components/LogBox.tsx @@ -186,8 +186,17 @@ export const Log: FC = ({ }, [accounts] ); - _message = _message.trim().replace(/\n /gi, "\n"); - const message = enrichAccounts(_message); + + let message: ReactNode; + + if (typeof _message === 'string') { + _message = _message.trim().replace(/\n /gi, "\n"); + message = enrichAccounts(_message) + } + else { + message = _message + } + const jsonData = enrichAccounts(_jsonData); return ( diff --git a/state/actions/deployHook.ts b/state/actions/deployHook.tsx similarity index 72% rename from state/actions/deployHook.ts rename to state/actions/deployHook.tsx index 5fcb8e6..a24f76c 100644 --- a/state/actions/deployHook.ts +++ b/state/actions/deployHook.tsx @@ -4,19 +4,21 @@ import toast from "react-hot-toast"; import state, { IAccount } from "../index"; import calculateHookOn, { TTS } from "../../utils/hookOnCalculator"; import { SetHookData } from "../../components/SetHookDialog"; +import { Link } from "../../components"; +import { ref } from "valtio"; export const sha256 = async (string: string) => { const utf8 = new TextEncoder().encode(string); - const hashBuffer = await crypto.subtle.digest('SHA-256', utf8); + 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')) - .join(''); + .map(bytes => bytes.toString(16).padStart(2, "0")) + .join(""); return hashHex; -} +}; function toHex(str: string) { - var result = ''; + var result = ""; for (var i = 0; i < str.length; i++) { result += str.charCodeAt(i).toString(16); } @@ -51,7 +53,10 @@ function arrayBufferToHex(arrayBuffer?: ArrayBuffer | null) { * hex string, signs the transaction and deploys it to * Hooks testnet. */ -export const deployHook = async (account: IAccount & { name?: string }, data: SetHookData) => { +export const deployHook = async ( + account: IAccount & { name?: string }, + data: SetHookData +) => { if ( !state.files || state.files.length === 0 || @@ -69,7 +74,15 @@ export const deployHook = async (account: IAccount & { name?: string }, data: Se 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 || '') } })); + const filteredHookParameters = HookParameters.filter( + hp => + hp.HookParameter.HookParameterName && hp.HookParameter.HookParameterValue + )?.map(aa => ({ + HookParameter: { + HookParameterName: toHex(aa.HookParameter.HookParameterName || ""), + HookParameterValue: toHex(aa.HookParameter.HookParameterValue || ""), + }, + })); // const filteredHookGrants = HookGrants.filter(hg => hg.HookGrant.Authorize || hg.HookGrant.HookHash).map(hg => { // return { // HookGrant: { @@ -97,16 +110,18 @@ export const deployHook = async (account: IAccount & { name?: string }, data: Se HookApiVersion: 0, Flags: 1, // ...(filteredHookGrants.length > 0 && { HookGrants: filteredHookGrants }), - ...(filteredHookParameters.length > 0 && { HookParameters: filteredHookParameters }), - } - } - ] + ...(filteredHookParameters.length > 0 && { + HookParameters: filteredHookParameters, + }), + }, + }, + ], }; 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; @@ -125,12 +140,28 @@ export const deployHook = async (account: IAccount & { name?: string }, data: Se }); state.deployLogs.push({ type: "success", - message: `[${submitRes.engine_result}] ${submitRes.engine_result_message} Validated ledger index: ${submitRes.validated_ledger_index}`, + message: ref( + <> + [{submitRes.engine_result}] {submitRes.engine_result_message}{" "} + Validated ledger index:{" "} + + {submitRes.validated_ledger_index} + + + ), + // message: `[${submitRes.engine_result}] ${submitRes.engine_result_message} Validated ledger index: ${submitRes.validated_ledger_index}`, }); } else { state.deployLogs.push({ type: "error", - message: `[${submitRes.engine_result || submitRes.error}] ${submitRes.engine_result_message || submitRes.error_exception}`, + message: `[${submitRes.engine_result || submitRes.error}] ${ + submitRes.engine_result_message || submitRes.error_exception + }`, }); } } catch (err) { @@ -152,10 +183,10 @@ 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 + return; } if (typeof window !== "undefined") { const tx = { @@ -168,9 +199,9 @@ export const deleteHook = async (account: IAccount & { name?: string }) => { Hook: { CreateCode: "", Flags: 1, - } - } - ] + }, + }, + ], }; const keypair = derive.familySeed(account.secret); @@ -188,7 +219,7 @@ export const deleteHook = async (account: IAccount & { name?: string }) => { }); if (submitRes.engine_result === "tesSUCCESS") { - toast.success('Hook deleted successfully ✅', { id: toastId }) + toast.success("Hook deleted successfully ✅", { id: toastId }); state.deployLogs.push({ type: "success", message: "Hook deleted successfully ✅", @@ -199,15 +230,20 @@ export const deleteHook = async (account: IAccount & { name?: string }) => { }); currentAccount.hooks = []; } else { - toast.error(`${submitRes.engine_result_message || submitRes.error_exception}`, { id: toastId }) + toast.error( + `${submitRes.engine_result_message || submitRes.error_exception}`, + { id: toastId } + ); state.deployLogs.push({ type: "error", - message: `[${submitRes.engine_result || submitRes.error}] ${submitRes.engine_result_message || submitRes.error_exception}`, + message: `[${submitRes.engine_result || submitRes.error}] ${ + submitRes.engine_result_message || submitRes.error_exception + }`, }); } } catch (err) { console.log(err); - toast.error('Error occured while deleting hoook', { id: toastId }) + toast.error("Error occured while deleting hoook", { id: toastId }); state.deployLogs.push({ type: "error", message: "Error occured while deleting hook", @@ -218,4 +254,4 @@ export const deleteHook = async (account: IAccount & { name?: string }) => { } return submitRes; } -}; \ No newline at end of file +}; diff --git a/state/index.ts b/state/index.ts index 949d74d..be0c31e 100644 --- a/state/index.ts +++ b/state/index.ts @@ -39,7 +39,7 @@ export interface IAccount { export interface ILog { type: "error" | "warning" | "log" | "success"; - message: string; + message: string | JSX.Element; key?: string; jsonData?: any, timestring?: string;