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

[UI] View badges mint status on Discover badges page #1280

Open
wants to merge 1 commit into
base: sepolia
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/pages/canvas-badge/Badges/BadgeList/BadgeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const useStyles = makeStyles()(theme => ({
}))

const BadgeCard = props => {
const { name, image, description, badgeContract, issuer, category, count, className } = props
const { name, minted, image, description, badgeContract, issuer, category, count, className } = props
const { classes } = useStyles()
const { isMobile } = useCheckViewport()

Expand All @@ -50,7 +50,7 @@ const BadgeCard = props => {
borderRadius: "2rem",
backgroundColor: "themeBackground.tag",
boxShadow: "none",
border: "none",
border: minted ? "2px solid green" : "none",
userSelect: "none",
cursor: "pointer",
"& p": {
Expand Down
19 changes: 16 additions & 3 deletions src/pages/canvas-badge/Badges/BadgeList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { ReactComponent as ArrowDownSvg } from "@/assets/svgs/canvas-badge/arrow
import LoadingButton from "@/components/LoadingButton"
import LoadingPage from "@/components/LoadingPage"
import { CANVAS_AND_BADGES_PAGE_SYMBOL, CATEGORY_LIST, SORT_LIST } from "@/constants"
import { CHAIN_ID } from "@/constants"
import { useRainbowContext } from "@/contexts/RainbowProvider"
import { checkIfHasBadgeByAddress } from "@/services/canvasService"
import { isAboveScreen } from "@/utils/dom"

import BadgeCard from "./BadgeCard"
Expand All @@ -20,6 +23,8 @@ import NoData from "./NoData"
const PAGE_SIZE = 20

const BadgeList = props => {
const { walletCurrentAddress, chainId, provider } = useRainbowContext()
const isL2 = useMemo(() => chainId === CHAIN_ID.L2, [chainId])
const {
searchParams: { category, sort, keyword, page },
onAddPage,
Expand Down Expand Up @@ -48,16 +53,24 @@ const BadgeList = props => {
const searchParamsStr = searchParams.toString()
return searchParamsStr ? `?${searchParamsStr}` : ""
}, [category, sort, keyword, page])

const setBadgesMintStatus = function (data) {
if (provider && isL2) {
data.forEach((badge, index) => {
checkIfHasBadgeByAddress(provider, walletCurrentAddress, badge.badgeContract).then(mintStatus => {
data[index].minted = mintStatus
})
})
}
}
useEffect(() => {
fetchBadgeList(`${queryStr}&page_size=${PAGE_SIZE}`)
}, [queryStr])

}, [queryStr, provider, walletCurrentAddress])
const fetchBadgeList = value => {
setLoading(true)
scrollRequest(`${fetchBadgesURL}${value}`)
.then(({ data, total }) => {
setHasMore((page - 1) * PAGE_SIZE + data.length < total)
setBadgesMintStatus(data)
if (prePage && page - prePage === 1) {
setBadgeList(pre => pre.concat(data))
} else {
Expand Down