Skip to content

Commit

Permalink
fix(Coinify): fix buttonLimitsHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed Jun 1, 2018
1 parent 212a04d commit 942c149
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Remote } from 'blockchain-wallet-v4/src'
import { StepTransition } from 'components/Utilities/Stepper'
import QuoteInput from './QuoteInput'
import { MethodContainer } from 'components/BuySell/styled.js'
import { checkoutButtonLimitsHelper } from 'services/CoinifyService'

const OrderCheckout = ({ quoteR, rateQuoteR, account, onFetchQuote, reason, limits, checkoutError,
type, defaultCurrency, symbol, checkoutBusy, busy, setMax, setMin, increaseLimit, onOrderCheckoutSubmit }) => {
Expand All @@ -20,10 +21,7 @@ const OrderCheckout = ({ quoteR, rateQuoteR, account, onFetchQuote, reason, limi

const limitsHelper = (quoteR, limits) => {
if (quoteR.error) return true
return quoteR.map(q => {
if (q.baseCurrency !== 'BTC') return Math.abs(q.baseAmount) > limits.max || Math.abs(q.baseAmount) < limits.min || Math.abs(q.quoteAmount) > limits.effectiveMax
if (q.baseCurrency === 'BTC') return Math.abs(q.quoteAmount) > limits.max || Math.abs(q.quoteAmount) < limits.min || Math.abs(q.baseAmount) > limits.effectiveMax
}).data
return checkoutButtonLimitsHelper(quoteR, limits, type)
}

const submitButtonHelper = () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ export const OrderDetails = ({ quoteR, onRefreshQuote, type, medium }) => (
? <Text size='13px' weight={300}><FormattedMessage id='orderdetails.amounttopurchase' defaultMessage='BTC Amount to Purchase' /></Text>
: <Text size='13px' weight={300}><FormattedMessage id='orderdetails.amounttosell' defaultMessage='BTC Amount to Sell' /></Text>
}
<Text size='13px' weight={300}>{quoteR.map(q => reviewOrder.renderFirstRow(q, type, medium)).getOrElse('~')}</Text>
<Text size='13px' weight={300}>{quoteR.map(q => reviewOrder.renderFirstRow(q, medium)).getOrElse('~')}</Text>
</OrderDetailsRow>
<OrderDetailsRow>
<Text size='13px' weight={300}><FormattedMessage id='orderdetails.tradingfee' defaultMessage='Trading Fee' /></Text>
<Text size='13px' weight={300}>{quoteR.map(q => reviewOrder.renderFeeRow(q, type, medium)).getOrElse('~')}</Text>
<Text size='13px' weight={300}>{quoteR.map(q => reviewOrder.renderFeeRow(q, medium)).getOrElse('~')}</Text>
</OrderDetailsRow>
<OrderDetailsRow>
{
type === 'buy'
? <Text size='13px' weight={300}><FormattedMessage id='orderdetails.totalcost' defaultMessage='Total Cost' /></Text>
: <Text size='13px' weight={300}><FormattedMessage id='orderdetails.totaltobereceived' defaultMessage='Total to be Received' /></Text>
}
<Text size='13px' weight={300} color='success'>{quoteR.map(q => reviewOrder.renderTotalRow(q, type, medium)).getOrElse('~')}</Text>
<Text size='13px' weight={300} color='success'>{quoteR.map(q => reviewOrder.renderTotalRow(q, medium)).getOrElse('~')}</Text>
</OrderDetailsRow>
</OrderDetailsTable>
{quoteR.map((q) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,23 @@ export const mockedLimits = {

export const reviewOrder = {
baseBtc: (q) => q.baseCurrency === 'BTC',
hasMedium: (paymentMediums, medium) => {
if (medium) return medium
if (paymentMediums && has(medium, paymentMediums)) {
return medium
} else {
return medium === 'bank' ? 'card' : 'bank'
}
},
renderFirstRow: (q, type, medium) => {
renderFirstRow: (q, medium) => {
const qAmt = Math.abs(q.quoteAmount)
const bAmt = Math.abs(q.baseAmount)
if (reviewOrder.baseBtc(q)) return `${bAmt / 1e8} BTC (${currencySymbolMap[q.quoteCurrency]}${qAmt.toFixed(2)})`
else return `${qAmt / 1e8} BTC (${currencySymbolMap[q.baseCurrency]}${bAmt.toFixed(2)})`
},
renderFeeRow: (q, type, medium) => {
renderFeeRow: (q, medium) => {
const med = medium
const fee = path(['paymentMediums', med], q) && Math.abs(q.paymentMediums[med]['fee'])
if (!fee) return `~`
if (reviewOrder.baseBtc(q)) return `${currencySymbolMap[q.quoteCurrency]}${fee && fee.toFixed(2)}`
else return `${currencySymbolMap[q.baseCurrency]}${fee && fee.toFixed(2)}`
},
renderTotalRow: (q, type, medium) => {
renderTotalRow: (q, medium) => {
const qAmt = Math.abs(q.quoteAmount)
const med = reviewOrder.hasMedium(q.paymentMediums, medium)
const fee = path(['paymentMediums', med], q) && Math.abs(q.paymentMediums[med]['fee'])
const totalBase = path(['paymentMediums', med], q) && Math.abs((q.paymentMediums[med]['total']).toFixed(2))
const fee = path(['paymentMediums', medium], q) && Math.abs(q.paymentMediums[medium]['fee'])
const totalBase = path(['paymentMediums', medium], q) && Math.abs((q.paymentMediums[medium]['total']).toFixed(2))
if (!fee) return `~`
if (reviewOrder.baseBtc(q)) return `${currencySymbolMap[q.quoteCurrency]}${(qAmt + (fee || 0)).toFixed(2)}`
else return `${currencySymbolMap[q.baseCurrency]}${totalBase}`
Expand Down Expand Up @@ -125,6 +116,18 @@ export const canCancelTrade = (trade) => {
return false
}

export const checkoutButtonLimitsHelper = (quoteR, limits, type) => {
return quoteR.map(q => {
if (type === 'sell') {
if (q.baseCurrency !== 'BTC') return Math.abs(q.quoteAmount / 1e8) > limits.max || Math.abs(q.quoteAmount / 1e8) < limits.min || Math.abs(q.quoteAmount) > limits.effectiveMax
if (q.baseCurrency !== 'BTC') return Math.abs(q.baseAmount / 1e8) > limits.max || Math.abs(q.baseAmount / 1e8) < limits.min || Math.abs(q.baseAmount) > limits.effectiveMax
} else {
if (q.baseCurrency !== 'BTC') return Math.abs(q.baseAmount) > limits.max || Math.abs(q.baseAmount) < limits.min || Math.abs(q.quoteAmount) > limits.effectiveMax
if (q.baseCurrency === 'BTC') return Math.abs(q.quoteAmount) > limits.max || Math.abs(q.quoteAmount) < limits.min || Math.abs(q.baseAmount) > limits.effectiveMax
}
}).data
}

export const statusHelper = status => {
switch (status) {
case 'awaiting_transfer_in':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default ({ api, options }) => {
const refreshedQuote = yield call(fetchQuote, {quote: quotePayload})
yield call(getPaymentMediums, {payload: refreshedQuote})
} catch (e) {

yield put(A.fetchQuoteFailure(e))
}
}

Expand Down

0 comments on commit 942c149

Please sign in to comment.