diff --git a/packages/suite/src/views/wallet/transactions/CoinjoinSummary/CoinjoinBalanceSection.tsx b/packages/suite/src/views/wallet/transactions/CoinjoinSummary/CoinjoinBalanceSection.tsx index 946ea84d8f8..fd7b52a8e35 100644 --- a/packages/suite/src/views/wallet/transactions/CoinjoinSummary/CoinjoinBalanceSection.tsx +++ b/packages/suite/src/views/wallet/transactions/CoinjoinSummary/CoinjoinBalanceSection.tsx @@ -2,7 +2,7 @@ import { useMemo } from 'react'; import styled, { useTheme } from 'styled-components'; -import { selectHasAccountTransactions } from '@suite-common/wallet-core'; +import { selectHasBitcoinAccountTransactions } from '@suite-common/wallet-core'; import { Card, Column } from '@trezor/components'; import { useSelector } from 'src/hooks/suite'; @@ -27,7 +27,9 @@ interface CoinjoinBalanceSectionProps { export const CoinjoinBalanceSection = ({ accountKey }: CoinjoinBalanceSectionProps) => { const hasAnonymitySetError = useSelector(selectHasAnonymitySetError); - const hasTransactions = useSelector(state => selectHasAccountTransactions(state, accountKey)); + const hasTransactions = useSelector(state => + selectHasBitcoinAccountTransactions(state, accountKey), + ); const theme = useTheme(); diff --git a/suite-common/wallet-core/src/accounts/accountsReducer.ts b/suite-common/wallet-core/src/accounts/accountsReducer.ts index 3592cc02443..9d87111e8ba 100644 --- a/suite-common/wallet-core/src/accounts/accountsReducer.ts +++ b/suite-common/wallet-core/src/accounts/accountsReducer.ts @@ -280,7 +280,10 @@ export const selectAccountByKey = createMemoizedSelector( }, ); -export const selectHasAccountTransactions = createMemoizedSelector( +// CAUTION!: This selector does not work for XRP accounts! It should be used only for Bitcoin-like accounts. +// Ripple backend does not provide the total transaction count info. +// The property`account.history.total` is always equal to -1 for XRP accounts. +export const selectHasBitcoinAccountTransactions = createMemoizedSelector( [selectAccountByKey], account => !!account?.history.total, ); diff --git a/suite-native/module-accounts-management/src/components/TransactionListHeader.tsx b/suite-native/module-accounts-management/src/components/TransactionListHeader.tsx index d9aa2a2f468..2fa56f162f1 100644 --- a/suite-native/module-accounts-management/src/components/TransactionListHeader.tsx +++ b/suite-native/module-accounts-management/src/components/TransactionListHeader.tsx @@ -5,8 +5,8 @@ import { useNavigation } from '@react-navigation/native'; import { AccountsRootState, + TransactionsRootState, selectAccountByKey, - selectHasAccountTransactions, selectIsPortfolioTrackerDevice, selectIsTestnetAccount, } from '@suite-common/wallet-core'; @@ -22,6 +22,7 @@ import { SendStackRoutes, StackNavigationProps, } from '@suite-native/navigation'; +import { TokensRootState, selectHasAccountAnyTransactions } from '@suite-native/tokens'; import { AccountDetailCryptoValue } from './AccountDetailCryptoValue'; import { AccountDetailGraph } from './AccountDetailGraph'; @@ -47,8 +48,8 @@ const TransactionListHeaderContent = ({ const account = useSelector((state: AccountsRootState) => selectAccountByKey(state, accountKey), ); - const accountHasTransactions = useSelector((state: AccountsRootState) => - selectHasAccountTransactions(state, accountKey), + const hasAccountTransactions = useSelector((state: TransactionsRootState & TokensRootState) => + selectHasAccountAnyTransactions(state, accountKey), ); const isTestnetAccount = useSelector((state: AccountsRootState) => selectIsTestnetAccount(state, accountKey), @@ -60,7 +61,7 @@ const TransactionListHeaderContent = ({ // Graph is temporarily hidden also for ERC20 tokens. // Will be solved in issue: https://github.com/trezor/trezor-suite/issues/7839 - const isGraphDisplayed = accountHasTransactions && !isTestnetAccount && !isTokenAccount; + const isGraphDisplayed = hasAccountTransactions && !isTestnetAccount && !isTokenAccount; if (isGraphDisplayed) { return ; @@ -87,8 +88,9 @@ export const TransactionListHeader = memo( selectAccountByKey(state, accountKey), ); - const accountHasTransactions = useSelector((state: AccountsRootState) => - selectHasAccountTransactions(state, accountKey), + const hasAccountTransactions = useSelector( + (state: TransactionsRootState & TokensRootState) => + selectHasAccountAnyTransactions(state, accountKey), ); const isTestnetAccount = useSelector((state: AccountsRootState) => selectIsTestnetAccount(state, accountKey), @@ -138,7 +140,7 @@ export const TransactionListHeader = memo( accountKey={accountKey} tokenContract={tokenContract} /> - {accountHasTransactions && ( + {hasAccountTransactions && ( {isReceiveButtonDisplayed && ( @@ -166,7 +168,7 @@ export const TransactionListHeader = memo( )} {isPriceCardDisplayed && } - {accountHasTransactions && ( + {hasAccountTransactions && ( diff --git a/suite-native/tokens/src/tokensSelectors.ts b/suite-native/tokens/src/tokensSelectors.ts index ced2d59bd2a..7f7696bf2b6 100644 --- a/suite-native/tokens/src/tokensSelectors.ts +++ b/suite-native/tokens/src/tokensSelectors.ts @@ -163,6 +163,11 @@ export const selectAccountTransactionsWithTokenTransfers = createMemoizedSelecto ) as WalletAccountTransaction[], ); +export const selectHasAccountAnyTransactions = createMemoizedSelector( + [selectAccountTransactionsWithTokenTransfers], + (transactions): boolean => transactions.length > 0, +); + export const selectAccountsKnownTokens = createMemoizedSelector( [selectAccountByKey, selectTokenDefinitions], (account, tokenDefinitions): TokenInfoBranded[] => {