diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/actions.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/actions.ts index 5af146e7db2..acacdf86efe 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/actions.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/actions.ts @@ -8,6 +8,7 @@ import { SBAccountType, SBBalancesType, SBCardType, + SBOrderActionType, SBOrderType, SBPairType, SBPaymentMethodsType, @@ -374,7 +375,7 @@ export const initializeBillingAddress = () => ({ }) export const initializeCheckout = ( - orderType: 'BUY' | 'SELL', + orderType: SBOrderActionType, amount?: string ) => ({ type: AT.INITIALIZE_CHECKOUT, diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/model.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/model.ts index 21e3c2a2c11..c2688beead7 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/model.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/model.ts @@ -4,6 +4,7 @@ import { FiatType, FiatTypeEnum, SBCardType, + SBOrderActionType, SBOrderType, SBPairsType, SBQuoteType @@ -30,7 +31,7 @@ export const splitPair = ( return pair.split('-') as [FiatType | CoinType, '-', FiatType | CoinType] } -export const getOrderType = (pair: SBPairsType): 'BUY' | 'SELL' => { +export const getOrderType = (pair: SBPairsType): SBOrderActionType => { return splitPair(pair)[0] in FiatTypeEnum ? 'SELL' : 'BUY' } diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/selectors.ts index fafb12e71a9..b6fca0e9620 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/selectors.ts @@ -22,10 +22,13 @@ export const getDefaultPaymentMethod = (state: RootState) => { orders: ExtractSuccess, sbMethods: ExtractSuccess ) => { - const { paymentType: type, inputCurrency } = orders[0] + const lastOrder = orders.shift() + if (!lastOrder) return undefined return sbMethods.methods.find( - method => method.type === type && method.currency === inputCurrency + method => + method.type === lastOrder.paymentType && + method.currency === lastOrder.inputCurrency ) } diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/types.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/types.ts index 103e6d6cd93..04958f206ac 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/types.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/types.ts @@ -9,6 +9,7 @@ import { SBAccountType, SBBalancesType, SBCardType, + SBOrderActionType, SBOrderType, SBPairType, SBPaymentMethodsType, @@ -34,7 +35,7 @@ export type SBAddCardErrorType = export type SBBillingAddressFormValuesType = NabuAddressType export type SBCheckoutFormValuesType = { amount: string - orderType: 'BUY' | 'SELL' + orderType: SBOrderActionType } export type SBCurrencySelectFormType = { search: string diff --git a/packages/blockchain-wallet-v4/src/network/api/simpleBuy/index.ts b/packages/blockchain-wallet-v4/src/network/api/simpleBuy/index.ts index d33ab6b2b28..ce4e94cfdd1 100644 --- a/packages/blockchain-wallet-v4/src/network/api/simpleBuy/index.ts +++ b/packages/blockchain-wallet-v4/src/network/api/simpleBuy/index.ts @@ -6,6 +6,7 @@ import { SBBalancesType, SBCardType, SBMoneyType, + SBOrderActionType, SBOrderType, SBPairsType, SBPairType, @@ -70,7 +71,7 @@ export default ({ const createSBOrder = ( pair: SBPairsType, - action: 'BUY' | 'SELL', + action: SBOrderActionType, pending: boolean, input: SBMoneyType, output: { @@ -211,7 +212,7 @@ export default ({ const getSBQuote = ( currencyPair: SBPairsType, - action: 'BUY' | 'SELL', + action: SBOrderActionType, amount: string ): SBQuoteType => authorizedGet({ diff --git a/packages/blockchain-wallet-v4/src/network/api/simpleBuy/types.ts b/packages/blockchain-wallet-v4/src/network/api/simpleBuy/types.ts index 07a4c7e03ef..e3ef2a1eebc 100644 --- a/packages/blockchain-wallet-v4/src/network/api/simpleBuy/types.ts +++ b/packages/blockchain-wallet-v4/src/network/api/simpleBuy/types.ts @@ -178,6 +178,7 @@ export type ISBBuyOrderType = { state: SBOrderStateType updatedAt: string } +export type SBOrderActionType = 'BUY' | 'SELL' export type SBBuyOrderType = ISBBuyOrderType & { inputCurrency: FiatType outputCurrency: CoinType @@ -200,7 +201,7 @@ export type SBOrderStateType = | 'EXPIRED' export type SBQuoteType = { - action: 'BUY' | 'SELL' + action: SBOrderActionType fee: string pair: SBPairsType rate: string