Skip to content

Commit

Permalink
Show "smart" merchant names
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdenio committed Mar 21, 2024
1 parent 1af8c28 commit 7db63d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/components/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTheme } from "@react-navigation/native";
import { LinearGradient } from "expo-linear-gradient";
import { memo } from "react";
import { View, Text, ViewProps, StyleSheet } from "react-native";
import { match } from "ts-pattern";

import {
TransactionCardCharge,
Expand Down Expand Up @@ -155,9 +156,20 @@ function Transaction({
: transaction.pending
? "Pending: "
: "")}
{transaction.appearance == "hackathon_grant"
? "💰 Hackathon grant"
: transaction.memo.replaceAll(/\s{2,}/g, " ")}
{match(transaction)
.with(
{ appearance: "hackathon_grant", has_custom_memo: false },
() => "💰 Hackathon grant",
)
// .with(
// {
// card_charge: { merchant: { smart_name: P.string } },
// has_custom_memo: false,
// },
// (tx) => tx.card_charge.merchant.smart_name,
// )
.otherwise((tx) => tx.memo)
.replaceAll(/\s{2,}/g, " ")}
</Text>
{transaction.missing_receipt && !hideMissingReceipt && (
<View>
Expand Down
13 changes: 10 additions & 3 deletions src/components/transaction/types/CardChargeTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import TransactionTitle, { Muted } from "../TransactionTitle";
import { TransactionViewProps } from "./TransactionViewProps";

export default function CardChargeTransaction({
transaction,
transaction: {
card_charge: { merchant, ...card_charge },
...transaction
},
orgId,
}: TransactionViewProps<TransactionCardCharge>) {
const navigation =
Expand All @@ -36,16 +39,20 @@ export default function CardChargeTransaction({
<View style={{ flexDirection: "column", alignItems: "center" }}>
<TransactionTitle badge={badge}>
{renderMoney(Math.abs(transaction.amount_cents))}{" "}
<Muted>charge at</Muted> {transaction.card_charge.merchant.name}
<Muted>charge at</Muted>{"\n"}{merchant.smart_name}
</TransactionTitle>
</View>
<TransactionDetails
details={[
{
label: "Memo",
value: merchant.name,
},
descriptionDetail(orgId, transaction, navigation),
{ label: "Spent on", value: renderDate(transaction.date) },
{
label: "Spent by",
value: <UserMention user={transaction.card_charge.card.user} />,
value: <UserMention user={card_charge.card.user} />,
},
]}
/>
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface TransactionBase
export interface CardCharge {
merchant: {
name: string;
smart_name?: string;
country: string;
};
charge_method?: "keyed_in" | "swipe" | "chip" | "contactless" | "online";
Expand Down

0 comments on commit 7db63d1

Please sign in to comment.