Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/show staked nfts #31

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions frontend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SupportedNetwork, AllianceContractConfig> = {
Expand All @@ -24,11 +24,15 @@ export const contracts: Record<SupportedNetwork, AllianceContractConfig> = {
collection:
"terra1phr9fngjv7a8an4dhmhd0u0f98wazxfnzccqtyheq4zqrrp4fpuqw3apw9",
dao: "terra1g0mfrpswewteaf9ky4rlj09wh5njp6u9xxk94uszplw4qz2f9mzq3k27fm",
daoStaking:
"terra1e54tcdyulrtslvf79htx4zntqntd4r550cg22sj24r6gfm0anrvq0y8tdv",
},
"pisco-1": {
minter: "terra1a78x4w8da7ycdfj3dryrelvwa2p8t7vxk8t0tfvtuduf00aw5y5qnurwru",
collection:
"terra1herk30j8sgn3dlth4g0haw6n3j2nwxfn6d4vwucaf48qwzsfe5wqa7h8f4",
dao: "terra1tay6vaymstcg95z4lwpaxujhzsnqylu39hl3328556y5edzsf8ysuzrtnq",
daoStaking:
"terra1e54tcdyulrtslvf79htx4zntqntd4r550cg22sj24r6gfm0anrvq0y8tdv",
},
}
1 change: 1 addition & 0 deletions frontend/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 22 additions & 0 deletions frontend/src/hooks/useUserNFTsFromStaking.tsx
Original file line number Diff line number Diff line change
@@ -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<TokensResponse, Error>({
queryKey: ["user_staked_nfts", userAddress, chainId],
queryFn: () => {
return lcd.wasm
.contractQuery<TokensResponse>(contractAddresses.daoStaking, {
user_stake: {
user: userAddress,
},
})
.then((res) => res)
},
})
}

export default useUserNFTsFromStaking
2 changes: 1 addition & 1 deletion frontend/src/pages/modal/ClaimModalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const ClaimModalPage = () => {
})
.catch((error: unknown) => {
setIsPending(false)
console.error("error in promise", error)
console.error(error)
})
}
}
Expand Down
101 changes: 22 additions & 79 deletions frontend/src/pages/nft/NFTs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,55 +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 [activeTab, setActiveTab] = useState("all")

// const [galleryFilters, setGalleryFilters] = useState<GalleryFiltersProps>({
// 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") {
Expand All @@ -79,29 +52,15 @@ export const NFTsPage = () => {

if (tab === "all") {
setActiveTab("all")
// setShowFilterRow(false)
} else {
setActiveTab("my")
// setShowFilterRow(false)
}
}

return (
<main className={styles.main}>
<section className={styles.main__content}>
<div className={styles.buttons}>
{/* {activeTab === "all" && (
<button
className={styles.filter__toggle}
onClick={() => setShowFilterRow(!showFilterRow)}
>
<FilterIcon
fill={"var(--token-dark-700)"}
height={16}
width={16}
/>
</button>
)} */}
<button
className={cx(styles.button, {
[styles.button__selected]: activeTab === "all",
Expand All @@ -118,27 +77,11 @@ export const NFTsPage = () => {
onClick={() => handleSwitch("my")}
>
My NFTs
<span className={styles.button__count}>
{userNfts?.tokens.length}
</span>
<span className={styles.button__count}>{userNfts.length}</span>
</button>
)}
</div>

{/* {activeTab === "all" && showFilterRow && (
<>
<SearchByID
setSearchValue={setSearchValue}
searchValue={searchValue}
isLoading={searchLoading}
/>
<FilterDropdowns
galleryFilters={galleryFilters}
setGalleryFilters={setGalleryFilters}
/>
</>
)} */}

{activeTab === "all" ? (
!areNftsLoading &&
allNfts && (
Expand All @@ -157,12 +100,12 @@ export const NFTsPage = () => {
)
) : (
<div className={styles.grid}>
{userNfts?.tokens.map((nft) => (
{userNfts.map((nft) => (
<NFTItem
key={nft}
id={parseInt(nft)}
imageUrl={NFT_PREVIEW_URL.replace("{id}", nft)}
title={nft.toString()}
key={nft.id}
id={parseInt(nft.id)}
imageUrl={NFT_PREVIEW_URL.replace("{id}", nft.id)}
title={nft.id.toString()}
/>
))}
</div>
Expand Down