AuctionCard Instant Sale first pass

This commit is contained in:
adamjeffries 2021-08-30 13:39:47 -05:00
parent 743fcf55d0
commit 5949de6fd4
No known key found for this signature in database
GPG Key ID: 71C4DC054797A48C
1 changed files with 77 additions and 24 deletions

View File

@ -373,7 +373,13 @@ export const AuctionCard = ({
onClick={() => setShowBidModal(true)}
style={{ marginTop: 20 }}
>
{loading ? <Spin /> : 'Place bid'}
{loading ? (
<Spin />
) : auctionView.isInstantSale ? (
'Buy Now'
) : (
'Place bid'
)}
</Button>
))}
@ -480,9 +486,51 @@ export const AuctionCard = ({
}
};
const instantSale = async () => {
setLoading(true);
// Placing a "bid" of the full amount results in a purchase to redeem.
if (
myPayingAccount &&
auctionView.auctionDataExtended?.info.instantSalePrice
) {
await sendPlaceBid(
connection,
wallet,
myPayingAccount.pubkey,
auctionView,
accountByMint,
auctionView.auctionDataExtended?.info.instantSalePrice,
);
setShowBidModal(false);
// Redeem the purchase immediately.
try {
await sendRedeemBid(
connection,
wallet,
myPayingAccount.pubkey,
auctionView,
accountByMint,
prizeTrackingTickets,
bidRedemptions,
bids,
// TODO: Replace with instant sale dialog
).then(() => setShowRedeemedBidModal(true));
} catch (e) {
console.error(e);
setShowRedemptionIssue(true);
}
}
setLoading(false);
};
return (
<>
<h2 className="modal-title">Place a bid</h2>
<h2 className="modal-title">
{auctionView.isInstantSale ? 'Instant Sale' : 'Place a bid'}
</h2>
{!!gapTime && (
<div
className="info-content"
@ -527,24 +575,26 @@ export const AuctionCard = ({
color: 'rgba(0, 0, 0, 0.5)',
}}
>
<InputNumber
autoFocus
className="input"
value={value}
style={{
width: '100%',
background: '#393939',
borderRadius: 16,
}}
onChange={setValue}
precision={4}
formatter={value =>
value
? `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
: ''
}
placeholder="Amount in SOL"
/>
{!auctionView.isInstantSale && (
<InputNumber
autoFocus
className="input"
value={value}
style={{
width: '100%',
background: '#393939',
borderRadius: 16,
}}
onChange={setValue}
precision={4}
formatter={value =>
value
? `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
: ''
}
placeholder="Amount in SOL"
/>
)}
<div
style={{
display: 'inline-block',
@ -572,21 +622,24 @@ export const AuctionCard = ({
type="primary"
size="large"
className="action-btn"
onClick={placeBid}
onClick={auctionView.isInstantSale ? instantSale : placeBid}
disabled={
tickSizeInvalid ||
gapBidInvalid ||
!myPayingAccount ||
value === undefined ||
value * LAMPORTS_PER_SOL < priceFloor ||
(!auctionView.isInstantSale &&
(value === undefined ||
value * LAMPORTS_PER_SOL < priceFloor)) ||
loading ||
!accountByMint.get(QUOTE_MINT.toBase58())
}
>
{loading || !accountByMint.get(QUOTE_MINT.toBase58()) ? (
<Spin />
) : auctionView.isInstantSale ? (
'Confirm Purchase'
) : (
'Place bid'
'Place Bid'
)}
</Button>
</>