Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): As a Developer, I want the SDK to be compatible with the new version of the subgraph #695

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Here are the addresses on those networks:

- [Linea Sepolia](https://api.studio.thegraph.com/query/67521/verax-v2-linea-sepolia/v0.0.2)
- [Linea Mainnet](https://api.studio.thegraph.com/query/67521/verax-v2-linea/v0.0.1)
- [Linea Mainnet (Backup)](https://api.goldsky.com/api/public/project_cm06hsedxpgls01xm39r67el8/subgraphs/verax-v2-arbitrum-nova/0.0.1/gn)
- [Linea Mainnet (Backup)](https://api.goldsky.com/api/public/project_clxx488osyuf501vygg71f86w/subgraphs/verax-v2-linea/0.0.1/gn)
- [Arbitrum Sepolia](https://api.studio.thegraph.com/query/67521/verax-v2-arbitrum-sepolia/v0.0.1)
- [Arbitrum Mainnet](https://api.studio.thegraph.com/query/67521/verax-v2-arbitrum/v0.0.1)
- [Arbitrum Nova](https://api.goldsky.com/api/public/project_cm06hsedxpgls01xm39r67el8/subgraphs/verax-v2-arbitrum-nova/0.0.1/gn)
Expand Down
2 changes: 1 addition & 1 deletion explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@tanstack/react-table": "^8.10.7",
"@verax-attestation-registry/verax-sdk": "1.11.0",
"@verax-attestation-registry/verax-sdk": "2.0.0-beta.3",
"@wagmi/core": "^1.4.7",
"abitype": "^0.10.3",
"class-variance-authority": "^0.7.0",
Expand Down
48 changes: 26 additions & 22 deletions explorer/src/constants/columns/attestation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColumnDef } from "@tanstack/react-table";
import { Attestation, VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { Attestation, Portal, Schema } from "@verax-attestation-registry/verax-sdk";
import { t } from "i18next";
import moment from "moment";
import { Chain, Hex } from "viem";
Expand All @@ -10,22 +10,20 @@ import { HelperIndicator } from "@/components/HelperIndicator";
import { Link } from "@/components/Link";
import { SortByDate } from "@/components/SortByDate";
import { ColumnsOptions } from "@/interfaces/components";
import { SWRKeys } from "@/interfaces/swr/enum";
import { SWRCell } from "@/pages/Attestations/components/SWRCell";
import { toAttestationById, toPortalById, toSchemaById } from "@/routes/constants";
import { getBlockExplorerLink } from "@/utils";
import { displayAmountWithComma } from "@/utils/amountUtils";
import { cropString } from "@/utils/stringUtils";

import { EMPTY_STRING, ITEMS_PER_PAGE_DEFAULT } from "../index";
import { EMPTY_0X_STRING, EMPTY_STRING, ITEMS_PER_PAGE_DEFAULT } from "../index";

interface ColumnsProps {
sortByDate: boolean;
sdk: VeraxSdk;
chain: Chain;
}

export const columns = ({ sortByDate = true, sdk, chain }: Partial<ColumnsProps> = {}): ColumnDef<Attestation>[] => [
export const columns = ({ sortByDate = true, chain }: Partial<ColumnsProps> = {}): ColumnDef<Attestation>[] => [
{
accessorKey: "id",
header: () => (
Expand All @@ -52,33 +50,23 @@ export const columns = ({ sortByDate = true, sdk, chain }: Partial<ColumnsProps>
</div>
),
cell: ({ row }) => {
if (!sdk) return null;
const portal = row.getValue("portal") as Portal;

const portalId = row.getValue("portal") as string;
const fetcher = () => sdk.portal.findOneById(portalId || EMPTY_STRING);

return (
<SWRCell swrKey={`${SWRKeys.GET_PORTAL_BY_ID}/${portalId}`} fetcher={fetcher} to={toPortalById(portalId)} />
);
return <SWRCell data={portal} to={toPortalById(portal.id)} />;
},
},
{
accessorKey: "schemaId",
accessorKey: "schema",
header: () => (
<div className="flex items-center gap-2.5">
<HelperIndicator type="schema" />
{t("attestation.list.columns.schema")}
</div>
),
cell: ({ row }) => {
if (!sdk) return null;
const schema = row.getValue("schema") as Schema;

const schemaId = row.getValue("schemaId") as string;
const fetcher = () => sdk.schema.findOneById(schemaId || EMPTY_STRING);

return (
<SWRCell swrKey={`${SWRKeys.GET_SCHEMA_BY_ID}/${schemaId}`} fetcher={fetcher} to={toSchemaById(schemaId)} />
);
return <SWRCell data={schema} to={toSchemaById(schema.id)} />;
},
},
{
Expand Down Expand Up @@ -120,10 +108,26 @@ export const skeletonAttestations = (itemPerPage = ITEMS_PER_PAGE_DEFAULT): Arra
decodedData: [EMPTY_STRING],
decodedPayload: [EMPTY_STRING],
attestationId: EMPTY_STRING,
schemaId: EMPTY_STRING,
schema: {
id: EMPTY_0X_STRING,
name: EMPTY_STRING,
description: EMPTY_STRING,
context: EMPTY_STRING,
schema: EMPTY_STRING,
attestationCounter: 0,
},
replacedBy: EMPTY_STRING,
attester: `0x${index}`,
portal: `0x${index}`,
portal: {
id: EMPTY_0X_STRING,
ownerAddress: EMPTY_0X_STRING,
modules: [EMPTY_0X_STRING],
isRevocable: false,
name: EMPTY_STRING,
description: EMPTY_STRING,
ownerName: EMPTY_STRING,
attestationCounter: 0,
},
attestedDate: 0,
expirationDate: 0,
revocationDate: 0,
Expand Down
1 change: 1 addition & 0 deletions explorer/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { arbitrum, arbitrumNova, arbitrumSepolia, base, baseSepolia, bsc, bscTes
import { lineaSepolia } from "@/config";

export const EMPTY_STRING = "";
export const EMPTY_0X_STRING = "0x";
export const SPACE_STRING = " ";
export const COMMA_STRING = ",";
export const DASH = "-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const AttestationInfo: React.FC<Attestation> = ({ ...attestation }) => {
},
{
title: t("attestation.info.portal"),
value: cropString(portal),
to: toPortalById(portal),
value: cropString(portal.name),
to: toPortalById(portal.id),
},
{
title: t("attestation.info.subject"),
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/pages/Attestation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Attestation = () => {
<AttestationInfo {...attestation} />
</div>
<div className="flex flex-col p-6 gap-12 w-full">
<AttestationSchemaCard schemaId={attestation.schemaId} />
<AttestationSchemaCard schemaId={attestation.schema.id} />
<AttestationData {...attestation} />
{/* TODO: uncomment when correct data will be available */}
{/* <RelatedAttestations mutate={mutate} /> */}
Expand Down
12 changes: 2 additions & 10 deletions explorer/src/pages/Attestations/components/SWRCell/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { Portal, Schema } from "@verax-attestation-registry/verax-sdk";
import useSWR from "swr";

import { Link } from "@/components/Link";
import { EMPTY_STRING } from "@/constants";

export const SWRCell: React.FC<{ swrKey: string; fetcher: () => Promise<Schema | Portal | undefined>; to: string }> = ({
swrKey,
fetcher,
to,
}) => {
const { data } = useSWR(swrKey, fetcher);

export const SWRCell: React.FC<{ data: Portal | Schema; to: string }> = ({ data, to }) => {
return (
<Link className="hover:underline transition" to={to} onClick={(e) => e.stopPropagation()}>
{data?.name || EMPTY_STRING}
{data.name}
</Link>
);
};
2 changes: 1 addition & 1 deletion explorer/src/pages/Attestations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const Attestations: React.FC = () => {

const data = isLoading
? { columns: columnsSkeletonRef.current, list: skeletonAttestations(itemsPerPage) }
: { columns: columns({ sdk, chain: network.chain }), list: attestationsList || [] };
: { columns: columns({ chain: network.chain }), list: attestationsList || [] };

return (
<TitleAndSwitcher>
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/pages/MyAttestations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const MyAttestations: React.FC = () => {
) : !attestationsList || !attestationsList.length ? (
<InfoBlock icon={<ArchiveIcon />} message={t("attestation.messages.emptyList")} />
) : (
<DataTable columns={columns({ sdk, chain })} data={attestationsList} link={APP_ROUTES.ATTESTATION_BY_ID} />
<DataTable columns={columns({ chain })} data={attestationsList} link={APP_ROUTES.ATTESTATION_BY_ID} />
)}
</TitleAndSwitcher>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const RecentAttestations: React.FC<{ schemaId: string }> = ({ schemaId })

const { data: attestations, isLoading } = useSWR(
`${SWRKeys.GET_RECENT_ATTESTATION}/${schemaId}/${chain.id}`,
() => sdk.attestation.findBy(5, 0, { schemaId }, "attestedDate", "desc"),
() => sdk.attestation.findBy(5, 0, { schema: schemaId }, "attestedDate", "desc"),
{
shouldRetryOnError: false,
},
Expand All @@ -27,7 +27,7 @@ export const RecentAttestations: React.FC<{ schemaId: string }> = ({ schemaId })
const data = isLoading
? { columns: columnsSkeletonRef.current, list: skeletonAttestations(5) }
: {
columns: columns({ sortByDate: false, sdk, chain }),
columns: columns({ sortByDate: false, chain }),
list: attestations || [],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const SearchAttestationsReceived: React.FC<SearchComponentProps> = ({ get
if (!data || !data.length) return null;
return (
<SearchWrapper title={t("attestation.received")} items={data.length}>
<DataTable columns={columns({ sdk, chain })} data={data} link={APP_ROUTES.ATTESTATION_BY_ID} />
<DataTable columns={columns({ chain })} data={data} link={APP_ROUTES.ATTESTATION_BY_ID} />
</SearchWrapper>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const loadAttestationReceivedList = async (
).filter(isNotNullOrUndefined);

const listBySchemaString = parsedString.schemaString
? await attestation.findBy(ITEMS_SEARCHED_DEFAULT, undefined, { schemaString: parsedString.schemaString })
? await attestation.findBy(ITEMS_SEARCHED_DEFAULT, undefined, { schema: parsedString.schemaString })
: [];

const results = [...(listByIds || []), ...(listBySubject || []), ...(listBySchemaString || [])];
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading