From e9af120c7b00e29b6930d9b17e22e2b4949f85be Mon Sep 17 00:00:00 2001 From: i701 Date: Sat, 26 Jul 2025 00:17:22 +0500 Subject: [PATCH] =?UTF-8?q?feat(wallet):=20update=20transaction=20type=20f?= =?UTF-8?q?rom=20CREDIT=20to=20TOPUP=20and=20display=20total=20debit/credi?= =?UTF-8?q?t=20amounts=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/wallet-transactions-table.tsx | 52 ++++++++++++++++++------ lib/backend-types.ts | 2 +- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/components/wallet-transactions-table.tsx b/components/wallet-transactions-table.tsx index 4cf6314..d419fb9 100644 --- a/components/wallet-transactions-table.tsx +++ b/components/wallet-transactions-table.tsx @@ -11,7 +11,7 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import { WalletTransaction } from "@/lib/backend-types"; +import type { WalletTransaction } from "@/lib/backend-types"; import { cn } from "@/lib/utils"; import { getWaleltTransactions } from "@/queries/wallet"; import { tryCatch } from "@/utils/tryCatch"; @@ -51,6 +51,16 @@ export async function WalletTransactionsTable({ } } const { data, meta } = transactions; + const totalDebit = data.reduce( + (acc, trx) => + acc + (trx.transaction_type === "DEBIT" ? trx.amount : 0), + 0, + ); + const totalCredit = data.reduce( + (acc, trx) => + acc + (trx.transaction_type === "TOPUP" ? trx.amount : 0), + 0, + ); return (
{data?.length === 0 ? ( @@ -58,8 +68,23 @@ export async function WalletTransactionsTable({

No transactions yet.

) : ( - <> +
+
+
+
+ Total Debit +
+

{totalDebit.toFixed(2)} MVR

+
+
+
+ Total Credit +
+

{totalCredit.toFixed(2)} MVR

+
+
+ Table of all transactions. @@ -76,7 +101,7 @@ export async function WalletTransactionsTable({ - {trx.transaction_type === "CREDIT" ? ( + {trx.transaction_type === "TOPUP" ? ( {trx.transaction_type} @@ -119,8 +144,8 @@ export async function WalletTransactionsTable({ @@ -157,9 +182,10 @@ export async function WalletTransactionsTable({ totalPages={meta?.last_page} currentPage={meta?.current_page} /> - - )} - + + ) + } + ); } @@ -168,7 +194,7 @@ function MobileTransactionDetails({ trx }: { trx: WalletTransaction }) {
@@ -195,7 +221,7 @@ function MobileTransactionDetails({ trx }: { trx: WalletTransaction }) {
- {trx.transaction_type === "CREDIT" ? ( + {trx.transaction_type === "TOPUP" ? ( {trx.transaction_type} @@ -210,8 +236,8 @@ function MobileTransactionDetails({ trx }: { trx: WalletTransaction }) { diff --git a/lib/backend-types.ts b/lib/backend-types.ts index 3f74075..943ddf3 100644 --- a/lib/backend-types.ts +++ b/lib/backend-types.ts @@ -105,7 +105,7 @@ export interface WalletTransaction { name: string; }; amount: number; - transaction_type: "DEBIT" | "CREDIT"; + transaction_type: "DEBIT" | "TOPUP"; description: string; reference_id: string; created_at: string;