Skip to content

Commit

Permalink
feat(suite): add empty state for cases when there are no "visible" tr…
Browse files Browse the repository at this point in the history
…ansactions
  • Loading branch information
vojtatranta committed Feb 11, 2025
1 parent f20a46b commit 1a1a06d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/suite/src/support/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export default defineMessages({
defaultMessage: 'No transactions',
id: 'TR_ACCOUNT_IS_EMPTY_TITLE',
},
TR_NO_VISIBLE_TRANSACTIONS: {
defaultMessage:
"No transactions to show. If you're looking for a specific transaction, check the <tabLink>Hidden tokens tab</tabLink>—but be cautious, as hidden tokens may carry risks.",
id: 'TR_NO_VISIBLE_TRANSACTIONS',
},
TR_ACCOUNT_PASSPHRASE_DISABLED: {
defaultMessage: 'Change passphrase settings to use this device',
id: 'TR_ACCOUNT_PASSPHRASE_DISABLED',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
import { useState } from 'react';
import { ReactNode, useState } from 'react';
import { useDispatch } from 'react-redux';

import styled from 'styled-components';

import { Card, Column, Link } from '@trezor/components';
import { typography } from '@trezor/theme';

import { goto } from 'src/actions/suite/routerActions';
import { Translation } from 'src/components/suite';
import { Account, WalletAccountTransaction } from 'src/types/wallet';

import { TransactionList } from './TransactionList';
import { useVisibleTransactions } from './useFetchTransactions';

const NoResults = styled.div`
text-align: center;
color: ${({ theme }) => theme.legacy.TYPE_DARK_GREY};
${typography.hint}
`;

export const NoVisibleTransactions = () => {
const dispatch = useDispatch();

return (
<Card>
<NoResults>
<Column alignItems="center">
<Translation
id="TR_NO_VISIBLE_TRANSACTIONS"
values={{
tabLink: (chunks: ReactNode[]) => (
<Link
onClick={event => {
event.preventDefault();
dispatch(
goto('wallet-tokens-hidden', { preserveParams: true }),
);
}}
>
{chunks}
</Link>
),
}}
/>
</Column>
</NoResults>
</Card>
);
};

interface TransactionListProps {
symbol: WalletAccountTransaction['symbol'];
account: Account;
Expand All @@ -25,6 +69,10 @@ export const WalletTransactionList = ({
numberOfPagesRequested: visiblePages,
});

if (!result.isLoading && result.visibleTransactions.length === 0) {
return <NoVisibleTransactions />;
}

return (
<TransactionList
customPageFetching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getIsPhishingTransaction,
selectNetworkTokenDefinitions,
} from '@suite-common/token-definitions';
import { DiscoveryStatus } from '@suite-common/wallet-constants';
import {
fetchAllTransactionsForAccountThunk,
fetchTransactionsPageThunk,
Expand All @@ -14,7 +15,7 @@ import {
} from '@suite-common/wallet-core';
import { getSynchronize } from '@trezor/utils';

import { useDispatch, useSelector } from 'src/hooks/suite';
import { useDiscovery, useDispatch, useSelector } from 'src/hooks/suite';
import { Account, WalletAccountTransaction } from 'src/types/wallet';

import { shouldAttemptToLoadNextPageForVisibleTransactions } from './transaction-fetch-utils';
Expand Down Expand Up @@ -154,6 +155,7 @@ export const useVisibleTransactions = ({
const allTransactions = useSelector(state =>
selectAccountTransactionsWithNulls(state, account.key),
);
const { discovery } = useDiscovery();

const {
fetchedAll,
Expand Down Expand Up @@ -215,5 +217,6 @@ export const useVisibleTransactions = ({
visibleTransactions,
visibleTotal: totalPossiblyVisible,
isFetching: isFetching || transactionsIsLoading,
isLoading: discovery && discovery?.status !== DiscoveryStatus.COMPLETED, // NOTE: loading indicates that the state of the data is unknown and we are "loading for the first time"
};
};

0 comments on commit 1a1a06d

Please sign in to comment.