From 62cce4c319052caf649a6797261ca06d2891dbd7 Mon Sep 17 00:00:00 2001 From: Will Sewell Date: Wed, 25 Feb 2026 11:55:20 +0000 Subject: [PATCH] Use useSonarEntities with entity dropdown in sale phase Replace useSonarEntity with useSonarEntities so a single hook call serves both the registration and sale phases. In the sale phase, show a dropdown to select the active entity when multiple entities exist (hidden when only one entity is present). Remove the redundant NotEligibleMessage box since EntityCard already surfaces eligibility state via EntityStateDescription. --- src/pages/Home.tsx | 87 ++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index ca753bc..fa4af52 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -1,19 +1,19 @@ import { useState, useEffect } from "react"; import { ConnectKitButton } from "connectkit"; -import { useSonarAuth, useSonarEntity, useSonarEntities } from "@echoxyz/sonar-react"; -import { saleUUID, sonarHomeURL, sonarConfig } from "../config"; +import { useSonarAuth, useSonarEntities } from "@echoxyz/sonar-react"; +import { saleUUID, sonarConfig } from "../config"; import { useAccount } from "wagmi"; import CommitCard from "../components/sale/CommitCard"; import { SaleEligibility } from "@echoxyz/sonar-core"; import { AuthenticationSection } from "../components/auth/AuthenticationSection"; import { EntityCard } from "../components/entity/EntityCard"; -import { NotEligibleMessage } from "../components/sale/NotEligibleMessage"; import { EntitiesList } from "../components/registration/EntitiesList"; import { EligibilityResults } from "../components/registration/EligibilityResults"; import { CommitmentDataCard } from "../components/sale/CommitmentDataCard"; export function Home() { const [saleIsLive, setSaleIsLive] = useState(false); + const [selectedEntityId, setSelectedEntityId] = useState(undefined); // Load sale state from localStorage useEffect(() => { @@ -34,7 +34,7 @@ export function Home() { const { address } = useAccount(); const { login, authenticated, logout, ready } = useSonarAuth(); - // Registration data + // Entities data const { loading: entitiesLoading, entities, @@ -45,17 +45,10 @@ export function Home() { const eligibleEntities = entities?.filter((entity) => entity.SaleEligibility === SaleEligibility.ELIGIBLE) || []; - // Sale data - const { - loading: entityLoading, - entity, - error: entityError, - } = useSonarEntity({ - saleUUID: saleUUID, - walletAddress: address, - }); + // Resolve the selected entity for the sale phase (default to first entity) + const selectedEntity = entities?.find((e) => e.EntityID === selectedEntityId) ?? entities?.[0]; - const isEligible = entity && entity.SaleEligibility === SaleEligibility.ELIGIBLE; + const isEligible = selectedEntity && selectedEntity.SaleEligibility === SaleEligibility.ELIGIBLE; const EntitySection = () => { if (!address || !authenticated) { @@ -67,7 +60,7 @@ export function Home() { ); } - if (entityLoading) { + if (entitiesLoading) { return (

Loading your entity information...

@@ -75,22 +68,22 @@ export function Home() { ); } - if (entityError) { + if (entitiesError) { return (

Error

-

{entityError.message}

+

{entitiesError.message}

); } - if (!entity) { + if (!entities || entities.length === 0) { return (

No Entity Found

- No entity found for this wallet. Please link your wallet on Sonar to continue. + No entity found for this account.

@@ -109,19 +102,40 @@ export function Home() { return (
- -

- You can switch entity by connecting a wallet that is linked to one of your other entities on{" "} - - Sonar - - . -

+ {entities.length > 1 && ( +
+ + +
+ )} + {selectedEntity && } + {selectedEntity && ( +

+ You can manage and add entities on{" "} + + Sonar + + . +

+ )}
); }; @@ -207,11 +221,11 @@ export function Home() {
{/* Connection Buttons */} + {/* Entity Information */}

Your Entity Information

-
@@ -220,16 +234,13 @@ export function Home() {

Commit funds

)} - {/* Not Eligible Message */} - {entity && !isEligible && } - {/* Commitment Data Card */}

Sale Commitment Data