Skip to content

Commit

Permalink
fix(simple buy): convert sddLimits to just limits in simplebuy, move …
Browse files Browse the repository at this point in the history
…some consts to model file, and convert string numbers into real numbers to compare properly
  • Loading branch information
blockdylanb committed Jan 30, 2021
1 parent 7c85186 commit 8089fea
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ export const UPDATE_PAYMENT_FAILURE = '@EVENT.UPDATE_SB_PAYMENT_FAILURE'
export const UPDATE_PAYMENT_LOADING = '@EVENT.UPDATE_SB_PAYMENT_LOADING'
export const UPDATE_PAYMENT_SUCCESS = '@EVENT.UPDATE_SB_PAYMENT_SUCCESS'

export const FETCH_SDD_LIMITS = '@EVENT.FETCH_SDD_LIMITS'
export const FETCH_SDD_LIMITS_FAILURE = '@EVENT.FETCH_SDD_LIMITS_FAILURE'
export const FETCH_SDD_LIMITS_LOADING = '@EVENT.FETCH_SDD_LIMITS_LOADING'
export const FETCH_SDD_LIMITS_SUCCESS = '@EVENT.FETCH_SDD_LIMITS_SUCCESS'
export const FETCH_LIMITS = '@EVENT.FETCH_LIMITS'
export const FETCH_LIMITS_FAILURE = '@EVENT.FETCH_LIMITS_FAILURE'
export const FETCH_LIMITS_LOADING = '@EVENT.FETCH_LIMITS_LOADING'
export const FETCH_LIMITS_SUCCESS = '@EVENT.FETCH_LIMITS_SUCCESS'

export const UPDATE_SDD_TRANSACTION_FINISHED =
'@EVENT.UPDATE_SDD_TRANSACTION_FINISHED'
Original file line number Diff line number Diff line change
Expand Up @@ -668,13 +668,13 @@ export const updatePaymentFailure = (error: string): SimpleBuyActionTypes => ({
}
})

export const fetchSDDLimits = (currency: FiatType) => ({
type: AT.FETCH_SDD_LIMITS,
export const fetchLimits = (currency: FiatType) => ({
type: AT.FETCH_LIMITS,
currency
})

export const fetchSDDLimitsFailure = (error: string): SimpleBuyActionTypes => ({
type: AT.FETCH_SDD_LIMITS_FAILURE,
export const fetchLimitsFailure = (error: string): SimpleBuyActionTypes => ({
type: AT.FETCH_LIMITS_FAILURE,
payload: {
error
}
Expand All @@ -690,16 +690,16 @@ export const updatePaymentSuccess = (
payment
}
})
export const fetchSDDLimitsLoading = (): SimpleBuyActionTypes => ({
type: AT.FETCH_SDD_LIMITS_LOADING
export const fetchLimitsLoading = (): SimpleBuyActionTypes => ({
type: AT.FETCH_LIMITS_LOADING
})

export const fetchSDDLimitsSuccess = (
sddLimits: SwapUserLimitsType
export const fetchLimitsSuccess = (
limits: SwapUserLimitsType
): SimpleBuyActionTypes => ({
type: AT.FETCH_SDD_LIMITS_SUCCESS,
type: AT.FETCH_LIMITS_SUCCESS,
payload: {
sddLimits
limits
}
})
export const updateSddTransactionFinished = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
WalletFiatType
} from 'blockchain-wallet-v4/src/types'
import { convertBaseToStandard } from '../exchange/services'
import { Limits } from 'core/types'
import { SBAddCardFormValuesType } from './types'
import moment from 'moment'

Expand All @@ -24,6 +25,9 @@ export const DEFAULT_SB_METHODS = {
methods: []
}

export const LIMIT = { min: '500', max: '10000' } as Limits
export const LIMIT_FACTOR = 100 // we get 10000 from API

export const SDD_TIER = 3

export const NO_CHECKOUT_VALS = 'No checkout values'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const INITIAL_STATE: SimpleBuyState = {
sellQuote: Remote.NotAsked,
step: 'CRYPTO_SELECTION',
swapAccount: undefined,
sddLimits: Remote.NotAsked
limits: Remote.NotAsked
}

export function simpleBuyReducer (
Expand Down Expand Up @@ -304,21 +304,21 @@ export function simpleBuyReducer (
sddVerified: Remote.Failure(action.payload.error)
}
}
case AT.FETCH_SDD_LIMITS_FAILURE: {
case AT.FETCH_LIMITS_FAILURE: {
return {
...state,
sddLimits: Remote.Failure(action.payload.error)
limits: Remote.Failure(action.payload.error)
}
}
case AT.FETCH_SDD_LIMITS_LOADING:
case AT.FETCH_LIMITS_LOADING:
return {
...state,
sddLimits: Remote.Loading
limits: Remote.Loading
}
case AT.FETCH_SDD_LIMITS_SUCCESS:
case AT.FETCH_LIMITS_SUCCESS:
return {
...state,
sddLimits: Remote.Success(action.payload.sddLimits)
limits: Remote.Success(action.payload.limits)
}
case AT.FETCH_SDD_VERIFIED_LOADING:
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default ({ api, coreSagas, networks }) => {
)
yield takeLatest(AT.FETCH_SDD_ELIGIBILITY, simpleBuySagas.fetchSDDEligible)
yield takeLatest(AT.FETCH_SDD_VERIFIED, simpleBuySagas.fetchSDDVerified)
yield takeLatest(AT.FETCH_SDD_LIMITS, simpleBuySagas.fetchSDDLimits)
yield takeLatest(AT.FETCH_LIMITS, simpleBuySagas.fetchLimits)
yield takeLatest(AT.FETCH_SB_ORDERS, simpleBuySagas.fetchSBOrders)
yield takeLatest(AT.FETCH_SB_PAIRS, simpleBuySagas.fetchSBPairs)
yield takeLatest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1385,19 +1385,19 @@ export default ({
yield put(actions.form.focus('simpleBuyCheckout', 'amount'))
}

const fetchSDDLimits = function * ({
const fetchLimits = function * ({
currency
}: ReturnType<typeof A.fetchSBFiatEligible>) {
try {
yield put(A.fetchSDDLimitsLoading())
yield put(A.fetchLimitsLoading())
const limits: ReturnType<typeof api.getSwapLimits> = yield call(
api.getSwapLimits,
currency
)
yield put(A.fetchSDDLimitsSuccess(limits))
yield put(A.fetchLimitsSuccess(limits))
} catch (e) {
const error = errorHandler(e)
yield put(A.fetchSDDLimitsFailure(error))
yield put(A.fetchLimitsFailure(error))
}
}

Expand All @@ -1412,14 +1412,14 @@ export default ({
deleteSBCard,
fetchBankTransferAccounts,
fetchBankTransferUpdate,
fetchLimits,
fetchSBBalances,
fetchSBCard,
fetchSBCardSDD,
fetchSBCards,
fetchSBFiatEligible,
fetchSDDEligible,
fetchSDDVerified,
fetchSDDLimits,
fetchSBOrders,
fetchSBPairs,
fetchSBPaymentAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
ExtractSuccess,
FiatTypeEnum,
SBPaymentMethodType,
SBPaymentTypes,
SDDLimits
SBPaymentTypes
} from 'blockchain-wallet-v4/src/types'
import { FiatType } from 'core/types'
import { getQuote } from 'blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/validation'
Expand All @@ -19,10 +18,9 @@ import {
} from '../exchange/services'
import { getInputFromPair, getOutputFromPair } from '../swap/model'
import { getRate } from '../swap/utils'
import { LIMIT } from './model'
import { SBCardStateEnum, SBCheckoutFormValuesType } from './types'

const SDD_LIMIT = { min: '500', max: '10000' } as SDDLimits

const hasEligibleFiatCurrency = currency =>
currency === FiatTypeEnum.USD ||
currency === FiatTypeEnum.GBP ||
Expand Down Expand Up @@ -286,13 +284,13 @@ export const getUserSddEligibleTier = (state: RootState) => {
)(sddEligibleR)
}

export const getUserSddLimit = (state: RootState) => {
export const getUserLimit = (state: RootState) => {
const sbMethodsR = getSBPaymentMethods(state)
return lift((sbMethods: ExtractSuccess<typeof sbMethodsR>) => {
const paymentMethod = sbMethods.methods.find(
method => method.type === 'PAYMENT_CARD'
)
return paymentMethod?.limits || SDD_LIMIT
return paymentMethod?.limits || LIMIT
})(sbMethodsR)
}

Expand All @@ -306,8 +304,7 @@ export const isUserSddVerified = (state: RootState) => {
sddVerified.taskComplete && sddVerified.verified
)(sddVerifiedR)
}
export const getSddLimits = (state: RootState) =>
state.components.simpleBuy.sddLimits
export const getLimits = (state: RootState) => state.components.simpleBuy.limits

export const getSddTransactionFinished = (state: RootState) =>
state.components.simpleBuy.sddTransactionFinished
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export type SimpleBuyState = {
fastLink: RemoteDataType<string, FastLinkType>
fiatCurrency: undefined | FiatType
fiatEligible: RemoteDataType<string, FiatEligibleType>
limits: RemoteDataType<string, undefined | SwapUserLimitsType>
method: undefined | SBPaymentMethodType
methods: RemoteDataType<string, SBPaymentMethodsType>
order: undefined | SBOrderType
Expand All @@ -154,7 +155,6 @@ export type SimpleBuyState = {
providerDetails: RemoteDataType<string, SBProviderDetailsType>
quote: RemoteDataType<string, SBQuoteType>
sddEligible: RemoteDataType<string, SDDEligibleType>
sddLimits: RemoteDataType<string, undefined | SwapUserLimitsType>
sddTransactionFinished: boolean
sddVerified: RemoteDataType<string, SDDVerifiedType>
sellOrder: undefined | SwapOrderType
Expand Down Expand Up @@ -523,22 +523,22 @@ interface UpdatePaymentSuccessAction {
type: typeof AT.UPDATE_PAYMENT_SUCCESS
}

interface FetchSDDLimitsFailure {
interface FetchLimitsFailure {
payload: {
error: string
}
type: typeof AT.FETCH_SDD_LIMITS_FAILURE
type: typeof AT.FETCH_LIMITS_FAILURE
}

interface FetchSDDLimitsLoading {
type: typeof AT.FETCH_SDD_LIMITS_LOADING
interface FetchLimitsLoading {
type: typeof AT.FETCH_LIMITS_LOADING
}

interface FetchSDDLimitsSuccess {
interface FetchLimitsSuccess {
payload: {
sddLimits: SwapUserLimitsType
limits: SwapUserLimitsType
}
type: typeof AT.FETCH_SDD_LIMITS_SUCCESS
type: typeof AT.FETCH_LIMITS_SUCCESS
}
interface UpdateSddTransactionFinished {
type: typeof AT.UPDATE_SDD_TRANSACTION_FINISHED
Expand Down Expand Up @@ -592,9 +592,9 @@ export type SimpleBuyActionTypes =
| FetchSellQuoteFailure
| FetchSellQuoteLoading
| FetchSellQuoteSuccess
| FetchSDDLimitsLoading
| FetchSDDLimitsFailure
| FetchSDDLimitsSuccess
| FetchLimitsLoading
| FetchLimitsFailure
| FetchLimitsSuccess
| FetchFastLinkType
| InitializeCheckout
| SetFastLinkAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ class Checkout extends PureComponent<Props> {
this.props.simpleBuyActions.fetchSDDEligible()
this.props.simpleBuyActions.fetchSBCards()
this.props.simpleBuyActions.fetchBankTransferAccounts()
this.props.simpleBuyActions.fetchSDDLimits(
this.props.fiatCurrency || 'USD'
)
this.props.simpleBuyActions.fetchLimits(this.props.fiatCurrency || 'USD')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export const getData = (state: RootState, ownProps: OwnProps) => {
const userSDDTierR = selectors.components.simpleBuy.getUserSddEligibleTier(
state
)
const sddLimitR = selectors.components.simpleBuy.getUserSddLimit(state)
const sddLimitR = selectors.components.simpleBuy.getUserLimit(state)
const cardsR = selectors.components.simpleBuy.getSBCards(state) || []
const bankTransferAccounts = selectors.components.simpleBuy
.getBankTransferAccounts(state)
.getOrElse([])
const sddLimitsR = selectors.components.simpleBuy.getSddLimits(state)
const limitsR = selectors.components.simpleBuy.getLimits(state)
const hasFiatBalance = selectors.components.simpleBuy.hasFiatBalances(state)

return lift(
Expand Down Expand Up @@ -62,7 +62,7 @@ export const getData = (state: RootState, ownProps: OwnProps) => {
sddLimit,
supportedCoins,
userData,
sddLimits: sddLimitsR.getOrElse(undefined)
limits: limitsR.getOrElse(undefined)
})
)(
cardsR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { FlyoutWrapper } from 'components/Flyout'
import { Form } from 'components/Form'
import { Icon, Text } from 'blockchain-info-components'
import { model } from 'data'
import { SBCheckoutFormValuesType } from 'data/types'
import Currencies from 'blockchain-wallet-v4/src/exchange/currencies'

Expand All @@ -28,8 +29,7 @@ import {
getMaxMin,
getQuote,
maximumAmount,
minimumAmount,
SDD_LIMIT_FACTOR
minimumAmount
} from './validation'
import { Props as OwnProps, SuccessStateType } from '.'
import { Row } from '../../../Swap/EnterAmount/Checkout'
Expand All @@ -39,7 +39,7 @@ import Failure from '../template.failure'
import IncreaseLimits from './IncreaseLimits'
import Payment from './Payment'

const SDD_LIMIT = { min: '500', max: '10000' }
const { LIMIT, LIMIT_FACTOR } = model.components.simpleBuy

const DAILY_LIMIT_MESSAGE = 'User exceeded daily trading limit'
const WEEKLY_LIMIT_MESSAGE = 'User exceeded weekly trading limit'
Expand Down Expand Up @@ -208,17 +208,16 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
const amtError =
typeof props.formErrors.amount === 'string' && props.formErrors.amount

const limits = props.sddLimit || SDD_LIMIT
const limits = props.sddLimit || LIMIT
const sddLimit = { ...limits }
if (
props.sddLimits?.maxPossibleOrder &&
Number(props.sddLimits.maxPossibleOrder) < Number(props.sddLimit.max)
props.limits?.maxPossibleOrder &&
Number(props.limits.maxPossibleOrder) < Number(props.sddLimit.max)
) {
sddLimit.max = props.sddLimits.maxPossibleOrder
sddLimit.max = props.limits.maxPossibleOrder
}
const isDailyLimitExceeded =
props.sddLimits?.daily?.available &&
Number(props.sddLimits.daily.available) === 0
props.limits?.daily?.available && Number(props.limits.daily.available) === 0

const max: string = getMaxMin(
'max',
Expand Down Expand Up @@ -261,7 +260,7 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
props.swapAccount,
props.isSddFlow,
sddLimit,
props.sddLimits
props.limits
)[fix]
const value = convertStandardToBase(conversionCoinType, maxMin)
props.simpleBuyActions.handleSBSuggestedAmountClick(
Expand Down Expand Up @@ -300,7 +299,7 @@ const Success: React.FC<InjectedFormProps<{}, Props> & Props> = props => {
: amountRowNode.children[amountRowNode.children.length - 1]
currencyNode.style.fontSize = `${fontSizeNumber * fontRatio}px`
}
const limit = Number(props.sddLimit.max) / SDD_LIMIT_FACTOR
const limit = Number(props.sddLimit.max) / LIMIT_FACTOR
// if user is attempting to send NC ERC20, ensure they have sufficient
// ETH balance else warn user and disable trade
const isErc20 = props.supportedCoins[cryptoCurrency].contractAddress
Expand Down

0 comments on commit 8089fea

Please sign in to comment.