diff --git a/packages/sdk/src/Platform/PlatfformManager.ts b/packages/sdk/src/Platform/PlatfformManager.ts index 44e27da2f..73f78430c 100644 --- a/packages/sdk/src/Platform/PlatfformManager.ts +++ b/packages/sdk/src/Platform/PlatfformManager.ts @@ -89,7 +89,7 @@ export class PlatformManager { return this.state.platformType === PlatformType.MobileWeb; } - isNotBrowser() { + static isNotBrowser() { return ( typeof window === 'undefined' || !window?.navigator || @@ -99,14 +99,22 @@ export class PlatformManager { ); } - isNodeJS() { - return this.isNotBrowser() && !this.isReactNative(); + isNotBrowser() { + return PlatformManager.isNotBrowser(); } - isBrowser() { + static isBrowser() { return !this.isNotBrowser(); } + isBrowser() { + return PlatformManager.isBrowser(); + } + + isNodeJS() { + return this.isNotBrowser() && !this.isReactNative(); + } + isUseDeepLink() { return this.state.useDeeplink; } diff --git a/packages/sdk/src/storage-manager/getStorageManager.ts b/packages/sdk/src/storage-manager/getStorageManager.ts index 8bec65d86..72e8ee80b 100644 --- a/packages/sdk/src/storage-manager/getStorageManager.ts +++ b/packages/sdk/src/storage-manager/getStorageManager.ts @@ -3,6 +3,7 @@ import { StorageManager, StorageManagerProps, } from '@metamask/sdk-communication-layer'; +import { PlatformManager } from 'src/Platform/PlatfformManager'; /* #if _NODEJS import { StorageManagerNode as SMDyn } from './StorageManagerNode'; @@ -17,14 +18,21 @@ import { StorageManagerAS as SMDyn } from './StorageManagerAS'; //#endif export const getStorageManager = ( - // platformManager: PlatformManager, options: StorageManagerProps, ): StorageManager => { - // TODO uncomment and test to use similar dynamic imports for each platforms and drop support for JSCC - // Currently might have an issue with NextJS and server side rendering - // if (platformManager.isNotBrowser()) { - // const { StorageManagerNode } = await import('./StorageManagerNode'); - // return new StorageManagerNode(options); - // } - return new SMDyn(options); + if (PlatformManager.isBrowser()) { + return new SMDyn(options); + } + + const noopStorageManager: StorageManager = { + persistChannelConfig: async () => undefined, + getPersistedChannelConfig: async () => undefined, + persistAccounts: async () => undefined, + getCachedAccounts: async () => [], + persistChainId: async () => undefined, + getCachedChainId: async () => undefined, + terminate: async () => undefined, + } as StorageManager; + + return noopStorageManager; };