-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
113 lines (104 loc) · 3.71 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
import { actions, selectors } from 'data'
import { bindActionCreators } from 'redux'
import { connect, ConnectedProps } from 'react-redux'
import {
OwnProps as EnterAmountOwnProps,
SuccessStateType as EnterAmountSuccessStateType
} from '../index'
import { getData } from './selectors'
import { RootState } from 'data/rootReducer'
import { SBPaymentMethodType } from 'core/types'
import { UserDataType } from 'data/types'
import Failure from '../template.failure'
import Loading from './template.loading'
import React, { PureComponent } from 'react'
import Success from './template.success'
class Checkout extends PureComponent<Props> {
componentDidMount () {
this.props.simpleBuyActions.initializeCheckout('BUY')
}
handleSubmit = () => {
// if the user is < tier 2 go to kyc but save order info
// if the user is tier 2 try to submit order, let BE fail
const { formValues, userData } = this.props.data.getOrElse({
userData: { tiers: { current: 0, next: 0, selected: 0 } } as UserDataType
} as SuccessStateType)
if (userData.tiers.current < 2) {
this.props.identityVerificationActions.verifyIdentity(
2,
false,
'SBEnterAmountCheckout'
)
this.props.simpleBuyActions.createSBOrder(
undefined,
this.props.method.type as SBPaymentMethodType['type']
)
} else if (!this.props.method) {
const fiatCurrency = this.props.fiatCurrency || 'USD'
this.props.simpleBuyActions.setStep({
step: 'PAYMENT_METHODS',
fiatCurrency,
pair: this.props.pair,
cryptoCurrency: this.props.cryptoCurrency,
order: this.props.order
})
} else if (formValues && this.props.method) {
switch (this.props.method.type) {
case 'PAYMENT_CARD':
this.props.simpleBuyActions.setStep({
step: 'ADD_CARD'
})
break
case 'USER_CARD':
this.props.simpleBuyActions.createSBOrder(this.props.method.id)
break
case 'BANK_ACCOUNT':
this.props.simpleBuyActions.createSBOrder()
break
case 'FUNDS':
// eslint-disable-next-line
console.log('Payment method type not supported.')
}
}
}
render () {
return this.props.data.cata({
Success: val => (
<Success {...this.props} {...val} onSubmit={this.handleSubmit} />
),
Failure: () => (
<Failure
fiatCurrency={this.props.fiatCurrency}
simpleBuyActions={this.props.simpleBuyActions}
formActions={this.props.formActions}
analyticsActions={this.props.analyticsActions}
/>
),
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
}
}
const mapStateToProps = (state: RootState) => ({
data: getData(state),
fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state),
cryptoCurrency:
selectors.components.simpleBuy.getCryptoCurrency(state) || 'BTC'
})
const mapDispatchToProps = dispatch => ({
analyticsActions: bindActionCreators(actions.analytics, dispatch),
identityVerificationActions: bindActionCreators(
actions.components.identityVerification,
dispatch
),
formActions: bindActionCreators(actions.form, dispatch),
profileActions: bindActionCreators(actions.modules.profile, dispatch),
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch)
})
const connector = connect(mapStateToProps, mapDispatchToProps)
type OwnProps = EnterAmountOwnProps & EnterAmountSuccessStateType
export type SuccessStateType = ReturnType<typeof getData>['data'] & {
formErrors: { amount?: 'ABOVE_MAX' | 'BELOW_MIN' | boolean }
}
export type Props = OwnProps & ConnectedProps<typeof connector>
export default connector(Checkout)