All files / src/components/Merchants/MerchantPreview/modals/shared residencyUtils.tsx

88.23% Statements 15/17
71.42% Branches 5/7
100% Functions 6/6
88.23% Lines 15/17

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        4x 48x                     96x     4x         48x   48x 44x     4x           4x                           4x   82x 82x     4x                 7x                             7x            
import { Stack } from "@mui/material";
import GiveChip from "@shared/Chip/GiveChip";
import { OFACTabType } from "@components/Merchants/MerchantPreview/OFAC/hooks/types";
 
export const buildStatusChips = (isResident?: boolean, isCitizen?: boolean) => {
  return [
    {
      key: "non-resident",
      label: "Non-resident",
      hidden: isResident !== false,
    },
    {
      key: "non-citizen",
      label: "Non-citizen",
      hidden: isCitizen !== false,
    },
  ].filter((chip) => !chip.hidden);
};
 
export const renderTitleWithNameAndTags = (
  name: string,
  isResident?: boolean,
  isCitizen?: boolean,
) => {
  const chips = buildStatusChips(isResident, isCitizen);
 
  if (chips.length === 0) {
    return name;
  }
 
  return (
    <Stack direction="row" alignItems="center" gap="12px">
      <span style={{ whiteSpace: "nowrap" }}>{name}</span>
 
      <Stack direction="row" alignItems="center" gap="4px">
        {chips.map(({ key, label }) => (
          <GiveChip
            key={key}
            label={label}
            size="small"
            variant="light"
            color="blue"
            sx={{ fontSize: "12px", height: "20px", border: "none" }}
          />
        ))}
      </Stack>
    </Stack>
  );
};
 
export const isUS = (value?: string): boolean => {
  // Treat empty string as "US" (default value when not explicitly set)
  const result = !value || value === "US";
  return result;
};
 
export const getResidencyFlags = ({
  activeTab,
  owner,
  PAH,
}: {
  activeTab: OFACTabType;
  owner?: any;
  PAH?: any;
}): { isResident: boolean | undefined; isCitizen: boolean | undefined } => {
  switch (activeTab) {
    case OFACTabType.BUSINESS_OWNER:
      return {
        // derived directly from authoritative fields
        isResident: isUS(owner?.countryOfResidence),
        isCitizen: isUS(owner?.citizenship),
      };
 
    case OFACTabType.PRIMARY_ACCOUNT_HOLDER:
      return {
        isResident: !PAH.isNotUSResident,
        isCitizen: !PAH.isNotUSCitizen,
      };
 
    default:
      return {
        isResident: undefined,
        isCitizen: undefined,
      };
  }
};