Skip to content

Commit

Permalink
feat(sb): default method
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Jul 23, 2020
1 parent 841b1ac commit cfc72a9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 25 deletions.
Expand Up @@ -411,7 +411,6 @@ const getPayloadObjectForStep = (payload: StepActionsPayload) => {
return {
step: payload.step,
cryptoCurrency: payload.cryptoCurrency,
defaultMethod: payload.defaultMethod,
fiatCurrency: payload.fiatCurrency,
order: payload.order,
pair: payload.pair
Expand All @@ -420,7 +419,6 @@ const getPayloadObjectForStep = (payload: StepActionsPayload) => {
return {
step: payload.step,
cryptoCurrency: payload.cryptoCurrency,
defaultMethod: payload.defaultMethod,
fiatCurrency: payload.fiatCurrency,
method: payload.method,
pair: payload.pair
Expand Down
Expand Up @@ -9,7 +9,6 @@ const INITIAL_STATE: SimpleBuyState = {
cardId: undefined,
cards: Remote.NotAsked,
cryptoCurrency: undefined,
defaultMethod: undefined,
everypay3DS: Remote.NotAsked,
fiatCurrency: undefined,
fiatEligible: Remote.NotAsked,
Expand Down Expand Up @@ -67,7 +66,6 @@ export function simpleBuyReducer (
...state,
account: Remote.NotAsked,
cardId: undefined,
defaultMethod: undefined,
order: undefined,
pairs: Remote.NotAsked,
quote: Remote.NotAsked,
Expand Down Expand Up @@ -241,7 +239,6 @@ export function simpleBuyReducer (
return {
...state,
cryptoCurrency: action.payload.cryptoCurrency,
defaultMethod: action.payload.defaultMethod,
fiatCurrency: action.payload.fiatCurrency,
step: action.payload.step,
pair: action.payload.pair,
Expand All @@ -260,7 +257,6 @@ export function simpleBuyReducer (
return {
...state,
cryptoCurrency: action.payload.cryptoCurrency,
defaultMethod: action.payload.defaultMethod,
fiatCurrency: action.payload.fiatCurrency,
step: action.payload.step,
order: action.payload.order
Expand Down
@@ -1,3 +1,5 @@
import { ExtractSuccess } from 'core/types'
import { lift } from 'ramda'
import { RootState } from 'data/rootReducer'

export const getEverypay3DSDetails = (state: RootState) =>
Expand All @@ -12,8 +14,23 @@ export const getCryptoCurrency = (state: RootState) =>
export const getFiatCurrency = (state: RootState) =>
state.components.simpleBuy.fiatCurrency || state.preferences.sbFiatCurrency

export const getDefaultMethod = (state: RootState) =>
state.components.simpleBuy.defaultMethod
export const getDefaultPaymentMethod = (state: RootState) => {
const ordersR = getSBOrders(state)
const sbMethodsR = getSBPaymentMethods(state)

const transform = (
orders: ExtractSuccess<typeof ordersR>,
sbMethods: ExtractSuccess<typeof sbMethodsR>
) => {
const { paymentType: type, inputCurrency } = orders[0]

return sbMethods.methods.find(
method => method.type === type && method.currency === inputCurrency
)
}

return lift(transform)(ordersR, sbMethodsR)
}

export const getSBBalances = (state: RootState) =>
state.components.simpleBuy.balances
Expand Down
Expand Up @@ -70,7 +70,6 @@ export type SimpleBuyState = {
cardId: undefined | string
cards: RemoteDataType<string, Array<SBCardType>>
cryptoCurrency: undefined | CoinType
defaultMethod: undefined | SBPaymentMethodType
everypay3DS: RemoteDataType<string, Everypay3DSResponseType>
fiatCurrency: undefined | FiatType
fiatEligible: RemoteDataType<string, FiatEligibleType>
Expand Down Expand Up @@ -290,7 +289,6 @@ export type StepActionsPayload =
}
| {
cryptoCurrency?: CoinType
defaultMethod?: SBPaymentMethodType
fiatCurrency: FiatType
method?: SBPaymentMethodType
order?: SBOrderType
Expand All @@ -308,7 +306,6 @@ export type StepActionsPayload =
}
| {
cryptoCurrency: CoinType
defaultMethod?: SBPaymentMethodType
fiatCurrency: FiatType
order?: SBOrderType
pair: SBPairType
Expand Down
Expand Up @@ -3,7 +3,7 @@ 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 { SBPairType, SBPaymentMethodType } from 'core/types'
import CryptoItem from './CryptoItem'
import React from 'react'
import styled from 'styled-components'
Expand Down Expand Up @@ -32,12 +32,13 @@ export type Props = OwnProps & SuccessStateType

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

Expand Down Expand Up @@ -72,7 +73,9 @@ const CryptoSelector: React.FC<InjectedFormProps<{}, Props> &
<CryptoItem
key={index}
value={value}
onClick={() => handleSubmit(value as SBPairType)}
onClick={() =>
handleSubmit(value as SBPairType, props.defaultMethod)
}
/>
))}
</Currencies>
Expand Down
Expand Up @@ -4,18 +4,23 @@ import { selectors } from 'data'

export const getData = state => {
const eligibilityR = selectors.components.simpleBuy.getSBFiatEligible(state)
const defaultMethodR = selectors.components.simpleBuy.getDefaultPaymentMethod(
state
)
const pairsR = selectors.components.simpleBuy.getSBPairs(state)
const userDataR = selectors.modules.profile.getUserData(state)

return lift(
(
eligibility: ExtractSuccess<typeof eligibilityR>,
defaultMethod: ExtractSuccess<typeof defaultMethodR>,
pairs: ExtractSuccess<typeof pairsR>,
userData: ExtractSuccess<typeof userDataR>
) => ({
eligibility,
defaultMethod,
pairs,
userData
})
)(eligibilityR, pairsR, userDataR)
)(eligibilityR, defaultMethodR, pairsR, userDataR)
}
Expand Up @@ -120,6 +120,7 @@ const getIcon = (value: SBPaymentMethodType): ReactElement => {

const Payment: React.FC<Props> = props => (
<PaymentContainer
role='button'
onClick={() =>
props.simpleBuyActions.setStep({
step: 'PAYMENT_METHODS',
Expand Down
Expand Up @@ -5,7 +5,7 @@ import {
} from 'components/Form/CreditCardBox/model'
import { convertBaseToStandard } from 'data/components/exchange/services'
import { fiatToString } from 'core/exchange/currency'
import { FiatType, SBPaymentMethodType } from 'core/types'
import { FiatType } from 'core/types'
import { FormattedMessage } from 'react-intl'
import { InjectedFormProps, reduxForm } from 'redux-form'
import { Props as OwnProps, SuccessStateType } from '.'
Expand Down Expand Up @@ -94,13 +94,7 @@ const Success: React.FC<InjectedFormProps<
key={i}
onClick={() => {
if (props.submitting) return
props.handleCreditCardClick({
...card,
type: 'USER_CARD',
limits: ccPaymentMethod
? ccPaymentMethod.limits
: { min: '500', max: '50000' }
})
props.handleCreditCardClick()
}}
>
<Child>
Expand Down Expand Up @@ -170,7 +164,7 @@ const Success: React.FC<InjectedFormProps<

type Props = OwnProps &
SuccessStateType & {
handleCreditCardClick: (defaultMethod?: SBPaymentMethodType) => void
handleCreditCardClick: () => void
}

export default reduxForm<{}, Props>({ form: 'linkedCards' })(Success)

0 comments on commit cfc72a9

Please sign in to comment.