|
|
|
@ -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<?SendFormState> => (dispatch: Dispatch, getState: GetState): ?SendFormState => {
|
|
|
|
|
export const loadEthereumDraftTransaction = (): PayloadAction<?EthereumSendFormState> => (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<?SendFormState> => (dispat
|
|
|
|
|
return state;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const loadRippleDraftTransaction = (): PayloadAction<?RippleSendFormState> => (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);
|
|
|
|
|