Skip to content

Commit

Permalink
feat(recurring buy): code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
milan-bc committed Jul 23, 2021
1 parent e975e77 commit e3ac19f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 41 deletions.
12 changes: 6 additions & 6 deletions packages/blockchain-info-components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { IcoMoonType } from './src/Icons/Icomoon'
import { ImageType } from './src/Images/Images'
import { CoinType, WalletCurrencyType } from 'core/types'
import { SwapBaseCounterTypes } from 'data/types'
import { Props as FlyoutContainerPropsType } from './src/Flyouts/Container'
import { Props as FlyoutContentPropsType } from './src/Flyouts/Content'
import { Props as FlyoutHeaderPropsType } from './src/Flyouts/Header'
import { Props as AmountSubHeaderPropsType } from './src/Flyouts/AmountSubHeader'
import { Props as FlyoutFooterPropsType } from './src/Flyouts/'
import { Props as CheckoutRowPropsType } from './src/Rows/CheckoutRow'
import { Props as FlyoutContainerPropsType } from './src/Flyouts/Container'
import { Props as FlyoutContentPropsType } from './src/Flyouts/Content'
import { Props as FlyoutHeaderPropsType } from './src/Flyouts/Header'
import { Props as AmountSubHeaderPropsType } from './src/Flyouts/AmountSubHeader'
import { Props as FlyoutFooterPropsType } from './src/Flyouts/'
import { Props as CheckoutRowPropsType } from './src/Rows/CheckoutRow'

type AllCoinsType = WalletCurrencyType | 'STX'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const SET_FAST_LINK = '@EVENT.SET_FAST_LINK'
export const FETCH_BANK_LINK_CREDENTIALS = '@EVENT.FETCH_BANK_LINK_CREDENTIALS'

export const CHANGE_SELECTED_BANK = '@EVENT.CHANGE_SELECTED_BANK'
export const CREATE_FIAT_DEPOSIT = '@EVENT.CREATE_FIAT_DEPOSIT'
export const DELETE_SAVED_BANK = '@EVENT.DELETE_SAVED_BANK'

export const FETCH_BANK_CREDENTIALS_LOADING = '@EVENT.FETCH_BANK_CREDENTIALS_LOADING'
export const FETCH_BANK_CREDENTIALS_SUCCESS = '@EVENT.FETCH_BANK_CREDENTIALS_SUCCESS'
export const FETCH_BANK_CREDENTIALS_ERROR = '@EVENT.FETCH_BANK_CREDENTIALS_ERROR'

export const FETCH_BANK_TRANSFER_ACCOUNTS = '@EVENT.FETCH_BANK_TRANSFER_ACCOUNTS'
export const FETCH_BANK_TRANSFER_ACCOUNTS_LOADING = '@EVENT.FETCH_BANK_TRANSFER_ACCOUNTS_LOADING'
export const FETCH_BANK_TRANSFER_ACCOUNTS_ERROR = '@EVENT.FETCH_BANK_TRANSFER_ACCOUNTS_ERROR'
export const FETCH_BANK_TRANSFER_ACCOUNTS_SUCCESS = '@EVENT.FETCH_BANK_TRANSFER_ACCOUNTS_SUCCESS'

export const FETCH_BANK_TRANSFER_UPDATE = '@EVENT.FETCH_BANK_TRANSFER_UPDATE'
export const FETCH_BANK_TRANSFER_UPDATE_LOADING = '@EVENT.FETCH_BANK_TRANSFER_UPDATE_LOADING'
export const FETCH_BANK_TRANSFER_UPDATE_ERROR = '@EVENT.FETCH_BANK_TRANSFER_UPDATE_ERROR'

export const FETCH_RECURRING_BUY_METHODS = '@EVENT.FETCH_RECURRING_BUY_METHODS'

export const HANDLE_DEPOSIT_FIAT_CLICK = '@EVENT.HANDLE_DEPOSIT_FIAT_CLICK'
export const HANDLE_WITHDRAW_CLICK = '@EVENT.HANDLE_WITHDRAW_CLICK'
export const SET_ADD_BANK_STEP = '@EVENT.SET_BROKERAGE_STEP'
export const SET_D_W_STEP = '@EVENT.SET_BROKERAGE_DW_STEP'
export const SET_BANK_DETAILS = '@EVENT.SET_BROKERAGE_BANK_DETAILS'
export const SHOW_MODAL = '@EVENT.SHOW_MODAL'
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
/* eslint-disable no-param-reassign */
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

import { ModalOriginType } from 'data/modals/types'
import Remote from 'blockchain-wallet-v4/src/remote/remote'
import { ModalOriginType } from 'data/modals/types'

import { RecurringBuyRegisteredList, RecurringBuyPeriods, RecurringBuyState, RecurringBuyStepPayload, RecurringBuyStepType } from './types'
import {
RecurringBuyPeriods,
RecurringBuyRegisteredList,
RecurringBuyState,
RecurringBuyStepPayload,
RecurringBuyStepType
} from './types'

const initialState: RecurringBuyState = {
active: undefined,
methods: Remote.NotAsked,
period: RecurringBuyPeriods.ONE_TIME,
registeredList: Remote.NotAsked,
step: RecurringBuyStepType.INIT_PAGE,
step: RecurringBuyStepType.INIT_PAGE
}

const recurringBuySlice = createSlice({
initialState,
name: 'recurringBuy',
reducers: {
setActive: (state, action: PayloadAction<RecurringBuyRegisteredList>) => {
state.active = action.payload
},
createRecurringBuy: () => {},
fetchMethods: () => {},
fetchRegisteredList: () => {},
methodsFailure: (state, action: PayloadAction<string>) => {
state.methods = Remote.Failure(action.payload)
},
methodsLoading: (state) => {
state.methods = Remote.Loading
},
methodsSuccess: (state, action: PayloadAction<RecurringBuyPeriods[]>) => {
state.methods = Remote.Success(action.payload)
},
methodsFailure: (state, action: PayloadAction<string>) => {
state.methods = Remote.Failure(action.payload)
registeredListFailure: (state, action: PayloadAction<string>) => {
state.registeredList = Remote.Failure(action.payload)
},
registeredListLoading: (state) => {
state.registeredList = Remote.Loading
},
registeredListSuccess: (state, action: PayloadAction<RecurringBuyRegisteredList[]>) => {
state.registeredList = Remote.Success(action.payload)
},
registeredListFailure: (state, action: PayloadAction<string>) => {
state.registeredList = Remote.Failure(action.payload)
setActive: (state, action: PayloadAction<RecurringBuyRegisteredList>) => {
state.active = action.payload
},
setPeriod: (state, action: PayloadAction<RecurringBuyPeriods>) => {
state.period = action.payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
Text,
TextGroup
} from 'blockchain-info-components'
import { fiatToString } from 'blockchain-wallet-v4/src/exchange/currency'
import { SBOrderType } from 'core/types'
import { fiatToString } from 'blockchain-wallet-v4/src/exchange/utils'
import { FiatType, SBOrderType } from 'core/types'
import { actions, selectors } from 'data'
import {
getBankAccount,
Expand All @@ -40,20 +40,19 @@ const Confirm = ({
order,
period,
quote,
recurringBuyActions,
supportedCoins
recurringBuyActions
}: Props) => {
const amount = getBaseAmount(order)
const currency = order.outputCurrency
const baseCurrency = getBaseCurrency(order, supportedCoins)
const baseCurrency = getBaseCurrency(order)
const paymentMethodId = getPaymentMethodId(order)
const subTotalAmount = fiatToString({
unit: getCounterCurrency(order, supportedCoins),
unit: getCounterCurrency(order) as FiatType,
value: getCounterAmount(order)
})
const fee = order.fee || quote.fee
const totalAmount = fiatToString({
unit: getCounterCurrency(order, supportedCoins),
unit: getCounterCurrency(order) as FiatType,
value: getCounterAmount(order)
})
const bankAccount = getBankAccount(order, bankAccounts)
Expand All @@ -79,7 +78,7 @@ const Confirm = ({
}
text={
<div data-e2e='rbExchangeRate'>
{displayFiat(order, supportedCoins, quote.rate)} / {baseCurrency}
{displayFiat(order, quote.rate)} / {baseCurrency}
</div>
}
toolTip={
Expand Down Expand Up @@ -109,7 +108,7 @@ const Confirm = ({

<CheckoutRow
title={<FormattedMessage id='copy.fee' defaultMessage='Fee' />}
text={displayFiat(order, supportedCoins, fee || '0')}
text={displayFiat(order, fee || '0')}
/>

<CheckoutRow
Expand All @@ -119,7 +118,7 @@ const Confirm = ({

<CheckoutRow
title={<FormattedMessage id='checkout.payment_method' defaultMessage='Payment Method' />}
text={getPaymentMethod(order, supportedCoins, {} as BankTransferAccountType)}
text={getPaymentMethod(order, {} as BankTransferAccountType)}
additionalText={getPaymentMethodDetails(order, bankAccount, cardDetails)}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import React, { useCallback } from 'react'
import { FormattedMessage } from 'react-intl'
import styled from 'styled-components'

import {
Button,
FlyoutFooter,
FlyoutHeader,
Image,
Link,
Text
} from 'blockchain-info-components'
import { Button, FlyoutFooter, FlyoutHeader, Image, Link, Text } from 'blockchain-info-components'
import { FlyoutWrapper } from 'components/Flyout'
import { getBaseAmount } from 'data/components/simpleBuy/model'

Expand Down Expand Up @@ -62,7 +55,9 @@ const FooterWrapper = styled(FlyoutWrapper)`
const GetStarted = ({ close, nextStep, order }: Props) => {
const amount = getBaseAmount(order)
const currency = order.outputCurrency
const closeModal = useCallback(() => { close() }, [])
const closeModal = useCallback(() => {
close()
}, [])

return (
<Wrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect } from 'react'
import { connect, ConnectedProps, useDispatch } from 'react-redux'

import { SBPaymentMethodType, SBPaymentTypes } from 'core/types'
import { actions, selectors } from 'data'
import { SBPaymentMethodType } from 'core/types'
import { actions } from 'data'
import { RootState } from 'data/rootReducer'

import Success from './template.success'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
Icon,
Text
} from 'blockchain-info-components'
import { fiatToString } from 'blockchain-wallet-v4/src/exchange/currency'
import { SBOrderType, WithdrawalLockCheckRule } from 'core/types'
import { fiatToString } from 'blockchain-wallet-v4/src/exchange/utils'
import { FiatType, SBOrderType, WithdrawalLockCheckRule } from 'blockchain-wallet-v4/src/types'
import { selectors } from 'data'
import { getCounterAmount, getCounterCurrency } from 'data/components/simpleBuy/model'
import { RootState } from 'data/rootReducer'
Expand Down Expand Up @@ -56,9 +56,9 @@ const StyledIcon = styled(Icon)`
}
`

const Success = ({ close, order, period, supportedCoins, withdrawLockCheck }: Props) => {
const Success = ({ close, order, period, withdrawLockCheck }: Props) => {
const fiatAmount = fiatToString({
unit: getCounterCurrency(order, supportedCoins),
unit: getCounterCurrency(order) as FiatType,
value: getCounterAmount(order)
})
const coin = order.outputCurrency
Expand Down

0 comments on commit e3ac19f

Please sign in to comment.