Skip to content

Commit

Permalink
feat: implemented select payment and render payments
Browse files Browse the repository at this point in the history
  • Loading branch information
milan-bc committed Jul 20, 2020
1 parent e0372fd commit 120b456
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 82 deletions.
Expand Up @@ -1144,6 +1144,7 @@ type MessagesType = {
'modals.simplebuy.card_limit': '{card} Limit'
'modals.simplebuy.card_expire': 'Exp: {month}/{year}'
'modals.simplebuy.instantly_buy': 'Instantly buy crypto with any Visa or Mastercard.'
'modals.simplebuy.most_popular': 'Most Popular'
'modals.simplebuy.selectcrypto': 'Select the crypto you want to buy.'
'modals.simplebuy.setupaccount': "Next, we'll set up your account."
'modals.simplebuy.success': 'Trade Complete'
Expand Down
@@ -0,0 +1,148 @@
import {
CARD_TYPES,
DEFAULT_CARD_SVG_LOGO
} from 'components/Form/CreditCardBox/model'
import { fiatToString } from 'core/exchange/currency'
import { FiatType } from 'core/types'
import { FormattedMessage } from 'react-intl'
import { Icon, Text } from 'blockchain-info-components'
import { Props } from '..'
import { SBFormPaymentMethod } from 'data/components/simpleBuy/types'
import { Title } from 'components/Flyout'
import React, { ReactElement } from 'react'
import styled from 'styled-components'

const PaymentContainer = styled.div`
border: 1px solid ${props => props.theme.grey100};
box-sizing: border-box;
width: 400px;
height: 80px;
border-radius: 8px;
margin-bottom: 24px;
display: flex;
flex-direction: row;
cursor: pointer;
padding: 12px 28px;
justify-content: space-between;
`

const DisplayIcon = styled.div`
position: relative;
display: flex;
flex-direction: column;
font-weight: 500;
justify-content: center;
color: ${props => props.theme.grey800};
`
const PaymentText = styled(Text)`
width: 285px;
justify-content: center;
display: flex;
flex-direction: column;
padding-left: 16px;
`
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.textBody};
width: 100%;
`

const renderCardText = (value: SBFormPaymentMethod): string => {
return value.card
? value.card.label
? value.card.label
: value.card.type
: 'Credit or Debit Card'
}

const renderCard = (value: SBFormPaymentMethod) => (
<>
<DisplayTitle>{renderCardText(value)}</DisplayTitle>
<DisplaySubTitle>
<FormattedMessage
id='modals.simplebuy.card_limit'
defaultMessage='{card} Limit'
values={{
card: `${fiatToString({
value: value.limits.max,
unit: String(value.currency) as FiatType
})} ${value.currency}`
}}
/>
</DisplaySubTitle>
</>
)

const renderFund = (value: SBFormPaymentMethod) => (
<>
<DisplayTitle>{value.currency}</DisplayTitle>
<DisplaySubTitle>
{fiatToString({
value: value.limits.max,
unit: String(value.currency) as FiatType
})}
</DisplaySubTitle>
</>
)

const getIcon = (value: SBFormPaymentMethod): ReactElement => {
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 <></>
default:
return <></>
}
}

const Payment: React.FC<Props> = props => (
<PaymentContainer
onClick={() =>
props.simpleBuyActions.setStep({
step: 'PAYMENT_METHODS',
pair: props.pair,
fiatCurrency: props.fiatCurrency || 'USD',
cryptoCurrency: props.cryptoCurrency
})
}
>
<DisplayIcon>{getIcon(props.method)}</DisplayIcon>
<PaymentText>
{props.method.type === 'USER_CARD'
? renderCard(props.method)
: renderFund(props.method)}
</PaymentText>
<PaymentArrowContainer>
<Icon cursor name='arrow-right' size='20px' color='grey600' />
</PaymentArrowContainer>
</PaymentContainer>
)

export default Payment
@@ -0,0 +1,67 @@
import { FormattedMessage } from 'react-intl'
import { Icon, Text } from 'blockchain-info-components'
import { Props } from '..'
import React from 'react'
import styled from 'styled-components'

const SelectPaymentContainer = styled.div`
border: 1px solid ${props => props.theme.grey100};
box-sizing: border-box;
width: 400px;
height: 80px;
border-radius: 8px;
margin-bottom: 24px;
display: flex;
flex-direction: row;
cursor: pointer;
padding: 23px 28px 28px 28px;
line-height: 32px;
justify-content: space-between;
`

const SelectIconWrapper = styled.div`
background-color: ${props => props.theme.blue000};
width: 32px;
height: 32px;
border-radius: 50%;
margin-right: 22px;
`
const SelectPaymentText = styled(Text)`
width: 285px;
font-style: normal;
font-weight: 600;
font-size: 14px;
line-height: 32px;
`

const SelectPayment: React.FC<Props> = props => (
<SelectPaymentContainer
onClick={() =>
props.simpleBuyActions.setStep({
step: 'PAYMENT_METHODS',
pair: props.pair,
fiatCurrency: props.fiatCurrency || 'USD',
cryptoCurrency: props.cryptoCurrency
})
}
>
<SelectIconWrapper>
<Icon
cursor
name='plus-in-circle-filled'
size='22px'
color='blue600'
style={{ marginLeft: '4px' }}
/>
</SelectIconWrapper>
<SelectPaymentText>
<FormattedMessage
id='modals.simplebuy.confirm.jump_to_payment'
defaultMessage='Select Cash or Card'
/>
</SelectPaymentText>
<Icon cursor name='arrow-right' size='20px' color='grey600' />
</SelectPaymentContainer>
)

export default SelectPayment
Expand Up @@ -20,7 +20,9 @@ import { SBCheckoutFormValuesType } from 'data/types'
import ActionButton from './ActionButton'
import Currencies from 'blockchain-wallet-v4/src/exchange/currencies'
import Failure from '../template.failure'
import Payment from './Payment'
import React from 'react'
import SelectPayment from './SelectPayment'
import styled from 'styled-components'

const CustomForm = styled(Form)`
Expand Down Expand Up @@ -91,36 +93,6 @@ const ErrorText = styled(Text)`
margin-bottom: 16px;
`

const JumpToPayment = styled.div`
border: 1px solid ${props => props.theme.grey100};
box-sizing: border-box;
width: 400px;
height: 80px;
border-radius: 8px;
margin-bottom: 24px;
display: flex;
flex-direction: row;
cursor: pointer;
padding: 23px 28px 28px 28px;
line-height: 32px;
justify-content: space-between;
`

const JumpIconWrapper = styled.div`
background-color: ${props => props.theme.blue000};
width: 32px;
height: 32px;
border-radius: 50%;
margin-right: 22px;
`
const JumpText = styled(Text)`
width: 285px;
font-style: normal;
font-weight: 600;
font-size: 14px;
line-height: 32px;
`

export type Props = OwnProps & SuccessStateType

const normalizeAmount = (
Expand Down Expand Up @@ -296,33 +268,8 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
</GreyBlueCartridge>
</Amounts>
)}
<JumpToPayment
onClick={() =>
props.simpleBuyActions.setStep({
step: 'PAYMENT_METHODS',
pair: props.pair,
fiatCurrency: props.fiatCurrency || 'USD',
cryptoCurrency: props.cryptoCurrency
})
}
>
<JumpIconWrapper>
<Icon
cursor
name='plus-in-circle-filled'
size='22px'
color='blue600'
style={{ marginLeft: '4px' }}
/>
</JumpIconWrapper>
<JumpText>
<FormattedMessage
id='modals.simplebuy.confirm.jump_to_payment'
defaultMessage='Select Cash or Card'
/>
</JumpText>
<Icon cursor name='arrow-right' size='20px' color='grey600' />
</JumpToPayment>
{method ? <Payment {...props} /> : <SelectPayment {...props} />}

{props.error && (
<ErrorText>
<Icon
Expand Down
Expand Up @@ -42,6 +42,7 @@ const DisplayTitle = styled(Title)`
flex-direction: column;
color: ${props => props.theme.textBlack};
width: 100%;
margin-bottom: 2px;
`

type Props = {
Expand All @@ -53,7 +54,7 @@ type Props = {

const BankAccount: React.FC<Props> = ({ value, onClick, icon, text }) => (
<DisplayContainer
data-e2e={`sb${value.type.toLowerCase()}CurrencySelector`}
data-e2e={`sb${value.type.toLowerCase()}BankAccount`}
role='button'
onClick={onClick}
>
Expand Down
Expand Up @@ -78,7 +78,7 @@ type Props = {

const Card: React.FC<Props> = ({ value, onClick, icon, text }) => (
<DisplayContainer
data-e2e={`sb${value.type.toLowerCase()}CurrencySelector`}
data-e2e={`sb${value.type.toLowerCase()}Cards`}
role='button'
onClick={onClick}
>
Expand Down
Expand Up @@ -61,7 +61,7 @@ type Props = {

const Fund: React.FC<Props> = ({ value, icon, onClick }) => (
<DisplayContainer
data-e2e={`sb${value.type.toLowerCase()}CurrencySelector`}
data-e2e={`sb${value.type.toLowerCase()}Fund`}
role='button'
onClick={onClick}
>
Expand Down
Expand Up @@ -51,6 +51,17 @@ const SubTitle = styled(Title)`
line-height: 21px;
`

const MostPopular = styled(Title)`
background: ${props => props.theme.green000};
border-radius: 8px;
color: ${props => props.theme.green500};
width: 114px;
text-align: center;
padding: 6px 12px;
font-weight: 600;
margin-top: 8px;
`

type Props = {
icon: ReactElement
onClick: (string) => void
Expand All @@ -60,7 +71,7 @@ type Props = {

const PaymentCard: React.FC<Props> = ({ value, onClick, icon, text }) => (
<DisplayContainer
data-e2e={`sb${value.type.toLowerCase()}CurrencySelector`}
data-e2e={`sb${value.type.toLowerCase()}PaymentCard`}
role='button'
onClick={onClick}
>
Expand All @@ -85,6 +96,12 @@ const PaymentCard: React.FC<Props> = ({ value, onClick, icon, text }) => (
defaultMessage='Instantly buy crypto with any Visa or Mastercard.'
/>
</SubTitle>
<MostPopular>
<FormattedMessage
id='modals.simplebuy.most_popular'
defaultMessage='Most Popular'
/>
</MostPopular>
</Content>
<Icon name='chevron-right' size='24px' color='grey400' />
</DisplayContainer>
Expand Down

0 comments on commit 120b456

Please sign in to comment.