Skip to content

Commit

Permalink
feat(sell p3): sell max
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Nov 18, 2020
1 parent e543c86 commit e308b5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
props.quote,
props.pair,
props.formValues,
method
method,
props.swapAccount
)[fix]
const min: string = getMaxMin(
'min',
Expand All @@ -167,7 +168,8 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
props.quote,
props.pair,
props.formValues,
method
method,
props.swapAccount
)[fix]

const handleMinMaxClick = () => {
Expand All @@ -179,7 +181,8 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
props.quote,
props.pair,
props.formValues,
method
method,
props.swapAccount
)[fix]
const value = convertStandardToBase(conversionCoinType, maxMin)
props.simpleBuyActions.handleSBSuggestedAmountClick(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
SBQuoteType,
SupportedWalletCurrenciesType
} from 'core/types'
import { SBCheckoutFormValuesType, SBFixType } from 'data/types'
import {
SBCheckoutFormValuesType,
SBFixType,
SwapAccountType
} from 'data/types'
import { UnitType } from 'core/exchange'
import Currencies from 'blockchain-wallet-v4/src/exchange/currencies'

Expand Down Expand Up @@ -67,7 +71,8 @@ export const getMaxMin = (
quote: SBQuoteType,
pair: SBPairType,
allValues?: SBCheckoutFormValuesType,
method?: SBPaymentMethodType
method?: SBPaymentMethodType,
account?: SwapAccountType
): { CRYPTO: string; FIAT: string } => {
switch (orderType) {
case 'BUY':
Expand Down Expand Up @@ -123,9 +128,18 @@ export const getMaxMin = (
const rate = quote.rate
switch (minOrMax) {
case 'max':
const maxAvailable = sbBalances[coin]?.available || '0'
const maxAvailable = account
? account.balance
: sbBalances[coin]?.available || '0'

const maxCrypto = convertBaseToStandard(coin, maxAvailable)
const maxSell = new BigNumber(pair.sellMax)
.dividedBy(rate)
.toFixed(Currencies[coin].units[coin].decimal_digits)

const maxCrypto = Math.min(
Number(convertBaseToStandard(coin, maxAvailable)),
Number(maxSell)
).toString()
const maxFiat = getQuote(quote, 'CRYPTO', maxCrypto)
return { FIAT: maxFiat, CRYPTO: maxCrypto }
case 'min':
Expand Down

0 comments on commit e308b5c

Please sign in to comment.