Skip to content

Commit

Permalink
chore: consolidate SwapQuoteStateType and BuyQuoteStateType
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Han committed Dec 15, 2021
1 parent 34e24ba commit 93a7fc1
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
BSPaymentMethodsType,
BSPaymentMethodType,
BSQuoteType,
BuyQuoteType,
BuyQuoteStateType,
CoinType,
CrossBorderLimits,
Everypay3DSResponseType,
Expand All @@ -21,7 +21,7 @@ import type {
SDDEligibleType,
SDDVerifiedType,
SwapOrderType,
SwapQuoteType,
SwapQuoteStateType,
SwapUserLimitsType
} from '@core/types'
import type { CountryType } from 'data/components/identityVerification/types'
Expand Down Expand Up @@ -125,7 +125,7 @@ export type BuySellState = {
account: RemoteDataType<string, BSAccountType>
addBank: boolean | undefined
balances: RemoteDataType<string, BSBalancesType>
buyQuote: RemoteDataType<string, { fee: string; pair: string; quote: BuyQuoteType; rate: number }>
buyQuote: RemoteDataType<string, BuyQuoteStateType>
card: RemoteDataType<string, BSCardType>
cardId: undefined | string
cards: RemoteDataType<string, Array<BSCardType>>
Expand Down Expand Up @@ -154,7 +154,7 @@ export type BuySellState = {
sddTransactionFinished: boolean
sddVerified: RemoteDataType<string, SDDVerifiedType>
sellOrder: undefined | SwapOrderType
sellQuote: RemoteDataType<string, { quote: SwapQuoteType; rate: number }>
sellQuote: RemoteDataType<string, SwapQuoteStateType>
step: keyof typeof BuySellStepType
swapAccount: undefined | SwapAccountType
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CrossBorderLimitsPayload,
PaymentValue,
SwapOrderType,
SwapQuoteType,
SwapQuoteStateType,
SwapUserLimitsType
} from '@core/types'
import { ModalOriginType } from 'data/modals/types'
Expand Down Expand Up @@ -97,7 +97,7 @@ const swapSlice = createSlice({
fetchQuoteLoading: (state) => {
state.quote = Remote.Loading
},
fetchQuoteSuccess: (state, action: PayloadAction<{ quote: SwapQuoteType; rate: number }>) => {
fetchQuoteSuccess: (state, action: PayloadAction<SwapQuoteStateType>) => {
state.quote = Remote.Success(action.payload)
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PaymentValue,
RemoteDataType,
SwapOrderType,
SwapQuoteType,
SwapQuoteStateType,
SwapUserLimitsType
} from '@core/types'

Expand Down Expand Up @@ -60,7 +60,7 @@ export type SwapState = {
order?: SwapOrderType
pairs: RemoteDataType<string, Array<string>>
payment: RemoteDataType<string, undefined | PaymentValue>
quote: RemoteDataType<string, { quote: SwapQuoteType; rate: number }>
quote: RemoteDataType<string, SwapQuoteStateType>
side: SwapSideType
step: keyof typeof SwapStepType
trades: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
BSPaymentMethodType,
BSPaymentTypes,
BSQuoteType,
BuyQuoteType,
BuyQuoteStateType,
OrderType,
PaymentValue,
SwapQuoteType,
SwapQuoteStateType,
SwapUserLimitsType
} from '@core/types'
import { model } from 'data'
Expand Down Expand Up @@ -62,7 +62,7 @@ export const getMaxMinSell = (
minOrMax: 'min' | 'max',
sbBalances: BSBalancesType,
orderType: BSOrderActionType,
quote: { quote: SwapQuoteType | BuyQuoteType; rate: number },
quote: SwapQuoteStateType,
pair: BSPairType,
payment?: PaymentValue,
allValues?: BSCheckoutFormValuesType,
Expand Down Expand Up @@ -110,10 +110,7 @@ export const getMaxMin = (
minOrMax: 'min' | 'max',
sbBalances: BSBalancesType,
orderType: BSOrderActionType,
QUOTE:
| BSQuoteType
| { quote: SwapQuoteType; rate: number }
| { pair: string; quote: BuyQuoteType; rate: number },
QUOTE: BSQuoteType | SwapQuoteStateType | BuyQuoteStateType,
pair: BSPairType,
payment?: PaymentValue,
allValues?: BSCheckoutFormValuesType,
Expand All @@ -123,13 +120,10 @@ export const getMaxMin = (
sddLimit = LIMIT,
limits?: SwapUserLimitsType
): { CRYPTO: string; FIAT: string } => {
let quote:
| BSQuoteType
| { quote: SwapQuoteType; rate: number }
| { pair: string; quote: BuyQuoteType; rate: number }
let quote: BSQuoteType | SwapQuoteStateType | BuyQuoteStateType
switch (orderType as OrderType) {
case OrderType.BUY:
quote = QUOTE as BSQuoteType | { pair: string; quote: BuyQuoteType; rate: number }
quote = QUOTE as BSQuoteType | BuyQuoteStateType
switch (minOrMax) {
case 'max':
// we need minimum of all max amounts including limits
Expand Down Expand Up @@ -257,7 +251,7 @@ export const getMaxMin = (
return { CRYPTO: '0', FIAT: '0' }
}
case OrderType.SELL:
quote = QUOTE as { quote: SwapQuoteType; rate: number }
quote = QUOTE as SwapQuoteStateType
return getMaxMinSell(
minOrMax,
sbBalances,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js'

import { Exchange } from '@core'
import { PaymentValue, RatesType, SwapQuoteType, SwapUserLimitsType } from '@core/types'
import { PaymentValue, RatesType, SwapQuoteStateType, SwapUserLimitsType } from '@core/types'
import { convertBaseToStandard, convertStandardToBase } from 'data/components/exchange/services'
import { BSCheckoutFormValuesType, SwapAccountType, SwapAmountFormValues } from 'data/types'
import { CRYPTO_DECIMALS } from 'services/forms'
Expand All @@ -13,7 +13,7 @@ export const getMaxMin = (
limits: SwapUserLimitsType,
baseRate: RatesType,
payment: undefined | PaymentValue,
quote: { quote: SwapQuoteType; rate: number },
quote: SwapQuoteStateType,
BASE: SwapAccountType,
COUNTER: SwapAccountType
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled from 'styled-components'

import { convertCoinToFiat } from '@core/exchange'
import { coinToString } from '@core/exchange/utils'
import { FiatType, PaymentValue, RatesType, RemoteDataType, SwapQuoteType } from '@core/types'
import { FiatType, PaymentValue, RatesType, RemoteDataType, SwapQuoteStateType } from '@core/types'
import { Icon, Link, SkeletonRectangle, Text, TextGroup } from 'blockchain-info-components'
import FiatDisplay from 'components/Display/FiatDisplay'
import { Row, Title, Value } from 'components/Flyout'
Expand Down Expand Up @@ -288,9 +288,7 @@ const mapStateToProps = (state: RootState, ownProps: OwnProps) => ({
.getRatesSelector(ownProps.counter.coin, state)
.getOrElse({} as RatesType),
paymentR: selectors.components.swap.getPayment(state).getOrElse({} as PaymentValue),
quoteR: selectors.components.swap
.getQuote(state)
.getOrElse({} as { quote: SwapQuoteType; rate: number }),
quoteR: selectors.components.swap.getQuote(state).getOrElse({} as SwapQuoteStateType),
walletCurrency: selectors.core.settings.getCurrency(state).getOrElse('USD') as FiatType
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,5 @@ export type BuyQuoteType = {
}
staticFee: null
}

export type BuyQuoteStateType = { pair: string; quote: BuyQuoteType; rate: number }
2 changes: 2 additions & 0 deletions packages/blockchain-wallet-v4/src/network/api/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ export type SwapQuoteType = {
staticFee: string
updatedAt: string
}

export type SwapQuoteStateType = { quote: SwapQuoteType; rate: number }

0 comments on commit 93a7fc1

Please sign in to comment.