add transaction confirmation notifications to nft transactions
This commit is contained in:
parent
98cd5a9e54
commit
c71c62f5f3
|
@ -27,6 +27,7 @@ import { abbreviateAddress } from 'utils/formatting'
|
|||
import EmptyState from './EmptyState'
|
||||
import { formatNumericValue } from 'utils/numbers'
|
||||
import Loading from '@components/shared/Loading'
|
||||
import { notify } from 'utils/notifications'
|
||||
|
||||
const AllBidsView = () => {
|
||||
const { publicKey } = useWallet()
|
||||
|
@ -37,6 +38,7 @@ const AllBidsView = () => {
|
|||
const [bidListing, setBidListing] = useState<null | Listing>(null)
|
||||
const [buying, setBuying] = useState('')
|
||||
const [cancellingBid, setCancellingBid] = useState('')
|
||||
const [accepting, setAccepting] = useState('')
|
||||
const { data: bids, refetch } = useBids()
|
||||
const bidsToLoad = bids ? bids : []
|
||||
const { data: loadedBids } = useLoadBids(bidsToLoad)
|
||||
|
@ -54,11 +56,18 @@ const AllBidsView = () => {
|
|||
const cancelBid = async (bid: Bid) => {
|
||||
setCancellingBid(bid.asset.mint.address.toString())
|
||||
try {
|
||||
await metaplex!.auctionHouse().cancelBid({
|
||||
const { response } = await metaplex!.auctionHouse().cancelBid({
|
||||
auctionHouse: auctionHouse!,
|
||||
bid,
|
||||
})
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error cancelling bid', e)
|
||||
} finally {
|
||||
|
@ -67,26 +76,47 @@ const AllBidsView = () => {
|
|||
}
|
||||
|
||||
const sellAsset = async (bid: Bid, tokenAccountPk: string) => {
|
||||
const tokenAccount = await metaplex
|
||||
?.tokens()
|
||||
.findTokenByAddress({ address: new PublicKey(tokenAccountPk) })
|
||||
setAccepting(bid.asset.mint.address.toString())
|
||||
try {
|
||||
const tokenAccount = await metaplex
|
||||
?.tokens()
|
||||
.findTokenByAddress({ address: new PublicKey(tokenAccountPk) })
|
||||
|
||||
await metaplex!.auctionHouse().sell({
|
||||
auctionHouse: auctionHouse!,
|
||||
bid: bid as PublicBid,
|
||||
sellerToken: tokenAccount!,
|
||||
})
|
||||
refetch()
|
||||
const { response } = await metaplex!.auctionHouse().sell({
|
||||
auctionHouse: auctionHouse!,
|
||||
bid: bid as PublicBid,
|
||||
sellerToken: tokenAccount!,
|
||||
})
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error accepting offer', e)
|
||||
} finally {
|
||||
setAccepting('')
|
||||
}
|
||||
}
|
||||
|
||||
const buyAsset = async (listing: Listing) => {
|
||||
setBuying(listing.asset.mint.address.toString())
|
||||
try {
|
||||
await metaplex!.auctionHouse().buy({
|
||||
const { response } = await metaplex!.auctionHouse().buy({
|
||||
auctionHouse: auctionHouse!,
|
||||
listing,
|
||||
})
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error buying nft', e)
|
||||
} finally {
|
||||
|
@ -194,7 +224,14 @@ const AllBidsView = () => {
|
|||
)
|
||||
}
|
||||
colorClass="fgd-3"
|
||||
text="Accept Offer"
|
||||
text={
|
||||
accepting ===
|
||||
x.asset.mint.address.toString() ? (
|
||||
<Loading />
|
||||
) : (
|
||||
'Accept Offer'
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
|
|
|
@ -12,6 +12,7 @@ import { ImgWithLoader } from '@components/ImgWithLoader'
|
|||
// import { useTranslation } from 'next-i18next'
|
||||
import { toUiDecimals } from '@blockworks-foundation/mango-v4'
|
||||
import Loading from '@components/shared/Loading'
|
||||
import { notify } from 'utils/notifications'
|
||||
|
||||
type ListingModalProps = {
|
||||
listing?: Listing
|
||||
|
@ -31,7 +32,7 @@ const BidNftModal = ({ isOpen, onClose, listing }: ListingModalProps) => {
|
|||
const bid = useCallback(async () => {
|
||||
setSubmittingOffer(true)
|
||||
try {
|
||||
await metaplex!.auctionHouse().bid({
|
||||
const { response } = await metaplex!.auctionHouse().bid({
|
||||
auctionHouse: auctionHouse!,
|
||||
price: token(bidPrice, MANGO_MINT_DECIMALS),
|
||||
mintAccount: noneListedAssetMode
|
||||
|
@ -40,6 +41,13 @@ const BidNftModal = ({ isOpen, onClose, listing }: ListingModalProps) => {
|
|||
})
|
||||
onClose()
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error making offer', e)
|
||||
} finally {
|
||||
|
|
|
@ -21,6 +21,7 @@ import { formatNumericValue } from 'utils/numbers'
|
|||
import Loading from '@components/shared/Loading'
|
||||
import SheenLoader from '@components/shared/SheenLoader'
|
||||
import EmptyState from './EmptyState'
|
||||
import { notify } from 'utils/notifications'
|
||||
|
||||
const YOUR_LISTINGS = 'Your Listings'
|
||||
const PRICE_LOW_HIGH = 'Price: Low to High'
|
||||
|
@ -71,11 +72,18 @@ const ListingsView = () => {
|
|||
const cancelListing = async (listing: Listing) => {
|
||||
setCancellingListing(listing.asset.mint.address.toString())
|
||||
try {
|
||||
await metaplex!.auctionHouse().cancelListing({
|
||||
const { response } = await metaplex!.auctionHouse().cancelListing({
|
||||
auctionHouse: auctionHouse!,
|
||||
listing: listing,
|
||||
})
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error cancelling listing', e)
|
||||
} finally {
|
||||
|
@ -86,11 +94,18 @@ const ListingsView = () => {
|
|||
const buyAsset = async (listing: Listing) => {
|
||||
setBuying(listing.asset.mint.address.toString())
|
||||
try {
|
||||
await metaplex!.auctionHouse().buy({
|
||||
const { response } = await metaplex!.auctionHouse().buy({
|
||||
auctionHouse: auctionHouse!,
|
||||
listing,
|
||||
})
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error buying nft', e)
|
||||
} finally {
|
||||
|
|
|
@ -17,6 +17,7 @@ import NftMarketButton from './NftMarketButton'
|
|||
import { useState } from 'react'
|
||||
import Loading from '@components/shared/Loading'
|
||||
import EmptyState from './EmptyState'
|
||||
import { notify } from 'utils/notifications'
|
||||
|
||||
const MyBidsModal = ({ isOpen, onClose }: ModalProps) => {
|
||||
const { publicKey } = useWallet()
|
||||
|
@ -35,11 +36,18 @@ const MyBidsModal = ({ isOpen, onClose }: ModalProps) => {
|
|||
const cancelBid = async (bid: Bid) => {
|
||||
setCancelling(bid.asset.mint.address.toString())
|
||||
try {
|
||||
await metaplex!.auctionHouse().cancelBid({
|
||||
const { response } = await metaplex!.auctionHouse().cancelBid({
|
||||
auctionHouse: auctionHouse!,
|
||||
bid,
|
||||
})
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error cancelling offer', e)
|
||||
} finally {
|
||||
|
|
|
@ -15,6 +15,7 @@ import { token } from '@metaplex-foundation/js'
|
|||
import metaplexStore from '@store/metaplexStore'
|
||||
import { useAuctionHouse, useLazyListings } from 'hooks/market/useAuctionHouse'
|
||||
import Loading from '@components/shared/Loading'
|
||||
import { notify } from 'utils/notifications'
|
||||
|
||||
const SellNftModal = ({ isOpen, onClose }: ModalProps) => {
|
||||
const { publicKey } = useWallet()
|
||||
|
@ -49,12 +50,19 @@ const SellNftModal = ({ isOpen, onClose }: ModalProps) => {
|
|||
if (isCurrentlyListed) {
|
||||
throw 'Item is currently listed by you'
|
||||
}
|
||||
await metaplex!.auctionHouse().list({
|
||||
const { response } = await metaplex!.auctionHouse().list({
|
||||
auctionHouse: auctionHouse!, // A model of the Auction House related to this listing
|
||||
mintAccount: new PublicKey(mint), // The mint account to create a listing for, used to find the metadata
|
||||
price: token(price, MANGO_MINT_DECIMALS), // The listing price
|
||||
})
|
||||
refetch()
|
||||
if (response) {
|
||||
notify({
|
||||
title: 'Transaction confirmed',
|
||||
type: 'success',
|
||||
txid: response.signature,
|
||||
})
|
||||
}
|
||||
onClose()
|
||||
} catch (e) {
|
||||
console.log('error listing nft', e)
|
||||
|
|
Loading…
Reference in New Issue