Skip to content

Commit

Permalink
Combine upcoming + active auctions (#1399)
Browse files Browse the repository at this point in the history
* Combine upcoming + active auctions

* Changeset

* Fix tests
  • Loading branch information
jessepinho authored Jul 3, 2024
1 parent 44de1cf commit 0cd4e87
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-pears-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'minifront': patch
---

Combine active + upcoming auctions
4 changes: 0 additions & 4 deletions apps/minifront/src/components/swap/auction-list/filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ const OPTIONS: PopoverMenuItem<TFilter>[] = [
label: 'Active',
value: 'active',
},
{
label: 'Upcoming',
value: 'upcoming',
},
{
label: 'All',
value: 'all',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,44 +107,14 @@ describe('getFilteredAuctionInfos()', () => {
);
});

it('filters out auctions that start after `fullSyncHeight`', () => {
expect(getFilteredAuctionInfos(AUCTION_INFOS, 'active', MOCK_FULL_SYNC_HEIGHT)).not.toContain(
MOCK_AUCTION_INFO_4,
);
});

it('filters out everything if `fullSyncHeight` is undefined', () => {
expect(getFilteredAuctionInfos(AUCTION_INFOS, 'active', undefined)).toEqual([]);
});
});

describe('when the `filter` is `upcoming`', () => {
it('filters out active auctions', () => {
expect(
getFilteredAuctionInfos(AUCTION_INFOS, 'upcoming', MOCK_FULL_SYNC_HEIGHT),
).not.toContain(MOCK_AUCTION_INFO_1);
});

it('filters out auctions with a nonzero `seq`', () => {
expect(
getFilteredAuctionInfos(AUCTION_INFOS, 'upcoming', MOCK_FULL_SYNC_HEIGHT),
).not.toContain(MOCK_AUCTION_INFO_2);
});

it('filters out auctions that end before `fullSyncHeight`', () => {
expect(
getFilteredAuctionInfos(AUCTION_INFOS, 'upcoming', MOCK_FULL_SYNC_HEIGHT),
).not.toContain(MOCK_AUCTION_INFO_3);
});

it('includes auctions that start after `fullSyncHeight`', () => {
expect(getFilteredAuctionInfos(AUCTION_INFOS, 'upcoming', MOCK_FULL_SYNC_HEIGHT)).toContain(
expect(getFilteredAuctionInfos(AUCTION_INFOS, 'active', MOCK_FULL_SYNC_HEIGHT)).toContain(
MOCK_AUCTION_INFO_4,
);
});

it('filters out everything if `fullSyncHeight` is undefined', () => {
expect(getFilteredAuctionInfos(AUCTION_INFOS, 'upcoming', undefined)).toEqual([]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const getFilteredAuctionInfos = (
return auctionInfos.filter(auctionInfo => {
if (!fullSyncHeight) return false;
if (!haveEnoughDataToDetermineIfAuctionMatchesFilter(auctionInfo)) return false;
if (filter === 'active') return auctionIsActive(auctionInfo, fullSyncHeight);
return auctionIsUpcoming(auctionInfo, fullSyncHeight);
return (
auctionIsActive(auctionInfo, fullSyncHeight) || auctionIsUpcoming(auctionInfo, fullSyncHeight)
);
});
};
17 changes: 3 additions & 14 deletions apps/minifront/src/components/swap/auction-list/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { AuctionInfo } from '../../../fetchers/auction-infos';
import { Filter } from '../../../state/swap/dutch-auction';

const byStartHeight =
(direction: 'ascending' | 'descending') => (a: AuctionInfo, b: AuctionInfo) => {
if (!a.auction.description?.startHeight || !b.auction.description?.startHeight) return 0;
if (direction === 'ascending') {
return Number(a.auction.description.startHeight - b.auction.description.startHeight);
}
return Number(b.auction.description.startHeight - a.auction.description.startHeight);
};

export const SORT_FUNCTIONS: Record<Filter, (a: AuctionInfo, b: AuctionInfo) => number> = {
all: byStartHeight('ascending'),
active: byStartHeight('descending'),
upcoming: byStartHeight('ascending'),
export const byStartHeightAscending = (a: AuctionInfo, b: AuctionInfo) => {
if (!a.auction.description?.startHeight || !b.auction.description?.startHeight) return 0;
return Number(a.auction.description.startHeight - b.auction.description.startHeight);
};
4 changes: 2 additions & 2 deletions apps/minifront/src/components/swap/auction-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getFilteredAuctionInfos } from './get-filtered-auction-infos';
import { LayoutGroup, motion } from 'framer-motion';
import { useAuctionInfos } from '../../../state/swap/dutch-auction';
import { useStatus } from '../../../state/status';
import { SORT_FUNCTIONS } from './helpers';
import { byStartHeightAscending } from './helpers';
import { Filters } from './filters';

const auctionListSelector = (state: AllSlices) => ({
Expand Down Expand Up @@ -47,7 +47,7 @@ export const AuctionList = () => {
const filteredAuctionInfos = useMemo(
() =>
[...getFilteredAuctionInfos(auctionInfos.data ?? [], filter, status?.fullSyncHeight)].sort(
SORT_FUNCTIONS[filter],
byStartHeightAscending,
),
[auctionInfos.data, filter, status?.fullSyncHeight],
);
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/state/swap/dutch-auction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MIN_OUTPUT_ESTIMATE_MULTIPLIER = 0.5;
*/
export const OUTPUT_LIMIT = 2 ** 52 - 1;

export type Filter = 'active' | 'upcoming' | 'all';
export type Filter = 'active' | 'all';

interface Actions {
setMinOutput: (minOutput: string) => void;
Expand Down

0 comments on commit 0cd4e87

Please sign in to comment.