diff --git a/.changeset/slow-peaches-vanish.md b/.changeset/slow-peaches-vanish.md deleted file mode 100644 index ac02855d1..000000000 --- a/.changeset/slow-peaches-vanish.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@onflow/fcl": minor ---- - -Use localStorage as default & export LOCAL_STORAGE/SESSION_STORAGE as helpers for fcl.storage.default configuration key diff --git a/packages/fcl/src/fcl.js b/packages/fcl/src/fcl.js index a8917b826..2b3677330 100644 --- a/packages/fcl/src/fcl.js +++ b/packages/fcl/src/fcl.js @@ -1,10 +1,10 @@ -export * from "./shared-exports" +export * from './shared-exports'; import {getMutate} from "./exec/mutate" export const mutate = getMutate({platform: "web"}) import {getCurrentUser} from "./current-user" -const currentUser = getCurrentUser({platform: "web"}) +const currentUser = getCurrentUser({platform:"web"}) export {currentUser} @@ -19,8 +19,6 @@ export const logIn = (opts = {}) => currentUser().authenticate(opts) export const authz = currentUser().authorization -export {LOCAL_STORAGE, SESSION_STORAGE} from "./utils/web" - import {config} from "@onflow/config" import {getDefaultConfig, coreStrategies} from "./utils/web" import {initServiceRegistry} from "./current-user/exec-service/plugins" diff --git a/packages/fcl/src/utils/web/default-config.js b/packages/fcl/src/utils/web/default-config.js index 6bc0ae177..3bbf571b0 100644 --- a/packages/fcl/src/utils/web/default-config.js +++ b/packages/fcl/src/utils/web/default-config.js @@ -1,8 +1,21 @@ -import {LOCAL_STORAGE} from "./storage" +const isServerSide = () => typeof window === "undefined" + +const getSessionStorage = () => { + try { + const SESSION_STORAGE = { + can: !isServerSide(), + get: async key => JSON.parse(sessionStorage.getItem(key)), + put: async (key, value) => sessionStorage.setItem(key, JSON.stringify(value)), + } + return SESSION_STORAGE + } catch (error) { + return null + } +} export const getDefaultConfig = () => { return { "discovery.wallet.method.default": "IFRAME/RPC", - "fcl.storage.default": LOCAL_STORAGE, + "fcl.storage.default": getSessionStorage(), } } diff --git a/packages/fcl/src/utils/web/index.js b/packages/fcl/src/utils/web/index.js index 7c943c9f8..edd0b8cb9 100644 --- a/packages/fcl/src/utils/web/index.js +++ b/packages/fcl/src/utils/web/index.js @@ -1,6 +1,5 @@ -export {renderFrame} from "./render-frame" -export {renderPop} from "./render-pop" -export {renderTab} from "./render-tab" -export {getDefaultConfig} from "./default-config" -export {coreStrategies} from "./coreStrategies" -export {LOCAL_STORAGE, SESSION_STORAGE} from "./storage" +export {renderFrame} from './render-frame' +export {renderPop} from './render-pop' +export {renderTab} from './render-tab' +export {getDefaultConfig} from './default-config' +export {coreStrategies} from './coreStrategies' diff --git a/packages/fcl/src/utils/web/storage.js b/packages/fcl/src/utils/web/storage.js deleted file mode 100644 index 3789191e4..000000000 --- a/packages/fcl/src/utils/web/storage.js +++ /dev/null @@ -1,13 +0,0 @@ -const isServerSide = () => typeof window === "undefined" - -export const SESSION_STORAGE = { - can: !isServerSide(), - get: async key => JSON.parse(sessionStorage.getItem(key)), - put: async (key, value) => sessionStorage.setItem(key, JSON.stringify(value)), -} - -export const LOCAL_STORAGE = { - can: !isServerSide(), - get: async key => JSON.parse(localStorage.getItem(key)), - put: async (key, value) => localStorage.setItem(key, JSON.stringify(value)), -}