All files / src/features/GiveRiskProfile index.tsx

83.33% Statements 10/12
78.26% Branches 18/23
33.33% Functions 1/3
83.33% Lines 10/12

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                                                          52x                 20x   20x                               20x   20x         20x               20x               20x     20x         20x                                                                        
import { Box, Stack } from "@mui/material";
import SidePanelHeaderVariant from "@shared/SidePanel/components/SidePanelHeader/SidePanelHeaderVariant";
import {
  SidePanelBodyWrapper,
  SidePanelContainerWrapper,
} from "@shared/SidePanel/SidePanelAtoms";
import { useTransactionRiskProfile } from "./hooks/useTransactionRiskProfile";
import RiskProfileHeader from "./components/RiskProfileHeader";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import {
  BasicSkeletonGenerator,
  DEFAULT_SPACING_OFFSET,
} from "./components/BasicSkeletonGenerator";
import useGetRiskProfile from "@features/TransactionsRiskProfile/hooks/useGetRiskProfile";
import { useTransactionHistory } from "@components/ManageMoney/TransactionTable/TransactionInfoModal/hooks";
import { checkPortals } from "@utils/routing";
import { Dispatch } from "react";
import { TTransaction } from "@features/TransactionPanel/types";
 
type Props = {
  data: any;
  onClose: () => void;
  setSelectedRow?: Dispatch<any>;
  isFirst?: boolean;
  isLast?: boolean;
  isModal?: boolean;
  openMainPanel?: (transaction: TTransaction) => void;
};
 
const GiveRiskProfile = ({
  data,
  onClose,
  setSelectedRow,
  isLast,
  isFirst,
  isModal,
  openMainPanel,
}: Props) => {
  const { isMobileView } = useCustomThemeV2();
 
  const headerProps = {
    actions: [],
    nextPrevState: {
      isFirst: isFirst ?? false,
      isLast: isLast ?? false,
      isPanelLoading: false,
    },
    handlers: {
      handleClose: onClose,
      handlePrevious: () => null,
      handleNext: () => null,
    } as any,
    isHiddenNextPrev: true,
    sidePanelName: "Transaction Risk Profile",
  };
 
  const { ActivePage, currentTab, setCurrentTab } = useTransactionRiskProfile();
 
  const { isAnyPaymentForm } = checkPortals();
  const {
    isLoading: isLoadingTransactionHistory,
    isFetched: isPanelFetched,
    displayedData,
  } = useTransactionHistory(
    isAnyPaymentForm ? data?.transactionID : data?.objID ?? data?.id,
    true,
    data,
    true,
  );
 
  const ipProfileID =
    data?.ipProfileID || displayedData?.ipProfileID || data?.riskObjID;
 
  const {
    data: riskProfileData,
    rawData,
    isLoading: isLoadingRiskProfile,
    //   hasMore,
    //   isListIPProfileAllowed,
  } = useGetRiskProfile(ipProfileID);
 
  const isLoading =
    data?.isLoading ||
    isLoadingRiskProfile ||
    isLoadingTransactionHistory ||
    (!isPanelFetched && !data?.riskObjID && !isModal);
 
  return (
    <SidePanelContainerWrapper>
      <SidePanelHeaderVariant variant="transaction" HeaderProps={headerProps} />
      <SidePanelBodyWrapper>
        {isLoading ? (
          <Box
            sx={{
              paddingY: isLoading && isMobileView ? 5 : DEFAULT_SPACING_OFFSET,
              paddingX: DEFAULT_SPACING_OFFSET,
            }}
          >
            <BasicSkeletonGenerator howMany={10} />
          </Box>
        ) : (
          <Stack spacing="20px" padding="20px">
            <RiskProfileHeader
              currentTab={currentTab}
              setCurrentTab={setCurrentTab}
            />
            <ActivePage
              isFirst={isFirst}
              isLast={isLast}
              setSelectedRow={setSelectedRow}
              data={data}
              riskProfileData={riskProfileData}
              rawData={rawData}
              openMainPanel={openMainPanel}
            />
          </Stack>
        )}
      </SidePanelBodyWrapper>
    </SidePanelContainerWrapper>
  );
};
 
export default GiveRiskProfile;