Skip to content

Commit

Permalink
refactor: remove deprecated getLocalCurrencyToDollarsExchangeRate s…
Browse files Browse the repository at this point in the history
…elector (#4154)

### Description

Minor refactor to remove the deprecated
`getLocalCurrencyToDollarsExchangeRate` selector.

Note that we'll remove `localCurrencyExchangeRatesSelector` soon too.

### Test plan

- Unit tests pass

### Related issues

- Fixes RET-830

### Backwards compatibility

Yes
  • Loading branch information
jeanregisser authored Sep 4, 2023
1 parent 9da8c03 commit 440acba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/exchange/CeloGoldHistoryChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import { LocalCurrencyCode } from 'src/localCurrency/consts'
import { convertDollarsToLocalAmount } from 'src/localCurrency/convert'
import {
getLocalCurrencyCode,
getLocalCurrencyToDollarsExchangeRate,
localCurrencyExchangeRatesSelector,
} from 'src/localCurrency/selectors'
import useSelector from 'src/redux/useSelector'
import colors from 'src/styles/colors'
import { Spacing } from 'src/styles/styles'
import variables from 'src/styles/variables'
import { tokensBySymbolSelector } from 'src/tokens/selectors'
import { Currency } from 'src/utils/currencies'
import { getLocalCurrencyDisplayValue } from 'src/utils/formatting'
import { formatFeedDate } from 'src/utils/time'
import { VictoryGroup, VictoryLine, VictoryScatter } from 'victory-native'
Expand Down Expand Up @@ -182,7 +183,7 @@ function CeloGoldHistoryChart({ testID, i18n }: Props) {
getLocalCurrencyDisplayValue(amount, localCurrencyCode || LocalCurrencyCode.USD, true),
[localCurrencyCode]
)
const localExchangeRate = useSelector(getLocalCurrencyToDollarsExchangeRate)
const localExchangeRate = useSelector(localCurrencyExchangeRatesSelector)?.[Currency.Dollar]
const dollarsToLocal = useCallback(
(amount: BigNumber.Value | null) =>
convertDollarsToLocalAmount(amount, localCurrencyCode ? localExchangeRate : 1),
Expand Down
5 changes: 3 additions & 2 deletions src/exchange/ExchangeHomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LocalCurrencyCode } from 'src/localCurrency/consts'
import { convertDollarsToLocalAmount } from 'src/localCurrency/convert'
import {
getLocalCurrencyCode,
getLocalCurrencyToDollarsExchangeRate,
localCurrencyExchangeRatesSelector,
} from 'src/localCurrency/selectors'
import DrawerTopBar from 'src/navigator/DrawerTopBar'
import { navigate } from 'src/navigator/NavigationService'
Expand All @@ -28,6 +28,7 @@ import colors from 'src/styles/colors'
import fontStyles from 'src/styles/fonts'
import variables from 'src/styles/variables'
import { tokensBySymbolSelector } from 'src/tokens/selectors'
import { Currency } from 'src/utils/currencies'
import { getLocalCurrencyDisplayValue } from 'src/utils/formatting'

function navigateToGuide() {
Expand Down Expand Up @@ -74,7 +75,7 @@ function ExchangeHomeScreen() {

const tokensBySymbol = useSelector(tokensBySymbolSelector)
const localCurrencyCode = useSelector(getLocalCurrencyCode)
const localExchangeRate = useSelector(getLocalCurrencyToDollarsExchangeRate)
const localExchangeRate = useSelector(localCurrencyExchangeRatesSelector)?.[Currency.Dollar]
const exchangeHistory = useSelector(exchangeHistorySelector)

const exchangeHistoryLength = exchangeHistory.aggregatedExchangeRates.length
Expand Down
3 changes: 1 addition & 2 deletions src/localCurrency/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import {
import {
getLocalCurrencyCode,
getLocalCurrencySymbol,
getLocalCurrencyToDollarsExchangeRate,
localCurrencyExchangeRatesSelector,
} from 'src/localCurrency/selectors'
import { CurrencyInfo } from 'src/localCurrency/types'
import useSelector from 'src/redux/useSelector'
import { Currency } from 'src/utils/currencies'

export function useDollarToLocalRate() {
return useSelector(getLocalCurrencyToDollarsExchangeRate)
return useSelector(localCurrencyExchangeRatesSelector)?.[Currency.Dollar]
}

export function useLocalCurrencyToShow(amount: MoneyAmount, currencyInfo?: CurrencyInfo) {
Expand Down
6 changes: 0 additions & 6 deletions src/localCurrency/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ export const localCurrencyToUsdSelector = createSelector(
(exchangeRates) => exchangeRates[Currency.Dollar]
)

// deprecated, please use |localCurrencyExchangeRatesSelector| instead.
export function getLocalCurrencyToDollarsExchangeRate(state: RootState) {
const exchangeRates = localCurrencyExchangeRatesSelector(state)
return exchangeRates?.[Currency.Dollar]
}

export function shouldFetchCurrentRate(state: RootState): boolean {
const { isLoading, lastSuccessfulUpdate } = state.localCurrency

Expand Down

0 comments on commit 440acba

Please sign in to comment.