-
Notifications
You must be signed in to change notification settings - Fork 504
/
template.success.tsx
170 lines (162 loc) · 5.04 KB
/
template.success.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
import { Button, Text } from 'blockchain-info-components'
import {
CARD_TYPES,
DEFAULT_CARD_SVG_LOGO
} from 'components/Form/CreditCardBox/model'
import { convertBaseToStandard } from 'data/components/exchange/services'
import { fiatToString } from 'core/exchange/currency'
import { FiatType } from 'core/types'
import { FormattedMessage } from 'react-intl'
import { InjectedFormProps, reduxForm } from 'redux-form'
import { Props as OwnProps, SuccessStateType } from '.'
import {
SettingComponent,
SettingContainer,
SettingHeader,
SettingSummary
} from 'components/Setting'
import media from 'services/ResponsiveService'
import React, { SyntheticEvent } from 'react'
import styled from 'styled-components'
const CardWrapper = styled.div`
display: flex;
padding: 16px;
border-radius: 8px;
margin-bottom: 12px;
justify-content: space-between;
border: 1px solid ${props => props.theme.grey000};
cursor: pointer;
width: 430px;
${media.mobile`
width: 100%;
`}
`
const CustomSettingContainer = styled(SettingContainer)`
${media.atLeastLaptopL`
flex-direction: row;
align-items: flex-start;
justify-content: space-between;
`}
`
const CustomSettingHeader = styled(SettingHeader)`
margin-bottom: 18px;
`
const CustomSettingComponent = styled(SettingComponent)`
margin-top: 36px;
${media.tablet`
margin-top: 8px;
`}
`
const Child = styled.div`
display: flex;
div:last-child {
margin-top: 4px;
}
`
const CardImg = styled.img`
margin-right: 14px;
width: 24px;
`
const CardDetails = styled.div<{ right?: boolean }>`
text-align: ${props => (props.right ? 'right' : 'initial')};
`
const Success: React.FC<InjectedFormProps<
{},
Props & { fiatCurrency?: FiatType }
> &
Props & { fiatCurrency?: FiatType }> = props => {
const ccPaymentMethod = props.paymentMethods.methods.find(
m => m.type === 'PAYMENT_CARD'
)
const activeCards = props.cards.filter(card => card.state === 'ACTIVE')
return !activeCards.length ? null : (
<CustomSettingContainer>
<SettingSummary>
<CustomSettingHeader>
<FormattedMessage
id='scenes.settings.linked_cards'
defaultMessage='Linked Cards'
/>
</CustomSettingHeader>
{activeCards.map((card, i) => {
let cardType = CARD_TYPES.find(
cardType => cardType.type === (card.card ? card.card.type : '')
)
if (card.state !== 'ACTIVE') return
return (
<CardWrapper
key={i}
onClick={() => {
if (props.submitting) return
props.handleCreditCardClick()
}}
>
<Child>
<CardImg
src={cardType ? cardType.logo : DEFAULT_CARD_SVG_LOGO}
/>
<CardDetails>
<Text size='16px' color='grey800' weight={600}>
{card.card.label || card.card.type}
</Text>
{ccPaymentMethod && (
<Text size='14px' color='grey600' weight={500}>
{fiatToString({
value: convertBaseToStandard(
'FIAT',
ccPaymentMethod.limits.max
),
unit: props.fiatCurrency || 'USD'
})}{' '}
{props.fiatCurrency} Limit
</Text>
)}
</CardDetails>
</Child>
<Child>
<CardDetails right>
<Text size='16px' color='grey800' weight={600}>
····{card.card.number}
</Text>
<Text size='14px' color='grey600' weight={500}>
Exp: {card.card.expireMonth}/{card.card.expireYear}
</Text>
</CardDetails>
<Button
data-e2e='removeCard'
nature='light-red'
disabled={props.submitting}
style={{ marginLeft: '18px', minWidth: 'auto' }}
// @ts-ignore
onClick={(e: SyntheticEvent) => {
e.stopPropagation()
props.simpleBuyActions.deleteSBCard(card.id)
}}
>
<FormattedMessage
id='buttons.remove'
defaultMessage='Remove'
/>
</Button>
</Child>
</CardWrapper>
)
})}
</SettingSummary>
<CustomSettingComponent>
<Button
nature='primary'
data-e2e='addCardFromSettings'
onClick={() => props.handleCreditCardClick()}
>
<FormattedMessage id='buttons.add_card' defaultMessage='Add Card' />
</Button>
</CustomSettingComponent>
</CustomSettingContainer>
)
}
type Props = OwnProps &
SuccessStateType & {
handleCreditCardClick: () => void
}
export default reduxForm<{}, Props>({ form: 'linkedCards' })(Success)