Skip to content

Commit

Permalink
feat(sb): move pending order check to showModal
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Jun 11, 2020
1 parent 56e6006 commit bead316
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 23 deletions.
Expand Up @@ -383,8 +383,6 @@ export default ({
}: ReturnType<typeof A.fetchSBOrders>) {
try {
const { skipLoading } = payload
if (!(yield call(isTier2))) return

if (!skipLoading) yield put(A.fetchSBOrdersLoading())
const orders = yield call(api.getSBOrders, {})
yield put(A.fetchSBOrdersSuccess(orders))
Expand Down Expand Up @@ -688,9 +686,21 @@ export default ({
actions.modals.showModal('SIMPLE_BUY_MODAL', { origin, cryptoCurrency })
)
const fiatCurrency = selectors.preferences.getSBFiatCurrency(yield select())
const latestPendingOrder = S.getSBLatestPendingOrder(yield select())

if (!fiatCurrency) {
yield put(A.setStep({ step: 'CURRENCY_SELECTION' }))
} else if (latestPendingOrder) {
const step =
latestPendingOrder.state === 'PENDING_CONFIRMATION'
? 'CHECKOUT_CONFIRM'
: 'ORDER_SUMMARY'
yield put(
A.setStep({
step,
order: latestPendingOrder
})
)
} else {
yield put(
A.setStep({ step: 'ENTER_AMOUNT', cryptoCurrency, fiatCurrency })
Expand Down
Expand Up @@ -43,6 +43,15 @@ export const getSBOrder = (state: RootState) => state.components.simpleBuy.order
export const getSBOrders = (state: RootState) =>
state.components.simpleBuy.orders

export const getSBLatestPendingOrder = (state: RootState) =>
state.components.simpleBuy.orders.getOrElse([]).find(order => {
return (
order.state === 'PENDING_CONFIRMATION' ||
order.state === 'PENDING_DEPOSIT' ||
order.state === 'DEPOSIT_MATCHED'
)
})

export const getSBSuggestedAmounts = (state: RootState) =>
state.components.simpleBuy.suggestedAmounts

Expand Down
Expand Up @@ -9,6 +9,7 @@ import {
SupportedCoinsType
} from 'core/types'
import { RootState } from 'data/rootReducer'
import { UserDataType } from 'data/types'
import DataError from 'components/DataError'
import Loading from './template.loading'
import React, { PureComponent } from 'react'
Expand All @@ -22,6 +23,19 @@ class CheckoutConfirm extends PureComponent<Props> {
}

handleSubmit = () => {
const { userData } = this.props.data.getOrElse({
userData: { tiers: { current: 0 } }
})

if (userData.tiers.current < 2) {
this.props.identityVerificationActions.verifyIdentity(
2,
false,
'SBEnterAmountCheckout'
)
return
}

if (this.props.order.paymentMethodId) {
this.props.simpleBuyActions.confirmSBCreditCardOrder(
this.props.order.paymentMethodId
Expand Down Expand Up @@ -58,6 +72,10 @@ const mapStateToProps = (state: RootState): LinkStatePropsType => ({
})

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

Expand All @@ -69,6 +87,7 @@ type OwnProps = {
}
export type SuccessStateType = {
quote: SBQuoteType
userData: UserDataType
}
type LinkStatePropsType = {
data: RemoteDataType<string, SuccessStateType>
Expand Down
Expand Up @@ -4,6 +4,7 @@ import { selectors } from 'data'

export const getData = (state: RootState) => {
const quoteR = selectors.components.simpleBuy.getSBQuote(state)
const userDataR = selectors.modules.profile.getUserData(state)

return lift(quote => ({ quote }))(quoteR)
return lift((quote, userData) => ({ quote, userData }))(quoteR, userDataR)
}
Expand Up @@ -99,7 +99,10 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
/>
</Title>
<Value>
{props.order.paymentMethodId ? 'Credit Card' : 'Bank Transfer'}
{props.order.paymentMethodId ||
props.order.paymentType === 'PAYMENT_CARD'
? 'Credit Card'
: 'Bank Transfer'}
</Value>
</Row>
<Row>
Expand Down
Expand Up @@ -69,26 +69,12 @@ const BannerButton = styled(Button)`
`

class SBOrderBanner extends PureComponent<Props> {
showModal = (latestPendingOrder: SBOrderType) => {
if (!latestPendingOrder) return
showModal = () => {
this.props.simpleBuyActions.showModal('PendingOrder')
this.props.simpleBuyActions.setStep({
step:
latestPendingOrder.state === 'PENDING_CONFIRMATION'
? 'CHECKOUT_CONFIRM'
: 'ORDER_SUMMARY',
order: latestPendingOrder
})
}

render () {
const latestPendingOrder = this.props.orders.find(order => {
return (
order.state === 'PENDING_CONFIRMATION' ||
order.state === 'PENDING_DEPOSIT' ||
order.state === 'DEPOSIT_MATCHED'
)
})
const { latestPendingOrder } = this.props

if (!latestPendingOrder) return null

Expand Down Expand Up @@ -121,7 +107,7 @@ class SBOrderBanner extends PureComponent<Props> {
</Column>
</Row>
<BannerButton
onClick={() => this.showModal(latestPendingOrder)}
onClick={() => this.showModal()}
jumbo
data-e2e='openPendingSBOrder'
nature='primary'
Expand All @@ -137,7 +123,9 @@ class SBOrderBanner extends PureComponent<Props> {
}

const mapStateToProps = (state: RootState): LinkStatePropsType => ({
orders: selectors.components.simpleBuy.getSBOrders(state).getOrElse([])
latestPendingOrder: selectors.components.simpleBuy.getSBLatestPendingOrder(
state
)
})

const mapDispatchToProps = (dispatch: Dispatch) => ({
Expand All @@ -148,7 +136,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
const connector = connect(mapStateToProps, mapDispatchToProps)

type LinkStatePropsType = {
orders: Array<SBOrderType>
latestPendingOrder?: SBOrderType
}
type Props = ConnectedProps<typeof connector>

Expand Down
Expand Up @@ -157,6 +157,7 @@ export type ISBBuyOrderType = {
insertedAt: string
outputQuantity: string
paymentMethodId?: string
paymentType?: SBPaymentMethodType['type']
price?: string
state: SBOrderStateType
updatedAt: string
Expand Down

0 comments on commit bead316

Please sign in to comment.