From f77711b0885afbe32ff65c0b609d2dd1b1d17cd9 Mon Sep 17 00:00:00 2001 From: Michael Merz Date: Tue, 12 Dec 2023 14:58:51 -0500 Subject: [PATCH 1/2] wip: start call for enterprise query --- frontend/src/pages/nft/NFTs.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/pages/nft/NFTs.tsx b/frontend/src/pages/nft/NFTs.tsx index 3d5da5d..e63ff3d 100644 --- a/frontend/src/pages/nft/NFTs.tsx +++ b/frontend/src/pages/nft/NFTs.tsx @@ -29,6 +29,7 @@ export const NFTsPage = () => { useAllMintedNFTsFromCollection() const { data: userNfts } = useUserNFTsFromCollection(walletAddress) + const { data: userStakedNfts } = useUserNFTsFromStaked(walletAddress) const [activeTab, setActiveTab] = useState("all") From 95c37d4f09e33f09a80030a915286c82432e2a40 Mon Sep 17 00:00:00 2001 From: Michael Merz Date: Tue, 12 Dec 2023 15:55:52 -0500 Subject: [PATCH 2/2] feat: query staking contract for nfts. --- frontend/src/config/index.ts | 8 +- frontend/src/hooks/index.ts | 1 + frontend/src/hooks/useUserNFTsFromStaking.tsx | 22 ++++ frontend/src/pages/modal/ClaimModalPage.tsx | 2 +- frontend/src/pages/nft/NFTs.tsx | 102 ++++-------------- 5 files changed, 52 insertions(+), 83 deletions(-) create mode 100644 frontend/src/hooks/useUserNFTsFromStaking.tsx diff --git a/frontend/src/config/index.ts b/frontend/src/config/index.ts index e140fb3..cac7796 100644 --- a/frontend/src/config/index.ts +++ b/frontend/src/config/index.ts @@ -9,13 +9,13 @@ export const NFT_PREVIEW_URL = // export const IPFS_NFT_URL = // "https://ipfs.io/ipfs/bafybeiaxgi4be5krl72hxlaqwafz4xmnint3il3sptcrehrizsiuqh6r7q/{id}.png" - // "https://ipfs.io/ipfs/bafybeiaxgi4be5krl72hxlaqwafz4xmnint3il3sptcrehrizsiuqh6r7q/{id}.png" - +// "https://ipfs.io/ipfs/bafybeiaxgi4be5krl72hxlaqwafz4xmnint3il3sptcrehrizsiuqh6r7q/{id}.png" export type AllianceContractConfig = { minter: AccAddress collection: AccAddress dao: AccAddress + daoStaking: AccAddress } export const contracts: Record = { @@ -24,11 +24,15 @@ export const contracts: Record = { collection: "terra1phr9fngjv7a8an4dhmhd0u0f98wazxfnzccqtyheq4zqrrp4fpuqw3apw9", dao: "terra1g0mfrpswewteaf9ky4rlj09wh5njp6u9xxk94uszplw4qz2f9mzq3k27fm", + daoStaking: + "terra1e54tcdyulrtslvf79htx4zntqntd4r550cg22sj24r6gfm0anrvq0y8tdv", }, "pisco-1": { minter: "terra1a78x4w8da7ycdfj3dryrelvwa2p8t7vxk8t0tfvtuduf00aw5y5qnurwru", collection: "terra1herk30j8sgn3dlth4g0haw6n3j2nwxfn6d4vwucaf48qwzsfe5wqa7h8f4", dao: "terra1tay6vaymstcg95z4lwpaxujhzsnqylu39hl3328556y5edzsf8ysuzrtnq", + daoStaking: + "terra1e54tcdyulrtslvf79htx4zntqntd4r550cg22sj24r6gfm0anrvq0y8tdv", }, } diff --git a/frontend/src/hooks/index.ts b/frontend/src/hooks/index.ts index 42f6f35..50fc79f 100644 --- a/frontend/src/hooks/index.ts +++ b/frontend/src/hooks/index.ts @@ -1,5 +1,6 @@ export { default as useAllMintedNFTsFromCollection } from "./useAllMintedNFTsFromCollection" export { default as useNFTFromCollection } from "./useNFTFromCollection" +export { default as useUserNFTsFromStaking } from "./useUserNFTsFromStaking" export { default as useUserNFTsFromCollection } from "./useUserNFTsFromCollection" export { default as useNFTFromMinter } from "./useNFTFromMinter" export { default as useAllianceContracts } from "./useAllianceContracts" diff --git a/frontend/src/hooks/useUserNFTsFromStaking.tsx b/frontend/src/hooks/useUserNFTsFromStaking.tsx new file mode 100644 index 0000000..e82fbf1 --- /dev/null +++ b/frontend/src/hooks/useUserNFTsFromStaking.tsx @@ -0,0 +1,22 @@ +import { useQuery } from "@tanstack/react-query" +import { TokensResponse } from "types/AllianceNftCollection" +import { useAppContext } from "contexts" + +const useUserNFTsFromStaking = (userAddress: string | undefined) => { + const { contractAddresses, chainId, lcd } = useAppContext() + + return useQuery({ + queryKey: ["user_staked_nfts", userAddress, chainId], + queryFn: () => { + return lcd.wasm + .contractQuery(contractAddresses.daoStaking, { + user_stake: { + user: userAddress, + }, + }) + .then((res) => res) + }, + }) +} + +export default useUserNFTsFromStaking diff --git a/frontend/src/pages/modal/ClaimModalPage.tsx b/frontend/src/pages/modal/ClaimModalPage.tsx index a891065..b09ac58 100644 --- a/frontend/src/pages/modal/ClaimModalPage.tsx +++ b/frontend/src/pages/modal/ClaimModalPage.tsx @@ -81,7 +81,7 @@ export const ClaimModalPage = () => { }) .catch((error: unknown) => { setIsPending(false) - console.error("error in promise", error) + console.error(error) }) } } diff --git a/frontend/src/pages/nft/NFTs.tsx b/frontend/src/pages/nft/NFTs.tsx index e63ff3d..2465cc3 100644 --- a/frontend/src/pages/nft/NFTs.tsx +++ b/frontend/src/pages/nft/NFTs.tsx @@ -2,10 +2,11 @@ import { useState } from "react" import classNames from "classnames/bind" import NFTItem from "components/nft/NFTItem" import { NFT_PREVIEW_URL } from "config" -// import { ReactComponent as FilterIcon } from "assets/Filter.svg" + import { useAllMintedNFTsFromCollection, useUserNFTsFromCollection, + useUserNFTsFromStaking, } from "hooks" import { useAppContext } from "contexts" import styles from "./NFTs.module.scss" @@ -20,56 +21,27 @@ export interface GalleryFiltersProps { } export const NFTsPage = () => { - // const [showFilterRow, setShowFilterRow] = useState(false) - // const [searchValue, setSearchValue] = useState("") - // const [searchLoading, setSearchLoading] = useState(false) - + /* Get user address from app store */ const { walletAddress } = useAppContext() + + /* Query All Minted NFTs from Collection */ const { data: allNfts, isLoading: areNftsLoading } = useAllMintedNFTsFromCollection() - const { data: userNfts } = useUserNFTsFromCollection(walletAddress) - const { data: userStakedNfts } = useUserNFTsFromStaked(walletAddress) - - const [activeTab, setActiveTab] = useState("all") - - // const [galleryFilters, setGalleryFilters] = useState({ - // planetNumber: null, - // planetNames: [], - // planetInhabitants: [], - // nftObjects: [], - // }) - - // useEffect(() => { - // if ( - // !galleryFilters.planetNames.length && - // !galleryFilters.planetInhabitants.length && - // !galleryFilters.nftObjects.length - // ) { - // setDisplayedNFTs(mockNFTs) - // return - // } + /* Query User NFTs from Collection */ + const { data: userNftsFromCollection } = + useUserNFTsFromCollection(walletAddress) - // const filtered = filterNFTs(mockNFTs, galleryFilters) - // setDisplayedNFTs(filtered) - // }, [galleryFilters]) + /* Query User NFTs from Staking contract */ + const { data: userStakedNfts } = useUserNFTsFromStaking(walletAddress) - // useEffect(() => { - // if (!searchValue) { - // setSearchLoading(false) - // setDisplayedNFTs(mockNFTs) - // return - // } + /* Merge User NFTs from Collection and Staking */ + const userNfts: { id: string; staked?: boolean }[] = [ + ...(userNftsFromCollection?.tokens.map((nft) => ({ id: nft })) || []), + ...(userStakedNfts?.tokens.map((nft) => ({ id: nft, staked: true })) || []), + ] - // setSearchLoading(true) - // setTimeout(() => { - // const filtered = mockNFTs.filter( - // (nft) => nft.id.toString() === searchValue - // ) - // setDisplayedNFTs(filtered) - // setSearchLoading(false) - // }, 1000) - // }, [searchValue]) + const [activeTab, setActiveTab] = useState("all") const handleSwitch = (tab: string) => { if (tab === "all" && activeTab === "all") { @@ -80,10 +52,8 @@ export const NFTsPage = () => { if (tab === "all") { setActiveTab("all") - // setShowFilterRow(false) } else { setActiveTab("my") - // setShowFilterRow(false) } } @@ -91,18 +61,6 @@ export const NFTsPage = () => {
- {/* {activeTab === "all" && ( - - )} */} )}
- {/* {activeTab === "all" && showFilterRow && ( - <> - - - - )} */} - {activeTab === "all" ? ( !areNftsLoading && allNfts && ( @@ -158,12 +100,12 @@ export const NFTsPage = () => { ) ) : (
- {userNfts?.tokens.map((nft) => ( + {userNfts.map((nft) => ( ))}