Skip to content

Commit

Permalink
fix(sell): only show payment options for fiatCurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Jul 27, 2020
1 parent ffd4a2a commit 22a9fdd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 67 deletions.
Expand Up @@ -7,8 +7,6 @@ import {
SBOrderActionType,
SBOrderType,
SBPairsType,
SBPairType,
SBPaymentMethodType,
SBQuoteType,
WalletFiatEnum,
WalletFiatType
Expand Down Expand Up @@ -54,32 +52,6 @@ export const getFiatFromPair = (pair: SBPairsType): FiatType => {
return splitPair(pair)[index] as FiatType
}

export const getNextPairAndFiatFromPayments = (
pair: SBPairType,
allPairs: SBPairType[],
method: SBPaymentMethodType,
fiatCurrency: FiatType = 'USD'
) => {
switch (method.type) {
case 'FUNDS':
const nextPair = allPairs.find(({ pair: tempPair }) => {
const currentCrypto = getCoinFromPair(pair.pair)
const nextFiat = method.currency

return (
getCoinFromPair(tempPair) === currentCrypto &&
getFiatFromPair(tempPair) === nextFiat
)
})

if (!nextPair) return NO_PAIR_SELECTED

return { fiatCurrency: method.currency, pair: nextPair }
default:
return { pair, fiatCurrency }
}
}

export const getOutputAmount = (
order: SBOrderType,
quote: SBQuoteType
Expand Down
Expand Up @@ -27,7 +27,6 @@ import {
getCoinFromPair,
getFiatFromPair,
getNextCardExists,
getNextPairAndFiatFromPayments,
NO_FIAT_CURRENCY,
NO_ORDER_EXISTS,
NO_PAIR_SELECTED
Expand Down Expand Up @@ -556,43 +555,17 @@ export default ({
const handleSBMethodChange = function * (
action: ReturnType<typeof A.handleSBMethodChange>
) {
const fiatCurrency = S.getFiatCurrency(yield select())
const fiatCurrency = S.getFiatCurrency(yield select()) || 'USD'
const pair = S.getSBPair(yield select())
const method = action.method
const { method } = action

if (!pair) return NO_PAIR_SELECTED

if (method.currency !== fiatCurrency) {
yield put(A.fetchSBSuggestedAmounts(method.currency))
yield put(A.fetchSBPairs(method.currency))
yield take(AT.FETCH_SB_PAIRS_SUCCESS)
}

const pairs = S.getSBPairs(yield select()).getOrElse([])

const result = getNextPairAndFiatFromPayments(
pair,
pairs,
method,
fiatCurrency
)

if (result === NO_PAIR_SELECTED) {
return yield put(A.fetchSBPairsFailure(NO_PAIR_SELECTED))
}

switch (method.type) {
case 'BANK_ACCOUNT':
case 'PAYMENT_CARD':
const isUserTier2 = yield call(isTier2)
if (isUserTier2) {
return yield put(
A.setStep({
step: 'TRANSFER_DETAILS',
displayBack: true,
...result
})
)
} else {
if (!isUserTier2) {
return yield put(
actions.components.identityVerification.verifyIdentity(
2,
Expand All @@ -601,12 +574,33 @@ export default ({
)
)
}
break
default:
// continue
}

switch (method.type) {
case 'BANK_ACCOUNT':
return yield put(
A.setStep({
step: 'TRANSFER_DETAILS',
displayBack: true,
fiatCurrency
})
)
case 'PAYMENT_CARD':
return yield put(
A.setStep({
step: 'ADD_CARD'
})
)
default:
yield put(
A.setStep({
step: 'ENTER_AMOUNT',
method,
...result
fiatCurrency,
pair
})
)
}
Expand Down
Expand Up @@ -124,14 +124,19 @@ class Payments extends PureComponent<InjectedFormProps<{}, Props> & Props> {
)

const funds = defaultMethods.filter(
method => method.value.type === 'FUNDS' && method.value.currency !== 'USD'
method =>
method.value.type === 'FUNDS' &&
method.value.currency !== 'USD' &&
method.value.currency === this.props.fiatCurrency
)

const paymentCard = defaultMethods.find(
method => method.value.type === 'PAYMENT_CARD'
)
const bankAccount = defaultMethods.find(
method => method.value.type === 'BANK_ACCOUNT'
method =>
method.value.type === 'BANK_ACCOUNT' &&
method.value.currency === this.props.fiatCurrency
)

const cardMethods = availableCards.map(card => ({
Expand Down Expand Up @@ -207,11 +212,7 @@ class Payments extends PureComponent<InjectedFormProps<{}, Props> & Props> {
key={`${paymentCard.text}`}
{...paymentCard}
icon={this.getIcon(paymentCard.value)}
onClick={() =>
this.props.simpleBuyActions.setStep({
step: 'ADD_CARD'
})
}
onClick={() => this.handleSubmit(paymentCard.value)}
/>
)}
{bankAccount && fiatCurrency && (
Expand Down

0 comments on commit 22a9fdd

Please sign in to comment.