Skip to content

Commit

Permalink
fix(sell): sell max limit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Dec 3, 2020
1 parent c9ec0b5 commit fc34dee
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,14 @@ const getPayloadObjectForStep = (payload: StepActionsPayload) => {

export const showModal = (
origin: SBShowModalOriginType,
cryptoCurrency?: CoinType
cryptoCurrency?: CoinType,
orderType?: SBOrderActionType
) => ({
type: AT.SHOW_MODAL,
payload: {
origin,
cryptoCurrency
cryptoCurrency,
orderType
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ export default ({
}

const showModal = function * ({ payload }: ReturnType<typeof A.showModal>) {
const { origin, cryptoCurrency } = payload
const { origin, cryptoCurrency, orderType } = payload
yield put(
actions.modals.showModal('SIMPLE_BUY_MODAL', { origin, cryptoCurrency })
)
Expand Down Expand Up @@ -1086,7 +1086,8 @@ export default ({
A.setStep({
step: 'ENTER_AMOUNT',
cryptoCurrency,
fiatCurrency
fiatCurrency,
orderType
})
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export type SimpleBuyState = {
payment: RemoteDataType<string, undefined | PaymentValue>
providerDetails: RemoteDataType<string, SBProviderDetailsType>
quote: RemoteDataType<string, SBQuoteType>
sellOrder: undefined | SwapOrderType,
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 @@ -370,6 +370,7 @@ interface SetStepAction {
interface ShowModalAction {
payload: {
cryptoCurrency?: CoinType
orderType?: SBOrderActionType,
origin: SBShowModalOriginType
}
type: typeof AT.SHOW_MODAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
coinToString,
fiatToString
} from 'blockchain-wallet-v4/src/exchange/currency'
import {
convertBaseToStandard,
convertStandardToBase
} from 'data/components/exchange/services'
import { convertBaseToStandard } from 'data/components/exchange/services'
import {
getCoinFromPair,
getFiatFromPair
Expand Down Expand Up @@ -175,9 +172,8 @@ export const getMaxMinSell = (
? account.balance
: sbBalances[coin]?.available || '0'

const maxSell = new BigNumber(
convertStandardToBase('FIAT', pair.sellMax)
)
const maxSell = new BigNumber(pair.sellMax)

.dividedBy(rate)
.toFixed(Currencies[coin].units[coin].decimal_digits)

Expand All @@ -186,7 +182,6 @@ export const getMaxMinSell = (
Number(maxSell)
).toString()
const maxFiat = getQuote(pair.pair, rate, 'CRYPTO', maxCrypto)

return { FIAT: maxFiat, CRYPTO: maxCrypto }
case 'min':
const minCrypto = new BigNumber(pair.sellMin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import media from 'services/ResponsiveService'
import React from 'react'
import styled from 'styled-components'

import { BuyOrSell } from 'blockchain-wallet-v4-frontend/src/modals/SimpleBuy/model'
import InterestTransactions from './TransactionList/template.interest'
import TransactionFilters from './TransactionFilters'
import TransactionList from './TransactionList'
Expand Down Expand Up @@ -144,22 +143,36 @@ class TransactionsContainer extends React.PureComponent<Props> {
</CoinTitle>
<TitleActionContainer>
{coin in CoinTypeEnum && (
<Button
<>
{/* <Button
nature='primary'
data-e2e='buyCrypto'
data-e2e='sellCrypto'
width='100px'
onClick={() => {
this.props.simpleBuyActions.showModal(
'TransactionList',
coin as CoinType
coin as CoinType,
'SELL'
)
}}
>
<BuyOrSell
crypto={coin as CoinType}
orderType={'BUY'}
coinModel={this.props.coinModel}
/>
</Button>
<FormattedMessage id="buttons.sell" defaultMessage="Sell" />
</Button> */}
<Button
nature='primary'
data-e2e='buyCrypto'
width='100px'
onClick={() => {
this.props.simpleBuyActions.showModal(
'TransactionList',
coin as CoinType,
'BUY'
)
}}
>
<FormattedMessage id='buttons.buy' defaultMessage='Buy' />
</Button>
</>
)}
{coin in WalletFiatEnum && (
<>
Expand Down
23 changes: 23 additions & 0 deletions packages/blockchain-wallet-v4/src/network/api/simpleBuy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SBTransactionsType
} from './types'
import { Moment } from 'moment'
import { SwapOrderStateType, SwapOrderType } from '../swap/types'
import { UserDataType } from 'data/types'
import axios from 'axios'

Expand Down Expand Up @@ -255,6 +256,27 @@ export default ({
type
}
})
// This is to get unified Sell trades from sellp3 using the swap 2.0 api
// Will eventually be used to get all trades, buy/sell/swap included
// keeping all the swap types until buy/sell everything else is together
const getUnifiedSellTrades = (
currency: FiatType,
limit?: number,
before?: string,
after?: string,
v2states?: SwapOrderStateType
): Array<SwapOrderType> =>
authorizedGet({
url: nabuUrl,
endPoint: `/trades/unified`,
data: {
currency,
limit,
before,
after,
states: v2states
}
})

const submitSBCardDetailsToEverypay = ({
accessToken,
Expand Down Expand Up @@ -333,6 +355,7 @@ export default ({
getSBFiatEligible,
getSBQuote,
getSBTransactions,
getUnifiedSellTrades,
submitSBCardDetailsToEverypay,
withdrawSBFunds
}
Expand Down
23 changes: 22 additions & 1 deletion packages/blockchain-wallet-v4/src/redux/data/custodial/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { APIType } from 'core/network/api'
import {
CoinType,
CoinTypeEnum,
FiatType,
ProcessedSwapOrderType,
SBPendingTransactionStateEnum,
WalletCurrencyType
Expand Down Expand Up @@ -124,8 +125,28 @@ export default ({ api }: { api: APIType }) => {
insertedAt: swap.createdAt
}))

// 4. sell p3 trades. Will eventually be used to fetch buy trades as well
const sellOrders: ReturnType<typeof api.getUnifiedSellTrades> = yield call(
api.getUnifiedSellTrades,
currency as FiatType,
20,
before,
after
)
const processedSells: Array<ProcessedSwapOrderType> = sellOrders.map(
sellOrder => ({
...sellOrder,
insertedAt: sellOrder.createdAt
})
)

const response: FetchCustodialOrdersAndTransactionsReturnType = {
orders: [...filteredOrders, ...transactions.items, ...processedSwaps]
orders: [
...filteredOrders,
...transactions.items,
...processedSwaps,
...processedSells
]
}

return response
Expand Down
14 changes: 14 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/data/fiat/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { call, put, select, take } from 'redux-saga/effects'
import { last } from 'ramda'

import { APIType } from 'core/network/api'
// import custodialSagas from '../custodial/sagas'
// import { FetchCustodialOrdersAndTransactionsReturnType } from 'core/types'
import Remote from '../../../remote'

import * as A from './actions'
Expand All @@ -10,6 +12,8 @@ import * as S from './selectors'
import { errorHandler } from 'blockchain-wallet-v4/src/utils'

export default ({ api }: { api: APIType }) => {
// const { fetchCustodialOrdersAndTransactions } = custodialSagas({ api })

const watchTransactions = function * () {
while (true) {
const action = yield take(AT.FETCH_FIAT_TRANSACTIONS)
Expand All @@ -33,6 +37,16 @@ export default ({ api }: { api: APIType }) => {
action.payload.currency,
reset ? undefined : next
)

// const custodialPage: FetchCustodialOrdersAndTransactionsReturnType = yield call(
// fetchCustodialOrdersAndTransactions,
// txPage,
// offset,
// atBounds,
// 'Fiat',
// reset ? null : nextSBTransactionsURL
// )

yield put(
A.fetchTransactionsSuccess(action.payload.currency, response, reset)
)
Expand Down

0 comments on commit fc34dee

Please sign in to comment.