Skip to content

Commit

Permalink
Merge pull request #4 from wpdas/fix/localstorage-nextjs
Browse files Browse the repository at this point in the history
Fix: naxios running on server side
  • Loading branch information
wpdas authored Jul 29, 2024
2 parents a342054 + 030b596 commit 6e272e3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wpdas/naxios",
"version": "2.1.0",
"version": "2.1.1",
"description": "Promise based NEAR Contract and NEAR Wallet client for browser",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/managers/contract-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ContractManager {

const outcome = JSON.parse(Buffer.from(res.result).toString()) as R

// If cache is avaiable, store data on it
// If cache is available, store data on it
if (config?.useCache && this.cache) {
await this.cache.setItem<R>(cacheKey, outcome)
}
Expand Down
6 changes: 6 additions & 0 deletions src/managers/wallet-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@near-wallet-selector/core'
import { setupModal } from '@near-wallet-selector/modal-ui'
import { WalletManagerConfig, Network, WalletStatus } from './types'
import { isClient } from '../utils/isClient'

const getTestnetConfig = () => ({
networkId: 'testnet',
Expand Down Expand Up @@ -57,6 +58,11 @@ export class WalletManager {
this.walletSelectorModules = config.walletSelectorModules
}

// Ensure it is going to run on client side only
if (!isClient()) {
return
}

this.changeWalletStatus('pending')

this.initNear().then(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/naxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet'
import ContractManager from './managers/contract-manager'
import WalletManager from './managers/wallet-manager'
import { NaxiosConstructor, Network, ContractApi } from './managers/types'
import { isClient } from './utils/isClient'

class naxios {
private rpcNodeUrl?: ContractManager['rpcNodeUrl']
Expand All @@ -16,6 +17,11 @@ class naxios {
this.contractId = config.contractId
this.network = config.network

// Ensure it is going to run on client side only
if (!isClient()) {
return
}

if (config.walletSelectorModules) {
this.walletSelectorModules = config.walletSelectorModules
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/isClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isClient = () => !(typeof window === 'undefined')

0 comments on commit 6e272e3

Please sign in to comment.