Skip to content

Commit 1ae031f

Browse files
committed
fix(suite): handle missing transaction in TxDetailModal
1 parent 5248994 commit 1ae031f

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/TxDetailModal/TxDetailModal.tsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
} from '@suite-common/wallet-core';
99
import { WalletAccountTransactionWithRequiredRbfParams } from '@suite-common/wallet-types';
1010
import { findChainedTransactions, getAccountKey, isPending } from '@suite-common/wallet-utils';
11+
import { Modal } from '@trezor/components';
1112

13+
import { Translation } from 'src/components/suite';
1214
import { useSelector } from 'src/hooks/suite';
1315
import { Account, WalletAccountTransaction } from 'src/types/wallet';
1416
import { getInstantStakeType } from 'src/utils/suite/ethereumStaking';
@@ -45,26 +47,27 @@ export const TxDetailModal = ({
4547
const accountKey = getAccountKey(descriptor, symbol, deviceState);
4648
const originalTx = useSelector(state =>
4749
selectTransactionByAccountKeyAndTxid(state, accountKey, txid),
48-
) as WalletAccountTransaction;
50+
);
4951

5052
// Filter out internal transfers that are instant staking transactions
51-
const filteredInternalTransfers = useMemo(
52-
() =>
53-
originalTx.internalTransfers.filter(t => {
54-
const stakeType = getInstantStakeType(t, descriptor, symbol);
55-
56-
return stakeType !== 'stake';
57-
}),
58-
[originalTx.internalTransfers, descriptor, symbol],
59-
);
53+
const filteredInternalTransfers = useMemo(() => {
54+
if (!originalTx) return [];
55+
56+
return originalTx.internalTransfers.filter(t => {
57+
const stakeType = getInstantStakeType(t, descriptor, symbol);
58+
59+
return stakeType !== 'stake';
60+
});
61+
}, [originalTx, descriptor, symbol]);
62+
63+
const tx = useMemo(() => {
64+
if (!originalTx) return null;
6065

61-
const tx = useMemo(
62-
() => ({
66+
return {
6367
...originalTx,
6468
internalTransfers: filteredInternalTransfers,
65-
}),
66-
[originalTx, filteredInternalTransfers],
67-
);
69+
};
70+
}, [originalTx, filteredInternalTransfers]);
6871

6972
const account = useSelector(state => selectAccountByKey(state, accountKey)) as Account;
7073
const network = getNetwork(account.symbol);
@@ -76,6 +79,7 @@ export const TxDetailModal = ({
7679
// TODO: replace this part will be refactored after blockbook implementation:
7780
// https://github.com/trezor/blockbook/issues/555
7881
const chainedTxs = useMemo(() => {
82+
if (!tx) return;
7983
if (!isPending(tx)) return;
8084

8185
return findChainedTransactions(tx.descriptor, tx.txid, transactions);
@@ -101,6 +105,14 @@ export const TxDetailModal = ({
101105
setTab(undefined);
102106
};
103107

108+
if (tx === null) {
109+
return (
110+
<Modal onCancel={onCancel} heading={<Translation id="TR_TRANSACTION_DETAILS" />}>
111+
<Translation id="TR_TRANSACTION_NOT_FOUND" />
112+
</Modal>
113+
);
114+
}
115+
104116
const canReplaceTransaction =
105117
hasRbfParams(tx) &&
106118
networkFeatures?.includes('rbf') &&

packages/suite/src/support/messages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,10 @@ export default defineMessages({
33513351
defaultMessage: 'Details',
33523352
id: 'TR_TRANSACTION_DETAILS',
33533353
},
3354+
TR_TRANSACTION_NOT_FOUND: {
3355+
defaultMessage: 'Transaction not found. Please try again later.',
3356+
id: 'TR_TRANSACTION_NOT_FOUND',
3357+
},
33543358
TR_TOKEN_ID_COLON: {
33553359
defaultMessage: 'Token ID:',
33563360
id: 'TR_TOKEN_ID_COLON',

0 commit comments

Comments
 (0)