Skip to content

Commit

Permalink
fix(suite-native): has account transactions selector
Browse files Browse the repository at this point in the history
  • Loading branch information
PeKne committed Feb 11, 2025
1 parent 94c0a9c commit 246db18
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();

Expand Down
5 changes: 4 additions & 1 deletion suite-common/wallet-core/src/accounts/accountsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useNavigation } from '@react-navigation/native';

import {
AccountsRootState,
TransactionsRootState,
selectAccountByKey,
selectHasAccountTransactions,
selectIsPortfolioTrackerDevice,
selectIsTestnetAccount,
} from '@suite-common/wallet-core';
Expand All @@ -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';
Expand All @@ -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),
Expand All @@ -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 <AccountDetailGraph accountKey={accountKey} />;
Expand All @@ -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),
Expand Down Expand Up @@ -138,7 +140,7 @@ export const TransactionListHeader = memo(
accountKey={accountKey}
tokenContract={tokenContract}
/>
{accountHasTransactions && (
{hasAccountTransactions && (
<HStack paddingTop="sp8" paddingHorizontal="sp16" flex={1} spacing="sp12">
{isReceiveButtonDisplayed && (
<Box flex={1}>
Expand Down Expand Up @@ -166,7 +168,7 @@ export const TransactionListHeader = memo(
)}
{isPriceCardDisplayed && <CoinPriceCard accountKey={accountKey} />}
</VStack>
{accountHasTransactions && (
{hasAccountTransactions && (
<Box marginTop="sp52" marginHorizontal="sp32">
<Text variant="titleSmall">
<Translation id="transactions.title" />
Expand Down
5 changes: 5 additions & 0 deletions suite-native/tokens/src/tokensSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] => {
Expand Down

0 comments on commit 246db18

Please sign in to comment.