WA-232 Created localStorage tokens utility class

This commit is contained in:
apanizo 2018-07-11 12:59:50 +02:00
parent ece4e4a5bf
commit 0f4d5cb33a
2 changed files with 29 additions and 0 deletions

View File

@ -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 {

View File

@ -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
}