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;