-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added end/withdraw all auctions button #1630
Changes from 9 commits
43ae857
37e6021
3a2a1ae
b52c6b5
3491b82
be5deb5
972cff2
e917112
0f85a91
2dc0cf0
f229b0e
58c3210
d21513b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 claimAllAuctionButtonSelector = (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 ClaimAllAuctionButton = () => { | ||
const { endAllAuctions, withdrawAllAuctions } = useStoreShallow(claimAllAuctionButtonSelector); | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, we can end/withdraw all only for Account 0 I will open a separate issue for this to add an account selector to the auction list UPD: I've changed the approach a bit, now users can end and withdraw auctions for all accounts, but auctions from different accounts will end or withdraw with different batches |
||
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'} | ||
Valentine1898 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</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'} | ||
Valentine1898 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Button> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
Withdraw all ended auctions, with a limit of 48 auctions per transaction | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
} | ||
|
||
return null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a temporary solution that allows you to close all auctions on accounts with different batches
If a user has auctions on account 0 and account 1, the first transaction will end all auctions on account 0, and the second transaction will end all auctions on account 1
see: #1166 (comment)