Skip to content

Commit

Permalink
fix(withdrawal-mins): wip 1, adding redux and selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Jun 24, 2020
1 parent 811f13d commit 1d983fa
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const FETCH_INTEREST_LIMITS_LOADING =
'@EVENT.INTEREST.FETCH_INTEREST_LIMITS_LOADING'
export const FETCH_INTEREST_LIMITS_SUCCESS =
'@EVENT.INTEREST.FETCH_INTEREST_LIMITS_SUCCESS'
export const SET_WITHDRAWAL_MINIMUMS = '@EVENT.INTEREST.SET_WITHDRAWAL_MINIMUMS'

// ACCOUNT
export const FETCH_INTEREST_PAYMENT_ACCOUNT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
InterestInstrumentsType,
InterestLimitsType,
InterestRateType,
InterestTransactionType
InterestTransactionType,
WithdrawalMinimumType
} from 'core/network/api/interest/types'

import * as AT from './actionTypes'
Expand Down Expand Up @@ -100,6 +101,13 @@ export const fetchInterestLimitsSuccess = (
payload: { interestLimits }
})

export const setWithdrawalMinimimums = (
withdrawalMinimums: WithdrawalMinimumType
) => ({
type: AT.SET_WITHDRAWAL_MINIMUMS,
payload: { withdrawalMinimums }
})

// ACCOUNT
export const fetchInterestAccount = (coin?: CoinType) => ({
type: AT.FETCH_INTEREST_PAYMENT_ACCOUNT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ const INITIAL_STATE: InterestState = {
name: 'ACCOUNT_SUMMARY'
},
transactions: [],
transactionsNextPage: null
transactionsNextPage: null,
withdrawalMinimums: [
{
symbol: 'BTC',
value: '.0005'
},
{
symbol: 'ETH',
value: '.002'
}
]
}

export function interestReducer (
Expand Down Expand Up @@ -200,6 +210,11 @@ export function interestReducer (
payment: Remote.Success(payload.payment)
}

case AT.SET_WITHDRAWAL_MINIMUMS:
return {
...state,
withdrawalMinimums: payload.withdrawalMinimums.minAmounts
}
case AT.SHOW_INTEREST_MODAL:
return {
...state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ export default ({
return yield put(
A.fetchInterestBalanceSuccess(DEFAULT_INTEREST_BALANCE)
)
// const response: ReturnType<typeof api.getInterestAccountBalance> = yield call(
// api.getInterestAccountBalance
// )
const response = yield call(api.getInterestAccountBalance)
const response: ReturnType<typeof api.getInterestAccountBalance> = yield call(
api.getInterestAccountBalance
)
yield put(A.fetchInterestBalanceSuccess(response))
} catch (e) {
const error = errorHandler(e)
Expand Down Expand Up @@ -247,6 +246,10 @@ export default ({
payload
}: ReturnType<typeof A.initializeWithdrawalForm>) {
try {
const response: ReturnType<typeof api.getWithdrawalMinsAndFees> = yield call(
api.getWithdrawalMinsAndFees
)
yield put(A.setWithdrawalMinimimums(response))
// init form for analytics
yield put(initialize('interestWithdrawalForm', {}))
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { FiatType, RemoteDataType } from 'core/types'

import { propEq } from 'ramda'
import { Remote } from 'blockchain-wallet-v4/src'
import { RootState } from 'data/rootReducer'
import { selectors } from 'data'
Expand Down Expand Up @@ -69,3 +71,14 @@ export const getWalletCurrency = (
): RemoteDataType<string, FiatType> => {
return selectors.core.settings.getCurrency(state)
}

export const getWithdrawalMinimums = (state: RootState, coin) =>
state.components.interest.withdrawalMinimums.find(propEq('symbol', coin))

// export const getWithdrawalMinimumCoin: (
// state: RootState,
// coin: CoinType
// ) => WithdrawalMinimumType = (state, coin) =>
// createSelector(getWithdrawalMinimums, withdrawalMins => {
// return find(propEq('symbol', coin))(withdrawalMins)
// })(state)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
InterestRateType,
InterestTransactionType,
PaymentValue,
RemoteDataType
RemoteDataType,
WithdrawalMinimumType
} from 'core/types'

//
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface InterestState {
}
transactions: Array<InterestTransactionType>
transactionsNextPage: string | null
withdrawalMinimums: WithdrawalMinimumType
}

//
Expand Down Expand Up @@ -129,6 +131,11 @@ interface FetchInterestLimitsSuccess {
type: typeof AT.FETCH_INTEREST_LIMITS_SUCCESS
}

interface SetWithdrawalMinimums {
payload: { withdrawalMinimums: WithdrawalMinimumType }
type: typeof AT.SET_WITHDRAWAL_MINIMUMS
}

// ACCOUNT
interface fetchInterestAccountFailure {
payload: { error: string }
Expand Down Expand Up @@ -276,6 +283,7 @@ export type InterestActionTypes =
| RequestWithdrawal
| RouteToTxHash
| SetInterestStep
| SetWithdrawalMinimums
| ShowInterestModal
| SetCoinDisplay
| SetDepositLimitsAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
InterestLimitsType,
RemoteDataType,
SupportedCoinsType
// WithdrawalMinimumType
} from 'core/types'
import { RatesType } from 'data/types'
import DataError from 'components/DataError'
Expand Down Expand Up @@ -78,6 +79,7 @@ export type SuccessStateType = {
rates: RatesType
supportedCoins: SupportedCoinsType
walletCurrency: FiatType
withdrawalMinimums: any
}

type LinkStatePropsType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ export const getData = state => {
)
const ratesR = selectors.components.interest.getRates(state)
const supportedCoinsR = selectors.core.walletOptions.getSupportedCoins(state)

const walletCurrencyR = selectors.core.settings.getCurrency(state)
const withdrawalMinimumsR = selectors.components.interest.getWithdrawalMinimums(
state,
coin
)
const interestLimitsR = selectors.components.interest.getInterestLimits(state)

return lift(
Expand All @@ -20,6 +23,7 @@ export const getData = state => {
rates,
supportedCoins,
walletCurrency,
withdrawalMinimums,
interestLimits
) => ({
accountBalances,
Expand All @@ -31,7 +35,15 @@ export const getData = state => {
rates,
supportedCoins,
walletCurrency,
withdrawalMinimums,
interestLimits
})
)(accountBalancesR, ratesR, supportedCoinsR, walletCurrencyR, interestLimitsR)
)(
accountBalancesR,
ratesR,
supportedCoinsR,
walletCurrencyR,
withdrawalMinimumsR,
interestLimitsR
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const WithdrawalForm: React.FC<InjectedFormProps<{}, Props> &
rates
)
if (!account) return null

return submitting ? (
<SendingWrapper>
<SpinningLoader />
Expand Down
11 changes: 10 additions & 1 deletion packages/blockchain-wallet-v4/src/network/api/interest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
InterestLimitsType,
InterestRateType,
InterestTransactionResponseType,
InterestWithdrawalResponseType
InterestWithdrawalResponseType,
WithdrawalMinimumType
} from './types'

export default ({ nabuUrl, authorizedGet, authorizedPost }) => {
Expand Down Expand Up @@ -68,6 +69,13 @@ export default ({ nabuUrl, authorizedGet, authorizedPost }) => {
endPoint: `/payments/accounts/savings?ccy=${ccy}`
})

const getWithdrawalMinsAndFees = (): WithdrawalMinimumType =>
authorizedGet({
url: nabuUrl,
ignoreQueryParams: true,
endPoint: '/payments/withdrawals/fees?product=SAVINGS'
})

const initiateInterestWithdrawal = (
amount: number,
currency: CoinType,
Expand All @@ -92,6 +100,7 @@ export default ({ nabuUrl, authorizedGet, authorizedPost }) => {
getInterestAccount,
getInterestSavingsRate,
getInterestTransactions,
getWithdrawalMinsAndFees,
initiateInterestWithdrawal
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ export type InterestWithdrawalResponseType = {
state: string
user: string
}

export type WithdrawalMinimumType = Array<{
symbol: CoinType | FiatType
value: string
}>

0 comments on commit 1d983fa

Please sign in to comment.