Works on local, fingers crossed (#1701)
This commit is contained in:
parent
6ea2c47942
commit
c0081b971b
1 changed files with 12 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { createContext, ReactNode, useContext, useState } from "react";
|
import { createContext, ReactNode, useContext } from "react";
|
||||||
|
|
||||||
type contractsContextType = Record<string, string>;
|
type contractsContextType = Record<string, string>;
|
||||||
|
|
||||||
|
@ -20,22 +20,26 @@ interface addContractsPayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ContractsProvider({ children }: Props) {
|
export function ContractsProvider({ children }: Props) {
|
||||||
const [contracts, setContracts] = useState<Record<string, string>>({});
|
|
||||||
|
|
||||||
const addContract = (payload: addContractsPayload) => {
|
const addContract = (payload: addContractsPayload) => {
|
||||||
setContracts((prevContracts) => ({
|
window.localStorage.setItem(
|
||||||
...prevContracts,
|
"contracts",
|
||||||
[payload.address]: payload.signature,
|
JSON.stringify({
|
||||||
}));
|
...JSON.parse(window.localStorage.getItem("contracts") || "{}"),
|
||||||
|
[payload.address]: payload.signature,
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = {
|
const value = {
|
||||||
contracts,
|
contracts:
|
||||||
|
typeof window !== "undefined" ? JSON.parse(window.localStorage.getItem("contracts") || "{}") : {},
|
||||||
addContract,
|
addContract,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
|
||||||
|
{/* @ts-ignore */}
|
||||||
<ContractsContext.Provider value={value}>{children}</ContractsContext.Provider>
|
<ContractsContext.Provider value={value}>{children}</ContractsContext.Provider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue