forked from comit-network/xmr-btc-swap
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gui): Preserve global state across page reloads (#48)
- Loading branch information
1 parent
c7c7cf1
commit d913206
Showing
5 changed files
with
35 additions
and
11 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
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 |
---|---|---|
@@ -1,9 +1,28 @@ | ||
import { configureStore } from "@reduxjs/toolkit"; | ||
import { combineReducers, configureStore } from "@reduxjs/toolkit"; | ||
import { persistReducer, persistStore } from "redux-persist"; | ||
import sessionStorage from "redux-persist/lib/storage/session"; | ||
import { reducers } from "store/combinedReducer"; | ||
|
||
// We persist the redux store in sessionStorage | ||
// The point of this is to preserve the store across reloads while not persisting it across GUI restarts | ||
// | ||
// If the user reloads the page, while a swap is running we want to | ||
// continue displaying the correct state of the swap | ||
const persistConfig = { | ||
key: "gui-global-state-store", | ||
storage: sessionStorage, | ||
}; | ||
|
||
const persistedReducer = persistReducer( | ||
persistConfig, | ||
combineReducers(reducers), | ||
); | ||
|
||
export const store = configureStore({ | ||
reducer: reducers, | ||
reducer: persistedReducer, | ||
}); | ||
|
||
export const persistor = persistStore(store); | ||
|
||
export type AppDispatch = typeof store.dispatch; | ||
export type RootState = ReturnType<typeof store.getState>; |
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