-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added end/withdraw all auctions button (#1630)
- Loading branch information
1 parent
afaaee9
commit 6094b6b
Showing
5 changed files
with
175 additions
and
2 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 @@ | ||
--- | ||
'minifront': minor | ||
--- | ||
|
||
Add a "claim all" button to the auctions list |
117 changes: 117 additions & 0 deletions
117
apps/minifront/src/components/swap/auction-list/end-or-withdraw-all-button.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,117 @@ | ||
import { useAuctionInfos } from '../../../state/swap/dutch-auction'; | ||
import { AddressIndex } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb'; | ||
import { Button } from '@repo/ui/components/ui/button'; | ||
import { AllSlices } from '../../../state'; | ||
import { useStoreShallow } from '../../../utils/use-store-shallow.ts'; | ||
import { filterWithLimit } from './helpers.ts'; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger, | ||
} from '@repo/ui/components/ui/tooltip'; | ||
import { AuctionInfo } from '../../../fetchers/auction-infos.ts'; | ||
|
||
const endOrWithdrawAllButtonSelector = (state: AllSlices) => ({ | ||
endAllAuctions: state.swap.dutchAuction.endAllAuctions, | ||
withdrawAllAuctions: state.swap.dutchAuction.withdrawAllAuctions, | ||
}); | ||
|
||
export interface AuctionsBatch { | ||
auctions: AuctionInfo[]; | ||
source: AddressIndex; | ||
} | ||
|
||
// Assemble batch auctions for end or withdrawal. | ||
// All auctions in the batch will have the same 'AddressIndex' | ||
export const assembleAuctionBatch = ( | ||
auctions: AuctionInfo[], | ||
filteredSeqNumber: bigint, | ||
batchLimit: number, | ||
): AuctionsBatch => { | ||
const filteredBySeqAuctions: AuctionInfo[] = auctions.filter( | ||
a => a.localSeqNum === filteredSeqNumber, | ||
); | ||
// Get the address index of the first auction in the list and filter other auctions with this address index | ||
const firstFoundAddressIndex = filteredBySeqAuctions[0]?.addressIndex; | ||
|
||
const filteredBySeqAndAddressIndexAuctions = filterWithLimit( | ||
filteredBySeqAuctions, | ||
a => a.addressIndex.equals(firstFoundAddressIndex), | ||
batchLimit, | ||
); | ||
return { auctions: filteredBySeqAndAddressIndexAuctions, source: firstFoundAddressIndex! }; | ||
}; | ||
|
||
export const EndOrWithdrawAllButton = () => { | ||
const { endAllAuctions, withdrawAllAuctions } = useStoreShallow(endOrWithdrawAllButtonSelector); | ||
const { data } = useAuctionInfos(); | ||
|
||
if (!data?.length) { | ||
return null; | ||
} | ||
if (data.some(a => a.localSeqNum === 0n)) { | ||
return ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger | ||
onClick={() => { | ||
// Chain has a transaction size limit, so we can add at most a batch of 48 auctions in a single transaction | ||
// see https://github.com/penumbra-zone/web/issues/1166#issuecomment-2263550249 | ||
const auctionBatch = assembleAuctionBatch(data, 0n, 48); | ||
|
||
void endAllAuctions( | ||
auctionBatch.auctions, | ||
// TODO Should use the index of the selected account after the account selector for the auction is implemented | ||
auctionBatch.source, | ||
); | ||
}} | ||
aria-label='End all open auctions, with a limit of 48 auctions per transaction' | ||
> | ||
<div className='w-[85px] shrink-0'> | ||
<Button size='sm' variant='secondary' className='w-full'> | ||
End all | ||
</Button> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
End all open auctions, with a limit of 48 auctions per transaction | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
} | ||
|
||
if (data.some(a => a.localSeqNum === 1n)) { | ||
return ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger | ||
onClick={() => { | ||
// Chain has a transaction size limit, so we can add at most a batch of 48 auctions in a single transaction | ||
// see https://github.com/penumbra-zone/web/issues/1166#issuecomment-2263550249 | ||
const auctionBatch = assembleAuctionBatch(data, 1n, 48); | ||
void withdrawAllAuctions( | ||
auctionBatch.auctions, | ||
// TODO Should use the index of the selected account after the account selector for the auction is implemented | ||
auctionBatch.source, | ||
); | ||
}} | ||
aria-label='Withdraw all ended auctions, with a limit of 48 auctions per transaction' | ||
> | ||
<div className='w-[95px] shrink-0'> | ||
<Button size='sm' variant='secondary' className='w-full'> | ||
Withdraw all | ||
</Button> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
Withdraw all ended auctions, with a limit of 48 auctions per transaction | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
} | ||
|
||
return null; | ||
}; |
20 changes: 20 additions & 0 deletions
20
apps/minifront/src/components/swap/auction-list/helpers.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
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