Skip to content

Commit d88c1e8

Browse files
authored
Merge pull request #5440 from EdgeApp/jon/fix/wallet-details-crash
Fix `useSelector` calls for accessing non-existent `exchangeRates`
2 parents 620cb56 + 00416fa commit d88c1e8

File tree

6 files changed

+13
-7
lines changed

6 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- changed: `TransactionListScene` split into two scenes: `TransactionListScene` and `WalletDetailsScene`
1313
- changed: All floating `NotificationCard`s are dismissible
1414
- fixed: Show correct staked balance for deprecated Velodrome pools
15+
- fixed: Crash when retrieving `exchangeRates` in some situations when no internet is available
1516

1617
## 4.21.1 (2025-01-28)
1718

src/actions/ReceiveDropdown.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FlashNotification } from '../components/navigation/FlashNotification'
77
import { Airship, showError } from '../components/services/AirshipInstance'
88
import { lstrings } from '../locales/strings'
99
import { getExchangeDenom, selectDisplayDenom } from '../selectors/DenominationSelectors'
10+
import { getExchangeRate } from '../selectors/WalletSelectors'
1011
import { ThunkAction } from '../types/reduxTypes'
1112
import { NavigationBase } from '../types/routerTypes'
1213
import { calculateSpamThreshold, convertNativeToDisplay, zeroString } from '../util/utils'
@@ -35,7 +36,7 @@ export function showReceiveDropdown(navigation: NavigationBase, transaction: Edg
3536

3637
// Check the spam limits:
3738
const { spamFilterOn } = state.ui.settings
38-
const exchangeRate = state.exchangeRates[`${currencyCode}_${isoFiatCurrencyCode}`]
39+
const exchangeRate = getExchangeRate(state, currencyCode, isoFiatCurrencyCode)
3940
const exchangeDenom = getExchangeDenom(wallet.currencyConfig, tokenId)
4041
const spamThreshold = calculateSpamThreshold(exchangeRate, exchangeDenom)
4142
if (spamFilterOn && (zeroString(exchangeRate) || lt(nativeAmount, spamThreshold))) {

src/components/scenes/WalletDetailsScene.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useWatch } from '../../hooks/useWatch'
1616
import { formatNumber } from '../../locales/intl'
1717
import { lstrings } from '../../locales/strings'
1818
import { getExchangeDenomByCurrencyCode } from '../../selectors/DenominationSelectors'
19+
import { getExchangeRate } from '../../selectors/WalletSelectors'
1920
import { FooterRender } from '../../state/SceneFooterState'
2021
import { useSceneScrollHandler } from '../../state/SceneScrollState'
2122
import { useDispatch, useSelector } from '../../types/reactRedux'
@@ -72,8 +73,9 @@ function WalletDetailsComponent(props: Props) {
7273

7374
// Selectors:
7475
const exchangeDenom = getExchangeDenomByCurrencyCode(wallet.currencyConfig, currencyCode)
75-
const fiatCurrencyCode = useSelector(state => state.ui.settings.defaultIsoFiat).replace('iso:', '')
76-
const exchangeRate = useSelector(state => state.exchangeRates[`${currencyCode}_${state.ui.settings.defaultIsoFiat}`])
76+
const defaultIsoFiat = useSelector(state => state.ui.settings.defaultIsoFiat)
77+
const fiatCurrencyCode = defaultIsoFiat.replace('iso:', '')
78+
const exchangeRate = useSelector(state => getExchangeRate(state, currencyCode, defaultIsoFiat))
7779
const spamFilterOn = useSelector(state => state.ui.settings.spamFilterOn)
7880
const activeUsername = useSelector(state => state.core.account.username)
7981
const isLightAccount = activeUsername == null

src/components/themed/TransactionListRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useHistoricalRate } from '../../hooks/useHistoricalRate'
1818
import { formatNumber } from '../../locales/intl'
1919
import { lstrings } from '../../locales/strings'
2020
import { getExchangeDenom } from '../../selectors/DenominationSelectors'
21+
import { getExchangeRate } from '../../selectors/WalletSelectors'
2122
import { useSelector } from '../../types/reactRedux'
2223
import { NavigationBase } from '../../types/routerTypes'
2324
import {
@@ -62,8 +63,7 @@ export function TransactionListRow(props: Props) {
6263
const defaultAmountFiat = metadata.exchangeAmount?.[defaultIsoFiat] ?? 0
6364

6465
// CryptoAmount
65-
const rateKey = `${currencyCode}_${defaultIsoFiat}`
66-
const exchangeRate: string = useSelector(state => state.exchangeRates[rateKey])
66+
const exchangeRate: string = useSelector(state => getExchangeRate(state, currencyCode, defaultIsoFiat))
6767
let maxConversionDecimals = DEFAULT_TRUNCATE_PRECISION
6868
if (exchangeRate != null && gt(exchangeRate, '0')) {
6969
const precisionAdjustValue = precisionAdjust({

src/components/tiles/NetworkFeeTile.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useDisplayDenom } from '../../hooks/useDisplayDenom'
55
import { useFiatText } from '../../hooks/useFiatText'
66
import { lstrings } from '../../locales/strings'
77
import { getExchangeDenom } from '../../selectors/DenominationSelectors'
8+
import { getExchangeRate } from '../../selectors/WalletSelectors'
89
import { useSelector } from '../../types/reactRedux'
910
import { getCryptoText } from '../../util/cryptoTextUtils'
1011
import { getDenomFromIsoCode } from '../../util/utils'
@@ -26,7 +27,7 @@ export const NetworkFeeTile = (props: Props) => {
2627
const defaultIsoFiat = useSelector(state => state.ui.settings.defaultIsoFiat)
2728

2829
const fiatDenomination = getDenomFromIsoCode(defaultIsoFiat)
29-
const exchangeRate = useSelector(state => state.exchangeRates[`${currencyCode}_${defaultIsoFiat}`])
30+
const exchangeRate = useSelector(state => getExchangeRate(state, currencyCode, defaultIsoFiat))
3031

3132
const exchangeDenominationMultiplier = getExchangeDenom(currencyConfig, null).multiplier
3233
const exchangeDenominationName = getExchangeDenom(currencyConfig, null).name

src/hooks/useTokenDisplayData.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EdgeCurrencyWallet, EdgeTokenId } from 'edge-core-js'
22

3+
import { getExchangeRate } from '../selectors/WalletSelectors'
34
import { useSelector } from '../types/reactRedux'
45
import { getDenomFromIsoCode, zeroString } from '../util/utils'
56

@@ -27,7 +28,7 @@ export const useTokenDisplayData = (props: { tokenId: EdgeTokenId; wallet: EdgeC
2728
// BASE / QUOTE = PRICE, where:
2829
// - 'Fiat' is the QUOTE, defined by the wallet's fiatCurrencyCode
2930
// - 'Yest' is an index for a historical price from 24 hours ago.
30-
const usdFiatPrice = useSelector(state => state.exchangeRates[`iso:USD_${isoFiatCurrencyCode}`])
31+
const usdFiatPrice = useSelector(state => getExchangeRate(state, currencyCode, isoFiatCurrencyCode))
3132
const assetFiatPrice = useCurrencyFiatRate({
3233
currencyCode,
3334
isoFiatCurrencyCode

0 commit comments

Comments
 (0)