Skip to content

Commit e5374c2

Browse files
yamijuanaustbot
andauthored
show funds modal issue when buying sale without enough balance (metaplex-foundation#1173)
* Refresh button loads token accounts with dropdown for all metadata * show funds modal issue when buying sale without enough balance * fixed refresh button style * changelog * small refactor Co-authored-by: Austin Adams <[email protected]>
1 parent c62189a commit e5374c2

File tree

7 files changed

+69
-25
lines changed

7 files changed

+69
-25
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ incremented for features.
4343
- Implement NFT Packs Redeem
4444
- Remove Websockets for useMeta
4545
- Redirect to home and reload on auction creation
46+
- Refresh metadata loads user metadata with dropdown menu
4647

4748
### Fixes
4849

@@ -69,6 +70,7 @@ incremented for features.
6970
- Fix NFT Packs creation transaction failing when adding multiple items
7071
- Fix layout on token selection
7172
- Fix type of sale and edition number for non master edition NFTs
73+
- Fix not allowing to buy a sale without enough balance
7274
- Added placeholder for images on create pack flow
7375

7476
### Breaking

js/packages/web/src/components/AuctionCard/index.tsx

+29-13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { useActionButtonContent } from './hooks/useActionButtonContent';
6363
import { endSale } from './utils/endSale';
6464
import { useInstantSaleState } from './hooks/useInstantSaleState';
6565
import { useTokenList } from '../../contexts/tokenList';
66+
import { FundsIssueModal } from "../FundsIssueModal";
6667

6768
async function calculateTotalCostOfRedeemingOtherPeoplesBids(
6869
connection: Connection,
@@ -228,6 +229,7 @@ export const AuctionCard = ({
228229
const [showPlaceBid, setShowPlaceBid] = useState<boolean>(false);
229230
const [lastBid, setLastBid] = useState<{ amount: BN } | undefined>(undefined);
230231
const [purchaseFinished, setPurchaseFinished] = useState<boolean>(false);
232+
const [showFundsIssueModal, setShowFundsIssueModal] = useState(false)
231233

232234
const [showWarningModal, setShowWarningModal] = useState<boolean>(false);
233235
const [printingCost, setPrintingCost] = useState<number>();
@@ -251,6 +253,9 @@ export const AuctionCard = ({
251253

252254
//console.log("[--P]AuctionCard", tokenInfo, mintKey)
253255
const myPayingAccount = balance.accounts[0];
256+
const instantSalePrice = useMemo(() =>
257+
auctionView.auctionDataExtended?.info.instantSalePrice
258+
, [auctionView.auctionDataExtended]);
254259
let winnerIndex: number | null = null;
255260
if (auctionView.myBidderPot?.pubkey)
256261
winnerIndex = auctionView.auction.info.bidState.getWinnerIndex(
@@ -355,6 +360,12 @@ export const AuctionCard = ({
355360
setLoading(false);
356361
};
357362
const instantSaleAction = () => {
363+
const isNotEnoughLamports = balance.balanceLamports < (instantSalePrice?.toNumber() || 0)
364+
if (isNotEnoughLamports) {
365+
setShowFundsIssueModal(true);
366+
return;
367+
}
368+
358369
if (canEndInstantSale) {
359370
return endInstantSale();
360371
}
@@ -364,8 +375,6 @@ export const AuctionCard = ({
364375

365376
const instantSale = async () => {
366377
setLoading(true);
367-
const instantSalePrice =
368-
auctionView.auctionDataExtended?.info.instantSalePrice;
369378
const winningConfigType =
370379
auctionView.participationItem?.winningConfigType ||
371380
auctionView.items[0][0].winningConfigType;
@@ -777,18 +786,25 @@ export const AuctionCard = ({
777786
<Spin />
778787
) : (
779788
auctionView.isInstantSale &&
780-
!isAlreadyBought &&
781-
!purchaseFinished && (
782-
<Button
783-
type="primary"
784-
size="large"
785-
className="ant-btn secondary-btn"
786-
disabled={loading}
787-
onClick={instantSaleAction}
788-
style={{ marginTop: 20, width: '100%' }}
789-
>
790-
{actionButtonContent}
789+
!isAlreadyBought && !purchaseFinished && (<>
790+
<FundsIssueModal
791+
message={"Price"}
792+
minimumFunds={fromLamports(instantSalePrice?.toNumber(), mintInfo)}
793+
currentFunds={balance.balance}
794+
isModalVisible={showFundsIssueModal}
795+
onClose={() => setShowFundsIssueModal(false)}
796+
/>
797+
<Button
798+
type="primary"
799+
size="large"
800+
className="ant-btn secondary-btn"
801+
disabled={loading}
802+
onClick={instantSaleAction}
803+
style={{ marginTop: 20, width: '100%' }}
804+
>
805+
{actionButtonContent}
791806
</Button>
807+
</>
792808
)
793809
))}
794810
{!hideDefaultAction && !wallet.connected && (

js/packages/web/src/components/FundsIssueModal/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { useTokenList } from "../../contexts/tokenList";
55
import { Button } from "antd";
66

77
export const FundsIssueModal = (props: {
8+
message: string,
89
isModalVisible: boolean,
910
minimumFunds: any,
1011
currentFunds: any,
1112
onClose: () => void
1213
}) => {
13-
const {currentFunds: balance, minimumFunds} = props
14+
const {currentFunds: balance, minimumFunds, message} = props
1415
const tokenInfo = useTokenList().mainnetTokens.filter(m=>m.address == WRAPPED_SOL_MINT.toBase58())[0]
1516
return (
1617
<MetaplexModal
@@ -36,7 +37,7 @@ export const FundsIssueModal = (props: {
3637
<div className="card-bid-info">
3738
<AmountLabel
3839
containerStyle={{ flexDirection: 'row' }}
39-
title={"Estimated minimum fee"}
40+
title={message}
4041
displaySymbol={"SOL"}
4142
amount={minimumFunds}
4243
iconSize={24}

js/packages/web/src/styles/app.less

+10
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ model-viewer {
342342
cursor: pointer !important;
343343
width: fit-content;
344344

345+
.refresh-overlay {
346+
border-radius: 8px;
347+
}
348+
button {
349+
&:not(.ant-btn-icon-only) {
350+
padding-right: 0;
351+
}
352+
border: none;
353+
}
354+
345355
& > span {
346356
font-weight: bold;
347357
font-size: 16px;

js/packages/web/src/views/artworks/index.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useWallet } from '@solana/wallet-adapter-react';
22
import React, { useEffect, useState } from 'react';
3-
import { Layout, Row, Col, Tabs, Button } from 'antd';
3+
import { Layout, Row, Col, Tabs, Button, Dropdown, Menu } from 'antd';
44
import { useMeta } from '../../contexts';
55
import { CardLoader } from '../../components/MyLoader';
66

77
import { ArtworkViewState } from './types';
88
import { useItems } from './hooks/useItems';
99
import ItemCard from './components/ItemCard';
1010
import { useUserAccounts } from '@oyster/common';
11+
import { DownOutlined } from "@ant-design/icons";
1112
import { isMetadata, isPack } from './utils';
1213

1314
const { TabPane } = Tabs;
@@ -51,9 +52,19 @@ export const ArtworksView = () => {
5152
);
5253

5354
const refreshButton = connected && storeIndexer.length !== 0 && (
54-
<Button className="refresh-button" onClick={() => pullAllMetadata()}>
55+
<Dropdown.Button
56+
className={"refresh-button padding0"}
57+
onClick={() => pullItemsPage(userAccounts)}
58+
icon={<DownOutlined />}
59+
overlayClassName={"refresh-overlay"}
60+
overlay={
61+
<Menu className={'gray-dropdown'}>
62+
<Menu.Item onClick={() => pullAllMetadata()}>Load All Metadata</Menu.Item>
63+
</Menu>
64+
}
65+
>
5566
Refresh
56-
</Button>
67+
</Dropdown.Button>
5768
);
5869

5970
return (

js/packages/web/src/views/auctionCreate/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,8 @@ const ReviewStep = (props: {
20142014
: 'Publish Auction'}
20152015
</Button>
20162016
<FundsIssueModal
2017-
minimumFunds={0.06}
2017+
message={"Estimated Minimum Fee"}
2018+
minimumFunds={MINIMUM_SAFE_FEE_AUCTION_CREATION}
20182019
currentFunds={balance}
20192020
isModalVisible={showFundsIssueModal}
20202021
onClose={() => setShowFundsIssueModal(false)}

js/packages/web/src/views/styles.less

+9-6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
color: #ffffff;
4646
}
4747
}
48+
.padding0 {
49+
padding: 0;
50+
}
4851
.modalp-40 {
4952
.ant-modal-body {
5053
padding: 40px;
@@ -394,11 +397,11 @@ h2 {
394397
margin-bottom: 10px;
395398
}
396399

397-
.black-dropdown {
398-
background-color: #121212;
399-
400-
.ant-dropdown-menu-item:hover {
401-
background-color: white;
402-
color: black;
400+
.gray-dropdown {
401+
background-color: #2a2a2a;
402+
padding: 10px 0px;
403+
border-radius: 8px;
404+
& > li:hover {
405+
background-color: #2a2a2a !important;
403406
}
404407
}

0 commit comments

Comments
 (0)