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 | 1x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 51x 9x 42x 71x 284x 180x 1x 71x 100x | import NiceModal from "@ebay/nice-modal-react";
import { Box, Stack } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import { parseAmount } from "@utils/index";
import { styled, useAppTheme } from "@theme/v2/Provider";
import { MONEY_TRANSFER_FEES_POPUP } from "modals/modal_names";
import { InfoIcon } from "@phosphor-icons/react";
import GiveDivider from "@shared/GiveDivider/GiveDivider";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { checkPortals } from "@utils/routing";
import {
RESERVE_FUND_TOOLTIP,
SUBTRACTED_FROM_BALANCE_TEXT,
} from "./constants";
import { useFormContext } from "react-hook-form";
type Props = {
fees: string;
newBalance: number;
sendTo?: string;
transferAmount?: number;
minimumReserveBPSFee?: string;
};
const FeeSection = ({
fees,
newBalance,
sendTo,
transferAmount,
minimumReserveBPSFee,
}: Props) => {
const { palette } = useAppTheme();
const { isMerchantPortal, isAcquirerManageMoney } = checkPortals();
const totalTaken = parseAmount(newBalance);
const {
formState: { errors },
} = useFormContext();
const isExceeding = errors?.amount?.type === "exeeds_max";
const isOTPStepWithMinimBPS =
!!transferAmount && minimumReserveBPSFee && isMerchantPortal;
const isOTPAcquirer = !!transferAmount && isAcquirerManageMoney;
const details = [
{
label: "Send To",
value: sendTo,
hidden: !sendTo || (isAcquirerManageMoney && !transferAmount),
},
{
label:
isOTPStepWithMinimBPS || isOTPAcquirer
? SUBTRACTED_FROM_BALANCE_TEXT
: "Transfer Amount",
value: `${isOTPStepWithMinimBPS ? totalTaken : transferAmount} USD`,
hidden: !transferAmount,
},
{ label: "Fee", value: `${fees} USD`, hidden: isAcquirerManageMoney },
{
label: "Reserve Funds Allocation",
value: `${minimumReserveBPSFee} USD`,
infoTooltip: RESERVE_FUND_TOOLTIP,
hidden: !minimumReserveBPSFee || !isMerchantPortal,
},
];
const totalText = (() => {
if (isOTPStepWithMinimBPS || isOTPAcquirer) return "Amount to Send";
if (!transferAmount && minimumReserveBPSFee && isMerchantPortal)
return SUBTRACTED_FROM_BALANCE_TEXT;
return "Total";
})();
return (
<FeesContainer>
<Stack spacing={2}>
{details
.filter((item) => !item.hidden)
.map((item) => (
<Box
key={item.label}
display="flex"
justifyContent="space-between"
alignItems="center"
>
<Stack direction="row" spacing={1} alignItems="center">
<GiveText variant="bodyS" color="secondary" lineHeight="1.5">
{item.label}
</GiveText>
{item.label === "Fee" && (
<InfoIconContainer
onClick={() => NiceModal.show(MONEY_TRANSFER_FEES_POPUP)}
data-testid="transfer-fee-button"
>
<InfoIcon fill={palette.icon?.["icon-secondary"]} />
</InfoIconContainer>
)}
{!!item.infoTooltip && (
<GiveTooltip
title={item.infoTooltip}
fluidWidth
placement="top"
>
<InfoIconContainer data-testid="reserve-fund-info-button">
<InfoIcon fill={palette.icon?.["icon-secondary"]} />
</InfoIconContainer>
</GiveTooltip>
)}
</Stack>
<GiveText variant="bodyS">{item.value}</GiveText>
</Box>
))}
</Stack>
{(!isAcquirerManageMoney || isOTPAcquirer) && <GiveDivider />}
<Box display="flex" justifyContent="space-between" alignItems="center">
<GiveText
variant="bodyS"
fontWeight="bold"
color={isExceeding ? "error" : "primary"}
>
{totalText}
</GiveText>
<GiveText
variant="bodyS"
fontWeight="bold"
color={isExceeding ? "error" : "primary"}
>
{isOTPStepWithMinimBPS ? transferAmount : parseAmount(newBalance)} USD
</GiveText>
</Box>
</FeesContainer>
);
};
const FeesContainer = styled(Box)(({ theme }) => ({
background: theme.palette.surface?.secondary,
padding: "16px",
borderRadius: "8px",
display: "flex",
flexDirection: "column",
gap: "4px",
}));
const InfoIconContainer = styled(Box)(() => ({
cursor: "pointer",
height: "16px",
width: "16px",
display: "flex",
alignItems: "center",
}));
export default FeeSection;
|