-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
76 lines (68 loc) · 2.19 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
68
69
70
71
72
73
74
75
76
import { actions, selectors } from 'data'
import { bindActionCreators, Dispatch } from 'redux'
import { connect, ConnectedProps } from 'react-redux'
import {
FiatType,
RemoteDataType,
SBBuyOrderType,
SBPaymentMethodsType,
SBSellOrderType
} from 'core/types'
import { getData } from './selectors'
import { Remote } from 'core'
import { RootState } from 'data/rootReducer'
import { SBAddCardFormValuesType } from 'data/types'
import DataError from 'components/DataError'
import Loading from './template.loading'
import React, { PureComponent } from 'react'
import Success from './template.success'
class AddCard extends PureComponent<Props> {
componentDidMount () {
if (!Remote.Success.is(this.props.data)) {
this.props.simpleBuyActions.fetchSBPaymentMethods(this.props.fiatCurrency)
}
}
handleSubmit = () => {
this.props.simpleBuyActions.addCardDetails()
}
render () {
return this.props.data.cata({
Success: val => (
<Success {...this.props} {...val} onSubmit={this.handleSubmit} />
),
Failure: e => (
<DataError
message={{ message: e }}
onClick={this.props.simpleBuyActions.fetchSBPaymentMethods}
/>
),
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
}
}
const mapStateToProps = (state: RootState): LinkStatePropsType => ({
data: getData(state),
fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state) || 'EUR'
})
const mapDispatchToProps = (dispatch: Dispatch): LinkDispatchPropsType => ({
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch)
})
const connector = connect(mapStateToProps, mapDispatchToProps)
type OwnProps = {
handleClose: () => void
}
type LinkDispatchPropsType = {
simpleBuyActions: typeof actions.components.simpleBuy
}
type LinkStatePropsType = {
data: RemoteDataType<string, SuccessStateType>
fiatCurrency: FiatType
}
export type SuccessStateType = {
formValues?: SBAddCardFormValuesType
order: SBBuyOrderType | SBSellOrderType | undefined
paymentMethods: SBPaymentMethodsType
}
export type Props = OwnProps & ConnectedProps<typeof connector>
export default connect(mapStateToProps, mapDispatchToProps)(AddCard)