Skip to content

Commit

Permalink
refactor: use viem isAddressEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Feb 19, 2025
1 parent 97bbaf5 commit cebbc81
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/communities/communityUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nftContracts } from '@/lib/contracts'
import { ReactNode } from 'react'

interface CommunityItem {
export interface CommunityItem {
leftImageSrc: string
title: string
subtitle: string
Expand Down
15 changes: 6 additions & 9 deletions src/app/communities/nft/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,12 @@ export default function Page() {
<div className="font-semibold">{nftInfo?.title}</div>
</div>
<div className="mb-[24px] font-extralight">{nftInfo?.longDescription}</div>
{hasActiveCampaign &&
isBoosted &&
boostData &&
isAddressEqual(boostData.nftContractAddress, nftAddress) && (
<div className="inline-flex items-center gap-1 pb-6">
<BoltSvg />
<GlowingLabel>Boosted {20}%</GlowingLabel>
</div>
)}
{hasActiveCampaign && isBoosted && boostData && boostData.nftContractAddress === nftAddress && (
<div className="inline-flex items-center gap-1 pb-6">
<BoltSvg />
<GlowingLabel>Boosted {20}%</GlowingLabel>
</div>
)}
{/* Hidden until we get social media data */}
<div className="gap-[8px] mt-[16px] mb-[24px] hidden">
{/* Chips with community links */}
Expand Down
2 changes: 1 addition & 1 deletion src/app/providers/NFT/BoosterContext.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query'
import { render, renderHook, screen, waitFor } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, Mock, vi } from 'vitest'
import { afterEach, describe, expect, it, vi, beforeEach } from 'vitest'
import { useAccount } from 'wagmi'
import { BoosterProvider, useFetchBoostData, useNFTBoosterContext } from './BoosterContext'

Expand Down
9 changes: 6 additions & 3 deletions src/app/providers/NFT/BoosterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AVERAGE_BLOCKTIME, NFT_BOOSTER_DATA_URL } from '@/lib/constants'
import { useQuery } from '@tanstack/react-query'
import axios from 'axios'
import { createContext, ReactNode, useContext, useMemo } from 'react'
import { Address } from 'viem'
import { Address, isAddressEqual } from 'viem'
import { useAccount } from 'wagmi'

interface HolderRewards {
Expand Down Expand Up @@ -52,7 +52,10 @@ export const BoosterProvider = ({ children }: BoosterContextProviderProps) => {
return { boostData, isLoading, error, hasActiveCampaign }
}

const currentBoost = boostData?.holders[address]
const [, currentBoost] =
Object.entries(boostData?.holders ?? {}).find(
([key]) => key.toLocaleLowerCase() === address.toLocaleLowerCase(),
) ?? []
const isBoosted =
currentBoost &&
(currentBoost.boostedRBTCRewards > 0 ||
Expand Down Expand Up @@ -93,7 +96,7 @@ export const useFetchBoostData = () => {
queryFn: async () => {
const { data } = await axiosInstance.get(`${NFT_BOOSTER_DATA_URL}/${latestFile}`)

return data
return { ...data, nftContractAddress: data.nftContractAddress.toLowerCase() }
},
queryKey: ['nftBoosterData'],
refetchInterval: AVERAGE_BLOCKTIME,
Expand Down
8 changes: 4 additions & 4 deletions src/app/shared/components/NFTBoosterCard/NFTBoosterCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const NFTBoosterCard: FC<NFTBoosterCardProps> = ({ nftThumbPath, boostVal
>
<g filter="url(#filter0_f_773_18628)">
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M17.7212 18.0696H259.721V74.0696H17.7212V18.0696ZM21.7212 22.0696V70.0696H255.721V22.0696H21.7212Z"
fill="url(#paint0_linear_773_18628)"
/>
Expand All @@ -34,9 +34,9 @@ export const NFTBoosterCard: FC<NFTBoosterCardProps> = ({ nftThumbPath, boostVal
width="276.2"
height="90.2"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB"
colorInterpolationFilters="sRGB"
>
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feFlood floodOpacity="0" result="BackgroundImageFix" />
<feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape" />
<feGaussianBlur stdDeviation="8.55" result="effect1_foregroundBlur_773_18628" />
</filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useNFTBoosterContext } from '@/app/providers/NFT/BoosterContext'
import { NFTBoosterCard } from '@/app/shared/components'
import { FC } from 'react'
import { communitiesMapByContract } from '../../../communities/communityUtils'
import { communitiesMapByContract } from '@/app/communities/communityUtils'

export const SelfContainedNFTBoosterCard: FC = () => {
const { hasActiveCampaign, currentBoost, boostData } = useNFTBoosterContext()
const { title } = communitiesMapByContract[boostData?.nftContractAddress ?? ''] ?? {}
const { title } = boostData?.nftContractAddress
? communitiesMapByContract[boostData.nftContractAddress]
: {}

return (
hasActiveCampaign &&
Expand Down

0 comments on commit cebbc81

Please sign in to comment.