WA-232 Created localStorage tokens utility class
This commit is contained in:
parent
ece4e4a5bf
commit
0f4d5cb33a
|
@ -5,6 +5,7 @@ import { type Owner } from '~/routes/safe/store/model/owner'
|
|||
export const SAFES_KEY = 'SAFES'
|
||||
export const TX_KEY = 'TX'
|
||||
export const OWNERS_KEY = 'OWNERS'
|
||||
export const TOKENS_KEY = 'TOKENS'
|
||||
|
||||
export const load = (key: string) => {
|
||||
try {
|
|
@ -0,0 +1,28 @@
|
|||
// @flow
|
||||
import { List } from 'immutable'
|
||||
import { load, TOKENS_KEY } from '~/utils/localStorage'
|
||||
|
||||
const getTokensKey = (safeAddress: string) => `${TOKENS_KEY}-${safeAddress}`
|
||||
|
||||
export const setTokens = (safeAddress: string, tokens: List<string>) => {
|
||||
try {
|
||||
const serializedState = JSON.stringify(tokens)
|
||||
const key = getTokensKey(safeAddress)
|
||||
localStorage.setItem(key, serializedState)
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line
|
||||
console.log('Error storing tokens in localstorage')
|
||||
}
|
||||
}
|
||||
|
||||
export const getTokens = (safeAddress: string): List<string> => {
|
||||
const key = getTokensKey(safeAddress)
|
||||
const data = load(key)
|
||||
|
||||
return data ? List(data) : List()
|
||||
}
|
||||
|
||||
export const storedTokensBefore = (safeAddress: string) => {
|
||||
const key = getTokensKey(safeAddress)
|
||||
return localStorage.getItem(key) === null
|
||||
}
|
Loading…
Reference in New Issue