aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/containers/latest_error.tsx
blob: 5272d961089bd099ce98b0bdbfc1637631a12e18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as React from 'react';

import { connect } from 'react-redux';

import { SlidingError } from '../components/sliding_error';
import { State } from '../redux/reducer';
import { errorDescription } from '../util/error_description';

export interface LatestErrorComponentProps {
    assetData?: string;
    latestError?: any;
    latestErrorDismissed?: boolean;
}

export const LatestErrorComponent: React.StatelessComponent<LatestErrorComponentProps> = props => {
    if (!props.latestError) {
        return <div />;
    }
    const slidingDirection = props.latestErrorDismissed ? 'down' : 'up';
    const { icon, message } = errorDescription(props.latestError, props.assetData);
    return <SlidingError direction={slidingDirection} icon={icon} message={message} />;
};

interface ConnectedState {
    assetData?: string;
    latestError?: any;
    latestErrorDismissed?: boolean;
}
export interface LatestErrorProps {}
const mapStateToProps = (state: State, _ownProps: LatestErrorProps): ConnectedState => ({
    assetData: state.selectedAssetData,
    latestError: state.latestError,
    latestErrorDismissed: state.latestErrorDismissed,
});

export const LatestError = connect(mapStateToProps)(LatestErrorComponent);