-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
234 lines (221 loc) · 6.74 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import {
CARD_TYPES,
DEFAULT_CARD_SVG_LOGO
} from 'components/Form/CreditCardBox/model'
import { FlyoutWrapper } from 'components/Flyout'
import { Form, InjectedFormProps, reduxForm } from 'redux-form'
import { FormattedMessage } from 'react-intl'
import { Icon, Text } from 'blockchain-info-components'
import { Props as OwnProps, SuccessStateType } from '../index'
import { SBPaymentMethodType } from 'core/types'
import BankAccount from './BankAccount'
import Card from './Card'
import Fund from './Fund'
import PaymentCard from './PaymentCard'
import React, { PureComponent, ReactElement } from 'react'
import styled from 'styled-components'
const Wrapper = styled.div`
display: flex;
justify-content: space-between;
flex-direction: column;
height: 100%;
`
const TopText = styled(Text)`
display: flex;
align-items: center;
margin-bottom: 7px;
`
const PaymentsWrapper = styled.div`
border-top: 1px solid ${props => props.theme.grey000};
`
const IconContainer = styled.div`
width: 38px;
height: 38px;
border-radius: 50%;
background-color: ${props => props.theme.blue000};
display: flex;
align-items: center;
justify-content: center;
`
export type Props = OwnProps & SuccessStateType
class Payments extends PureComponent<InjectedFormProps<{}, Props> & Props> {
getType = (value: SBPaymentMethodType) => {
switch (value.type) {
case 'BANK_ACCOUNT':
return 'Deposit Cash'
case 'PAYMENT_CARD':
return 'Add a Credit or Debit Card'
case 'USER_CARD':
return value && value.card
? value.card.label
? value.card.label
: value.card.type
: 'Add a Credit or Debit Card'
case 'FUNDS':
return ''
}
}
handleSubmit = (method: SBPaymentMethodType) => {
this.props.simpleBuyActions.handleSBMethodChange(method)
}
getIcon = (value: SBPaymentMethodType): ReactElement => {
switch (value.type) {
case 'BANK_ACCOUNT':
return (
<IconContainer>
<Icon size='18px' color='blue600' name='arrow-down' />
</IconContainer>
)
case 'PAYMENT_CARD':
return (
<IconContainer>
<Icon size='18px' color='blue600' name='bank-filled' />
</IconContainer>
)
case 'USER_CARD':
const { card } = value
if (!card) {
return <></>
}
const cardType = CARD_TYPES.find(cc => cc.type === card.type)
return (
<img
height='18px'
width='auto'
src={cardType ? cardType.logo : DEFAULT_CARD_SVG_LOGO}
/>
)
case 'FUNDS':
return (
<Icon
size='32px'
color='fiat'
name={value.currency.toLowerCase() as 'eur' | 'gbp'}
/>
)
}
}
renderCardText = (value: SBPaymentMethodType): string => {
return value.card
? value.card.label
? value.card.label
: value.card.type
: 'Credit or Debit Card'
}
render () {
const { fiatCurrency } = this.props
const availableCards = this.props.cards.filter(
card => card.state === 'ACTIVE'
)
const defaultMethods = this.props.paymentMethods.methods.map(value => ({
text: this.getType(value),
value
}))
const defaultCardMethod = this.props.paymentMethods.methods.find(
m => m.type === 'PAYMENT_CARD'
)
const funds = defaultMethods.filter(
method => method.value.type === 'FUNDS' && method.value.currency !== 'USD'
)
const paymentCard = defaultMethods.find(
method => method.value.type === 'PAYMENT_CARD'
)
const bankAccount = defaultMethods.find(
method => method.value.type === 'BANK_ACCOUNT'
)
const cardMethods = availableCards.map(card => ({
text: card.card
? card.card.label
? card.card.label
: card.card.type
: 'Credit or Debit Card',
value: {
...card,
card: card.card,
type: 'USER_CARD',
currency: card.currency,
limits:
defaultCardMethod && defaultCardMethod.limits
? defaultCardMethod.limits
: { min: '1000', max: '500000' }
} as SBPaymentMethodType
}))
return (
<Wrapper>
<Form>
<FlyoutWrapper>
<TopText color='grey800' size='20px' weight={600}>
<Icon
cursor
name='arrow-left'
size='20px'
color='grey600'
style={{ marginRight: '28px' }}
role='button'
onClick={() =>
this.props.simpleBuyActions.setStep({
step: 'ENTER_AMOUNT',
fiatCurrency: this.props.fiatCurrency || 'USD',
pair: this.props.pair
})
}
/>
<div>
<FormattedMessage
id='modals.simplebuy.paymentmethods'
defaultMessage='Payment Methods'
/>
</div>
</TopText>
</FlyoutWrapper>
<PaymentsWrapper>
{funds &&
funds.map((fund, index) => (
<Fund
key={`${fund.text}-${index}`}
value={fund.value}
icon={this.getIcon(fund.value)}
onClick={() => this.handleSubmit(fund.value)}
balance={this.props.balances[fund.value.currency].available}
/>
))}
{cardMethods &&
cardMethods.map((cardMethod, index) => (
<Card
key={`${cardMethod.text}-${index}`}
value={cardMethod.value}
text={this.renderCardText(cardMethod.value)}
icon={this.getIcon(cardMethod.value)}
onClick={() => this.handleSubmit(cardMethod.value)}
/>
))}
{paymentCard && (
<PaymentCard
key={`${paymentCard.text}`}
{...paymentCard}
icon={this.getIcon(paymentCard.value)}
onClick={() =>
this.props.simpleBuyActions.setStep({
step: 'ADD_CARD'
})
}
/>
)}
{bankAccount && fiatCurrency && (
<BankAccount
key={`${bankAccount.text}`}
{...bankAccount}
icon={this.getIcon(bankAccount.value)}
onClick={() => this.handleSubmit(bankAccount.value)}
/>
)}
</PaymentsWrapper>
</Form>
</Wrapper>
)
}
}
export default reduxForm<{}, Props>({
form: 'sbPaymentMethods',
destroyOnUnmount: false
})(Payments)