-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix small bugs with auction UIs (#1197)
* Add 'block' label to block heights * Add AuctionId to ExpandedDetails * Set overflow-hidden on box so that auction ID fits * Show ended auctions as completed, even when their endHeight hasn't been reached * Add changeset * Fix logic * Refactor ProgressBar a bit to indicate if an auction ended unfulfilled * Fix seqnum bug * Reorganize * Reorganize more
- Loading branch information
1 parent
67d9bcf
commit fc9418c
Showing
16 changed files
with
161 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@penumbra-zone/ui': patch | ||
--- | ||
|
||
Fixed a couple bugs, and displayed the auction ID in its details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { DutchAuction } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1/auction_pb'; | ||
import { createGetter } from './utils/create-getter'; | ||
|
||
export const getDescription = createGetter( | ||
(dutchAuction?: DutchAuction) => dutchAuction?.description, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
packages/ui/components/ui/dutch-auction-component/get-progress.test.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
packages/ui/components/ui/dutch-auction-component/progress-bar/indicator.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
...ages/ui/components/ui/dutch-auction-component/progress-bar/indicator/get-progress.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { getProgress } from './get-progress'; | ||
|
||
describe('getProgress()', () => { | ||
const startHeight = 1_001n; | ||
const endHeight = 2_000n; | ||
|
||
it('returns 0 when `fullSyncHeight` is undefined and `seqNum` is undefined', () => { | ||
expect(getProgress(startHeight, endHeight, undefined, undefined)).toBe(0); | ||
}); | ||
|
||
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; | ||
|
||
expect(getProgress(startHeight, endHeight, fullSyncHeight)).toBe(0); | ||
}); | ||
|
||
it('clamps to 1 if the end height has been passed', () => { | ||
const fullSyncHeight = 10_000n; | ||
|
||
expect(getProgress(startHeight, endHeight, fullSyncHeight)).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/ui/components/ui/dutch-auction-component/progress-bar/indicator/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { DutchAuction } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1/auction_pb'; | ||
import { CircleArrowRight, CircleCheck, CircleX } from 'lucide-react'; | ||
import { getProgress } from './get-progress'; | ||
import { getDescription } from '@penumbra-zone/getters/dutch-auction'; | ||
import { isZero } from '@penumbra-zone/types/amount'; | ||
|
||
export const Indicator = ({ | ||
dutchAuction, | ||
fullSyncHeight, | ||
}: { | ||
dutchAuction: DutchAuction; | ||
fullSyncHeight?: bigint; | ||
}) => { | ||
const description = getDescription(dutchAuction); | ||
const seqNum = dutchAuction.state?.seq; | ||
if (seqNum === undefined) return null; | ||
|
||
const auctionEnded = | ||
(!!seqNum && seqNum > 0n) || (!!fullSyncHeight && fullSyncHeight >= description.endHeight); | ||
const endedUnfulfilled = | ||
auctionEnded && | ||
!!dutchAuction.state?.inputReserves && | ||
!isZero(dutchAuction.state.inputReserves); | ||
|
||
const progress = getProgress( | ||
description.startHeight, | ||
description.endHeight, | ||
fullSyncHeight, | ||
seqNum, | ||
); | ||
|
||
return ( | ||
<div className='absolute' style={{ left: `max(${progress * 100}% - 16px, 0px)` }}> | ||
{endedUnfulfilled ? ( | ||
<CircleX size={16} className='text-red' /> | ||
) : auctionEnded ? ( | ||
<CircleCheck size={16} className='text-green' /> | ||
) : ( | ||
<CircleArrowRight size={16} /> | ||
)} | ||
</div> | ||
); | ||
}; |