Skip to content

Commit

Permalink
fix(prices): pass correct options to date-fns sub function
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed May 16, 2022
1 parent 9a3e2e2 commit fc33476
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import { reduxForm } from 'redux-form'
import styled from 'styled-components'

import { Exchange } from '@core'
import {
CoinfigType,
CoinType,
FiatType,
OrderType,
TimeRange,
WalletCurrencyType,
WalletFiatType
} from '@core/types'
import { CoinType, FiatType, OrderType, TimeRange, WalletFiatType } from '@core/types'
import { Button, Icon, Text } from 'blockchain-info-components'
import { SavedRecurringBuy } from 'components/Box'
import EmptyResults from 'components/EmptyResults'
Expand Down
20 changes: 10 additions & 10 deletions packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,37 @@ export default ({ api }: { api: APIType }) => {
if (base in FiatTypeEnum) return
yield put(A.fetchPriceChangeLoading(base, range))

const time =
const startTime =
range === TimeRange.ALL
? getUnixTime(start[base] || 0)
: getTime(sub(new Date(), { [range]: 1 }))
: getTime(sub(new Date(), { [`${range}s`]: 1 }))

const previous: ReturnType<typeof api.getPriceIndex> = yield call(
const startData: ReturnType<typeof api.getPriceIndex> = yield call(
api.getPriceIndex,
base,
quote,
time
startTime
)
const current: ReturnType<typeof api.getPriceIndex> = yield call(
const currentData: ReturnType<typeof api.getPriceIndex> = yield call(
api.getPriceIndex,
base,
quote,
getTime(new Date())
)

// Overall coin price movement
const overallChange = getPercentChange(current.price, previous.price)
const overallChange = getPercentChange(currentData.price, startData.price)
// User's position, if given an amount will provide the
// change for that amount or else will fallback to 0
const currentPosition = new BigNumber(positionAmt).times(current.price).toNumber()
const previousPosition = new BigNumber(positionAmt).times(previous.price).toNumber()
const currentPosition = new BigNumber(positionAmt).times(currentData.price).toNumber()
const previousPosition = new BigNumber(positionAmt).times(startData.price).toNumber()
const positionChange = getPercentChange(currentPosition, previousPosition)

yield put(
A.fetchPriceChangeSuccess(
base,
previous.price,
current.price,
startData.price,
currentData.price,
range,
overallChange,
positionChange
Expand Down

0 comments on commit fc33476

Please sign in to comment.