-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
196 lines (184 loc) · 6.01 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { actions, selectors } from 'data'
import { bindActionCreators, compose, Dispatch } from 'redux'
import {
CoinType,
SBOrderType,
SBPairType,
SBPaymentMethodType
} from 'core/types'
import { connect } from 'react-redux'
import { ModalPropsType } from '../types'
import { RootState } from 'data/rootReducer'
import { SimpleBuyStepType } from 'data/types'
import AddCard from './AddCard'
import BillingAddress from './BillingAddress'
import CancelOrder from './CancelOrder'
import CheckoutConfirm from './CheckoutConfirm'
import CryptoSelection from './CryptoSelection'
import CurrencySelection from './CurrencySelection'
import EnterAmount from './EnterAmount'
import Flyout, { duration, FlyoutChild } from 'components/Flyout'
import ModalEnhancer from 'providers/ModalEnhancer'
import OrderSummary from './OrderSummary'
import PaymentMethods from './PaymentMethods'
import React, { PureComponent } from 'react'
import ThreeDSHandler from './ThreeDSHandler'
import TransferDetails from './TransferDetails'
class SimpleBuy extends PureComponent<Props, State> {
state: State = { show: false, direction: 'left' }
componentDidMount () {
/* eslint-disable */
this.setState({ show: true })
/* eslint-enable */
}
componentDidUpdate (prevProps: Props) {
if (this.props.step === prevProps.step) return
if (
SimpleBuyStepType[this.props.step] > SimpleBuyStepType[prevProps.step]
) {
/* eslint-disable */
this.setState({ direction: 'left' })
} else {
this.setState({ direction: 'right' })
/* eslint-enable */
}
}
componentWillUnmount () {
this.props.simpleBuyActions.pollSBBalances()
this.props.simpleBuyActions.destroyCheckout()
this.props.formActions.destroy('ccBillingAddress')
this.props.formActions.destroy('addCCForm')
}
handleClose = () => {
this.setState({ show: false })
setTimeout(() => {
this.props.close()
}, duration)
}
render () {
return (
<Flyout
{...this.props}
onClose={this.handleClose}
in={this.state.show}
direction={this.state.direction}
data-e2e='simpleBuyModal'
>
{this.props.step === 'CURRENCY_SELECTION' && (
<FlyoutChild>
<CurrencySelection {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'ENTER_AMOUNT' && (
<FlyoutChild>
<EnterAmount {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'CRYPTO_SELECTION' && (
<FlyoutChild>
<CryptoSelection {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'PAYMENT_METHODS' && (
<FlyoutChild>
<PaymentMethods {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'ADD_CARD' && (
<FlyoutChild>
<AddCard {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'CC_BILLING_ADDRESS' && (
<FlyoutChild>
<BillingAddress {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === '3DS_HANDLER' && (
<FlyoutChild>
<ThreeDSHandler {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'CHECKOUT_CONFIRM' && (
<FlyoutChild>
<CheckoutConfirm {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'ORDER_SUMMARY' && (
<FlyoutChild>
<OrderSummary {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'TRANSFER_DETAILS' && (
<FlyoutChild>
<TransferDetails {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
{this.props.step === 'CANCEL_ORDER' && (
<FlyoutChild>
<CancelOrder {...this.props} handleClose={this.handleClose} />
</FlyoutChild>
)}
</Flyout>
)
}
}
const mapStateToProps = (state: RootState) => ({
step: selectors.components.simpleBuy.getStep(state),
cardId: selectors.components.simpleBuy.getSBCardId(state),
pair: selectors.components.simpleBuy.getSBPair(state),
method: selectors.components.simpleBuy.getSBPaymentMethod(state),
order: selectors.components.simpleBuy.getSBOrder(state),
cryptoCurrency: selectors.components.simpleBuy.getCryptoCurrency(state)
})
const mapDispatchToProps = (dispatch: Dispatch): LinkDispatchPropsType => ({
formActions: bindActionCreators(actions.form, dispatch),
settingsActions: bindActionCreators(actions.modules.settings, dispatch),
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch)
})
const enhance = compose(
ModalEnhancer('SIMPLE_BUY_MODAL', { transition: duration }),
connect(mapStateToProps, mapDispatchToProps)
)
type OwnProps = ModalPropsType
export type LinkDispatchPropsType = {
formActions: typeof actions.form
settingsActions: typeof actions.modules.settings
simpleBuyActions: typeof actions.components.simpleBuy
}
type LinkStatePropsType =
| {
step:
| 'CURRENCY_SELECTION'
| 'CRYPTO_SELECTION'
| '3DS_HANDLER'
| 'CC_BILLING_ADDRESS'
}
| {
order: SBOrderType
step:
| 'CHECKOUT_CONFIRM'
| 'TRANSFER_DETAILS'
| 'ORDER_SUMMARY'
| 'CANCEL_ORDER'
}
| {
cardId?: string
cryptoCurrency?: CoinType
pair: SBPairType
step: 'ADD_CARD'
}
| {
method?: SBPaymentMethodType
order?: SBOrderType
pair: SBPairType
step: 'ENTER_AMOUNT'
}
| {
order: SBOrderType
pair: SBPairType
step: 'PAYMENT_METHODS'
}
type Props = OwnProps & LinkDispatchPropsType & LinkStatePropsType
type State = { direction: 'left' | 'right'; show: boolean }
export default enhance(SimpleBuy)