Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | 7x 7x 262x 262x 262x 262x 262x 262x 262x 262x 262x 262x 262x 262x 262x 262x 262x 2096x 262x 262x 262x 262x 262x 262x 262x 262x 262x 524x 2882x | import { MANAGE_MONEY_TABLE_TYPES } from "@constants/constants";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import { useGetStats } from "@services/api/products/transactions";
import { checkPortals } from "@utils/routing";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { Stat } from "@features/Products/data.types";
import {
MANAGE_MONEY_BANNER_TITLE,
TRANSACTION_BANNER_TITTLE,
} from "@pages/ManageMoney/constants";
import { useTranslation } from "react-i18next";
import { namespaces } from "localization/resources/i18n.constants";
import { TEmptyStateWrapperSection } from "@shared/EmptyState/types";
// volumes and their fees
const grossVolumeFees = [
"settledPurchasesVolume",
"settledChargebacksVolume",
"settledPreChargebackRefundsVolume",
"settledRefundsVolume",
"preChargebackRefundsFeesVolume",
"refundsFeesVolume",
"settledPurchasesFeesVolume",
"chargebacksFeesVolume",
];
type Params = {
isProcessing?: boolean;
type?: TEmptyStateWrapperSection;
selectedTabFilter?: string | number;
};
/**
* Derives the banner stats (title + main/parse stats) shared between the full
* `ManageMoneyBanner` and the compact-on-scroll banner. Keeping this in one
* place guarantees the compact banner shows the exact same values as the
* default banner (AC004). `useGetStats`/`useGetMerchantById` are react-query
* cached, so consuming this hook in more than one place issues no extra fetch.
*/
export const useManageMoneyBannerStats = ({
isProcessing,
type,
selectedTabFilter,
}: Params) => {
const { data } = useGetStats();
const { t } = useTranslation(namespaces.pages.manageMoney);
const { isWideView, isLargeView } = useCustomThemeV2();
const {
isMerchantPortal,
isManageMoney,
isProcessing: isProcessingPage,
isTransactions,
} = checkPortals();
const isManageMoneyUI = isManageMoney || isTransactions;
const { data: merchantData, isLoading } = useGetMerchantById();
const dataIsNotReady = data === undefined || isLoading;
const {
authorizedPurchasesCuttOffCount = 0,
capturedPurchasesCuttOffCount = 0,
} = data || {};
const dataForTotal = isMerchantPortal
? data?.sumApprovedPurchases
: data?.purchasesVolume;
const isAcquirerProviderManageMoney =
type === MANAGE_MONEY_TABLE_TYPES.ACQUIRER_PROVIDER;
const isNewStats = isMerchantPortal;
const reserveFundsStat = {
isAmount: true,
title: "Reserve Funds",
value: dataIsNotReady ? "-" : data?.reserveBalance / 100 || 0,
};
const isTransactionTable = !isMerchantPortal && isTransactions;
//to be used for Purchases counter in pending tab in transactions table
const calculatedPendingPurchasesCount =
authorizedPurchasesCuttOffCount + capturedPurchasesCuttOffCount;
const grossVolume = grossVolumeFees.reduce(
(sum, key) => sum + (data?.[key] ?? 0),
0,
);
const isTransactionTablePendingTab =
isTransactionTable && selectedTabFilter === "-pending";
const isTransactionTableAllTab =
isTransactionTable && ["-all", 0].includes(selectedTabFilter ?? "");
const transactionTableMainStat = {
title: isTransactionTablePendingTab
? "Pending Gross Sales"
: `Gross Volume`,
value: dataIsNotReady
? "-"
: ((isTransactionTablePendingTab
? data?.pendingPurchasesVolume
: grossVolume) ?? 0) / 100,
};
const breakpointStatsMain = isManageMoneyUI ? isLargeView : isWideView;
const mainStats = [
{
isAmount: true,
title: isTransactionTable
? transactionTableMainStat.title
: t("AvailableBalance"),
value: dataIsNotReady
? "-"
: isTransactionTable
? transactionTableMainStat.value
: data?.availableBalance / 100 || 0,
},
{
...reserveFundsStat,
hidden: !(isNewStats && breakpointStatsMain),
},
] as Stat[];
const usedRatio = isTransactionTablePendingTab
? data?.pendingPurchasesRatio
: data?.successfulPurchasesRatio;
const stats = [
{
isAmount: true,
title: "Gross Sales",
value: dataIsNotReady ? "-" : data?.purchasesVolume / 100 || 0,
hidden: !isTransactionTableAllTab,
},
{
...reserveFundsStat,
hidden: !isNewStats || breakpointStatsMain,
},
{
isAmount: true,
title: isProcessing
? "Total Processing Volume"
: isNewStats
? "Volume"
: "Lifetime",
value: dataIsNotReady
? "-"
: (dataForTotal ? dataForTotal / 100 : 0) || 0,
hidden: isNewStats || isAcquirerProviderManageMoney || isTransactionTable,
},
{
title: "Transactions",
value: dataIsNotReady ? "-" : data?.transactionsCount || 0,
hidden: isNewStats || isAcquirerProviderManageMoney || isTransactionTable,
},
{
title: "Refunds",
value: dataIsNotReady ? "-" : data?.refundsCount || 0,
hidden: isNewStats || isAcquirerProviderManageMoney || isTransactionTable,
},
{
title: "Chargebacks",
value: dataIsNotReady ? "-" : data?.chargebacksCount || 0,
hidden: isNewStats || isAcquirerProviderManageMoney || isTransactionTable,
},
{
title: "Pending Credits",
isAmount: true,
value: dataIsNotReady ? "-" : data?.pendingCredit / 100 || 0,
hidden: !isAcquirerProviderManageMoney || isTransactionTable,
},
{
title: "Pending Debits",
isAmount: true,
value: dataIsNotReady ? "-" : data?.pendingDebit / 100 || 0,
hidden: !isAcquirerProviderManageMoney || isTransactionTable,
},
{
title: `Approved`,
isAmount: false,
value: dataIsNotReady ? "-" : calculatedPendingPurchasesCount,
hidden: !isTransactionTablePendingTab,
},
{
title: "Declined",
isAmount: false,
value: dataIsNotReady ? "-" : data?.declinedPurchasesCount || 0,
hidden: !isTransactionTablePendingTab,
},
{
title: isTransactionTablePendingTab
? "Approval Ratio (%)"
: `Success Ratio (%)`,
isAmount: false,
value: dataIsNotReady ? "-" : usedRatio ?? 0,
hidden: !isTransactionTablePendingTab,
},
] as Stat[];
const title =
!isAcquirerProviderManageMoney && !isMerchantPortal
? TRANSACTION_BANNER_TITTLE
: MANAGE_MONEY_BANNER_TITLE;
return {
title,
isProcessingBanner: isProcessingPage || isAcquirerProviderManageMoney,
dataIsNotReady,
mainStats: mainStats.filter((stat) => !stat.hidden),
parseStats: stats.filter((stat) => !stat.hidden),
};
};
|