Skip to content

Commit

Permalink
feat(brokerage): code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
milan-bc committed Jun 2, 2021
1 parent 568d76e commit b4332fe
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 254 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { defaultTo, filter, prop } from 'ramda'
import { bindActionCreators, Dispatch } from 'redux'

import { Remote } from 'blockchain-wallet-v4/src'
import {
ExtractSuccess,
SBOrderType,
WalletFiatType
} from 'blockchain-wallet-v4/src/types'
import { ExtractSuccess, SBOrderType, WalletFiatType } from 'blockchain-wallet-v4/src/types'
import DataError from 'components/DataError'
import { actions, selectors } from 'data'
import { getFiatFromPair, getOrderType } from 'data/components/simpleBuy/model'
Expand All @@ -27,8 +23,6 @@ import { getData } from './selectors'
import Success from './template.success'

class CheckoutConfirm extends PureComponent<Props> {
state = {}

componentDidMount() {
this.props.simpleBuyActions.fetchSBQuote(
this.props.order.pair,
Expand All @@ -53,8 +47,8 @@ class CheckoutConfirm extends PureComponent<Props> {
sbBalances,
userData
} = this.props.data.getOrElse({
userData: { tiers: { current: 0 } } as UserDataType,
isSddFlow: false
isSddFlow: false,
userData: { tiers: { current: 0 } } as UserDataType
} as SuccessStateType)

const userTier = userData?.tiers?.current
Expand All @@ -65,10 +59,7 @@ class CheckoutConfirm extends PureComponent<Props> {
if (isUserSddVerified) {
if (cards && cards.length > 0) {
const card = cards[0]
return this.props.simpleBuyActions.confirmSBOrder(
card.id,
this.props.order
)
return this.props.simpleBuyActions.confirmSBOrder(card.id, this.props.order)
}
return this.props.simpleBuyActions.setStep({
step: 'ADD_CARD'
Expand All @@ -88,28 +79,24 @@ class CheckoutConfirm extends PureComponent<Props> {
switch (this.props.order.paymentType) {
case 'FUNDS':
const available = sbBalances[inputCurrency]?.available || '0'
if (
new BigNumber(available).isGreaterThanOrEqualTo(
this.props.order.inputQuantity
)
) {
if (new BigNumber(available).isGreaterThanOrEqualTo(this.props.order.inputQuantity)) {
return this.props.simpleBuyActions.confirmSBFundsOrder()
} else {
return this.props.simpleBuyActions.setStep({
step: 'BANK_WIRE_DETAILS',
fiatCurrency: inputCurrency,
displayBack: false
})
}
return this.props.simpleBuyActions.setStep({
displayBack: false,
fiatCurrency: inputCurrency,
step: 'BANK_WIRE_DETAILS'
})

case 'PAYMENT_CARD':
if (this.props.order.paymentMethodId) {
return this.props.simpleBuyActions.confirmSBOrder(
this.props.order.paymentMethodId,
this.props.order
)
} else {
return this.props.simpleBuyActions.setStep({ step: 'ADD_CARD' })
}
return this.props.simpleBuyActions.setStep({ step: 'ADD_CARD' })

case 'BANK_TRANSFER':
const [bankAccount] = filter(
(b: BankTransferAccountType) =>
Expand All @@ -120,41 +107,39 @@ class CheckoutConfirm extends PureComponent<Props> {
// if yapily we need the auth screen before creating the order
if (paymentPartner === BankPartners.YAPILY) {
return this.props.simpleBuyActions.setStep({
step: 'AUTHORIZE_PAYMENT',
order: this.props.order
order: this.props.order,
step: 'AUTHORIZE_PAYMENT'
})
}
if (this.props.order.paymentMethodId) {
return this.props.simpleBuyActions.confirmSBOrder(
this.props.order.paymentMethodId,
this.props.order
)
} else {
this.props.brokerageActions.showModal(
BrokerageModalOriginType.ADD_BANK,
'ADD_BANK_YODLEE_MODAL'
)
return this.props.brokerageActions.setAddBankStep({
addBankStep: AddBankStepType.ADD_BANK_HANDLER
})
}
this.props.brokerageActions.showModal(
BrokerageModalOriginType.ADD_BANK,
'ADD_BANK_YODLEE_MODAL'
)
return this.props.brokerageActions.setAddBankStep({
addBankStep: AddBankStepType.ADD_BANK_HANDLER
})

default:
// Not a valid payment method type, go back to CRYPTO_SELECTION
return this.props.simpleBuyActions.setStep({
step: 'CRYPTO_SELECTION',
fiatCurrency: getFiatFromPair(this.props.order.pair)
fiatCurrency: getFiatFromPair(this.props.order.pair),
step: 'CRYPTO_SELECTION'
})
}
}

render() {
return this.props.data.cata({
Success: val => (
<Success {...this.props} {...val} onSubmit={this.handleSubmit} />
),
Failure: e => <DataError message={{ message: e }} />,
Failure: (e) => <DataError message={{ message: e }} />,
Loading: () => <Loading />,
NotAsked: () => <Loading />
NotAsked: () => <Loading />,
Success: (val) => <Success {...this.props} {...val} onSubmit={this.handleSubmit} />
})
}
}
Expand All @@ -167,13 +152,13 @@ const mapStateToProps = (state: RootState) => ({
})

const mapDispatchToProps = (dispatch: Dispatch) => ({
brokerageActions: bindActionCreators(actions.components.brokerage, dispatch),
identityVerificationActions: bindActionCreators(
actions.components.identityVerification,
dispatch
),
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch),
sendActions: bindActionCreators(actions.components.send, dispatch),
brokerageActions: bindActionCreators(actions.components.brokerage, dispatch)
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch)
})

const connector = connect(mapStateToProps, mapDispatchToProps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ const Success: React.FC<InjectedFormProps<{ form: string }, Props> & Props> = (p
<TextGroup inline>
<Text size='14px'>
<FormattedMessage
id='modals.simplebuy.paying_with_card'
defaultMessage='Blockchain.com requires a fee when paying with a card.'
id='modals.simplebuy.confirm.coin_tooltip'
defaultMessage='Blockchain.com provides the best market price we receive and applies a spread.'
/>
</Text>
<Link
Expand Down

0 comments on commit b4332fe

Please sign in to comment.