OSDN Git Service

Add convert all the hard-code to i18n
[bytom/bytom-electron.git] / src / utility / localStorage.js
1 export const clear = () => {
2   try {
3     localStorage.clear()
4   } catch (err) {
5     // Local storage is not available.
6   }
7 }
8
9 export const exportState = (store) => () => {
10   const state = store.getState()
11   const exportable = {
12     core: {
13       clientToken: (state.core || {}).clientToken,
14
15       // TODO: If the dashboard has a way of probing the core for a token
16       // requirement, we won't need to store these anymore.
17       requireClientToken: (state.core || {}).requireClientToken,
18       validToken: (state.core || {}).validToken,
19       btmAmountUnit: state.core.btmAmountUnit,
20     },
21     app:{
22       navAdvancedState : state.app.navAdvancedState,
23     },
24     transaction: {
25       generated: (state.transaction || {}).generated,
26     },
27     tutorial: state.tutorial
28   }
29
30   try {
31     localStorage.setItem('reduxState', JSON.stringify(exportable))
32   } catch (err) { /* localstorage not available */ }
33 }
34
35 export const importState = () => {
36   let state
37   try {
38     state = localStorage.getItem('reduxState')
39   } catch (err) { /* localstorage not available */ }
40
41   if (!state) return {}
42
43   try {
44     return JSON.parse(state)
45   } catch (_) {
46     return {}
47   }
48 }