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 217 | 4x 4x 4x 4x 4x 4x 3x 1x 4x 54x | import { CURRENCY } from "@constants/constants";
import { parseAmount } from "@utils/index";
import { DetailsSectionItem } from "../types";
import { cardIconsMap } from "@features/MerchantPortal/ManageMoney/ManageMoneyTable.atoms";
import GiveAvatar from "@shared/Avatar/GiveAvatar";
import { addSizeToImage } from "@utils/image.helpers";
import BoolIcon from "../Details/BoolIcon";
export default function useGenerateDetailsSections({ data }: { data: any }) {
const { stats, ipInfo } = data || {};
const { customers, cards } = stats || {};
const isHosting = ipInfo?.security?.hosting;
const isIsp = ipInfo?.connection?.isp;
const isVPN =
ipInfo?.security?.anonymous ||
ipInfo?.security?.hosting ||
ipInfo?.security?.vpn;
const sections: DetailsSectionItem[] = [
{
type: "detail",
title: "Transaction Statistics",
listData: [
{
label: "Transactions",
value: stats?.numTransactions || 0,
disableParseAmount: true,
},
{
label: "Declined",
value: stats?.numTransactionsDeclined || 0,
disableParseAmount: true,
},
{
label: "Errors",
value: stats?.numTransactionsFailed || 0,
disableParseAmount: true,
},
{
label: "Unique Pay Method",
value: stats?.numPaymethods || 0,
disableParseAmount: true,
},
{ label: "Currency", value: CURRENCY },
{
label: "Min Amount",
value: parseAmount(
stats?.minTransactionCost ? stats.minTransactionCost / 100 : 0,
),
},
{
label: "Max Amount",
value: parseAmount(
stats?.maxTransactionCost ? stats.maxTransactionCost / 100 : 0,
),
},
{
label: "Average",
value: parseAmount(
stats?.avgTransactionCost ? stats?.avgTransactionCost / 100 : 0,
),
},
],
},
{
type: "cards",
title: "Payment Cards",
listData: cards?.map((item: any) => {
return {
label: `•••• ${item?.last4}`,
icon: cardIconsMap()[
cardNameMap[
item?.brand as keyof typeof cardNameMap
] as keyof typeof cardIconsMap
],
value: parseAmount(item?.sum ? item.sum / 100 : 0),
caption: `${item?.isDebit ? "Debit" : "Credit"} Card`,
};
}),
},
{
type: "users",
title: "User Accounts",
listData: customers?.map((item: any) => {
return {
label: `${item?.firstName || ""} ${item?.lastName || ""}`.trim(),
icon: (
<GiveAvatar
size="32px"
shape="rounded"
imageUrl={
item?.imageURL ? addSizeToImage(item.imageURL, "thumb") : ""
}
/>
),
value: item?.email || "",
};
}),
},
{
type: "detail",
title: "Merchant Visits",
listData: [
{
label: "Unique Merchants",
value: stats?.numMerchants || 0,
disableParseAmount: true,
},
{
label: "Unique Authenticated Users",
value: stats?.numUsers || 0,
disableParseAmount: true,
},
{
label: "Unique Customers",
value: stats?.numCustomers || 0,
disableParseAmount: true,
},
],
},
{
type: "detail",
title: "Emails",
listData: [
{
label: "Unique Emails",
value: stats?.numEmails || 0,
disableParseAmount: true,
},
{
label: "Valid Emails",
value: stats?.numEmailsValid || 0,
disableParseAmount: true,
},
{
label: "Rejected Emails",
value: stats?.numEmailsRejected || 0,
disableParseAmount: true,
},
],
},
{
type: "detail",
title: "Additional Information",
listData: [
{
label: "Country",
value: ipInfo?.country || "-",
disableParseAmount: true,
},
{
label: "Country Code",
value: ipInfo?.country_code || "-",
disableParseAmount: true,
},
{
label: "Currency",
value: ipInfo?.currency?.name || "-",
disableParseAmount: true,
},
{
label: "Currency Code",
value: ipInfo?.currency?.code || "-",
disableParseAmount: true,
},
{
label: "City",
value: ipInfo?.city || "-",
disableParseAmount: true,
},
{
label: "Region (State)",
value: ipInfo?.region || "-",
disableParseAmount: true,
},
{
label: "Provider Type",
value: ipInfo?.connection?.org || "-",
disableParseAmount: true,
},
{
label: "Provider Domain",
value: ipInfo?.connection?.domain || "-",
disableParseAmount: true,
},
{
label: "Is Hosting",
value: isHosting ? "Yes" : "No",
disableParseAmount: true,
icon: <BoolIcon positive={isHosting} />,
},
{
label: "Is ISP",
value: isIsp ? "Yes" : "No",
disableParseAmount: true,
icon: <BoolIcon positive={isIsp} />,
},
{
label: "Is VPN",
value: isVPN ? "Yes" : "No",
disableParseAmount: true,
icon: <BoolIcon positive={isVPN} />,
},
],
},
];
return { sections };
}
const cardNameMap = {
Mastercard: "mastercard",
"American Express": "amex",
Visa: "visa",
Discover: "discover",
};
|