type definition fixes

This commit is contained in:
Mikhail Mikheev 2020-06-29 15:29:27 +04:00
parent f2f9cb7d81
commit ed72219f03
2 changed files with 7 additions and 4 deletions

View File

@ -12,7 +12,7 @@ export const CUSTOM_TOKENS_KEY = 'CUSTOM_TOKENS'
export const saveActiveTokens = async (tokens: Map<string, Token>): Promise<void> => {
try {
await saveToStorage(ACTIVE_TOKENS_KEY, tokens.toJS())
await saveToStorage(ACTIVE_TOKENS_KEY, tokens.toJS() as Record<string, TokenProps>)
} catch (err) {
console.error('Error storing tokens in localstorage', err)
}

View File

@ -10,7 +10,7 @@ export const storage = new ImmortalStorage(stores)
const PREFIX = `v2_${getNetwork()}`
export const loadFromStorage = async <T extends unknown>(key: string): Promise<T | undefined> => {
export const loadFromStorage = async <T = unknown>(key: string): Promise<T | undefined> => {
try {
const stringifiedValue = await storage.get(`${PREFIX}__${key}`)
if (stringifiedValue === null || stringifiedValue === undefined) {
@ -24,7 +24,10 @@ export const loadFromStorage = async <T extends unknown>(key: string): Promise<T
}
}
export const saveToStorage = async (key, value) => {
export const saveToStorage = async (
key: string,
value: Record<string, unknown> | boolean | string | number | Array<unknown>,
): Promise<void> => {
try {
const stringifiedValue = JSON.stringify(value)
await storage.set(`${PREFIX}__${key}`, stringifiedValue)
@ -33,7 +36,7 @@ export const saveToStorage = async (key, value) => {
}
}
export const removeFromStorage = async (key) => {
export const removeFromStorage = async (key: string): Promise<void> => {
try {
await storage.remove(`${PREFIX}__${key}`)
} catch (err) {