Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(suite-common): fetch stake data based on device account symbols #15460

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading