Skip to content

Commit

Permalink
Show ended auctions as completed, even when their endHeight hasn't be…
Browse files Browse the repository at this point in the history
…en reached
  • Loading branch information
jessepinho committed May 28, 2024
1 parent adbab44 commit 32c7442
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,38 @@ describe('getProgress()', () => {
const startHeight = 1_001n;
const endHeight = 2_000n;

it('returns 0 when `fullSyncHeight` is undefined', () => {
expect(getProgress(startHeight, endHeight, undefined)).toBe(0);
it('returns 0 when `fullSyncHeight` is undefined and `seqNum` is undefined', () => {
expect(getProgress(startHeight, endHeight, undefined, undefined)).toBe(0);
});

it('returns a decimal representing the progress between the start and end heights', () => {
it('returns 0 when `fullSyncHeight` is undefined and `seqNum` is `0n`', () => {
expect(getProgress(startHeight, endHeight, undefined, 0n)).toBe(0);
});

it('returns 1 when `fullSyncHeight` is undefined and `seqNum` is `1n`', () => {
expect(getProgress(startHeight, endHeight, undefined, 1n)).toBe(1);
});

it('returns a decimal representing the progress between the start and end heights when `seqNum` is undefined', () => {
const fullSyncHeight = 1_500n;

expect(getProgress(startHeight, endHeight, fullSyncHeight)).toBe(0.5);
});

it('returns a decimal representing the progress between the start and end heights when `seqNum` is `0n`', () => {
const fullSyncHeight = 1_500n;
const seqNum = 0n;

expect(getProgress(startHeight, endHeight, fullSyncHeight, seqNum)).toBe(0.5);
});

it('returns 1 if `seqNum` is greater than 0 which means the auction has ended)', () => {
const fullSyncHeight = 1_500n;
const seqNum = 1n;

expect(getProgress(startHeight, endHeight, fullSyncHeight, seqNum)).toBe(1);
});

it('clamps to 0 if the start height has not yet been reached', () => {
const fullSyncHeight = 500n;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const getProgress = (
startHeight: bigint,
endHeight: bigint,
fullSyncHeight?: bigint,
seqNum?: bigint,
): number => {
if (seqNum) return 1;
if (!fullSyncHeight) return 0;

const currentDistanceFromStartHeightInclusive = Number(fullSyncHeight) - Number(startHeight) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export const ProgressBar = ({
fullSyncHeight?: bigint;
seqNum?: bigint;
}) => {
const progress = getProgress(auction.startHeight, auction.endHeight, fullSyncHeight);
const progress = getProgress(auction.startHeight, auction.endHeight, fullSyncHeight, seqNum);

const auctionEnded =
(!!seqNum && seqNum > 0n) || (!!fullSyncHeight && fullSyncHeight >= auction.endHeight);
const auctionIsUpcoming = !!fullSyncHeight && fullSyncHeight < auction.startHeight;
const auctionIsUpcoming =
seqNum === 0n && !!fullSyncHeight && fullSyncHeight < auction.startHeight;
const auctionIsInProgress =
seqNum === 0n &&
!!fullSyncHeight &&
fullSyncHeight >= auction.startHeight &&
fullSyncHeight <= auction.endHeight;
Expand Down

0 comments on commit 32c7442

Please sign in to comment.