From 187bbc7fc14ccc0385981a38602334de65e2506c Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 13:26:18 -0700 Subject: latestErrorDismissed -> latestErrorDisplay enum --- packages/instant/src/containers/latest_error.tsx | 11 +++++------ packages/instant/src/redux/reducer.ts | 25 +++++++++++------------- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'packages') diff --git a/packages/instant/src/containers/latest_error.tsx b/packages/instant/src/containers/latest_error.tsx index 5272d9610..7f36d3bf8 100644 --- a/packages/instant/src/containers/latest_error.tsx +++ b/packages/instant/src/containers/latest_error.tsx @@ -3,34 +3,33 @@ import * as React from 'react'; import { connect } from 'react-redux'; import { SlidingError } from '../components/sliding_error'; -import { State } from '../redux/reducer'; +import { LatestErrorDisplay, State } from '../redux/reducer'; import { errorDescription } from '../util/error_description'; export interface LatestErrorComponentProps { assetData?: string; latestError?: any; - latestErrorDismissed?: boolean; + slidingDirection: 'down' | 'up'; } export const LatestErrorComponent: React.StatelessComponent = props => { if (!props.latestError) { return
; } - const slidingDirection = props.latestErrorDismissed ? 'down' : 'up'; const { icon, message } = errorDescription(props.latestError, props.assetData); - return ; + return ; }; interface ConnectedState { assetData?: string; latestError?: any; - latestErrorDismissed?: boolean; + slidingDirection: 'down' | 'up'; } export interface LatestErrorProps {} const mapStateToProps = (state: State, _ownProps: LatestErrorProps): ConnectedState => ({ assetData: state.selectedAssetData, latestError: state.latestError, - latestErrorDismissed: state.latestErrorDismissed, + slidingDirection: state.latestErrorDisplay === LatestErrorDisplay.Present ? 'up' : 'down', }); export const LatestError = connect(mapStateToProps)(LatestErrorComponent); diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 4ff49c225..d23064db7 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -7,22 +7,19 @@ import { AsyncProcessState } from '../types'; import { Action, ActionTypes } from './actions'; -interface BaseState { +export enum LatestErrorDisplay { + Present, + Hidden, +} +export interface State { selectedAssetData?: string; selectedAssetAmount?: BigNumber; selectedAssetBuyState: AsyncProcessState; ethUsdPrice?: BigNumber; latestBuyQuote?: BuyQuote; + latestError?: any; + latestErrorDisplay: LatestErrorDisplay; } -interface StateWithError extends BaseState { - latestError: any; - latestErrorDismissed: boolean; -} -interface StateWithoutError extends BaseState { - latestError: undefined; - latestErrorDismissed: undefined; -} -export type State = StateWithError | StateWithoutError; export const INITIAL_STATE: State = { // TODO: Remove hardcoded zrxAssetData @@ -32,7 +29,7 @@ export const INITIAL_STATE: State = { ethUsdPrice: undefined, latestBuyQuote: undefined, latestError: undefined, - latestErrorDismissed: undefined, + latestErrorDisplay: LatestErrorDisplay.Hidden, }; export const reducer = (state: State = INITIAL_STATE, action: Action): State => { @@ -61,18 +58,18 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State => return { ...state, latestError: action.data, - latestErrorDismissed: false, + latestErrorDisplay: LatestErrorDisplay.Present, }; case ActionTypes.HIDE_ERROR: return { ...state, - latestErrorDismissed: true, + latestErrorDisplay: LatestErrorDisplay.Hidden, }; case ActionTypes.CLEAR_ERROR: return { ...state, latestError: undefined, - latestErrorDismissed: undefined, + latestErrorDisplay: LatestErrorDisplay.Hidden, }; default: return state; -- cgit v1.2.3