Skip to content

Commit

Permalink
feat(pricing): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Han committed Dec 7, 2021
1 parent 2477926 commit 00f1617
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
)
try {
const pair = S.getBSPair(yield select())
const buyQuote = S.getBuyQuote(yield select())
if (!values) throw new Error(NO_CHECKOUT_VALUES)
if (!pair) throw new Error(NO_PAIR_SELECTED)
const { fix, orderType, period } = values
Expand Down Expand Up @@ -367,10 +368,14 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
input,
output,
paymentType,
buyQuote.data.quote.quoteId,
period,
paymentMethodId
)

// eslint-disable-next-line no-console
console.log('[buyOrder is here!!!]: ', buyOrder)

yield put(actions.form.stopSubmit(FORM_BS_CHECKOUT))
yield put(A.fetchOrders())
yield put(A.setStep({ order: buyOrder, step: 'CHECKOUT_CONFIRM' }))
Expand Down Expand Up @@ -814,8 +819,26 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
const fetchBuyQuote = function* ({ payload }: ReturnType<typeof A.fetchBuyQuote>) {
try {
yield put(A.fetchQuoteLoading())

const { inputValue, pair, paymentMethod, paymentMethodId, profile } = payload

const quote: ReturnType<typeof api.getBuyQuote> = yield call(
api.getBuyQuote,
pair,
profile,
inputValue,
paymentMethod,
paymentMethodId
)

yield put(A.fetchBuyQuoteSuccess({ quote }))
const refresh = -moment().diff(quote.quoteExpiresAt)
yield delay(refresh)
} catch (e) {
const error = errorHandler(e)
yield put(A.fetchBuyQuoteFailure(error))
yield delay(FALLBACK_DELAY)
// yield put(A.startPollSellQuote(payload))
}
}

Expand Down Expand Up @@ -1419,6 +1442,7 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
fetchBSOrders,
fetchBSPairs,
fetchBSQuote,
fetchBuyQuote,
fetchCrossBorderLimits,
fetchFiatEligible,
fetchLimits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ export const getBSLatestPendingOrder = (state: RootState) =>
return order.state === 'PENDING_CONFIRMATION' || order.state === 'PENDING_DEPOSIT'
})

export const getBuyQuote = (state: RootState) => state.components.buySell.buyQuote

export const getSellQuote = (state: RootState) => state.components.buySell.sellQuote

export const getSellOrder = (state: RootState) => state.components.buySell.sellOrder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
BSPaymentMethodType,
BSPaymentTypes,
BSQuoteType,
BuyQuoteType,
CoinType,
CrossBorderLimits,
CrossBorderLimitsPyload,
Expand Down Expand Up @@ -45,6 +46,7 @@ const initialState: BuySellState = {
account: Remote.NotAsked,
addBank: undefined,
balances: Remote.NotAsked,
buyQuote: Remote.NotAsked,
card: Remote.NotAsked,
cardId: undefined,
cards: Remote.NotAsked,
Expand Down Expand Up @@ -203,7 +205,31 @@ const buySellSlice = createSlice({
fetchBalanceSuccess: (state, action: PayloadAction<BSBalancesType>) => {
state.balances = Remote.Success(action.payload)
},
fetchBuyQuote: (state, action: PayloadAction<any>) => {}, // TODO: @sean types
fetchBuyQuote: (
state,
action: PayloadAction<{
// TODO
inputValue: '500'
pair: BSPairsType
paymentMethod: 'BANK_TRANSFER'
paymentMethodId: 'd74992e0-a462-4aeb-903e-fc8e9a11bb40'
profile: 'SIMPLEBUY'
}>
) => {},
fetchBuyQuoteFailure: (state, action: PayloadAction<string>) => {
state.buyQuote = Remote.Failure(action.payload)
},
fetchBuyQuoteLoading: (state) => {
state.buyQuote = Remote.Loading
},
fetchBuyQuoteSuccess: (
state,
action: PayloadAction<{
quote: BuyQuoteType
}>
) => {
state.buyQuote = Remote.Success(action.payload)
},
fetchCard: () => {},
fetchCardFailure: (state, action: PayloadAction<string>) => {
state.card = Remote.Failure(action.payload)
Expand All @@ -227,8 +253,8 @@ const buySellSlice = createSlice({
action.payload.filter((card) => card.state !== BSCardStateEnum.BLOCKED)
)
},

fetchCrossBorderLimits: (state, action: PayloadAction<CrossBorderLimitsPyload>) => {},

fetchCrossBorderLimitsFailure: (state, action: PayloadAction<unknown>) => {
state.crossBorderLimits = Remote.Failure(action.payload)
},
Expand All @@ -238,8 +264,8 @@ const buySellSlice = createSlice({
fetchCrossBorderLimitsSuccess: (state, action: PayloadAction<CrossBorderLimits>) => {
state.crossBorderLimits = Remote.Success(action.payload)
},

fetchFiatEligible: (state, action: PayloadAction<FiatType>) => {},

fetchFiatEligibleFailure: (state, action: PayloadAction<string>) => {
state.fiatEligible = Remote.Failure(action.payload)
},
Expand Down Expand Up @@ -489,6 +515,17 @@ const buySellSlice = createSlice({
state.cryptoCurrency = action.payload.cryptoCurrency
state.orderType = action.payload.orderType
},
startPollBuyQuote: (
state,
action: PayloadAction<{
// TODO
inputValue: '500'
pair: BSPairsType
paymentMethod: 'BANK_TRANSFER'
paymentMethodId: 'd74992e0-a462-4aeb-903e-fc8e9a11bb40'
profile: 'SIMPLEBUY'
}>
) => {},
startPollSellQuote: (
state,
action: PayloadAction<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
BSPaymentMethodsType,
BSPaymentMethodType,
BSQuoteType,
BuyQuoteType,
CoinType,
CrossBorderLimits,
Everypay3DSResponseType,
Expand Down Expand Up @@ -122,6 +123,7 @@ export type BuySellState = {
account: RemoteDataType<string, BSAccountType>
addBank: boolean | undefined
balances: RemoteDataType<string, BSBalancesType>
buyQuote: RemoteDataType<string, { quote: BuyQuoteType }>
card: RemoteDataType<string, BSCardType>
cardId: undefined | string
cards: RemoteDataType<string, Array<BSCardType>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas; network
const amount = convertStandardToBase(BASE.coin, swapAmountFormValues.cryptoAmount)

const quote = S.getQuote(yield select()).getOrFail('NO_SWAP_QUOTE')
// eslint-disable-next-line no-console
console.log('[quote]: ', quote)
const refundAddr = onChain ? yield call(selectReceiveAddress, BASE, networks) : undefined
const destinationAddr = toChain
? yield call(selectReceiveAddress, COUNTER, networks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect, ConnectedProps } from 'react-redux'
import { bindActionCreators, Dispatch } from 'redux'

import { Remote } from '@core'
import { FiatType, RemoteDataType, BSOrderActionType, BSOrderType, BSPairType } from '@core/types'
import { BSOrderActionType, BSOrderType, BSPairType, FiatType, RemoteDataType } from '@core/types'
import { FlyoutOopsError } from 'components/Flyout'
import { actions, selectors } from 'data'
import { RootState } from 'data/rootReducer'
Expand Down
26 changes: 25 additions & 1 deletion packages/blockchain-wallet-v4/src/network/api/buySell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
BSTransactionStateType,
BSTransactionsType,
BSTransactionType,
BuyQuoteType,
CardAcquirer,
FiatEligibleType,
NabuAddressType
Expand Down Expand Up @@ -113,6 +114,7 @@ export default ({
input: BSMoneyType,
output: BSMoneyType,
paymentType: BSPaymentMethodType['type'],
quoteId: string,
period?: RecurringBuyPeriods,
paymentMethodId?: BSCardType['id']
): BSOrderType =>
Expand All @@ -125,7 +127,8 @@ export default ({
pair,
paymentMethodId,
paymentType,
period
period,
quoteId
},
endPoint: `/simple-buy/trades${pending ? '?action=pending' : ''}`,
removeDefaultPostData: true,
Expand Down Expand Up @@ -336,6 +339,26 @@ export default ({
url: nabuUrl
})

const getBuyQuote = (
pair: string,
profile: string,
inputValue: string,
paymentMethod: string,
paymentMethodId: string
): BuyQuoteType =>
authorizedPost({
contentType: 'application/json',
data: {
inputValue,
pair,
paymentMethod,
paymentMethodId,
profile
},
endPoint: '/brokerage/quote',
url: nabuUrl
})

type getBSTransactionsType = {
currency: string
fromId?: string
Expand Down Expand Up @@ -499,6 +522,7 @@ export default ({
getBSTransactions,
getBankTransferAccountDetails,
getBankTransferAccounts,
getBuyQuote,
getCardAcquirers,
getPaymentById,
getRBPaymentInfo,
Expand Down
19 changes: 19 additions & 0 deletions packages/blockchain-wallet-v4/src/network/api/buySell/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,22 @@ export type CardAcquirer = {
cardAcquirerAccountCodes: string[]
cardAcquirerName: CardAcquirerName
}

export type BuyQuoteType = {
feeDetails: {
fee: string
feeFlags: []
feeWithoutPromo: string
}
networkFee: null
price: string
quoteCreatedAt: string
quoteExpiresAt: string
quoteId: string
quoteMarginPercent: number
sampleDepositAddress: null
settlementDetails: {
availability: string
}
staticFee: null
}

0 comments on commit 00f1617

Please sign in to comment.