All files / src/features/TransactionPanel/components/Summary TransactionSummaryDetails.tsx

71.42% Statements 10/14
64.86% Branches 24/37
80% Functions 4/5
76.92% Lines 10/13

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                                    55x         332x   332x       1471x 1471x 80x                     1391x                                                                                                                                                                                                                                                                                   55x 1383x   332x                  
import { Box, SxProps } from "@mui/material";
import { Stack } from "@mui/material";
import { Grid } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import { CustomTheme } from "@theme/v2/palette.interface";
import { styled, useAppTheme } from "@theme/v2/Provider";
import { parseAmount } from "@utils/index";
import { Fragment } from "react";
import type { TransactionSummaryDetailsItem } from "../../helpers/getTransactionLineItems";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import GiveDivider from "@shared/GiveDivider/GiveDivider";
 
type Props = {
  list: TransactionSummaryDetailsItem[];
  isHideBorder?: boolean;
  sx?: SxProps;
};
 
const TransactionSummaryDetails = ({
  list,
  isHideBorder = false,
  sx,
}: Props) => {
  const theme = useAppTheme();
 
  return (
    <DetailsContainer theme={theme} isHideBorder={isHideBorder} sx={sx}>
      <Grid container spacing={2} alignItems="center">
        {list.map((item) => {
          Iif (item?.hidden) return null;
          if (item?.isDivider)
            return (
              <GiveDivider
                bgType="transparent"
                ml={2}
                mb={0}
                sx={{
                  width: "calc(100% - 20px)",
                }}
                key={item.label}
              />
            );
          return (
            <Fragment key={item.label}>
              <Grid item xs={6}>
                <GiveText
                  variant="bodyS"
                  color="secondary"
                  sx={{
                    display: "inline-flex",
                    alignItems: "center",
                    justifyContent: "center",
                    fontWeight: item?.bold ? 700 : undefined,
                    whiteSpace: "normal",
                    wordBreak: "keep-all",
                    gap: 0.5,
                  }}
                >
                  {item?.label}
                  {item?.tooltipMessage && (
                    <GiveTooltip
                      title={item?.tooltipMessage ?? ""}
                      disableHoverListener={!item?.tooltipMessage} // optional: no tooltip if empty
                      fluidWidth
                    >
                      <span
                        style={{
                          display: "inline-flex",
                          alignItems: "center",
                        }}
                      >
                        {item?.startIcon}
                      </span>
                    </GiveTooltip>
                  )}
                </GiveText>
              </Grid>
              <Grid item xs={6}>
                <Stack spacing={1}>
                  {["string", "number", "Date"].includes(typeof item.value) ? (
                    <Stack direction="row" spacing={1} alignItems="center">
                      {item?.icon && (
                        <Box display="flex" alignItems="center" height="100%">
                          <Box
                            sx={{
                              display: "inline-flex",
                              alignItems: "center",
                              lineHeight: 0,
                            }}
                          >
                            {item.icon}
                          </Box>
                        </Box>
                      )}
                      <GiveText
                        variant="bodyS"
                        sx={{
                          fontWeight: item?.bold ? 700 : undefined,
                          wordBreak: "break-word",
                          ...item?.value?.sx,
                        }}
                      >
                        {typeof item.value === "number" &&
                        !item.disableParseAmount
                          ? parseAmount(item.value)
                          : item.value}
                      </GiveText>
                    </Stack>
                  ) : (
                    <Stack spacing={0.5}>
                      {item?.value?.onClick ? (
                        <GiveText
                          data-testid={item?.testId}
                          variant="bodyS"
                          role="button"
                          tabIndex={0}
                          sx={{
                            fontWeight: item?.bold ? 700 : undefined,
                            wordBreak: "break-word",
                            cursor: "pointer",
                            color: theme.palette?.primitive?.blue["100"],
                            textDecoration: "none",
                            "&:hover": {
                              textDecoration: "underline",
                            },
                            "&:focus-visible": {
                              outline: `2px solid ${theme.palette?.primitive?.blue["100"]}`,
                              outlineOffset: 2,
                              borderRadius: 2,
                            },
                          }}
                          onClick={item?.value?.onClick}
                          onKeyDown={(e) => {
                            if (e.key === "Enter" || e.key === " ") {
                              e.preventDefault();
                              item?.value?.onClick?.();
                            }
                          }}
                        >
                          {item?.value?.name}
                        </GiveText>
                      ) : (
                        <GiveText
                          variant="bodyS"
                          sx={{
                            fontWeight: item?.bold ? 700 : undefined,
                            wordBreak: "break-word",
                          }}
                          color="link"
                        >
                          {item?.value?.name}
                        </GiveText>
                      )}
                      <GiveText
                        variant="bodyS"
                        color="secondary"
                        sx={{
                          fontWeight: item?.bold ? 700 : undefined,
                          wordBreak: "break-all",
                        }}
                      >
                        {item?.value?.id}
                      </GiveText>
                    </Stack>
                  )}
                  {item?.caption && (
                    <GiveText variant="bodyS" color="secondary">
                      {item?.caption}
                    </GiveText>
                  )}
                </Stack>
              </Grid>
            </Fragment>
          );
        })}
      </Grid>
    </DetailsContainer>
  );
};
 
const DetailsContainer = styled(Box, {
  shouldForwardProp: (prop) => prop !== "isHideBorder",
})(
  ({ theme, isHideBorder }: { theme: CustomTheme; isHideBorder: boolean }) => ({
    padding: "16px 0",
    borderTop: isHideBorder
      ? "none"
      : `1px solid ${theme.palette?.border?.primary}`,
  }),
);
 
export default TransactionSummaryDetails;