-
Notifications
You must be signed in to change notification settings - Fork 504
/
index.tsx
196 lines (183 loc) · 4.92 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 {
CARD_TYPES,
DEFAULT_CARD_SVG_LOGO
} from 'components/Form/CreditCardBox/model'
import { convertBaseToStandard } from 'data/components/exchange/services'
import { DisplayIcon } from 'components/SimpleBuy'
import { fiatToString } from 'core/exchange/currency'
import { FiatType, SBPaymentMethodType } from 'core/types'
import { FormattedMessage } from 'react-intl'
import { IcoMoonType } from 'blockchain-info-components/src/Icons/Icomoon'
import { Icon, Text } from 'blockchain-info-components'
import { Props } from '..'
import { Title } from 'components/Flyout'
import React, { ReactElement } from 'react'
import styled, { css } from 'styled-components'
type PaymentContainerProps = {
isMethod: boolean
}
const PaymentContainer = styled.div<PaymentContainerProps>`
border: 1px solid ${props => props.theme.grey100};
box-sizing: border-box;
height: 80px;
border-radius: 8px;
margin-bottom: 24px;
display: flex;
flex-direction: row;
cursor: pointer;
padding: ${props => (props.isMethod ? `12px 28px` : `23px 28px`)};
justify-content: space-between;
${props => !props.isMethod && `line-height: 32px;`}
`
const PaymentText = styled(Text)<PaymentContainerProps>`
flex: 1;
justify-content: center;
display: flex;
flex-direction: column;
padding-left: 16px;
${props =>
!props.isMethod &&
css`
font-style: normal;
font-weight: 600;
font-size: 14px;
line-height: 35px;
`}
`
const PaymentArrowContainer = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
`
const DisplayTitle = styled(Title)`
align-items: left;
font-weight: 600;
display: flex;
flex-direction: column;
line-height: 24px;
color: ${props => props.theme.textBlack};
width: 100%;
`
const DisplaySubTitle = styled(Title)`
align-items: left;
font-weight: 500;
font-size: 12px;
line-height: 24px;
color: ${props => props.theme.grey600};
width: 100%;
`
const DisplayPaymentIcon = styled(DisplayIcon)<PaymentContainerProps>`
justify-content: center;
${props =>
!props.isMethod &&
css`
background-color: ${props => props.theme.blue000};
width: 32px;
height: 32px;
border-radius: 50%;
`}
`
const renderCardText = (value: SBPaymentMethodType): string => {
return value.card
? value.card.label
? value.card.label
: value.card.type
: 'Credit or Debit Card'
}
const renderCard = (value: SBPaymentMethodType) => (
<>
<DisplayTitle>{renderCardText(value)}</DisplayTitle>
<DisplaySubTitle>
<FormattedMessage
id='modals.simplebuy.card_limit'
defaultMessage='{card} Limit'
values={{
card: `${fiatToString({
value: convertBaseToStandard('FIAT', value.limits.max),
unit: String(value.currency) as FiatType
})} ${value.currency}`
}}
/>
</DisplaySubTitle>
</>
)
const renderFund = (value: SBPaymentMethodType) => (
<>
<DisplayTitle>{value.currency}</DisplayTitle>
<DisplaySubTitle>
{fiatToString({
value: convertBaseToStandard('FIAT', value.limits.max),
unit: String(value.currency) as FiatType
})}
</DisplaySubTitle>
</>
)
const getIcon = (value: SBPaymentMethodType | undefined): ReactElement => {
if (!value) {
return (
<Icon
cursor
name='plus-in-circle-filled'
size='22px'
color='blue600'
style={{ marginLeft: '5px' }}
/>
)
}
switch (value.type) {
case 'USER_CARD':
let cardType = CARD_TYPES.find(
card => card.type === (value.card ? value.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 keyof IcoMoonType}
/>
)
default:
return <></>
}
}
const getText = (value: SBPaymentMethodType | undefined): ReactElement => {
if (!value) {
return (
<FormattedMessage
id='modals.simplebuy.confirm.jump_to_payment'
defaultMessage='Select Cash or Card'
/>
)
}
return value.type === 'USER_CARD' ? renderCard(value) : renderFund(value)
}
const Payment: React.FC<Props> = props => (
<PaymentContainer
onClick={() =>
props.simpleBuyActions.setStep({
step: 'PAYMENT_METHODS',
pair: props.pair,
fiatCurrency: props.fiatCurrency || 'USD',
cryptoCurrency: props.cryptoCurrency
})
}
isMethod={!!props.method}
>
<DisplayPaymentIcon isMethod={!!props.method}>
{getIcon(props.method)}
</DisplayPaymentIcon>
<PaymentText isMethod={!!props.method}>{getText(props.method)}</PaymentText>
<PaymentArrowContainer>
<Icon cursor name='arrow-right' size='20px' color='grey600' />
</PaymentArrowContainer>
</PaymentContainer>
)
export default Payment