mirror of
https://github.com/trezor/trezor-wallet
synced 2024-12-01 04:38:15 +00:00
load coin specific tx drafts
This commit is contained in:
parent
9cc11e11be
commit
2cc28c4bf6
@ -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);
|
||||
|
@ -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({
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user