From 00a252240279f3642bd04ba2e0e2c15d2e763cd6 Mon Sep 17 00:00:00 2001 From: Matthew Bunday Date: Tue, 13 Aug 2024 16:29:37 -0400 Subject: [PATCH] Add buildathon participant SBT badge (#833) --- apps/web/src/abis/BuildathonSBT.ts | 9 +++++++++ .../Badges/index.tsx | 4 ++-- .../hooks/useBaseGuild.ts | 0 .../hooks/useBuildathonParticipant.ts | 19 +++++++++++++++++++ .../hooks/useCoinbaseVerifications.ts | 0 .../hooks/useTalentProtocol.ts | 0 .../UsernameProfileSectionBadges/index.tsx | 12 +++++++----- 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 apps/web/src/abis/BuildathonSBT.ts rename apps/web/src/{ => components/Basenames/UsernameProfileSectionBadges}/hooks/useBaseGuild.ts (100%) create mode 100644 apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useBuildathonParticipant.ts rename apps/web/src/{ => components/Basenames/UsernameProfileSectionBadges}/hooks/useCoinbaseVerifications.ts (100%) rename apps/web/src/{ => components/Basenames/UsernameProfileSectionBadges}/hooks/useTalentProtocol.ts (100%) diff --git a/apps/web/src/abis/BuildathonSBT.ts b/apps/web/src/abis/BuildathonSBT.ts new file mode 100644 index 0000000..7283058 --- /dev/null +++ b/apps/web/src/abis/BuildathonSBT.ts @@ -0,0 +1,9 @@ +export default [ + { + inputs: [{ internalType: 'address', name: 'owner', type: 'address' }], + name: 'balanceOf', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, +] as const; diff --git a/apps/web/src/components/Basenames/UsernameProfileSectionBadges/Badges/index.tsx b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/Badges/index.tsx index ad293df..28abe13 100644 --- a/apps/web/src/components/Basenames/UsernameProfileSectionBadges/Badges/index.tsx +++ b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/Badges/index.tsx @@ -1,6 +1,6 @@ -import { CoinbaseVerifications } from 'apps/web/src/hooks/useCoinbaseVerifications'; +import { CoinbaseVerifications } from '../hooks/useCoinbaseVerifications'; import { StaticImageData } from 'next/dist/shared/lib/get-img-props'; -import { GuildBadges } from 'apps/web/src/hooks/useBaseGuild'; +import { GuildBadges } from '../hooks/useBaseGuild'; // image imports import verifiedIdentity from './images/verifiedIdentity.webp'; diff --git a/apps/web/src/hooks/useBaseGuild.ts b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useBaseGuild.ts similarity index 100% rename from apps/web/src/hooks/useBaseGuild.ts rename to apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useBaseGuild.ts diff --git a/apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useBuildathonParticipant.ts b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useBuildathonParticipant.ts new file mode 100644 index 0000000..10a51a9 --- /dev/null +++ b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useBuildathonParticipant.ts @@ -0,0 +1,19 @@ +import { useReadContract } from 'wagmi'; +import BuildathonSBT from 'apps/web/src/abis/BuildathonSBT'; + +const PARTICIPANT_SBT_ADDRESS = '0x59ca61566C03a7Fb8e4280d97bFA2e8e691DA3a6'; + +export default function useBuildathonParticipant(address?: `0x${string}`): boolean { + const { data: balanceOf } = useReadContract({ + address: PARTICIPANT_SBT_ADDRESS, + abi: BuildathonSBT, + functionName: 'balanceOf', + args: [address ?? '0x'], + query: { + enabled: !!address, + }, + }); + + if (!balanceOf) return false; + return balanceOf > 0; +} diff --git a/apps/web/src/hooks/useCoinbaseVerifications.ts b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useCoinbaseVerifications.ts similarity index 100% rename from apps/web/src/hooks/useCoinbaseVerifications.ts rename to apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useCoinbaseVerifications.ts diff --git a/apps/web/src/hooks/useTalentProtocol.ts b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useTalentProtocol.ts similarity index 100% rename from apps/web/src/hooks/useTalentProtocol.ts rename to apps/web/src/components/Basenames/UsernameProfileSectionBadges/hooks/useTalentProtocol.ts diff --git a/apps/web/src/components/Basenames/UsernameProfileSectionBadges/index.tsx b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/index.tsx index 7becde8..ee92ef3 100644 --- a/apps/web/src/components/Basenames/UsernameProfileSectionBadges/index.tsx +++ b/apps/web/src/components/Basenames/UsernameProfileSectionBadges/index.tsx @@ -5,9 +5,10 @@ import { BadgeNames, } from 'apps/web/src/components/Basenames/UsernameProfileSectionBadges/Badges'; import UsernameProfileSectionTitle from 'apps/web/src/components/Basenames/UsernameProfileSectionTitle'; -import { useBaseGuild } from 'apps/web/src/hooks/useBaseGuild'; -import { useCoinbaseVerification } from 'apps/web/src/hooks/useCoinbaseVerifications'; -import { useTalentProtocol } from 'apps/web/src/hooks/useTalentProtocol'; +import { useBaseGuild } from './hooks/useBaseGuild'; +import { useCoinbaseVerification } from './hooks/useCoinbaseVerifications'; +import { useTalentProtocol } from './hooks/useTalentProtocol'; +import useBuildathonParticipant from './hooks/useBuildathonParticipant'; import { useMemo } from 'react'; function BadgesLoop({ @@ -68,10 +69,11 @@ function BuilderSection() { const { profileAddress, currentWalletIsOwner } = useUsernameProfile(); const { badges, empty } = useBaseGuild(profileAddress); const talentScore = useTalentProtocol(profileAddress); + const buildathonParticipant = useBuildathonParticipant(profileAddress); const combinedBadges = useMemo( - () => ({ ...badges, TALENT_SCORE: talentScore }), - [badges, talentScore], + () => ({ ...badges, TALENT_SCORE: talentScore, BUILDATHON_PARTICIPANT: buildathonParticipant }), + [badges, talentScore, buildathonParticipant], ); const combinedEmpty = empty && !talentScore;