From 41953c79de6b6c8ca540b5c6a98f7d76d50da5e9 Mon Sep 17 00:00:00 2001 From: Nadai2010 Date: Sat, 10 Aug 2024 20:25:19 +0100 Subject: [PATCH] Remove MenuItem, uncomment refetch and add modify contactsData --- .../nextjs/components/MenuItem/MenuItem.tsx | 29 ------------------- .../scaffold-stark/useScaffoldReadContract.ts | 8 ++--- .../utils/scaffold-stark/contractsData.ts | 24 +++++++++++++++ 3 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 packages/nextjs/components/MenuItem/MenuItem.tsx diff --git a/packages/nextjs/components/MenuItem/MenuItem.tsx b/packages/nextjs/components/MenuItem/MenuItem.tsx deleted file mode 100644 index c7b0df5a..00000000 --- a/packages/nextjs/components/MenuItem/MenuItem.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import Link from "next/link"; -import React from "react"; -import { HeaderMenuLink } from "~~/components/Header"; - -interface MenuItemProps { - link: HeaderMenuLink; - isActive: boolean; -} - -const MenuItem: React.FC = ({ link, isActive }) => { - return ( -
  • - - {link.icon} - {link.label} - -
  • - ); -}; - -export default MenuItem; diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts b/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts index 3831b4be..53e82f59 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts @@ -34,9 +34,9 @@ export const useScaffoldReadContract = < ...(readConfig as any), }) as Omit, "data" | "refetch"> & { data: AbiFunctionOutputs | undefined; - // refetch: (options?: { - // throwOnError: boolean; - // cancelRefetch: boolean; - // }) => Promise>; + refetch: (options?: { + throwOnError: boolean; + cancelRefetch: boolean; + }) => Promise>; }; }; diff --git a/packages/nextjs/utils/scaffold-stark/contractsData.ts b/packages/nextjs/utils/scaffold-stark/contractsData.ts index c450adf6..cd77516f 100644 --- a/packages/nextjs/utils/scaffold-stark/contractsData.ts +++ b/packages/nextjs/utils/scaffold-stark/contractsData.ts @@ -5,3 +5,27 @@ export function getAllContracts() { const contractsData = contracts?.[scaffoldConfig.targetNetworks[0].network]; return contractsData ? contractsData : {}; } + +function bigIntToHex(bigInt: bigint) { + return bigInt.toString(16); +} + +function hexToUtf8(hexStr: string) { + let bytes = []; + for (let i = 0; i < hexStr.length; i += 2) { + bytes.push(parseInt(hexStr.substring(i, i + 2), 16)); + } + try { + return new TextDecoder("utf-8").decode(new Uint8Array(bytes)); + } catch (e) { + console.error("Failed to decode:", e); + return ""; + } +} + +export function decodeBigIntArrayToText(byteArray: string[]) { + return byteArray + .map((bigInt) => bigIntToHex(BigInt(bigInt))) // Convert each BigInt to hexadecimal + .map((hex) => hexToUtf8(hex)) // Decode each hexadecimal to text + .join(""); // Join all texts into a single string +}