Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { List, ListItemProps } from "components/List";
import {
renderActionIcon,
renderIconComponent,
shouldShowMemo,
} from "components/screens/HistoryScreen/helpers";
import { CreateAccountTransactionDetailsContent } from "components/screens/HistoryScreen/mappers/createAccount";
import { PaymentTransactionDetailsContent } from "components/screens/HistoryScreen/mappers/payment";
Expand Down Expand Up @@ -164,8 +165,9 @@ export const TransactionDetailsBottomSheetCustomContent: React.FC<
</Text>
),
},
// Hide memo line for M addresses (memo is encoded in the address)
!isDestinationMuxed
// Show memo only for classic Send/Receive (Payment/CreateAccount) operations
// and hide for M addresses (memo is encoded in the address)
shouldShowMemo(transactionDetails.transactionType, isDestinationMuxed)
? {
icon: (
<Icon.File02 size={16} color={themeColors.foreground.primary} />
Expand Down
46 changes: 46 additions & 0 deletions src/components/screens/HistoryScreen/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { shouldShowMemo } from "components/screens/HistoryScreen/helpers";
import { TransactionType } from "components/screens/HistoryScreen/types";

describe("shouldShowMemo", () => {
describe("returns true (show memo)", () => {
it("shows memo for PAYMENT when destination is not muxed", () => {
expect(shouldShowMemo(TransactionType.PAYMENT, false)).toBe(true);
});

it("shows memo for CREATE_ACCOUNT when destination is not muxed", () => {
expect(shouldShowMemo(TransactionType.CREATE_ACCOUNT, false)).toBe(true);
});
});

describe("returns false (hide memo) for muxed destinations", () => {
it("hides memo for PAYMENT when destination is muxed", () => {
expect(shouldShowMemo(TransactionType.PAYMENT, true)).toBe(false);
});

it("hides memo for CREATE_ACCOUNT when destination is muxed", () => {
expect(shouldShowMemo(TransactionType.CREATE_ACCOUNT, true)).toBe(false);
});
});

describe("returns false (hide memo) for non-classic transaction types", () => {
const nonClassicTypes = [
TransactionType.SWAP,
TransactionType.CHANGE_TRUST,
TransactionType.CONTRACT,
TransactionType.CONTRACT_MINT,
TransactionType.CONTRACT_TRANSFER,
TransactionType.UNKNOWN,
];

it.each(nonClassicTypes)(
"hides memo for %s (not muxed)",
(transactionType) => {
expect(shouldShowMemo(transactionType, false)).toBe(false);
},
);

it.each(nonClassicTypes)("hides memo for %s (muxed)", (transactionType) => {
expect(shouldShowMemo(transactionType, true)).toBe(false);
});
});
});
25 changes: 25 additions & 0 deletions src/components/screens/HistoryScreen/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
import { Horizon } from "@stellar/stellar-sdk";
import { TransactionType } from "components/screens/HistoryScreen/types";
import Icon from "components/sds/Icon";
import { OPERATION_TYPES } from "config/constants";
import { SorobanTokenInterface } from "helpers/soroban";
Expand Down Expand Up @@ -93,3 +94,27 @@ export const isSorobanTokenMint = (fnName: string | undefined): boolean =>
*/
export const isSorobanTokenTransfer = (fnName: string | undefined): boolean =>
fnName === SorobanTokenInterface.transfer;

/**
* Determines if the memo field should be displayed for a transaction.
* Memo is only relevant for classic Send/Receive operations (Payment and
* CreateAccount). It is also hidden when the destination is a muxed address
* Determines if the memo field should be displayed in the History details UI
* for a given transaction.
*
* Although Stellar allows attaching a memo to any transaction, this screen
* currently only shows the memo for classic Send/Receive operations
* (Payment and CreateAccount). The memo is also hidden when the destination
* is a muxed address, since the destination address already encodes the
* memo-like data.
*/
export const shouldShowMemo = (
transactionType: TransactionType,
isDestinationMuxed: boolean,
): boolean => {
const isClassicSendReceive =
transactionType === TransactionType.PAYMENT ||
transactionType === TransactionType.CREATE_ACCOUNT;

return isClassicSendReceive && !isDestinationMuxed;
};
Loading