From 042540ec95146417165386f3ca9c5de7ef749111 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 25 May 2018 11:27:21 +0200 Subject: [PATCH] removed SessionStorageService --- src/js/services/SessionStorageService.js | 158 ----------------------- src/js/services/index.js | 2 - 2 files changed, 160 deletions(-) delete mode 100644 src/js/services/SessionStorageService.js diff --git a/src/js/services/SessionStorageService.js b/src/js/services/SessionStorageService.js deleted file mode 100644 index d1033eb1..00000000 --- a/src/js/services/SessionStorageService.js +++ /dev/null @@ -1,158 +0,0 @@ -/* @flow */ -'use strict'; - -import * as LocalStorageActions from '../actions/LocalStorageActions'; -import * as SendFormActions from '../actions/SendFormActions'; - -import { DEVICE } from 'trezor-connect'; -import * as CONNECT from '../actions/constants/TrezorConnect'; -import * as MODAL from '../actions/constants/modal'; -import * as TOKEN from '../actions/constants/token'; -import * as ACCOUNT from '../actions/constants/account'; -import * as DISCOVERY from '../actions/constants/discovery'; -import * as SEND from '../actions/constants/send'; -import * as WEB3 from '../actions/constants/web3'; -import * as PENDING from '../actions/constants/pendingTx'; -import { LOCATION_CHANGE } from 'react-router-redux'; -import { findAccountTokens } from '../reducers/TokensReducer'; - -import type { - Middleware, - MiddlewareAPI, - MiddlewareDispatch, - State, - Dispatch, - Action, - AsyncAction, - GetState -} from '~/flowtype'; - -import type { TrezorDevice } from '~/flowtype'; -import type { Account } from '../reducers/AccountsReducer'; -import type { Token } from '../reducers/TokensReducer'; -import type { PendingTx } from '../reducers/PendingTxReducer'; -import type { Discovery } from '../reducers/DiscoveryReducer'; - - -const save = (dispatch: Dispatch, getState: GetState): void => { - - if (typeof window.sessionStorage === 'undefined') return; - - const accountState = getState().selectedAccount; - const sendState = getState().sendForm; - if (accountState && !sendState.untouched) { - const value = { - address: sendState.address, - amount: sendState.amount, - setMax: sendState.setMax, - selectedCurrency: sendState.selectedCurrency, - selectedFeeLevel: sendState.selectedFeeLevel, - advanced: sendState.advanced, - gasLimit: sendState.gasLimit, - gasPrice: sendState.gasPrice, - data: sendState.data, - nonce: sendState.nonce, - touched: sendState.touched - } - - try { - window.sessionStorage.setItem(`SEND:${accountState.location}`, JSON.stringify(value) ); - } catch (error) { - console.error("Saving sessionStorage error: " + error) - } - - } -} - -const load = (dispatch: Dispatch, getState: GetState): void => { - - if (typeof window.localStorage === 'undefined') return; - - const accountState = getState().selectedAccount; - const sendState = getState().sendForm; - - if (accountState) { - try { - const key: string = `SEND:${accountState.location}`; - const value: string = window.sessionStorage.getItem(key); - const json = JSON.parse(value); - - if (json) { - - // check if this token still exists in user tokens list - if (json.selectedCurrency !== sendState.coinSymbol) { - const token = getState().tokens.find(t => t.symbol === json.selectedCurrency); - if (!token) { - window.sessionStorage.removeItem(key); - return; - } - } - - dispatch({ - type: SEND.FROM_SESSION_STORAGE, - address: json.address, - amount: json.amount, - setMax: false, - selectedCurrency: json.selectedCurrency, - selectedFeeLevel: json.selectedFeeLevel, - advanced: json.advanced, - gasLimit: json.gasLimit, - gasPrice: json.gasPrice, - data: json.data, - nonce: json.nonce, - touched: json.touched, - }); - - if (json.setMax) { - dispatch(SendFormActions.onSetMax()); - } else { - // dispatch(SendFormActions.validation()); - dispatch(SendFormActions.onAmountChange(json.amount)); - } - - - } - } catch (error) { - console.error("Loading sessionStorage error: " + error) - } - } -} - - -const clear = (getState: GetState) => { - if (typeof window.localStorage === 'undefined') return; - - const accountState = getState().selectedAccount; - if (accountState) { - const key: string = `SEND:${accountState.location}`; - window.sessionStorage.removeItem(key); - } -} - -const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (action: Action): Action => { - - if (action.type === ACCOUNT.DISPOSE) { - // if (action.type === SEND.DISPOSE) { - // save fields before dispose action - save(api.dispatch, api.getState); - } - - next(action); - - - switch (action.type) { - - // load fields after action - case SEND.INIT : - load(api.dispatch, api.getState); - break; - - case SEND.TX_COMPLETE : - clear(api.getState); - break; - } - - return action; -}; - -export default LocalStorageService; \ No newline at end of file diff --git a/src/js/services/index.js b/src/js/services/index.js index f5b6e7da..0417349a 100644 --- a/src/js/services/index.js +++ b/src/js/services/index.js @@ -5,7 +5,6 @@ import WalletService from './WalletService'; import LogService from './LogService'; import RouterService from './RouterService'; import LocalStorageService from './LocalStorageService'; -import SessionStorageService from './SessionStorageService'; import CoinmarketcapService from './CoinmarketcapService'; import TrezorConnectService from './TrezorConnectService'; @@ -14,7 +13,6 @@ export default [ LogService, RouterService, LocalStorageService, - SessionStorageService, TrezorConnectService, CoinmarketcapService, ]; \ No newline at end of file