Skip to content

Commit

Permalink
feat: implemented select crypto step
Browse files Browse the repository at this point in the history
  • Loading branch information
milan-bc committed Jul 13, 2020
1 parent 4bda1dc commit f5884dd
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 119 deletions.
Expand Up @@ -423,7 +423,6 @@ export const setStep = (
}
| {
cryptoCurrency?: CoinType
defaultMethod?: SBFormPaymentMethod
fiatCurrency: FiatType
step: 'CRYPTO_SELECTION'
}
Expand All @@ -444,7 +443,6 @@ export const setStep = (
? {
step: payload.step,
cryptoCurrency: payload.cryptoCurrency,
defaultMethod: payload.defaultMethod,
fiatCurrency: payload.fiatCurrency
}
: payload.step === 'CHECKOUT_CONFIRM' ||
Expand Down
Expand Up @@ -157,13 +157,22 @@ export default ({
yield put(A.fetchSBOrders())
if (state === 'PENDING_CONFIRMATION' && fiatCurrency) {
const pair = S.getSBPair(yield select())
yield put(
A.setStep({
step: 'ENTER_AMOUNT',
fiatCurrency,
pair
})
)
if (pair) {
yield put(
A.setStep({
step: 'ENTER_AMOUNT',
fiatCurrency,
pair
})
)
} else {
yield put(
A.setStep({
step: 'CRYPTO_SELECTION',
fiatCurrency
})
)
}
} else {
yield put(actions.modals.closeAllModals())
}
Expand Down Expand Up @@ -208,10 +217,12 @@ export default ({
if (step !== 'ENTER_AMOUNT') {
const pair = S.getSBPair(yield select())
const fiatCurrency = S.getFiatCurrency(yield select()) || 'EUR'
yield put(A.setStep({ step: 'ENTER_AMOUNT', fiatCurrency, pair }))
yield take(AT.INITIALIZE_CHECKOUT)
yield delay(3000)
yield put(actions.form.startSubmit('simpleBuyCheckout'))
if (pair) {
yield put(A.setStep({ step: 'ENTER_AMOUNT', fiatCurrency, pair }))
yield take(AT.INITIALIZE_CHECKOUT)
yield delay(3000)
yield put(actions.form.startSubmit('simpleBuyCheckout'))
}
}

const error = errorHandler(e)
Expand Down
Expand Up @@ -32,12 +32,7 @@ export const getSBQuote = (state: RootState) => state.components.simpleBuy.quote

export const getSBPairs = (state: RootState) => state.components.simpleBuy.pairs

export const getSBPair = (state: RootState) =>
state.components.simpleBuy.pair || {
buyMax: '',
buyMin: '',
pair: ''
}
export const getSBPair = (state: RootState) => state.components.simpleBuy.pair

export const getSBPaymentMethods = (state: RootState) =>
state.components.simpleBuy.methods
Expand Down
Expand Up @@ -5,7 +5,6 @@ import {
FiatType,
RemoteDataType,
SBBuyOrderType,
SBPairType,
SBPaymentMethodsType,
SBSellOrderType
} from 'core/types'
Expand Down Expand Up @@ -48,8 +47,7 @@ class AddCard extends PureComponent<Props> {

const mapStateToProps = (state: RootState): LinkStatePropsType => ({
data: getData(state),
fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state) || 'EUR',
pair: selectors.components.simpleBuy.getSBPair(state)
fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state) || 'EUR'
})

const mapDispatchToProps = (dispatch: Dispatch): LinkDispatchPropsType => ({
Expand All @@ -67,7 +65,6 @@ type LinkDispatchPropsType = {
type LinkStatePropsType = {
data: RemoteDataType<string, SuccessStateType>
fiatCurrency: FiatType
pair: SBPairType
}
export type SuccessStateType = {
formValues?: SBAddCardFormValuesType
Expand Down
@@ -0,0 +1,93 @@
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 { SBPairType } from 'core/types'
import CryptoItem from './CryptoItem'
import React from 'react'
import styled from 'styled-components'

const Wrapper = styled.div`
display: flex;
justify-content: space-between;
flex-direction: column;
height: 100%;
`
const Currencies = styled.div`
border-top: 1px solid ${props => props.theme.grey000};
`
const TopText = styled(Text)`
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
`

const SubTitleText = styled(Text)`
margin-top: 0;
`
const CloseIcon = styled(Icon)`
position: absolute;
top: 28px;
right: 28px;
`
export type Props = OwnProps & SuccessStateType

const CryptoSelector: React.FC<InjectedFormProps<{}, Props> &
Props> = props => {
const handleSubmit = (pair: SBPairType) => {
props.simpleBuyActions.destroyCheckout()
props.simpleBuyActions.setStep({
step: 'ENTER_AMOUNT',
fiatCurrency: props.fiatCurrency,
pair
})
}

return (
<Wrapper>
<Form>
<FlyoutWrapper>
<CloseIcon
cursor
data-e2e='sbCloseModalIcon'
name='close'
size='16px'
color='grey600'
role='button'
onClick={props.handleClose}
/>
<TopText color='grey800' size='20px' weight={600}>
<FormattedMessage
id='modals.simplebuy.cryptoselect'
defaultMessage='Buy with Cash or Card'
/>
</TopText>
<SubTitleText color='grey600' weight={500}>
<FormattedMessage
id='modals.simplebuy.selectcrypto'
defaultMessage='Select the crypto you want to buy.'
/>
</SubTitleText>
</FlyoutWrapper>
<Currencies>
{props.pairs.map((value, index) => (
<CryptoItem
key={index}
rates={props.rates}
supportedCoins={props.supportedCoins}
value={value}
onClick={() => handleSubmit(value as SBPairType)}
/>
))}
</Currencies>
</Form>
</Wrapper>
)
}

export default reduxForm<{}, Props>({
form: 'sbCryptoSelection',
destroyOnUnmount: false
})(CryptoSelector)
@@ -1,92 +1,18 @@
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 '.'
import { SBPairType } from 'core/types'
import CryptoItem from './CryptoItem'
import { LinkStatePropsType, Props as OwnProps, SuccessStateType } from '.'
import CryptoSelector from './CryptoSelector'
import React from 'react'
import styled from 'styled-components'
import Unsupported from './template.unsupported'

const Wrapper = styled.div`
display: flex;
justify-content: space-between;
flex-direction: column;
height: 100%;
`
const Currencies = styled.div`
border-top: 1px solid ${props => props.theme.grey000};
`
const TopText = styled(Text)`
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
`

const SubTitleText = styled(Text)`
margin-top: 0;
`
const CloseIcon = styled(Icon)`
position: absolute;
top: 28px;
right: 28px;
`
export type Props = OwnProps & SuccessStateType

const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
const handleSubmit = (pair: SBPairType) => {
props.simpleBuyActions.destroyCheckout()
props.simpleBuyActions.setStep({
step: 'ENTER_AMOUNT',
fiatCurrency: props.fiatCurrency,
pair
})
}

return (
<Wrapper>
<Form>
<FlyoutWrapper>
<CloseIcon
cursor
data-e2e='sbCloseModalIcon'
name='close'
size='16px'
color='grey600'
role='button'
onClick={props.handleClose}
/>
<TopText color='grey800' size='20px' weight={600}>
<FormattedMessage
id='modals.simplebuy.cryptoselect'
defaultMessage='Buy with Cash or Card'
/>
</TopText>
<SubTitleText color='grey600' weight={500}>
<FormattedMessage
id='modals.simplebuy.selectcrypto'
defaultMessage='Select the crypto you want to buy.'
/>
</SubTitleText>
</FlyoutWrapper>
<Currencies>
{props.pairs.map((value, index) => (
<CryptoItem
key={index}
rates={props.rates}
supportedCoins={props.supportedCoins}
value={value}
onClick={() => handleSubmit(value as SBPairType)}
/>
))}
</Currencies>
</Form>
</Wrapper>
const Success: React.FC<Props> = props => {
return props.pairs.length &&
props.eligibility.eligible &&
props.fiatCurrency ? (
<CryptoSelector {...props} />
) : (
<Unsupported {...props} />
)
}

export default reduxForm<{}, Props>({
form: 'sbCryptoSelection',
destroyOnUnmount: false
})(Success)
export type Props = OwnProps & SuccessStateType & LinkStatePropsType

export default Success

0 comments on commit f5884dd

Please sign in to comment.