Skip to content

Commit

Permalink
Merge pull request #1093 from kadena-community/feat/graph/show-tx-pag…
Browse files Browse the repository at this point in the history
…e-and-recent-tx

[@kadena/graph-client][@kadena/graph] Show recent and all transactions (Feature)
  • Loading branch information
nil-amrutlal authored Oct 19, 2023
2 parents ca421ba + 141d0ae commit ba7276f
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 228 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilly-bees-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@kadena/graph-client': patch
'@kadena/graph': patch
---

Show tx overview in block page and create transactions page; make transactions query dynamically assign filters; minor fixes and refactoring
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
GetAccountQuery,
GetBlockFromHashQuery,
GetChainAccountQuery,
GetTransactionsQuery,
} from '@/__generated__/sdk';
import routes from '@constants/routes';
import { Box, Button, ContentHeader, Link, Table } from '@kadena/react-ui';
Expand All @@ -14,7 +15,8 @@ interface ICompactTransactionsTableProps {
transactions:
| GetAccountQuery['account']['transactions']
| GetChainAccountQuery['chainAccount']['transactions']
| GetBlockFromHashQuery['block']['transactions'];
| GetBlockFromHashQuery['block']['transactions']
| GetTransactionsQuery['transactions'];
}

export const CompactTransactionsTable = (
Expand All @@ -30,7 +32,7 @@ export const CompactTransactionsTable = (
description={
description
? description
: 'All transactions where this account is the initiator.'
: 'All transactions where this account is the initiator'
}
/>
<Box margin={'$4'} />
Expand Down Expand Up @@ -58,7 +60,9 @@ export const CompactTransactionsTable = (
</Table.Td>
<Table.Td>{edge?.node.height}</Table.Td>
<Table.Td>
<Link href={`${routes.TRANSACTION}/${edge?.node.requestKey}`}>
<Link
href={`${routes.TRANSACTIONS}/${edge?.node.requestKey}`}
>
<span title={edge?.node.requestKey}>
{truncate(edge?.node.requestKey)}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export const CompactTransfersTable = (
</Link>
</Table.Td>
<Table.Td>
<Link href={`${routes.TRANSACTION}/${edge?.node.requestKey}`}>
<Link
href={`${routes.TRANSACTIONS}/${edge?.node.requestKey}`}
>
<span title={edge?.node.requestKey}>
{truncate(edge?.node.requestKey)}
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { Box, Button, Link, Table } from '@kadena/react-ui';

import type { GetTransactionsQuery } from '@/__generated__/sdk';
import routes from '@/constants/routes';
import type { FetchMoreOptions, FetchMoreQueryOptions } from '@apollo/client';
import React from 'react';

type DataType = GetTransactionsQuery;

interface IVariableType {
first: number | null;
last: number | null;
after: string | null;
before: string | null;
}

interface IExpandedTransactionsTableProps {
transactions: GetTransactionsQuery['transactions'];
fetchMore: (
fetchMoreOptions: FetchMoreQueryOptions<IVariableType, DataType> &
FetchMoreOptions,
) => Promise<any>;
}

export const ExtendedTransactionsTable = (
props: IExpandedTransactionsTableProps,
): JSX.Element => {
const { transactions, fetchMore } = props;
const pageSize: number = 10;

return (
<>
<Box marginBottom="$3">
<span>{`Showing ${pageSize} results per page`}</span>

<Button
variant="compact"
onClick={() =>
fetchMore({
variables: {
first: pageSize,
last: null,
after: transactions.pageInfo.endCursor,
before: null,
},
updateQuery: (prev, { fetchMoreResult }) => {
if (!fetchMoreResult) return prev;
return fetchMoreResult;
},
})
}
disabled={!transactions.pageInfo.hasNextPage}
style={{ float: 'right' }}
>
Next Page
</Button>
<Button
variant="compact"
onClick={() =>
fetchMore({
variables: {
first: null,
last: pageSize,
after: null,
before: transactions.pageInfo.startCursor,
},
updateQuery: (prev, { fetchMoreResult }) => {
if (!fetchMoreResult) return prev;

if (fetchMoreResult.transactions.edges.length < pageSize) {
return {
...prev,
transactions: {
...fetchMoreResult.transactions,
edges: [
...fetchMoreResult.transactions.edges,
...prev.transactions.edges,
].slice(0, pageSize),
},
};
}

return fetchMoreResult;
},
})
}
disabled={!transactions.pageInfo.hasPreviousPage}
style={{ float: 'right', marginRight: '10px' }}
>
Previous Page
</Button>
</Box>
<Table.Root wordBreak="break-word">
<Table.Head>
<Table.Tr>
<Table.Th>Chain</Table.Th>
<Table.Th>Timestamp</Table.Th>
<Table.Th>Block Height</Table.Th>
<Table.Th>Request Key</Table.Th>
<Table.Th>Code</Table.Th>
</Table.Tr>
</Table.Head>
<Table.Body>
{transactions.edges.map((edge, index) => {
return (
<Table.Tr key={index}>
<Table.Td>{edge?.node.chainId}</Table.Td>
<Table.Td>
{new Date(edge?.node.creationTime).toLocaleString()}
</Table.Td>
<Table.Td>{edge?.node.height}</Table.Td>
<Table.Td>
<Link
href={`${routes.TRANSACTIONS}/${edge?.node.requestKey}`}
>
{edge?.node.requestKey}
</Link>
</Table.Td>
<Table.Td>
{edge?.node.code || (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Table.Td>
</Table.Tr>
);
})}
</Table.Body>
</Table.Root>
</>
);
};
2 changes: 1 addition & 1 deletion packages/apps/graph-client/src/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
ACCOUNT_TRANSACTIONS: '/account/transactions',
ACCOUNT_TRANSFERS: '/account/transfers',
HOME: '/',
TRANSACTION: '/transaction',
TRANSACTIONS: '/transactions',
EVENT: '/event',
BLOCK_OVERVIEW: '/block/overview',
BLOCK_TRANSACTIONS: '/block/transactions',
Expand Down
9 changes: 7 additions & 2 deletions packages/apps/graph-client/src/graphql/queries.graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ export const getTransactions: DocumentNode = gql`
${CORE_TRANSACTION_FIELDS}
query getTransactions(
$moduleName: String!
$accountName: String!
$moduleName: String
$accountName: String
$chainId: String
$blockHash: String
$after: String
$before: String
$first: Int
Expand All @@ -154,6 +155,7 @@ export const getTransactions: DocumentNode = gql`
moduleName: $moduleName
accountName: $accountName
chainId: $chainId
blockHash: $blockHash
after: $after
before: $before
first: $first
Expand All @@ -169,6 +171,9 @@ export const getTransactions: DocumentNode = gql`
cursor
node {
...CoreTransactionFields
block {
hash
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getTransactionByRequestKey: DocumentNode = gql`
transaction(requestKey: $requestKey) {
...AllTransactionFields
block {
id
hash
}
events {
...CoreEventFields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useGetTransactionsQuery } from '@/__generated__/sdk';
import { ExtendedTransactionsTable } from '@/components/extended-transactions-table/extended-transactions-table';
import Loader from '@components/loader/loader';
import { mainStyle } from '@components/main/styles.css';
import { Text } from '@components/text';
import routes from '@constants/routes';
import { Box, Button, Link, Notification, Table } from '@kadena/react-ui';
import { Box, Notification } from '@kadena/react-ui';
import Head from 'next/head';
import { useRouter } from 'next/router';
import React from 'react';
Expand Down Expand Up @@ -51,103 +51,10 @@ const AccountTransactions: React.FC = () => {
</Notification.Root>
)}
{data?.transactions && (
<>
<Box marginBottom="$3">
<span>Showing 10 results per page</span>
<Button
variant="compact"
onClick={() =>
fetchMore({
variables: {
first: 10,
last: null,
after: data.transactions.pageInfo.endCursor,
before: null,
},
updateQuery: (prev, { fetchMoreResult }) => {
if (!fetchMoreResult) return prev;
return fetchMoreResult;
},
})
}
disabled={!data.transactions.pageInfo.hasNextPage}
style={{ float: 'right' }}
>
Next Page
</Button>
<Button
variant="compact"
onClick={() =>
fetchMore({
variables: {
first: null,
last: 10,
after: null,
before: data.transactions.pageInfo.startCursor,
},
updateQuery: (prev, { fetchMoreResult }) => {
if (!fetchMoreResult) return prev;

if (fetchMoreResult.transactions.edges.length < 10) {
return {
...prev,
transactions: {
...fetchMoreResult.transactions,
edges: [
...fetchMoreResult.transactions.edges,
...prev.transactions.edges,
].slice(0, 10),
},
};
}

return fetchMoreResult;
},
})
}
disabled={!data.transactions.pageInfo.hasPreviousPage}
style={{ float: 'right', marginRight: '10px' }}
>
Previous Page
</Button>
</Box>
<Table.Root wordBreak="break-word">
<Table.Head>
<Table.Tr>
<Table.Th>Chain</Table.Th>
<Table.Th>Timestamp</Table.Th>
<Table.Th>Block Height</Table.Th>
<Table.Th>Request Key</Table.Th>
<Table.Th>Code</Table.Th>
</Table.Tr>
</Table.Head>
<Table.Body>
{data.transactions.edges.map((edge, index) => {
return (
<Table.Tr key={index}>
<Table.Td>{edge?.node.chainId}</Table.Td>
<Table.Td>
{new Date(edge?.node.creationTime).toLocaleString()}
</Table.Td>
<Table.Td>{edge?.node.height}</Table.Td>
<Table.Td>
<Link
href={`${routes.TRANSACTION}/${edge?.node.requestKey}`}
>
{edge?.node.requestKey}
</Link>
</Table.Td>
<Table.Td>
{edge?.node.code || (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Table.Td>
</Table.Tr>
);
})}
</Table.Body>
</Table.Root>
</>
<ExtendedTransactionsTable
transactions={data.transactions}
fetchMore={fetchMore}
/>
)}
</div>
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const AccountTransfers: React.FC = () => {
</Table.Td>
<Table.Td>
<Link
href={`${routes.TRANSACTION}/${edge?.node.requestKey}`}
href={`${routes.TRANSACTIONS}/${edge?.node.requestKey}`}
>
{edge?.node.requestKey}
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ const Block: React.FC = () => {
router.query.hash as string
}`}
transactions={data.block.transactions}
description="All transactions present in this block"
/>
)}
</div>
Expand Down
Loading

0 comments on commit ba7276f

Please sign in to comment.