1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 01:08:27 +00:00

+ SessionStorageActions

This commit is contained in:
Szymon Lesisz 2018-05-25 11:20:39 +02:00
parent 2025198d85
commit d74c2ceaba

View File

@ -0,0 +1,43 @@
/* @flow */
'use strict';
import type { State as SendFormState } from '../reducers/SendFormReducer';
const PREFIX: string = 'trezor:draft-tx:';
export const save = (location: string, state: SendFormState): void => {
if (typeof window.localStorage === 'undefined') return;
if (!state.untouched) {
try {
window.sessionStorage.setItem(`${PREFIX}${location}`, JSON.stringify(state) );
} catch (error) {
console.error("Saving sessionStorage error: " + error)
}
}
}
export const load = (location: string): ?SendFormState => {
if (typeof window.localStorage === 'undefined') return;
try {
const value: string = window.sessionStorage.getItem(`${PREFIX}${location}`);
return JSON.parse(value);
} catch (error) {
console.error("Loading sessionStorage error: " + error)
}
return;
}
export const clear = (location: string) => {
if (typeof window.localStorage === 'undefined') return;
try {
window.sessionStorage.removeItem(`${PREFIX}${location}`);
} catch (error) {
console.error("Clearing sessionStorage error: " + error)
}
}