Skip to content

Commit 5bec79b

Browse files
committed
Don't create new stake position map objects in useSelector
1 parent d131935 commit 5bec79b

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/components/scenes/Staking/StakeOptionsScene.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useIconColor } from '../../../hooks/useIconColor'
1010
import { lstrings } from '../../../locales/strings'
1111
import { getStakePlugins } from '../../../plugins/stake-plugins/stakePlugins'
1212
import type { StakePolicy } from '../../../plugins/stake-plugins/types'
13+
import { EMPTY_STAKE_POSITION_MAP } from '../../../reducers/StakingReducer'
1314
import { useSelector } from '../../../types/reactRedux'
1415
import type { EdgeAppSceneProps } from '../../../types/routerTypes'
1516
import { getCurrencyCode } from '../../../util/CurrencyInfoHelpers'
@@ -46,9 +47,10 @@ const StakeOptionsSceneComponent: React.FC<Props> = props => {
4647
const [stakePlugins = []] = useAsyncValue(
4748
async () => await getStakePlugins(wallet.currencyInfo.pluginId)
4849
)
49-
const stakePositionMap = useSelector(
50-
state => state.staking.walletStakingMap[wallet.id]?.stakePositionMap ?? {}
51-
)
50+
const stakePositionMap =
51+
useSelector(
52+
state => state.staking.walletStakingMap[wallet.id]?.stakePositionMap
53+
) ?? EMPTY_STAKE_POSITION_MAP
5254
const theme = useTheme()
5355

5456
const account = useSelector(state => state.core.account)

src/components/themed/TransactionListTop.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { formatNumber, toPercentString } from '../../locales/intl'
2828
import { lstrings } from '../../locales/strings'
2929
import { getStakePlugins } from '../../plugins/stake-plugins/stakePlugins'
3030
import type { StakePlugin } from '../../plugins/stake-plugins/types'
31+
import { EMPTY_STAKE_POSITION_MAP } from '../../reducers/StakingReducer'
3132
import {
3233
getExchangeDenom,
3334
selectDisplayDenom
@@ -111,10 +112,10 @@ export const TransactionListTop: React.FC<Props> = props => {
111112
const exchangeRates = useSelector(state => state.exchangeRates)
112113
const defaultIsoFiat = useSelector(state => state.ui.settings.defaultIsoFiat)
113114
const countryCode = useSelector(state => state.ui.countryCode)
114-
const stakePositionMap = useSelector(
115-
// Fallback to a default state using the reducer if the wallet is not found
116-
state => state.staking.walletStakingMap[wallet.id]?.stakePositionMap ?? {}
117-
)
115+
const stakePositionMap =
116+
useSelector(
117+
state => state.staking.walletStakingMap[wallet.id]?.stakePositionMap
118+
) ?? EMPTY_STAKE_POSITION_MAP
118119

119120
const defaultFiat = removeIsoPrefix(defaultIsoFiat)
120121
const theme = useTheme()

src/reducers/StakingReducer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export type StakePolicyMap = Record<string, StakePolicy>
7272

7373
export type StakePositionMap = Record<string, StakePosition>
7474

75+
export const EMPTY_STAKE_POSITION_MAP: Readonly<StakePositionMap> =
76+
Object.freeze({})
77+
7578
export const staking: Reducer<StakingState, Action> = combineReducers({
7679
walletStakingMap: (state = {}, action: Action) => {
7780
if (action.type.startsWith('STAKING/')) {

0 commit comments

Comments
 (0)