Skip to content

Commit

Permalink
fix(interest): get limits in currency
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed May 26, 2020
1 parent b947947 commit c5b2dd8
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CoinType, PaymentValue } from 'core/types'
import { CoinType, FiatType, PaymentValue } from 'core/types'
import {
InterestAccountBalanceType,
InterestAccountType,
Expand Down Expand Up @@ -79,8 +79,9 @@ export const fetchInterestInstrumentsSuccess = (
})

// LIMITS
export const fetchInterestLimits = () => ({
type: AT.FETCH_INTEREST_LIMITS
export const fetchInterestLimits = (coin?: CoinType, currency?: FiatType) => ({
type: AT.FETCH_INTEREST_LIMITS,
payload: { coin, currency }
})
export const fetchInterestLimitsFailure = (
error: string
Expand Down Expand Up @@ -174,8 +175,8 @@ export const setTransactionsNextPage = (
export const initializeDepositModal = (): InterestActionTypes => ({
type: AT.INITIALIZE_DEPOSIT_MODAL
})
export const initializeDepositForm = (coin: CoinType) => ({
payload: { coin },
export const initializeDepositForm = (coin: CoinType, currency: FiatType) => ({
payload: { coin, currency },
type: AT.INITIALIZE_DEPOSIT_FORM
})
export const setDepositLimits = (limits: InterestMinMaxType) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default ({
interestSagas.fetchInterestInstruments
)
yield takeLatest(
// @ts-ignore
AT.FETCH_INTEREST_LIMITS,
interestSagas.fetchInterestLimits
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ export default ({
}
}

const fetchInterestLimits = function * () {
const fetchInterestLimits = function * ({ payload }) {
const { coin, currency } = payload
try {
yield put(A.fetchInterestLimitsLoading())
const response: ReturnType<typeof api.getInterestLimits> = yield call(
api.getInterestLimits
api.getInterestLimits,
coin,
currency
)
yield put(A.fetchInterestLimitsSuccess(response.limits))
} catch (e) {
Expand Down Expand Up @@ -183,17 +186,17 @@ export default ({
const initializeDepositForm = function * ({
payload
}: ReturnType<typeof A.initializeDepositForm>) {
const { coin, currency } = payload
let defaultAccountR
let payment: PaymentType = <PaymentType>{}

yield put(A.setPaymentLoading())
yield put(A.fetchInterestLimits())
yield put(A.fetchInterestLimits(coin, currency))
yield take([
AT.FETCH_INTEREST_LIMITS_SUCCESS,
AT.FETCH_INTEREST_LIMITS_FAILURE
])

switch (payload.coin) {
switch (coin) {
case 'BTC':
const accountsR = yield select(
selectors.core.common.btc.getAccountsBalances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as AT from './actionTypes'
import {
AccountTypes,
CoinType,
FiatType,
InterestAccountBalanceType,
InterestAccountType,
InterestEligibleType,
Expand Down Expand Up @@ -113,6 +114,11 @@ interface FetchInterestInstrumentsSuccess {
}

// LIMITS

interface FetchInterestLimits {
payload: { coin?: CoinType; currency?: FiatType }
type: typeof AT.FETCH_INTEREST_LIMITS
}
interface FetchInterestLimitsFailure {
payload: { error: string }
type: typeof AT.FETCH_INTEREST_LIMITS_FAILURE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { PureComponent } from 'react'
import { actions } from 'data'
import {
CoinType,
FiatType,
InterestAccountBalanceType,
InterestLimitsType,
InterestRateType,
Expand All @@ -22,13 +23,21 @@ class AccountSummaryContainer extends PureComponent<Props> {
state = {}

componentDidMount () {
this.props.interestActions.fetchInterestLimits()
this.handleFetchInterestLimits()
}

handleDepositClick = () => {
this.props.interestActions.showInterestModal('DEPOSIT')
}

handleFetchInterestLimits = () => {
const { coin, walletCurrency } = this.props.data.getOrElse({
coin: 'BTC' as CoinType,
walletCurrency: 'GBP' as FiatType
})
this.props.interestActions.fetchInterestLimits(coin, walletCurrency)
}

handleRefresh = () => {
this.props.interestActions.showInterestModal('ACCOUNT_SUMMARY')
}
Expand Down Expand Up @@ -78,6 +87,7 @@ export type SuccessStateType = {
interestLimits: InterestLimitsType
interestRate: InterestRateType
supportedCoins: SupportedCoinsType
walletCurrency: FiatType
}

type LinkStatePropsType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,28 @@ export const getData = state => {
const interestLimitsR = selectors.components.interest.getInterestLimits(state)
const interestRateR = selectors.components.interest.getInterestRate(state)
const supportedCoinsR = selectors.core.walletOptions.getSupportedCoins(state)
const walletCurrencyR = selectors.core.settings.getCurrency(state)

return lift(
(accountBalances, interestLimits, interestRate, supportedCoins) => ({
(
accountBalances,
interestLimits,
interestRate,
supportedCoins,
walletCurrency
) => ({
accountBalances,
coin,
interestLimits,
interestRate,
supportedCoins
supportedCoins,
walletCurrency
})
)(accountBalancesR, interestLimitsR, interestRateR, supportedCoinsR)
)(
accountBalancesR,
interestLimitsR,
interestRateR,
supportedCoinsR,
walletCurrencyR
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ import Success from './template.success'

class DepositForm extends PureComponent<Props> {
componentDidMount () {
this.props.interestActions.initializeDepositForm('BTC')
this.handleInitializeDepositForm()
}

handleRefresh = () => {
this.props.interestActions.initializeDepositForm('BTC')
this.handleInitializeDepositForm()
}

handleInitializeDepositForm = () => {
const { coin, walletCurrency } = this.props.data.getOrElse({
coin: 'BTC' as CoinType,
walletCurrency: 'GBP' as FiatType
})
this.props.interestActions.initializeDepositForm(coin, walletCurrency)
}

handleSubmit = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ export default ({ nabuUrl, authorizedGet, authorizedPost }) => {
endPoint: '/savings/instruments'
})

const getInterestLimits = (): { limits: InterestLimitsType } =>
const getInterestLimits = (
ccy?: CoinType,
currency?: FiatType
): { limits: InterestLimitsType } =>
authorizedGet({
url: nabuUrl,
endPoint: '/savings/limits'
endPoint: `/savings/limits?ccy=${ccy}&currency=${currency}&`
})

const getInterestTransactions = (
Expand Down

0 comments on commit c5b2dd8

Please sign in to comment.