diff --git a/packages/suite/src/components/wallet/WalletLayout/AccountsMenu/AccountSection.tsx b/packages/suite/src/components/wallet/WalletLayout/AccountsMenu/AccountSection.tsx index 6c97617b7e4..fdf79dcd751 100644 --- a/packages/suite/src/components/wallet/WalletLayout/AccountsMenu/AccountSection.tsx +++ b/packages/suite/src/components/wallet/WalletLayout/AccountsMenu/AccountSection.tsx @@ -1,6 +1,6 @@ import { Account } from '@suite-common/wallet-types'; import { selectCoinDefinitions } from '@suite-common/token-definitions'; -import { selectEthAccountHasStaked, selectSolStakingAccounts } from '@suite-common/wallet-core'; +import { selectEthAccountHasStaked, selectSolAccountHasStaked } from '@suite-common/wallet-core'; import { isSupportedStakingNetworkSymbol } from '@suite-common/wallet-utils'; import { useSelector } from 'src/hooks/suite'; @@ -37,12 +37,13 @@ export const AccountSection = ({ const coinDefinitions = useSelector(state => selectCoinDefinitions(state, symbol)); const hasEthStaked = useSelector(state => selectEthAccountHasStaked(state, account.key)); - const solStakingAccounts = useSelector(state => selectSolStakingAccounts(state, account.key)); + const hasSolStaked = useSelector(state => selectSolAccountHasStaked(state, account.key)); + // TODO: remove isDebugModeActive when staking will be ready for launch - const hasSolStakingAccount = !!solStakingAccounts?.length && isDebugModeActive; // for solana + const isSolStakingEnabled = hasSolStaked && isDebugModeActive; const isStakeShown = - isSupportedStakingNetworkSymbol(symbol) && (hasEthStaked || hasSolStakingAccount); + isSupportedStakingNetworkSymbol(symbol) && (hasEthStaked || isSolStakingEnabled); const showGroup = ['ethereum', 'solana', 'cardano'].includes(networkType); diff --git a/packages/suite/src/views/dashboard/AssetsView/AssetCard/AssetCard.tsx b/packages/suite/src/views/dashboard/AssetsView/AssetCard/AssetCard.tsx index 02450123243..4490fc1cdaa 100644 --- a/packages/suite/src/views/dashboard/AssetsView/AssetCard/AssetCard.tsx +++ b/packages/suite/src/views/dashboard/AssetsView/AssetCard/AssetCard.tsx @@ -19,7 +19,7 @@ import { AssetFiatBalance } from '@suite-common/assets'; import { TokenInfo } from '@trezor/connect'; import { Account, RatesByKey } from '@suite-common/wallet-types'; import { isTestnet } from '@suite-common/wallet-utils'; -import { selectAssetAccountsThatStaked } from '@suite-common/wallet-core'; +import { selectDebugFilteredAssetAccountsThatStaked } from '@suite-common/wallet-core'; import { selectCoinDefinitions } from '@suite-common/token-definitions'; import { FiatCurrencyCode } from '@suite-common/suite-config'; @@ -33,6 +33,7 @@ import { import { useAccountSearch, useLoadingSkeleton, useSelector } from 'src/hooks/suite'; import { goto } from 'src/actions/suite/routerActions'; import { FiatHeader } from 'src/components/wallet/FiatHeader'; +import { selectIsDebugModeActive } from 'src/reducers/suite/suiteReducer'; import { CoinmarketBuyButton } from '../CoinmarketBuyButton'; import { AssetCardInfo, AssetCardInfoSkeleton } from './AssetCardInfo'; @@ -123,14 +124,21 @@ export const AssetCard = ({ const stakingAccountsForAsset = stakingAccounts.filter(account => account.symbol === symbol); const coinDefinitions = useSelector(state => selectCoinDefinitions(state, symbol)); - const accountsThatStaked = useSelector(state => - selectAssetAccountsThatStaked(state, stakingAccountsForAsset), + + // TODO: remove this logic when Solana staking is available + const isDebugModeActive = useSelector(selectIsDebugModeActive); + const debugFilteredStakedAccounts = useSelector(state => + selectDebugFilteredAssetAccountsThatStaked( + state, + stakingAccountsForAsset, + isDebugModeActive, + ), ); const { tokensFiatBalance, assetStakingBalance, shouldRenderStakingRow, shouldRenderTokenRow } = handleTokensAndStakingData( assetTokens, - accountsThatStaked, + debugFilteredStakedAccounts, symbol, localCurrency, coinDefinitions, diff --git a/packages/suite/src/views/dashboard/AssetsView/AssetTable/AssetRow.tsx b/packages/suite/src/views/dashboard/AssetsView/AssetTable/AssetRow.tsx index ef90a0696e0..862da2bb791 100644 --- a/packages/suite/src/views/dashboard/AssetsView/AssetTable/AssetRow.tsx +++ b/packages/suite/src/views/dashboard/AssetsView/AssetTable/AssetRow.tsx @@ -8,7 +8,7 @@ import { isTestnet } from '@suite-common/wallet-utils'; import { spacings } from '@trezor/theme'; import { TokenInfo } from '@trezor/blockchain-link-types'; import { selectCoinDefinitions } from '@suite-common/token-definitions'; -import { selectAssetAccountsThatStaked } from '@suite-common/wallet-core'; +import { selectDebugFilteredAssetAccountsThatStaked } from '@suite-common/wallet-core'; import { Account, RatesByKey } from '@suite-common/wallet-types'; import { AssetFiatBalance } from '@suite-common/assets'; import { FiatCurrencyCode } from '@suite-common/suite-config'; @@ -24,6 +24,7 @@ import { import { goto } from 'src/actions/suite/routerActions'; import { useAccountSearch, useDispatch, useSelector } from 'src/hooks/suite'; import { TokenIconSetWrapper } from 'src/components/wallet/TokenIconSetWrapper'; +import { selectIsDebugModeActive } from 'src/reducers/suite/suiteReducer'; import { AssetCoinLogo } from '../AssetCoinLogo'; import { AssetCoinName } from '../AssetCoinName'; @@ -81,8 +82,15 @@ export const AssetRow = memo( const stakingAccountsForAsset = stakingAccounts.filter( account => account.symbol === network.symbol, ); - const accountsThatStaked = useSelector(state => - selectAssetAccountsThatStaked(state, stakingAccountsForAsset), + + // TODO: remove this logic when Solana staking is available + const isDebugModeActive = useSelector(selectIsDebugModeActive); + const debugFilteredStakedAccounts = useSelector(state => + selectDebugFilteredAssetAccountsThatStaked( + state, + stakingAccountsForAsset, + isDebugModeActive, + ), ); const { @@ -92,7 +100,7 @@ export const AssetRow = memo( shouldRenderTokenRow, } = handleTokensAndStakingData( assetTokens, - accountsThatStaked, + debugFilteredStakedAccounts, symbol, localCurrency, coinDefinitions, diff --git a/packages/suite/src/views/dashboard/AssetsView/AssetsView.tsx b/packages/suite/src/views/dashboard/AssetsView/AssetsView.tsx index f5133732a32..80193c305ed 100644 --- a/packages/suite/src/views/dashboard/AssetsView/AssetsView.tsx +++ b/packages/suite/src/views/dashboard/AssetsView/AssetsView.tsx @@ -10,6 +10,7 @@ import { getFiatRateKey, toFiatCurrency, isSupportedEthStakingNetworkSymbol, + isSupportedSolStakingNetworkSymbol, } from '@suite-common/wallet-utils'; import { type NetworkSymbol, @@ -139,8 +140,10 @@ export const AssetsView = () => { ? assetNativeCryptoBalance.toNumber() : '0', assetTokens: assetTokens?.length ? assetTokens : undefined, - stakingAccounts: accounts.filter(account => - isSupportedEthStakingNetworkSymbol(account.symbol), + stakingAccounts: accounts.filter( + account => + isSupportedEthStakingNetworkSymbol(account.symbol) || + isSupportedSolStakingNetworkSymbol(account.symbol), ), accounts, }; diff --git a/packages/suite/src/views/wallet/staking/components/StakingDashboard/StakingDashboard.tsx b/packages/suite/src/views/wallet/staking/components/StakingDashboard/StakingDashboard.tsx index 6d71c3634d1..253196940a2 100644 --- a/packages/suite/src/views/wallet/staking/components/StakingDashboard/StakingDashboard.tsx +++ b/packages/suite/src/views/wallet/staking/components/StakingDashboard/StakingDashboard.tsx @@ -1,4 +1,4 @@ -import { selectEthAccountHasStaked, selectSolStakingAccounts } from '@suite-common/wallet-core'; +import { selectEthAccountHasStaked, selectSolAccountHasStaked } from '@suite-common/wallet-core'; import { SelectedAccountStatus } from '@suite-common/wallet-types'; import { getNetworkDisplaySymbol } from '@suite-common/wallet-config'; @@ -17,14 +17,13 @@ export const StakingDashboard = ({ selectedAccount, dashboard }: StakingDashboar const hasEthStaked = useSelector(state => selectEthAccountHasStaked(state, selectedAccount.account?.key ?? ''), ); - const solStakingAccounts = useSelector(state => - selectSolStakingAccounts(state, selectedAccount.account?.key), + const hasSolStaked = useSelector(state => + selectSolAccountHasStaked(state, selectedAccount.account?.key), ); if (selectedAccount.status !== 'loaded') return null; - const hasSolStakingAccount = !!solStakingAccounts?.length; - const shouldShowDashboard = hasEthStaked || hasSolStakingAccount; + const shouldShowDashboard = hasEthStaked || hasSolStaked; return ( { + if (!account || account.networkType !== 'solana') return false; + + return !!account.misc.solStakingAccounts?.length; +}); diff --git a/suite-common/wallet-core/src/transactions/transactionsReducer.ts b/suite-common/wallet-core/src/transactions/transactionsReducer.ts index e706ba0c737..110d55a2ac0 100644 --- a/suite-common/wallet-core/src/transactions/transactionsReducer.ts +++ b/suite-common/wallet-core/src/transactions/transactionsReducer.ts @@ -32,7 +32,11 @@ import { fetchTransactionsPageThunk, fetchAllTransactionsForAccountThunk, } from './transactionsThunks'; -import { AccountsRootState, selectAccountByKey } from '../accounts/accountsReducer'; +import { + AccountsRootState, + selectAccountByKey, + selectSolAccountHasStaked, +} from '../accounts/accountsReducer'; export type AccountTransactionsFetchStatusDetail = | { @@ -386,7 +390,24 @@ export const selectEthAccountHasStaked = createMemoizedSelector( export const selectAssetAccountsThatStaked = ( state: TransactionsRootState & AccountsRootState, accounts: Account[], -) => accounts.filter(account => selectEthAccountHasStaked(state, account.key)); +) => + accounts.filter( + account => + selectEthAccountHasStaked(state, account.key) || + selectSolAccountHasStaked(state, account.key), + ); + +export const selectDebugFilteredAssetAccountsThatStaked = ( + state: TransactionsRootState & AccountsRootState, + accounts: Account[], + isDebugModeActive: boolean, +) => { + const accountsThatStaked = selectAssetAccountsThatStaked(state, accounts); + + return !isDebugModeActive + ? accountsThatStaked.filter(account => account.networkType !== 'solana') + : accountsThatStaked; +}; export const selectAccountTransactionsFetchStatus = ( state: TransactionsRootState,