diff --git a/package.json b/package.json index 8c2bb47..f167823 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ }, "main": "dist/index.js", "module": "dist/index.es.js", + "browser": { + "localPorridge": false + }, "files": [ "dist" ], @@ -23,6 +26,7 @@ "dependencies": { "arweave": "^1.9.1", "cacheweave": "^1.0.0", + "localporridge": "^1.0.0", "moment": "^2.28.0", "node-fetch": "^2.6.1", "smartweave": "^0.3.6" diff --git a/rollup.config.js b/rollup.config.js index 3959b20..d61ad8a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -45,6 +45,7 @@ const config = { resolve({ preferBuiltins: true, jsnext: true, + browser: true, }), alias({ "@utils": __dirname + "/src/utils", diff --git a/src/lib/get_tokens.ts b/src/lib/get_tokens.ts index 51a2d41..3e2205b 100644 --- a/src/lib/get_tokens.ts +++ b/src/lib/get_tokens.ts @@ -4,6 +4,7 @@ import { maxInt } from "@utils/constants"; import { getData } from "cacheweave"; import Arweave from "arweave"; import { VertoToken, EdgeQueryResponse } from "types"; +import localPorridge from "localporridge"; export const getTokens = async ( client: Arweave, @@ -26,14 +27,14 @@ export const getTokens = async ( const IDs: { type: string; id: string }[] = []; tokenTxs.map((tx) => IDs.push({ type: "tx", id: tx.node.id })); - // TODO(@johnletey): Use `localPorridge` to grab custom tokens. - // @ts-ignore - if (typeof window !== "undefined") { + const storage = // @ts-ignore - const cache = JSON.parse(localStorage.getItem("customTokens") || "[]"); - - cache.map((entry: string) => IDs.push({ type: "contract", id: entry })); - } + typeof localStorage == "undefined" + ? new localPorridge("./.cache.json") + : // @ts-ignore + localStorage; + const cache = JSON.parse(storage.getItem("customTokens") || "[]"); + cache.map((entry: string) => IDs.push({ type: "contract", id: entry })); const tokens: VertoToken[] = []; for (const entry of IDs) { diff --git a/tsconfig.json b/tsconfig.json index 263bfaa..28f69a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "noUnusedLocals": true, "noImplicitReturns": true, "target": "es2015", - "module": "es2015", + "module": "esnext", "lib": ["es2015"], "paths": { "@queries/*": ["queries/*"], diff --git a/yarn.lock b/yarn.lock index 0615893..d905407 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1322,6 +1322,11 @@ levn@^0.4.1: prelude-ls "^1.2.1" type-check "~0.4.0" +localporridge@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/localporridge/-/localporridge-1.0.0.tgz#718eb86547b075ec78b369a26b7d1b6fddd171d5" + integrity sha512-mCaTeK+CMBUElyxQiLOIB0GdEOTZwvYl/VyqynJ+ApQbelItugJnp4+45jBcFbSAvFV9lStnkCK1ZbCNL75iUg== + locate-path@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"