@@ -18,6 +18,7 @@ import { CurrencySelector } from "components/shared/CurrencySelector";
1818import { SolidityInput } from "contract-ui/components/solidity-inputs" ;
1919import { useTrack } from "hooks/analytics/useTrack" ;
2020import { useAllChainsData } from "hooks/chains/allChains" ;
21+ import { useTxNotifications } from "hooks/useTxNotifications" ;
2122import { isAlchemySupported } from "lib/wallet/nfts/alchemy" ;
2223import { isMoralisSupported } from "lib/wallet/nfts/moralis" ;
2324import { isSimpleHashSupported } from "lib/wallet/nfts/simpleHash" ;
@@ -125,6 +126,15 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
125126 walletAddress : account ?. address ,
126127 } ) ;
127128 const sendAndConfirmTx = useSendAndConfirmTransaction ( ) ;
129+ const listingNotifications = useTxNotifications (
130+ "NFT listed Successfully" ,
131+ "Failed to list NFT" ,
132+ ) ;
133+
134+ const auctionNotifications = useTxNotifications (
135+ "Auction created successfully" ,
136+ "Failed to create an auction" ,
137+ ) ;
128138
129139 const form = useForm < ListForm > ( {
130140 defaultValues :
@@ -351,14 +361,11 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
351361 endTimestamp,
352362 } ) ;
353363
354- const promise = sendAndConfirmTx . mutateAsync ( transaction , {
364+ await sendAndConfirmTx . mutateAsync ( transaction , {
355365 onSuccess : ( ) => setOpen ( false ) ,
356366 } ) ;
357- toast . promise ( promise , {
358- loading : "Listing NFT" ,
359- success : "NFT listed successfully" ,
360- error : "Failed to list NFT" ,
361- } ) ;
367+
368+ listingNotifications . onSuccess ( ) ;
362369 } else if ( formData . listingType === "auction" ) {
363370 let minimumBidAmountWei : bigint ;
364371 let buyoutBidAmountWei : bigint ;
@@ -403,7 +410,7 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
403410 buyoutBidAmountWei : buyoutBidAmountWei * selectedQuantity ,
404411 } ) ;
405412
406- const promise = sendAndConfirmTx . mutateAsync ( transaction , {
413+ await sendAndConfirmTx . mutateAsync ( transaction , {
407414 onSuccess : ( ) => {
408415 trackEvent ( {
409416 category : "marketplace" ,
@@ -423,15 +430,15 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
423430 } ) ;
424431 } ,
425432 } ) ;
426- toast . promise ( promise , {
427- loading : "Creating auction" ,
428- success : "Auction created successfully" ,
429- error : "Failed to create auction" ,
430- } ) ;
433+ auctionNotifications . onSuccess ( ) ;
431434 }
432435 } catch ( err ) {
433436 console . error ( err ) ;
434- toast . error ( "Failed to list NFT" ) ;
437+ if ( formData . listingType === "auction" ) {
438+ auctionNotifications . onError ( err ) ;
439+ } else {
440+ listingNotifications . onError ( err ) ;
441+ }
435442 }
436443
437444 setIsFormLoading ( false ) ;
0 commit comments