forked from dwallet-labs/dwallet-network
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dapp-kit] default storage to memory storage when local storage isn't…
… available in an SSR context (#15554) ## Description dapp-kit breaks when used in a framework like Next since we default to using local storage for persisting connection data which doesn't exist in an SSR context. While we're working on better support for these frameworks, this PR fixes the immediate breakage issue by defaulting to memory storage when local storage isn't available. I also added the option to entirely disable data persistence by setting `storage: null` in the `WalletProvider`. Most of this was copy-pasta'd from @Jordan-Mysten's Next PR, I did hoist the storage determination logic up to the `WalletProvider` since I think it might be more clear to consumers what storage ends up being used. I don't have a super strong opinion on where this lives (`WalletProvider.tsx` or `walletStore.ts`), so I'm glad to change this back if anyone has a preference. ## Test Plan - Existing persistence tests pass - Tested manually - CI --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
1 parent
6b31612
commit 9ba167b
Showing
5 changed files
with
55 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@mysten/dapp-kit': patch | ||
--- | ||
|
||
Default storage to memory storage when local storage isn't available during SSR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { WalletWithRequiredFeatures } from '@mysten/wallet-standard'; | ||
|
||
import { createInMemoryStore } from '../utils/stateStorage.js'; | ||
|
||
export const SUI_WALLET_NAME = 'Sui Wallet'; | ||
|
||
export const DEFAULT_STORAGE = | ||
typeof window !== 'undefined' && window.localStorage ? localStorage : createInMemoryStore(); | ||
|
||
export const DEFAULT_STORAGE_KEY = 'sui-dapp-kit:wallet-connection-info'; | ||
|
||
export const DEFAULT_REQUIRED_FEATURES: (keyof WalletWithRequiredFeatures['features'])[] = [ | ||
'sui:signTransactionBlock', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { StateStorage } from 'zustand/middleware'; | ||
|
||
export function createInMemoryStore(): StateStorage { | ||
const store = new Map(); | ||
return { | ||
getItem(key: string) { | ||
return store.get(key); | ||
}, | ||
setItem(key: string, value: string) { | ||
store.set(key, value); | ||
}, | ||
removeItem(key: string) { | ||
store.delete(key); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters