From 7d77724ec8d8ed8590be93b3e64a109aaea9265d Mon Sep 17 00:00:00 2001 From: Anshul Goel Date: Wed, 20 Jul 2022 18:59:48 +0530 Subject: [PATCH 1/2] fix: able to remove token, add check for auctionHouse on re-add --- src/pages/admin/tokens/edit.tsx | 103 ++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 30 deletions(-) diff --git a/src/pages/admin/tokens/edit.tsx b/src/pages/admin/tokens/edit.tsx index 31b3a599..b0d41188 100644 --- a/src/pages/admin/tokens/edit.tsx +++ b/src/pages/admin/tokens/edit.tsx @@ -1,6 +1,6 @@ import { ReactElement, useMemo, useState } from 'react' import { NextPageContext } from 'next' -import { gql } from '@apollo/client' +import { gql, useQuery } from '@apollo/client' import { isNil } from 'ramda' import { useConnection, useWallet } from '@solana/wallet-adapter-react' import { toast } from 'react-toastify' @@ -15,11 +15,16 @@ import { AdminLayout } from '../../../layouts/Admin' import { Wallet } from '@metaplex/js' import { PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js' import { NATIVE_MINT } from '@solana/spl-token' -import { initMarketplaceSDK, Marketplace } from '@holaplex/marketplace-js-sdk' +import { + AuctionHouse, + initMarketplaceSDK, + Marketplace, +} from '@holaplex/marketplace-js-sdk' import { createCreateAuctionHouseInstruction } from '@metaplex-foundation/mpl-auction-house/dist/src/generated/instructions' import { AuctionHouseProgram } from '@metaplex-foundation/mpl-auction-house' import { useTokenList } from './../../../hooks/tokenList' -import { PendingTransaction } from '@holaplex/marketplace-js-sdk/dist/transaction' +import { Trash2 } from 'react-feather' +import { isSol } from '../../../modules/sol' const SUBDOMAIN = process.env.MARKETPLACE_SUBDOMAIN @@ -84,6 +89,18 @@ export async function getServerSideProps({ req }: NextPageContext) { } } +interface GetAuctionHouse { + auctionHouse: AuctionHouse | null +} + +const GET_AUCTION_HOUSE = gql` + query GetAuctionHouse($address: String!) { + auctionHouse(address: $address) { + address + treasuryMint + } + } +` interface AdminEditTokensProps extends AppProps { marketplace: Marketplace } @@ -142,33 +159,45 @@ async function assembleAuctionHouses( const [auctionHouse, bump] = await AuctionHouseProgram.findAuctionHouseAddress(publicKey, tMintKey) - const [feeAccount, feePayerBump] = - await AuctionHouseProgram.findAuctionHouseFeeAddress(auctionHouse) - - const [treasuryAccount, treasuryBump] = - await AuctionHouseProgram.findAuctionHouseTreasuryAddress(auctionHouse) - - const auctionHouseCreateInstruction = createCreateAuctionHouseInstruction( - { - treasuryMint: tMintKey, - payer: wallet.publicKey, - authority: wallet.publicKey, - feeWithdrawalDestination: fwdKey, - treasuryWithdrawalDestination: twdAta, - treasuryWithdrawalDestinationOwner: twdKey, - auctionHouse, - auctionHouseFeeAccount: feeAccount, - auctionHouseTreasury: treasuryAccount, + // Check if auctionHouse already exists, if exist dont add createInstruction, just return auctionHouse + const ahQuery = useQuery(GET_AUCTION_HOUSE, { + variables: { + address: auctionHouse.toBase58(), }, - { - bump, - feePayerBump, - treasuryBump, - sellerFeeBasisPoints, - requiresSignOff, - canChangeSalePrice, - } - ) + }) + const ahData = ahQuery.data?.auctionHouse + + let auctionHouseCreateInstruction + + if (!ahData) { + const [feeAccount, feePayerBump] = + await AuctionHouseProgram.findAuctionHouseFeeAddress(auctionHouse) + + const [treasuryAccount, treasuryBump] = + await AuctionHouseProgram.findAuctionHouseTreasuryAddress(auctionHouse) + + auctionHouseCreateInstruction = createCreateAuctionHouseInstruction( + { + treasuryMint: tMintKey, + payer: wallet.publicKey, + authority: wallet.publicKey, + feeWithdrawalDestination: fwdKey, + treasuryWithdrawalDestination: twdAta, + treasuryWithdrawalDestinationOwner: twdKey, + auctionHouse, + auctionHouseFeeAccount: feeAccount, + auctionHouseTreasury: treasuryAccount, + }, + { + bump, + feePayerBump, + treasuryBump, + sellerFeeBasisPoints, + requiresSignOff, + canChangeSalePrice, + } + ) + } return { auctionHouseCreateInstruction, address: auctionHouse.toBase58() } }) @@ -179,7 +208,9 @@ async function assembleAuctionHouses( result.forEach((r) => { auctionHouses.push({ address: r.address }) - instructions.push(r.auctionHouseCreateInstruction) + if (r.auctionHouseCreateInstruction) { + instructions.push(r.auctionHouseCreateInstruction) + } }) return { auctionHouses, instructions } @@ -410,6 +441,18 @@ const AdminEditTokens = ({ marketplace }: AdminEditTokensProps) => { tokenInfo={tokenMap.get(field.address)} loading={loadingTokens} /> + {!isSol(field.address) && ( +
+ {/* +- Make default +- */} + remove(index)} + size="2rem" + /> +
+ )} ) })} From eaa03909d31ea7438bb2e5fe06838acaa3e66c10 Mon Sep 17 00:00:00 2001 From: Anshul Goel Date: Thu, 21 Jul 2022 12:45:56 +0530 Subject: [PATCH 2/2] fix: use client to query outside component --- src/pages/admin/tokens/edit.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/admin/tokens/edit.tsx b/src/pages/admin/tokens/edit.tsx index b0d41188..d2d789e0 100644 --- a/src/pages/admin/tokens/edit.tsx +++ b/src/pages/admin/tokens/edit.tsx @@ -160,7 +160,8 @@ async function assembleAuctionHouses( await AuctionHouseProgram.findAuctionHouseAddress(publicKey, tMintKey) // Check if auctionHouse already exists, if exist dont add createInstruction, just return auctionHouse - const ahQuery = useQuery(GET_AUCTION_HOUSE, { + const ahQuery = await client.query({ + query: GET_AUCTION_HOUSE, variables: { address: auctionHouse.toBase58(), },