From d6bad1bcf1c99a0708632153c8bf88dcd4c63258 Mon Sep 17 00:00:00 2001 From: Will Sewell Date: Wed, 25 Feb 2026 13:58:47 +0000 Subject: [PATCH] Use useSonarEntities with entity dropdown in sale phase --- src/app/page.tsx | 85 ++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index a512478..278232a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,13 +1,11 @@ "use client"; import { useState, useEffect } from "react"; -import { saleUUID, sonarHomeURL } from "@/lib/config"; +import { saleUUID, sonarHomeURL, sonarConfig } from "@/lib/config"; import { useAccount } from "wagmi"; import { SaleEligibility } from "@echoxyz/sonar-core"; import { EntityCard } from "./components/entity/EntityCard"; -import { NotEligibleMessage } from "./components/sale/NotEligibleMessage"; import { AuthenticationSection } from "./components/auth/AuthenticationSection"; -import { useSonarEntity } from "./hooks/use-sonar-entity"; import { useSonarEntities } from "./hooks/use-sonar-entities"; import { useSession } from "./hooks/use-session"; import CommitCard from "./components/sale/CommitCard"; @@ -18,6 +16,7 @@ import { CommitmentDataCard } from "./components/sale/CommitmentDataCard"; export default function Home() { const [saleIsLive, setSaleIsLive] = useState(false); + const [selectedEntityId, setSelectedEntityId] = useState(undefined); const { sonarConnected } = useSession(); const { address } = useAccount(); @@ -36,15 +35,15 @@ export default function Home() { localStorage.setItem("sale_is_live", String(newState)); }; - // Registration data (all entities for the user) + // Entities data const { loading: entitiesLoading, entities, error: entitiesError } = useSonarEntities(); const eligibleEntities = entities?.filter((entity) => entity.SaleEligibility === SaleEligibility.ELIGIBLE) || []; - // Sale data (entity for current wallet) - const { loading: entityLoading, entity, error: entityError } = useSonarEntity(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) { @@ -56,7 +55,7 @@ export default function Home() { ); } - if (entityLoading) { + if (entitiesLoading) { return (

Loading your entity information...

@@ -64,22 +63,22 @@ export default 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.

@@ -98,19 +97,40 @@ export default 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 + + . +

+ )}
); }; @@ -194,22 +214,23 @@ export default function Home() {
{sonarConnected && (
-

Your Entity Information

- - {isEligible && address && ( +
+

Your Entity Information

+ +
+ + {isEligible && address && selectedEntity && (

Commit funds

)} - - {entity && !isEligible && }
)}