import { createContext, ReactNode, useContext } from "react"; type contractsContextType = Record; const contractsContextDefaultValue: contractsContextType = {}; const ContractsContext = createContext(contractsContextDefaultValue); export function useContracts() { return useContext(ContractsContext); } type Props = { children: ReactNode; }; interface addContractsPayload { address: string; signature: string; } export function ContractsProvider({ children }: Props) { const addContract = (payload: addContractsPayload) => { window.localStorage.setItem( "contracts", JSON.stringify({ ...JSON.parse(window.localStorage.getItem("contracts") || "{}"), [payload.address]: payload.signature, }) ); }; const value = { contracts: typeof window !== "undefined" ? JSON.parse(window.localStorage.getItem("contracts") || "{}") : {}, addContract, }; return ( <> {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} {/* @ts-ignore */} {children} ); }