Skip to content

Commit

Permalink
Refactor SWR keys and RecentAttestations component to support portal …
Browse files Browse the repository at this point in the history
…and schema-specific recent attestations
  • Loading branch information
Chirag-S-Kotian committed Nov 29, 2024
1 parent 5beac7a commit bdb1f88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions explorer/src/interfaces/swr/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export enum SWRKeys {
GET_RELATED_ATTESTATION = "getRelatedAttestations",
GET_ATTESTATION_LIST = "getAttestationList",
GET_ATTESTATION_COUNT = "getAttestationCount",
GET_RECENT_ATTESTATION = "getRecentAttestations",
GET_RECENT_ATTESTATION_SCHEMA = "getRecentAttestationsSchema",
GET_RECENT_ATTESTATION_PORTAL = "getRecentAttestationsPortal",
GET_RECENT_ATTESTATION_GLOBAL = "getRecentAttestations",
GET_MODULE_LIST = "getModuleList",
GET_MODULE_COUNT = "getModuleCount",
SEARCH = "search",
GET_PORTALS_BY_ISSUER = "getPortalsByIssuer",
GET_PORTAL_BY_ID = "getPortalByID",
GET_PORTAL_MODULE_LIST = "getPortalModuleList",
GET_PORTAL_LIST = "getPortalList",
GET_RECENT_ATTESTATION_GLOBAL = "GET_RECENT_ATTESTATION_GLOBAL",
}
2 changes: 2 additions & 0 deletions explorer/src/pages/Portal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useNetworkContext } from "@/providers/network-provider/context";

import { PortalLoadingSkeleton } from "./components/PortalLoadingSkeleton";
import { PortalModules } from "./components/PortalModules";
import { RecentAttestations } from "../Schema/components/RecentAttestations";

export const Portal = () => {
const { id } = useParams();
Expand Down Expand Up @@ -92,6 +93,7 @@ export const Portal = () => {
))}
</div>
</div>
<RecentAttestations portalId={portal.id} />
<PortalModules portalModules={portal.modules} />
</section>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ import { SWRKeys } from "@/interfaces/swr/enum";
import { useNetworkContext } from "@/providers/network-provider/context";
import { APP_ROUTES } from "@/routes/constants";

export const RecentAttestations: React.FC<{ schemaId?: string }> = ({ schemaId }) => {
export const RecentAttestations: React.FC<{ schemaId?: string; portalId?: string }> = ({ schemaId, portalId }) => {
const {
sdk,
network: { chain, network },
} = useNetworkContext();

const fetchKey = schemaId
? `${SWRKeys.GET_RECENT_ATTESTATION}/${schemaId}/${chain.id}`
? `${SWRKeys.GET_RECENT_ATTESTATION_SCHEMA}/${schemaId}/${chain.id}`
: portalId
? `${SWRKeys.GET_RECENT_ATTESTATION_PORTAL}/${portalId}/${chain.id}`
: `${SWRKeys.GET_RECENT_ATTESTATION_GLOBAL}/${chain.id}`;

const fetchFunction = schemaId
? () => sdk.attestation.findBy(5, 0, { schema: schemaId }, "attestedDate", "desc")
: portalId
? () => sdk.attestation.findBy(5, 0, { portal: portalId }, "attestedDate", "desc")
: () => sdk.attestation.findBy(5, 0, {}, "attestedDate", "desc");

const { data: attestations, isLoading } = useSWR(fetchKey, fetchFunction, {
Expand Down

0 comments on commit bdb1f88

Please sign in to comment.