diff --git a/suite-common/wallet-core/src/accounts/accountsReducer.ts b/suite-common/wallet-core/src/accounts/accountsReducer.ts index a99d9ef0295..44086df7f7e 100644 --- a/suite-common/wallet-core/src/accounts/accountsReducer.ts +++ b/suite-common/wallet-core/src/accounts/accountsReducer.ts @@ -1,5 +1,5 @@ import { isAnyOf } from '@reduxjs/toolkit'; -import { A, G, pipe } from '@mobily/ts-belt'; +import { A, F, G, pipe } from '@mobily/ts-belt'; import { createReducerWithExtraDeps, @@ -325,6 +325,18 @@ export const selectVisibleNonEmptyDeviceAccountsByNetworkSymbol = createMemoized ), ); +export const selectAllNetworkSymbolsOfVisibleAccounts = createMemoizedSelector( + [selectAccounts], + accounts => + pipe( + accounts, + A.filter(account => account.visible), + A.map(account => account.symbol), + A.uniq, + F.toMutable, + ), +); + export const selectNonEmptyDeviceAccounts = createMemoizedSelector( [selectDeviceAccounts], accounts => diff --git a/suite-common/wallet-core/src/stake/stakeThunks.ts b/suite-common/wallet-core/src/stake/stakeThunks.ts index 8ff31070dfb..85f581fca26 100644 --- a/suite-common/wallet-core/src/stake/stakeThunks.ts +++ b/suite-common/wallet-core/src/stake/stakeThunks.ts @@ -7,6 +7,7 @@ import { SupportedNetworkSymbol } from '@suite-common/wallet-types'; import { selectEverstakeData } from './stakeSelectors'; import { EVERSTAKE_ENDPOINT_TYPES, EverstakeEndpointType, ValidatorsQueue } from './stakeTypes'; import { EVERSTAKE_ENDPOINT_PREFIX } from './stakeConstants'; +import { selectAllNetworkSymbolsOfVisibleAccounts } from '../accounts/accountsReducer'; const STAKE_MODULE = '@common/wallet-core/stake'; @@ -60,11 +61,15 @@ export const fetchEverstakeData = createThunk< export const initStakeDataThunk = createThunk( `${STAKE_MODULE}/initStakeDataThunk`, (_, { getState, dispatch, extra }) => { + //because fetch only happens every 5 minutes we fetch according all devices in case a device is changed within those 5 minutes + const accountsNetworks = selectAllNetworkSymbolsOfVisibleAccounts(getState()); + //also join with enabled networks in case account was not yet discovered, but network is already enabled const enabledNetworks = extra.selectors.selectEnabledNetworks(getState()); + const networks = [...new Set([...accountsNetworks, ...enabledNetworks])]; - const ethereumBasedNetworksWithStaking = getStakingSymbols(enabledNetworks); + const networksWithStaking = getStakingSymbols(networks); - const promises = ethereumBasedNetworksWithStaking.flatMap(networkSymbol => + const promises = networksWithStaking.flatMap(networkSymbol => Object.values(EverstakeEndpointType).map(endpointType => { const data = selectEverstakeData(getState(), networkSymbol, endpointType);