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

fix(suite-native): after coin enabling is enabled, show relevant normal accounts #14228

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
10 changes: 10 additions & 0 deletions suite-common/wallet-core/src/accounts/accountsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ export const selectAccountsByNetworkAndDeviceState = memoizeWithArgs(
},
);

export const selectFirstNormalAccountForNetworkSymbol = memoizeWithArgs(
(state: AccountsRootState & DeviceRootState, networkSymbol: NetworkSymbol) =>
selectDeviceAccountsForNetworkSymbolAndAccountType(state, networkSymbol, 'normal').filter(
account => account.index === 0,
)[0] ?? null,
{
size: Object.keys(networks).length,
},
);

export const selectAccountLabel = (
state: AccountsRootState,
accountKey?: AccountKey,
Expand Down
30 changes: 28 additions & 2 deletions suite-native/discovery/src/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
selectDeviceAccountsForNetworkSymbolAndAccountType,
selectDeviceState,
disableAccountsThunk,
selectFirstNormalAccountForNetworkSymbol,
} from '@suite-common/wallet-core';
import { selectIsAccountAlreadyDiscovered } from '@suite-native/accounts';
import TrezorConnect from '@trezor/connect';
Expand All @@ -33,7 +34,11 @@ import { requestDeviceAccess } from '@suite-native/device-mutex';
import { analytics, EventType } from '@suite-native/analytics';
import { FeatureFlag, selectIsFeatureFlagEnabled } from '@suite-native/feature-flags';

import { selectDiscoveryInfo, setDiscoveryInfo } from './discoveryConfigSlice';
import {
selectDiscoveryInfo,
selectEnabledDiscoveryNetworkSymbols,
setDiscoveryInfo,
} from './discoveryConfigSlice';
import {
selectCanRunDiscoveryForDevice,
selectDiscoveryAccountsAnalytics,
Expand Down Expand Up @@ -694,7 +699,28 @@ export const discoveryCheckThunk = createThunk(
// It removes accounts for disabled networks and checks whether to start discovery and start if needed
export const applyDiscoveryChangesThunk = createThunk(
`${DISCOVERY_MODULE_PREFIX}/applyDiscoveryChangesThunk`,
(_, { dispatch }) => {
(_, { dispatch, getState }) => {
const isCoinEnablingActive = selectIsFeatureFlagEnabled(
getState(),
FeatureFlag.IsCoinEnablingActive,
);

// Make sure that first normal account is visible for enabled networks when coin enabling is active
// This might be needed in case user has View only device from before coin enabling was active
// in such case the first normal account can be invisible. We need to make it visible.
if (isCoinEnablingActive) {
const enabledDiscoveryNetworkSymbols = selectEnabledDiscoveryNetworkSymbols(getState());
enabledDiscoveryNetworkSymbols.forEach(networkSymbol => {
const firstNormalAccount = selectFirstNormalAccountForNetworkSymbol(
getState(),
networkSymbol,
);

if (firstNormalAccount && !firstNormalAccount.visible) {
dispatch(accountsActions.changeAccountVisibility(firstNormalAccount, true));
}
});
}
dispatch(disableAccountsThunk());
dispatch(discoveryCheckThunk());
},
Expand Down
Loading