Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contracts): add new adapter for lowdb to support browser env #1416

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions cli/ts/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ export {
ContractStorage,
EContracts,
EMode,
PollFactory__factory as PollFactoryFactory,
MessageProcessorFactory__factory as MessageProcessorFactoryFactory,
TallyFactory__factory as TallyFactoryFactory,
MACI__factory as MACIFactory,
type MACI,
type EASGatekeeper,
type IVerifyingKeyStruct,
type VkRegistry,
} from "maci-contracts";

export * from "maci-contracts/typechain-types";

export { VerifyingKey, type IVkObjectParams } from "maci-domainobjs";

export type {
Expand Down
7 changes: 6 additions & 1 deletion contracts/tasks/helpers/ContractStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies, no-console */
import low from "lowdb";
import FileSync from "lowdb/adapters/FileSync";
import LocalStorageSync from "lowdb/adapters/LocalStorage";

import path from "path";

Expand Down Expand Up @@ -40,7 +41,11 @@ export class ContractStorage {
* Initialize class properties only once
*/
private constructor() {
this.db = low(new FileSync<TStorage>(path.resolve(__dirname, "..", "..", "./deployed-contracts.json")));
this.db = low(
typeof window !== "undefined"
? new LocalStorageSync<TStorage>("deployed-contracts")
: new FileSync<TStorage>(path.resolve(__dirname, "..", "..", "./deployed-contracts.json")),
);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion contracts/tasks/helpers/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { BaseContract, ContractFactory, Signer } from "ethers";
import low from "lowdb";
import FileSync from "lowdb/adapters/FileSync";
import LocalStorageSync from "lowdb/adapters/LocalStorage";

import path from "path";

Expand Down Expand Up @@ -63,7 +64,11 @@ export class Deployment {
["poll", []],
]);
this.hre = hre;
this.config = low(new FileSync<TConfig>(path.resolve(__dirname, "..", "..", "./deploy-config.json")));
this.config = low(
typeof window !== "undefined"
? new LocalStorageSync<TConfig>("deploy-config")
: new FileSync<TConfig>(path.resolve(__dirname, "..", "..", "./deploy-config.json")),
);
this.storage = ContractStorage.getInstance();
}

Expand Down
1 change: 1 addition & 0 deletions contracts/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"lib": ["dom"],
"outDir": "./build"
},
"include": ["./ts", "./scripts", "./typechain-types", "./tasks"],
Expand Down
1 change: 1 addition & 0 deletions contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"lib": ["dom"],
"outDir": "./build"
},
"include": ["./ts", "./scripts", "./tests", "./typechain-types", "./tasks"],
Expand Down
Loading