Skip to content

Commit

Permalink
Added a filter for specifying the variable to proof (#18)
Browse files Browse the repository at this point in the history
* Added a filter for specifying the variable to proof

* removed console.log

* Update version library
  • Loading branch information
Mautjee authored Aug 17, 2023
1 parent 664b367 commit bd0d5ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zk-states",
"packageManager": "[email protected]",
"version": "0.0.14",
"version": "0.0.15",
"description": "Verifiable state manager for React based on SnarkyJS & Mina protocol",
"typesVersions": {
"<4.0": {
Expand Down
7 changes: 4 additions & 3 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { ZkAppWorkerClient } from "./zkAppWorkerClient";

let oldState = INITIAL_STATE;

const stringifyState = (state: object) => {
const stringifyState = <T extends object>(state: T, toProof: (keyof T)[]) => {
const stateVariables: Record<string, unknown> = {};
Object.entries(state).forEach(([key, value]) => {
if (typeof value !== "function") {
if (typeof value !== "function" && toProof.includes(key as keyof T)) {
stateVariables[key] = value;
}
});
Expand All @@ -22,6 +22,7 @@ const stringifyState = (state: object) => {
export const createZKState = <T extends object>(
worker: Worker,
createState: StateCreator<T, [], []>,
toProof: (keyof T)[],
) => {
const useZKStore = create<T>(createState);
const zkAppWorkerClient = new ZkAppWorkerClient(worker);
Expand Down Expand Up @@ -55,7 +56,7 @@ export const createZKState = <T extends object>(
useEffect(() => {
if (!isInitialized) return;

const newState = stringifyState(state);
const newState = stringifyState<T>(state, toProof);

if (newState === oldState) return;

Expand Down

0 comments on commit bd0d5ce

Please sign in to comment.