Skip to content

Commit

Permalink
feat(contracts): use local storage for deployed contracts and config …
Browse files Browse the repository at this point in the history
…in browser
  • Loading branch information
0xmad committed May 1, 2024
1 parent c53cbee commit c7f1db8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
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

0 comments on commit c7f1db8

Please sign in to comment.