Skip to content

Commit

Permalink
fix: [GSW-2032] Reduce cognitive complexity
Browse files Browse the repository at this point in the history
Refactor this function to reduce its Cognitive Complexity from 60 to the 15 allowed.
Cognitive Complexity of functions should not be too high typescript:S3776
Software qualities impacted:
Maintainability
  • Loading branch information
tfrg committed Dec 18, 2024
1 parent c8e7c81 commit 4c5e499
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,13 @@ const EarnMyPositionContainer: React.FC<EarnMyPositionContainerProps> = ({ addre
],
);

let nextIndex = maybeNextDisplayIndex;

switch (minLength) {
case previousElementCenterXToScreenCenterX:
nextIndex = maybeNextDisplayIndex - 1;
break;
case nextElementCenterXToScreenCenterX:
nextIndex = maybeNextDisplayIndex + 1;
break;
case currentElementCenterXToScreenCenterX:
nextIndex = maybeNextDisplayIndex;
break;
}
const distanceMap = {
[previousElementCenterXToScreenCenterX]: maybeNextDisplayIndex - 1,
[currentElementCenterXToScreenCenterX]: maybeNextDisplayIndex,
[nextElementCenterXToScreenCenterX]: maybeNextDisplayIndex + 1,
};

const nextIndex = distanceMap[minLength];

if (nextIndex > childrenLength) {
setCurrentIndex(childrenLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,13 @@ const IncentivizedPoolCardListContainer: React.FC = () => {
],
);

let nextIndex = maybeNextDisplayIndex;

switch (minLength) {
case previousElementCenterXToScreenCenterX:
nextIndex = maybeNextDisplayIndex - 1;
break;
case nextElementCenterXToScreenCenterX:
nextIndex = maybeNextDisplayIndex + 1;
break;
case currentElementCenterXToScreenCenterX:
nextIndex = maybeNextDisplayIndex;
break;
}
const distanceMap = {
[previousElementCenterXToScreenCenterX]: maybeNextDisplayIndex - 1,
[currentElementCenterXToScreenCenterX]: maybeNextDisplayIndex,
[nextElementCenterXToScreenCenterX]: maybeNextDisplayIndex + 1,
};

const nextIndex = distanceMap[minLength];

if (nextIndex > childrenLength) {
setCurrentIndex(childrenLength);
Expand Down

0 comments on commit 4c5e499

Please sign in to comment.