Skip to content

Commit

Permalink
feat(sell): sell order summary
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Dec 2, 2020
1 parent 66bd21a commit c660390
Show file tree
Hide file tree
Showing 14 changed files with 598 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ const getPayloadObjectForStep = (payload: StepActionsPayload) => {
return { step: payload.step, order: payload.order }
case '3DS_HANDLER':
return { step: payload.step, order: payload.order }
case 'SELL_ORDER_SUMMARY':
return { step: payload.step, sellOrder: payload.sellOrder }
default:
return { step: payload.step }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SBPairsType,
SBPaymentTypes,
SupportedWalletCurrenciesType,
SwapOrderType,
WalletFiatType
} from 'blockchain-wallet-v4/src/types'
import { convertBaseToStandard } from '../exchange/services'
Expand Down Expand Up @@ -101,6 +102,19 @@ export const getCounterCurrency = (
]?.coinTicker || 'USD'
)
}
// These methods are being used for just sell p3, since we're release sell first
// Separately from Buy and the order types are different. Once buy is
export const getSellBaseAmount = (sellOrder: SwapOrderType): string => {
const coinCurrency = getCoinFromPair(sellOrder.pair)
return convertBaseToStandard(
coinCurrency as CoinType,
sellOrder.priceFunnel.inputMoney
)
}

export const getSellCounterAmount = (sellOrder: SwapOrderType): string => {
return convertBaseToStandard('FIAT', sellOrder.priceFunnel.outputMoney)
}

export const getNextCardExists = (
existingCards: Array<SBCardType>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const INITIAL_STATE: SimpleBuyState = {
providerDetails: Remote.NotAsked,
quote: Remote.NotAsked,
sellQuote: Remote.NotAsked,
sellOrder: undefined,
step: 'CURRENCY_SELECTION',
swapAccount: undefined
}
Expand Down Expand Up @@ -332,6 +333,12 @@ export function simpleBuyReducer (
displayBack: action.payload.displayBack,
addBank: action.payload.addBank
}
case 'SELL_ORDER_SUMMARY':
return {
...state,
step: action.payload.step,
sellOrder: action.payload.sellOrder
}
default: {
return {
...state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,32 +297,22 @@ export default ({
}
}
yield put(actions.form.stopSubmit('simpleBuyCheckout'))
yield put(actions.modals.closeModal())
yield put(
actions.modals.showModal('SWAP_MODAL', { origin: 'SimpleBuyLink' })
)
yield put(
actions.components.swap.setStep({
step: 'SUCCESSFUL_SWAP',
options: { order: sellOrder }
A.setStep({
step: 'SELL_ORDER_SUMMARY',
sellOrder: sellOrder
})
)

yield put(actions.components.swap.fetchTrades())
return yield put(actions.components.swap.fetchTrades())
}

if (!paymentType) throw new Error(NO_PAYMENT_TYPE)

if (
(orderType === 'BUY' && fix === 'CRYPTO') ||
(orderType === 'SELL' && fix === 'FIAT')
) {
if (orderType === 'BUY' && fix === 'CRYPTO') {
delete input.amount
}
if (
(orderType === 'BUY' && fix === 'FIAT') ||
(orderType === 'SELL' && fix === 'CRYPTO')
) {
if (orderType === 'BUY' && fix === 'FIAT') {
delete output.amount
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ export const getSBLatestPendingOrder = (state: RootState) =>
)
})

export const getSellOrder = (state: RootState) =>
state.components.simpleBuy.sellOrder

export const getStep = (state: RootState) => state.components.simpleBuy.step

export const getSwapAccount = (state: RootState) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SBPaymentMethodType,
SBProviderDetailsType,
SBQuoteType,
SwapOrderType,
SwapQuoteType
} from 'core/types'
import { SwapAccountType } from '../swap/types'
Expand Down Expand Up @@ -55,6 +56,7 @@ export enum SimpleBuyStepType {
'ORDER_SUMMARY',
'PREVIEW_SELL',
'CHECKOUT_CONFIRM',
'SELL_ORDER_SUMMARY',
'ADD_CARD',
'CC_BILLING_ADDRESS',
'3DS_HANDLER',
Expand Down Expand Up @@ -98,7 +100,8 @@ export type SimpleBuyState = {
payment: RemoteDataType<string, undefined | PaymentValue>
providerDetails: RemoteDataType<string, SBProviderDetailsType>
quote: RemoteDataType<string, SBQuoteType>
sellQuote: RemoteDataType<string, { quote: SwapQuoteType; rate: number }>
sellOrder: undefined | SwapOrderType,
sellQuote: RemoteDataType<string, { quote: SwapQuoteType; rate: number }>,
step: keyof typeof SimpleBuyStepType
swapAccount: undefined | SwapAccountType
}
Expand Down Expand Up @@ -303,12 +306,12 @@ interface FetchSellQuoteSuccess {
}

interface InitializeCheckout {
account?: SwapAccountType,
amount: string,
cryptoAmount?: string,
orderType: SBOrderActionType,
pair?: SBPairType,
pairs: Array<SBPairType>,
account?: SwapAccountType
amount: string
cryptoAmount?: string
orderType: SBOrderActionType
pair?: SBPairType
pairs: Array<SBPairType>
type: typeof AT.INITIALIZE_CHECKOUT
}

Expand All @@ -317,6 +320,10 @@ export type StepActionsPayload =
order: SBOrderType
step: 'CHECKOUT_CONFIRM' | 'ORDER_SUMMARY' | 'CANCEL_ORDER'
}
| {
sellOrder: SwapOrderType
step: 'SELL_ORDER_SUMMARY'
}
| {
cryptoCurrency: CoinType
fiatCurrency: FiatType
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// import { actions } from 'data'
// import { bindActionCreators, compose, Dispatch } from 'redux'
// import { connect } from 'react-redux'
// import { SwapOrderType } from 'core/types'
// import React, { PureComponent } from 'react'
// import Template from './template'

// export type OwnProps = {
// handleClose: () => void
// order: SwapOrderType
// }
// export type LinkDispatchPropsType = {
// swapActions: typeof actions.components.swap
// }
// type LinkStatePropsType = {}
// type Props = OwnProps & LinkDispatchPropsType & LinkStatePropsType
// type State = {}

// class CancelOrder extends PureComponent<Props, State> {
// state = {}

// handleSubmit = () => {
// this.props.swapActions.cancelOrder(this.props.order)
// }

// render () {
// return <Template {...this.props} onSubmit={this.handleSubmit} />
// }
// }

// const mapStateToProps = (): LinkStatePropsType => ({})

// const mapDispatchToProps = (dispatch: Dispatch): LinkDispatchPropsType => ({
// swapActions: bindActionCreators(actions.components.swap, dispatch)
// })

// const enhance = compose(connect(mapStateToProps, mapDispatchToProps))

// export default enhance(CancelOrder)
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// import { Button, HeartbeatLoader, Icon, Text } from 'blockchain-info-components'
// import { ErrorCartridge } from 'components/Cartridge'
// import { FlyoutWrapper } from 'components/Flyout'
// import { Form } from 'components/Form'
// import { FormattedMessage } from 'react-intl'
// import { getOrderType } from 'data/components/simpleBuy/model'
// import { InjectedFormProps, reduxForm } from 'redux-form'
// import { LinkDispatchPropsType, OwnProps } from '.'
// import React from 'react'
// import styled from 'styled-components'

// const Wrapper = styled.div`
// width: 100%;
// height: 100%;
// display: flex;
// align-items: center;
// justify-content: center;
// `
// const CustomForm = styled(Form)`
// text-align: center;
// `

// type Props = OwnProps & LinkDispatchPropsType

// const Template: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
// return (
// <Wrapper>
// <FlyoutWrapper>
// <CustomForm onSubmit={props.handleSubmit}>
// <Icon
// name='alert-filled'
// color='orange400'
// size='52px'
// style={{ display: 'block' }}
// />
// <Text
// color='grey800'
// size='24px'
// weight={600}
// style={{ marginTop: '32px' }}
// >
// <FormattedMessage
// id='modals.simplebuy.cancelorder.areyousure'
// defaultMessage='Are you sure?'
// />
// </Text>
// <Text
// color='grey600'
// weight={500}
// size='16px'
// lineHeight='150%'
// style={{ marginTop: '8px', marginBottom: '48px' }}
// >
// <FormattedMessage
// id='modals.simplebuy.cancelorder.outcome'
// defaultMessage='Cancelling this {pair} {orderType} will remove your order. You can always create a new order from the menu if you cancel now.'
// values={{
// pair: props.order.pair,
// orderType: orderType === 'BUY' ? 'Buy' : 'Sell'
// }}
// />
// </Text>
// {props.error && (
// <div style={{ marginBottom: '16px' }}>
// <ErrorCartridge>Error: {props.error}</ErrorCartridge>
// </div>
// )}
// <Button
// fullwidth
// size='16px'
// height='48px'
// nature='light'
// data-e2e='cancelSBOrder'
// disabled={props.submitting}
// type='submit'
// >
// {props.submitting ? (
// <HeartbeatLoader color='blue100' height='20px' width='20px' />
// ) : (
// <FormattedMessage
// id='modals.simplebuy.cancelorder.cancel'
// defaultMessage='Yes. Cancel Order'
// />
// )}
// </Button>
// <Button
// fullwidth
// size='16px'
// height='48px'
// nature='primary'
// data-e2e='cancelSBOrder'
// disabled={props.submitting}
// onClick={() =>
// props.simpleBuyActions.setStep({
// step:
// props.order.state === 'PENDING_CONFIRMATION'
// ? 'CHECKOUT_CONFIRM'
// : 'ORDER_SUMMARY',
// order: props.order
// })
// }
// style={{ marginTop: '16px' }}
// type='button'
// >
// <FormattedMessage
// id='modals.simplebuy.cancelorder.goback'
// defaultMessage='No. Go Back'
// />
// </Button>
// </CustomForm>
// </FlyoutWrapper>
// </Wrapper>
// )
// }

// export default reduxForm<{}, Props>({ form: 'cancelSBOrderForm' })(Template)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { actions, selectors } from 'data'
import { bindActionCreators, Dispatch } from 'redux'
import { connect, ConnectedProps } from 'react-redux'
import {
FiatTypeEnum,
SupportedCoinType,
SupportedWalletCurrenciesType,
SwapOrderType
} from 'core/types'
import { RootState } from 'data/rootReducer'
import React, { PureComponent } from 'react'
import Success from './template.success'

// This is a new order summary created for sell p3. Order type looks like what is currently a swap order type rather than an SB order type
// Created this separate template so that we don't have to force types to match. Should be resued when Buy uses swap2.0 apis, and OrderSummary folder
// can be deleted

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

componentDidMount () {
this.props.simpleBuyActions.fetchSBOrders()
}

handleRefresh = () => {
this.props.simpleBuyActions.fetchSBCards()
}

render () {
return <Success {...this.props} />
}
}

const mapStateToProps = (state: RootState): LinkStatePropsType => ({
sellOrder: selectors.components.simpleBuy.getSellOrder(state),
supportedCoins: selectors.core.walletOptions
.getSupportedCoins(state)
.getOrElse({
ALGO: { colorCode: 'algo' } as SupportedCoinType,
BTC: { colorCode: 'btc' } as SupportedCoinType,
BCH: { colorCode: 'bch' } as SupportedCoinType,
ETH: { colorCode: 'eth' } as SupportedCoinType,
PAX: { colorCode: 'pax' } as SupportedCoinType,
USDT: { colorCode: 'usdt' } as SupportedCoinType,
WDGLD: { colorCode: 'wdgld' } as SupportedCoinType,
XLM: { colorCode: 'xlm' } as SupportedCoinType
} as Omit<SupportedWalletCurrenciesType, keyof FiatTypeEnum>)
})

const mapDispatchToProps = (dispatch: Dispatch) => ({
simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch),
sendActions: bindActionCreators(actions.components.send, dispatch)
})
const connector = connect(mapStateToProps, mapDispatchToProps)

export type OwnProps = {
handleClose: () => void
}

type LinkStatePropsType = {
sellOrder: SwapOrderType | undefined,
supportedCoins: SupportedWalletCurrenciesType
}
export type Props = OwnProps & ConnectedProps<typeof connector>

export default connector(SellOrderSummary)

0 comments on commit c660390

Please sign in to comment.