diff --git a/developer-preview/src/lib/getPreviewData.tsx b/developer-preview/src/lib/getPreviewData.tsx index 1002cb3..23a35b8 100644 --- a/developer-preview/src/lib/getPreviewData.tsx +++ b/developer-preview/src/lib/getPreviewData.tsx @@ -1,9 +1,11 @@ import { type AbiFunction, + bytesToHex, createPublicClient, decodeFunctionData, erc20Abi, getAbiItem, + hexToBytes, http, isAddress, isHex, @@ -18,9 +20,25 @@ import type { ABI, ERC7730Schema, FieldFormatter } from "~/types/ERC7730Schema"; const publicClient = createPublicClient({ chain: mainnet, transport: http() }); const get = (values: unknown, path: string) => - path - .split(".") - .reduce((acc, key) => acc && (acc as Record)[key], values); + path.split(".").reduce((acc, key) => { + if (!acc) return; + const slice = /^\[(-?\d+)?(?::(-?\d+))?\]$/.exec(key); + if (slice && isHex(acc)) { + return bytesToHex( + hexToBytes(acc).slice( + Number(slice[1]), + slice[2] + ? Number(slice[2]) >= 0 + ? Number(slice[2]) + 1 + : Number(slice[2]) === -1 + ? undefined + : Number(slice[2]) + : undefined, + ), + ); + } + return (acc as Record)[key]; + }, values); const fetchAndParse = async (url: string, parse: (json: unknown) => ABI) => { const response = await fetch(url);