All files / src/features/MerchantPortal/ManageMoney/modals/SendMoneyModal helpers.ts

95.65% Statements 22/23
87.5% Branches 14/16
100% Functions 5/5
100% Lines 19/19

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                61x           51x 51x 51x     61x     9x 9x   5x     61x 135x   123x     123x   123x     61x         55x   10x 15x 15x                       10x    
import { TFeeObject } from "@components/Merchants/MerchantPreview/data.types";
import { CURRENCY } from "@constants/constants";
import { BalanceDataType } from "../../hooks/useBalances";
import { ProcessorBalanceType } from "./types";
import { toEnFormat } from "@utils/index";
import { CheasapeakeIcon, WorldpayIcon } from "@shared/ProcessorIcons";
import React from "react";
 
export const calculateBpsFee = (
  amount: number,
  bps: number,
  reserveFunds: number,
) => {
  // 1 BPS = 0.01%, so we divide bps by 10,000 to get the multiplier
  const requiredReserveMove = (amount * bps) / 10000;
  const missingFromReserve = Math.max(0, requiredReserveMove - reserveFunds);
  return missingFromReserve;
};
 
export const getAmountAsNumber = (
  amount: string | number | undefined,
): number => {
  Iif (typeof amount === "number") return amount;
  if (!amount) return 0;
  // Remove commas and parse as float
  return parseFloat(amount.toString().replaceAll(",", "")) || 0;
};
 
export const calculateFeePerTransaction = (fee: Omit<TFeeObject, "value">) => {
  if (!fee) return "";
 
  const providerFee = fee?.parentBaselinePercent;
 
  const val =
    (fee?.baselinePercent + fee?.adjustmentPercent + providerFee) / 100;
 
  return `${val}% + ${fee?.baselineFixed / 100} ${CURRENCY}`;
};
 
export const buildAcquirerBalanceInfo = ({
  processorBalances,
}: {
  processorBalances?: BalanceDataType[];
}) => {
  if (!processorBalances || processorBalances.length === 0) return null;
 
  const dataArr: ProcessorBalanceType[] = processorBalances.map((item) => {
    const isWorldpay = item.processorName === "worldpay";
    return {
      label: isWorldpay
        ? "Worldpay Available Balance (USD)"
        : "Chesapeake RS2 Available Balance (USD)",
      value: toEnFormat(item.availableBalance / 100),
      icon: isWorldpay
        ? React.createElement(WorldpayIcon)
        : React.createElement(CheasapeakeIcon),
      name: item.processorName,
    };
  });
 
  return dataArr;
};