Skip to content

Commit

Permalink
feat(suite-common): fetch stake data based on device account symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Nov 20, 2024
1 parent 58b854c commit be23fc9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 13 additions & 1 deletion suite-common/wallet-core/src/accounts/accountsReducer.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 =>
Expand Down
9 changes: 7 additions & 2 deletions suite-common/wallet-core/src/stake/stakeThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit be23fc9

Please sign in to comment.