Skip to content

Commit

Permalink
Improvements to transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdenio committed Feb 9, 2024
1 parent e76f49a commit 7695522
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
20 changes: 14 additions & 6 deletions src/components/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import { renderMoney } from "../util";

import UserAvatar from "./UserAvatar";

function transactionIcon(
code: TransactionType,
): React.ComponentProps<typeof Ionicons>["name"] {
function transactionIcon({
code,
...transaction
}: TransactionWithoutId): React.ComponentProps<typeof Ionicons>["name"] {
switch (code) {
case TransactionType.Donation:
case TransactionType.PartnerDonation:
Expand All @@ -26,7 +27,11 @@ function transactionIcon(
case TransactionType.CheckDeposit:
return "receipt-outline";
case TransactionType.Disbursement:
return "arrow-redo-outline";
if (transaction.amount_cents > 0) {
return "add-circle-outline";
} else {
return "remove-circle-outline";
}
case TransactionType.StripeCard:
case TransactionType.StripeForceCapture:
return "card-outline";
Expand Down Expand Up @@ -62,7 +67,7 @@ function TransactionIcon({
} else {
return (
<Ionicons
name={transactionIcon(transaction.code)}
name={transactionIcon(transaction)}
color={palette.muted}
size={20}
/>
Expand Down Expand Up @@ -114,7 +119,10 @@ function Transaction({
numberOfLines={1}
style={{
fontSize: 14,
color: transaction.pending ? palette.muted : themeColors.text,
color:
transaction.pending || transaction.declined
? palette.muted
: themeColors.text,
overflow: "hidden",
flex: 1,
}}
Expand Down
32 changes: 22 additions & 10 deletions src/components/transaction/types/TransferTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useNavigation } from "@react-navigation/native";
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import humanizeString from "humanize-string";
import { View } from "react-native";
import useSWR from "swr";

import { StackParamList } from "../../../lib/NavigatorParamList";
import Organization from "../../../lib/types/Organization";
import { TransactionTransfer } from "../../../lib/types/Transaction";
import { renderMoney } from "../../../util";
import { renderMoney, statusColor } from "../../../util";
import Badge from "../../Badge";
import UserMention from "../../UserMention";
import TransactionDetails, { descriptionDetail } from "../TransactionDetails";
import TransactionTitle, { Muted } from "../TransactionTitle";
Expand All @@ -27,7 +29,13 @@ export default function TransferTransaction({

return (
<View>
<TransactionTitle>
<TransactionTitle
badge={
<Badge color={statusColor(transfer.status)}>
{humanizeString(transfer.status)}
</Badge>
}
>
{renderMoney(Math.abs(transaction.amount_cents))}{" "}
{props.orgId == transfer.from.id ? (
<>
Expand Down Expand Up @@ -58,18 +66,22 @@ export default function TransferTransaction({
{
label: "From",
value: transfer.from.name,
onPress: userInFromOrg
? () =>
navigation.navigate("Event", { organization: transfer.from })
: undefined,
onPress:
userInFromOrg && transfer.from.id != props.orgId
? () =>
navigation.navigate("Event", {
organization: transfer.from,
})
: undefined,
},
{
label: "To",
value: transfer.to.name,
onPress: userInToOrg
? () =>
navigation.navigate("Event", { organization: transfer.to })
: undefined,
onPress:
userInToOrg && transfer.to.id != props.orgId
? () =>
navigation.navigate("Event", { organization: transfer.to })
: undefined,
},
]}
/>
Expand Down
5 changes: 4 additions & 1 deletion src/lib/types/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ export interface TransactionCheck extends TransactionBase {
check: Check;
}

export interface Transfer {
export interface Transfer extends HcbApiObject<"xfr"> {
from: Organization;
to: Organization;
sender?: User;
memo: string;
status: "pending" | "completed" | "rejected";
amount_cents: number;
transaction_id: TransactionBase["id"];
}

export interface TransactionTransfer extends TransactionBase {
Expand Down
7 changes: 4 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export function renderDate(date: string) {
}

export function statusColor(status: string) {
if (status == "deposited") {
if (status == "deposited" || status == "completed") {
return palette.success;
}
if (status == "in_transit" || status == "issued") {
} else if (status == "in_transit" || status == "issued") {
return palette.info;
} else if (status == "rejected") {
return palette.primary;
} else {
return palette.muted;
}
Expand Down

0 comments on commit 7695522

Please sign in to comment.