Skip to content

Commit

Permalink
Merge pull request #62 from AElfProject/feature/aelf-scan-tmrwdao
Browse files Browse the repository at this point in the history
feat: aelf scan indexer
  • Loading branch information
yongenaelf authored Nov 15, 2024
2 parents 98545b9 + 99c1a43 commit 55fac63
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 99 deletions.
7 changes: 4 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SOLANG_BUILD_SERVER_BASE_URL=https://playground-next.test.aelf.dev
SOLIDITY_ENABLED=false
GA_TAG=
GITHUB_API_KEY=
NEXT_PUBLIC_FAUCET_API_URL =
NEXT_PUBLIC_GOOGLE_CAPTCHA_SITEKEY =
NEXT_PUBLIC_INDEXER_GRAPHQL_ENDPOINT =
NEXT_PUBLIC_FAUCET_API_URL=
NEXT_PUBLIC_GOOGLE_CAPTCHA_SITEKEY=
NEXT_PUBLIC_AELFSCAN_GRAPHQL_ENDPOINT=
NEXT_PUBLIC_TMRWDAO_GRAPHQL_ENDPOINT=
55 changes: 9 additions & 46 deletions app/deployments/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
} from "@/components/ui/table";
import { format } from "date-fns";
import Link from "next/link";
import { useLogs, useProposalsInfo, useTransactions } from "@/data/client";
import { useContractList } from "@/data/graphql";

export default function Page() {
const wallet = useWallet();
const { data } = useTransactions(wallet?.wallet.address);
const contractTransactions = data?.filter(i => i.method === "DeployUserSmartContract");
const { data, loading } = useContractList(wallet?.wallet.address);

if (loading) return <div>Loading...</div>;

return (
<div className="container px-4 py-12 md:px-6 lg:py-16">
Expand All @@ -26,20 +27,16 @@ export default function Page() {
<TableRow>
<TableHead className="w-1/3">Date and time</TableHead>
<TableHead className="w-1/3">Contract Address</TableHead>
<TableHead className="w-1/3">Proposal</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{contractTransactions ? (
contractTransactions
{data ? (
data.contractList.items
.map((i) => (
<TableRow key={i.id}>
<TableCell>{format(i.time, "PPPppp")}</TableCell>
<TableCell>
<ContractAddress id={i.tx_id} />
</TableCell>
<TableRow key={i.address}>
<TableCell>{format(i.metadata.block.blockTime, "PPPppp")}</TableCell>
<TableCell>
<Proposal id={i.tx_id} />
<ViewAddressOnExplorer address={i.address} />
</TableCell>
</TableRow>
))
Expand All @@ -59,26 +56,6 @@ export default function Page() {
);
}

function Proposal({ id }: { id: string }) {
const { data, isLoading, error } = useLogs(id);

if (isLoading) return <span>Loading...</span>;
if (error || !data || !data.proposalId) return <span>-</span>;

return <ViewProposalOnExplorer id={data.proposalId} />;
}

function ContractAddress({ id }: { id: string }) {
const { data: logs } = useLogs(id);
const { data: info } = useProposalsInfo(logs?.proposalId ? [logs.proposalId] : []);
const { data, isLoading, error } = useLogs(info?.getNetworkDaoProposalReleasedIndex.data?.[0]?.transactionInfo.transactionId);

if (isLoading) return <span>Loading...</span>;
if (error || !data) return <span>-</span>;

return <ViewAddressOnExplorer address={data.address} />;
}

function ViewAddressOnExplorer({ address }: { address: string }) {
return (
<Link
Expand All @@ -92,17 +69,3 @@ function ViewAddressOnExplorer({ address }: { address: string }) {
</Link>
);
}

function ViewProposalOnExplorer({ id }: { id: string }) {
return (
<Link
className="hover:underline"
href={`https://test.tmrwdao.com/network-dao/proposal/${id}?chainId=tDVW`}
title="View on TMRWDAO"
target="_blank"
rel="noopener noreferrer"
>
{id}
</Link>
);
}
36 changes: 20 additions & 16 deletions components/providers/apollo-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@
// ^ this file needs the "use client" pragma
// https://github.com/apollographql/apollo-client-nextjs/tree/main?tab=readme-ov-file#in-client-components-and-streaming-ssr

import { HttpLink } from "@apollo/client";
import { HttpLink, ApolloLink } from "@apollo/client";
import {
ApolloNextAppProvider,
ApolloClient,
InMemoryCache,
} from "@apollo/experimental-nextjs-app-support";
import { env } from 'next-runtime-env';
import { env } from "next-runtime-env";

const tmrwdaoLink = new HttpLink({
uri: env("NEXT_PUBLIC_TMRWDAO_GRAPHQL_ENDPOINT"),
fetchOptions: { cache: "no-store" },
});

const aelfscanLink = new HttpLink({
uri: env("NEXT_PUBLIC_AELFSCAN_GRAPHQL_ENDPOINT"),
fetchOptions: { cache: "no-store" },
});

export const AELFSCAN_CLIENT_NAME = "aelfscanLink";

// have a function to create a client for you
function makeClient() {
const httpLink = new HttpLink({
// this needs to be an absolute url, as relative urls cannot be used in SSR
uri: env("NEXT_PUBLIC_INDEXER_GRAPHQL_ENDPOINT"),
// you can disable result caching here if you want to
// (this does not work if you are rendering your page with `export const dynamic = "force-static"`)
fetchOptions: { cache: "no-store" },
// you can override the default `fetchOptions` on a per query basis
// via the `context` property on the options passed as a second argument
// to an Apollo Client data fetching hook, e.g.:
// const { data } = useSuspenseQuery(MY_QUERY, { context: { fetchOptions: { cache: "force-cache" }}});
});

// use the `ApolloClient` from "@apollo/experimental-nextjs-app-support"
return new ApolloClient({
// use the `InMemoryCache` from "@apollo/experimental-nextjs-app-support"
cache: new InMemoryCache(),
link: httpLink,
link: ApolloLink.split(
(operation) => operation.getContext().clientName === AELFSCAN_CLIENT_NAME,
aelfscanLink, //if above
tmrwdaoLink
),
});
}

Expand All @@ -39,4 +43,4 @@ export function ApolloWrapper({ children }: React.PropsWithChildren) {
{children}
</ApolloNextAppProvider>
);
}
}
119 changes: 85 additions & 34 deletions data/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,94 @@
import { useQuery, gql } from '@apollo/client';
import { AELFSCAN_CLIENT_NAME } from "@/components/providers/apollo-wrapper";
import { useQuery, gql } from "@apollo/client";

interface GetNetworkDaoProposalReleasedIndexResponse {
getNetworkDaoProposalReleasedIndex: {
data: Array<{
proposalId: string
orgType: string
transactionInfo: {
transactionId: string
getNetworkDaoProposalReleasedIndex: {
data: Array<{
proposalId: string;
orgType: string;
transactionInfo: {
transactionId: string;
};
}>;
};
}

export const useProposalReleaseInfo = (
proposalIds: string[] = [],
pollInterval: number = 0
) => {
return useQuery<GetNetworkDaoProposalReleasedIndexResponse>(
gql`
query GetNetworkDaoProposalReleasedIndex(
$input: GetNetworkDaoProposalReleasedIndexInput!
) {
getNetworkDaoProposalReleasedIndex(input: $input) {
data {
proposalId
orgType
transactionInfo {
transactionId
}
}>
}
}
}
`,
{
variables: {
input: {
startBlockHeight: 1,
endBlockHeight: 4000000000,
orgType: "PARLIAMENT",
skipCount: 0,
maxResultCount: 1,
proposalIds: proposalIds,
},
},
pollInterval,
skip: proposalIds.length === 0,
}
}
);
};

export const useProposalReleaseInfo = (proposalIds: string[] = [], pollInterval: number = 0) => {
interface GetContractListResponse {
contractList: {
items: Array<{
address: string;
metadata: {
block: {
blockTime: string;
};
};
}>;
};
}

return useQuery<GetNetworkDaoProposalReleasedIndexResponse>(gql`
query GetNetworkDaoProposalReleasedIndex($input: GetNetworkDaoProposalReleasedIndexInput!) {
getNetworkDaoProposalReleasedIndex(input: $input) {
data {
proposalId
orgType
transactionInfo {
transactionId
}
}
export const useContractList = (author?: string) => {
return useQuery<GetContractListResponse>(
gql`
query ContractList($input: GetContractInfoDto) {
contractList(input: $input) {
items {
address
metadata {
block {
blockTime
}
}
}
}
`, {
variables: {
"input": {
"startBlockHeight": 1,
"endBlockHeight": 4000000000,
"orgType": "PARLIAMENT",
"skipCount": 0,
"maxResultCount": 1,
"proposalIds": proposalIds
},
}
`,
{
variables: {
input: {
author: author,
maxResultCount: 1000,
skipCount: 0,
},
pollInterval,
skip: proposalIds.length === 0
})
}
},
skip: !author,
context: {clientName: AELFSCAN_CLIENT_NAME}
}
);
};

0 comments on commit 55fac63

Please sign in to comment.