Skip to content

Commit

Permalink
fix(STK-258): Bar showing complete on the first order (#196)
Browse files Browse the repository at this point in the history
* fix: update the computations to check the order progress bar
* fix: check if the stack has remaining funds as an edge case cover
  • Loading branch information
ElRodrigote authored Aug 7, 2024
1 parent 756db33 commit f0118ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions packages/app/components/OrdersProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { StackOrderProps, totalStackOrdersDone } from "@/models/stack-order";
import {
stackHasRemainingFunds,
StackOrderProps,
totalStackOrdersDone,
} from "@/models/stack-order";
import React, { useRef, useEffect } from "react";

const FULL_BAR_WIDTH = 100;

export const OrdersProgressBar = ({ stackOrder }: StackOrderProps) => {
const progressBarRef = useRef<HTMLDivElement>(null);
const totalOrders = totalStackOrdersDone(stackOrder)
? totalStackOrdersDone(stackOrder)
: stackOrder.orderSlots.length;
const totalOrders = stackOrder.orderSlots.length
? stackOrder.orderSlots.length
: 1;

useEffect(() => {
if (progressBarRef.current) {
const width = (100 * totalStackOrdersDone(stackOrder)) / totalOrders;
const width = stackHasRemainingFunds(stackOrder)
? (FULL_BAR_WIDTH * totalStackOrdersDone(stackOrder)) / totalOrders
: FULL_BAR_WIDTH;
progressBarRef.current.style.width = `${width}%`;
}
}, [stackOrder, totalOrders]);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/models/stack-order/stack-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const totalStacked = (order: StackOrder) =>
);
}, 0) ?? 0;

const stackHasRemainingFunds = (stackOrder: StackOrder) =>
export const stackHasRemainingFunds = (stackOrder: StackOrder) =>
totalFundsUsed(stackOrder) > stacklyFee(stackOrder) &&
stackRemainingFunds(stackOrder) > stacklyFee(stackOrder);

Expand Down

0 comments on commit f0118ad

Please sign in to comment.