-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
67 lines (59 loc) · 2.11 KB
/
index.tsx
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { bindActionCreators, Dispatch } from 'redux'
import { connect, ConnectedProps } from 'react-redux'
import React, { PureComponent } from 'react'
import { actions, selectors } from 'data'
import {
ExtractSuccess,
FiatType,
RemoteDataType,
SBOrderType,
SBPairType,
SBPaymentMethodType
} from 'core/types'
import { getData } from './selectors'
import { Remote } from 'blockchain-wallet-v4/src'
import { RootState } from 'data/rootReducer'
import Failure from './template.failure'
import Loading from './template.loading'
import Success from './template.success'
class EnterAmount extends PureComponent<Props> {
componentDidMount () {
if (this.props.fiatCurrency && !Remote.Success.is(this.props.data)) {
this.props.simpleBuyActions.fetchSBPaymentMethods(this.props.fiatCurrency)
this.props.simpleBuyActions.fetchSBOrders()
this.props.simpleBuyActions.fetchSBCards()
}
}
render () {
return this.props.data.cata({
Success: val => <Success {...val} {...this.props} />,
Failure: () => <Failure {...this.props} />,
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
}
}
const mapStateToProps = (state: RootState): LinkStatePropsType => ({
data: getData(state),
fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state)
})
export const mapDispatchToProps = (dispatch: Dispatch) => ({
analyticsActions: bindActionCreators(actions.analytics, dispatch),
formActions: bindActionCreators(actions.form, dispatch),
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch)
})
const connector = connect(mapStateToProps, mapDispatchToProps)
export type OwnProps = {
handleClose: () => void
method?: SBPaymentMethodType
order?: SBOrderType
pair: SBPairType
}
export type SuccessStateType = ExtractSuccess<ReturnType<typeof getData>>
export type LinkStatePropsType = {
data: RemoteDataType<string, SuccessStateType>
fiatCurrency: undefined | FiatType
}
export type LinkDispatchPropsType = ReturnType<typeof mapDispatchToProps>
export type Props = OwnProps & ConnectedProps<typeof connector>
export default connector(EnterAmount)