diff --git a/src/utils/localStorage.js b/src/utils/localStorage/index.js similarity index 97% rename from src/utils/localStorage.js rename to src/utils/localStorage/index.js index 474e3dbb..f908a03a 100644 --- a/src/utils/localStorage.js +++ b/src/utils/localStorage/index.js @@ -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 { diff --git a/src/utils/localStorage/tokens.js b/src/utils/localStorage/tokens.js new file mode 100644 index 00000000..a29fd3fb --- /dev/null +++ b/src/utils/localStorage/tokens.js @@ -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) => { + 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 => { + 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 +}