From 2cc28c4bf6be19ce98d8eb67823f08461f0b02e7 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Mon, 3 Dec 2018 19:28:18 +0100 Subject: [PATCH] load coin specific tx drafts --- src/actions/SessionStorageActions.js | 22 +++++++++++++++++++--- src/actions/ethereum/SendFormActions.js | 2 +- src/actions/ripple/SendFormActions.js | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/actions/SessionStorageActions.js b/src/actions/SessionStorageActions.js index 6e696960..3686d8f4 100644 --- a/src/actions/SessionStorageActions.js +++ b/src/actions/SessionStorageActions.js @@ -2,7 +2,8 @@ import * as storageUtils from 'utils/storage'; import { findToken } from 'reducers/TokensReducer'; -import type { State as SendFormState } from 'reducers/SendFormEthereumReducer'; +import type { State as EthereumSendFormState } from 'reducers/SendFormEthereumReducer'; +import type { State as RippleSendFormState } from 'reducers/SendFormRippleReducer'; import type { ThunkAction, PayloadAction, @@ -27,11 +28,11 @@ export const saveDraftTransaction = (): ThunkAction => (dispatch: Dispatch, getS storageUtils.set(TYPE, key, JSON.stringify(state)); }; -export const loadDraftTransaction = (): PayloadAction => (dispatch: Dispatch, getState: GetState): ?SendFormState => { +export const loadEthereumDraftTransaction = (): PayloadAction => (dispatch: Dispatch, getState: GetState): ?EthereumSendFormState => { const key = getTxDraftKey(getState); const value: ?string = storageUtils.get(TYPE, key); if (!value) return null; - const state: ?SendFormState = JSON.parse(value); + const state: ?EthereumSendFormState = JSON.parse(value); if (!state) return null; // decide if draft is valid and should be returned // ignore this draft if has any error @@ -52,6 +53,21 @@ export const loadDraftTransaction = (): PayloadAction => (dispat return state; }; +export const loadRippleDraftTransaction = (): PayloadAction => (dispatch: Dispatch, getState: GetState): ?RippleSendFormState => { + const key = getTxDraftKey(getState); + const value: ?string = storageUtils.get(TYPE, key); + if (!value) return null; + const state: ?RippleSendFormState = JSON.parse(value); + if (!state) return null; + // decide if draft is valid and should be returned + // ignore this draft if has any error + if (Object.keys(state.errors).length > 0) { + storageUtils.remove(TYPE, key); + return null; + } + return state; +}; + export const clear = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { const key = getTxDraftKey(getState); storageUtils.remove(TYPE, key); diff --git a/src/actions/ethereum/SendFormActions.js b/src/actions/ethereum/SendFormActions.js index 1d0d28dd..1f29b2ac 100644 --- a/src/actions/ethereum/SendFormActions.js +++ b/src/actions/ethereum/SendFormActions.js @@ -132,7 +132,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS if (!account || !network) return; - const stateFromStorage = dispatch(SessionStorageActions.loadDraftTransaction()); + const stateFromStorage = dispatch(SessionStorageActions.loadEthereumDraftTransaction()); if (stateFromStorage) { // TODO: consider if current gasPrice should be set here as "recommendedGasPrice" dispatch({ diff --git a/src/actions/ripple/SendFormActions.js b/src/actions/ripple/SendFormActions.js index c7c49c3d..8cf9e2aa 100644 --- a/src/actions/ripple/SendFormActions.js +++ b/src/actions/ripple/SendFormActions.js @@ -96,7 +96,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS if (!account || !network) return; - const stateFromStorage = dispatch(SessionStorageActions.loadDraftTransaction()); + const stateFromStorage = dispatch(SessionStorageActions.loadRippleDraftTransaction()); if (stateFromStorage) { // TODO: consider if current gasPrice should be set here as "recommendedGasPrice" dispatch({