Commit d97edba1 authored by isstuev's avatar isstuev

latest batches socket

parent d768e1d8
...@@ -504,7 +504,7 @@ export const RESOURCES = { ...@@ -504,7 +504,7 @@ export const RESOURCES = {
pathParams: [ 'number' as const ], pathParams: [ 'number' as const ],
}, },
zkevm_l2_txn_batch_txs: { zkevm_l2_txn_batch_txs: {
path: 'api/v2/transactions/zkevm-batch/:number', path: '/api/v2/transactions/zkevm-batch/:number',
pathParams: [ 'number' as const ], pathParams: [ 'number' as const ],
filterFields: [], filterFields: [],
}, },
......
...@@ -15,7 +15,7 @@ export const txnBatchesData: ZkEvmL2TxnBatchesResponse = { ...@@ -15,7 +15,7 @@ export const txnBatchesData: ZkEvmL2TxnBatchesResponse = {
status: 'Unfinalized', status: 'Unfinalized',
verify_tx_hash: null, verify_tx_hash: null,
sequence_tx_hash: null, sequence_tx_hash: null,
number: 5218590, number: 5218591,
tx_count: 9, tx_count: 9,
}, },
], ],
......
...@@ -37,4 +37,4 @@ export type ZkEvmL2TxnBatchTxs = { ...@@ -37,4 +37,4 @@ export type ZkEvmL2TxnBatchTxs = {
next_page_params: null; next_page_params: null;
} }
export type NewZkEvmBatchSocketResponse = { batch: ZkEvmL2TxnBatch }; export type NewZkEvmBatchSocketResponse = { batch: ZkEvmL2TxnBatchesItem };
import { Box, Heading, Flex, Text, VStack } from '@chakra-ui/react'; import { Box, Heading, Flex, Text, VStack } from '@chakra-ui/react';
// import { useQueryClient } from '@tanstack/react-query'; import { useQueryClient } from '@tanstack/react-query';
// import { AnimatePresence } from 'framer-motion'; import { AnimatePresence } from 'framer-motion';
import React from 'react'; import React from 'react';
// import type { SocketMessage } from 'lib/socket/types'; import type { SocketMessage } from 'lib/socket/types';
// import type { ZkEvmL2TxnBatch } from 'types/api/zkEvmL2TxnBatches'; import type { ZkEvmL2TxnBatchesItem } from 'types/api/zkEvmL2TxnBatches';
import { route } from 'nextjs-routes'; import { route } from 'nextjs-routes';
// import useApiQuery, { getResourceKey } from 'lib/api/useApiQuery'; import useApiQuery, { getResourceKey } from 'lib/api/useApiQuery';
import useApiQuery from 'lib/api/useApiQuery';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
// import useSocketChannel from 'lib/socket/useSocketChannel'; import useSocketChannel from 'lib/socket/useSocketChannel';
// import useSocketMessage from 'lib/socket/useSocketMessage'; import useSocketMessage from 'lib/socket/useSocketMessage';
import { ZKEVM_L2_TXN_BATCHES_ITEM } from 'stubs/zkEvmL2'; import { ZKEVM_L2_TXN_BATCHES_ITEM } from 'stubs/zkEvmL2';
import LinkInternal from 'ui/shared/LinkInternal'; import LinkInternal from 'ui/shared/LinkInternal';
...@@ -21,7 +20,7 @@ import LatestZkevmL2BatchItem from './LatestZkevmL2BatchItem'; ...@@ -21,7 +20,7 @@ import LatestZkevmL2BatchItem from './LatestZkevmL2BatchItem';
const LatestZkEvmL2Batches = () => { const LatestZkEvmL2Batches = () => {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const batchesMaxCount = isMobile ? 2 : 5; const batchesMaxCount = isMobile ? 2 : 5;
// const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { data, isPlaceholderData, isError } = useApiQuery('homepage_zkevm_l2_batches', { const { data, isPlaceholderData, isError } = useApiQuery('homepage_zkevm_l2_batches', {
queryOptions: { queryOptions: {
...@@ -29,28 +28,27 @@ const LatestZkEvmL2Batches = () => { ...@@ -29,28 +28,27 @@ const LatestZkEvmL2Batches = () => {
}, },
}); });
// const handleNewBatchMessage: SocketMessage.NewZkEvmL2Batch['handler'] = React.useCallback((payload) => { const handleNewBatchMessage: SocketMessage.NewZkEvmL2Batch['handler'] = React.useCallback((payload) => {
// queryClient.setQueryData(getResourceKey('homepage_zkevm_l2_batches'), (prevData: Array<ZkEvmL2TxnBatch> | undefined) => { queryClient.setQueryData(getResourceKey('homepage_zkevm_l2_batches'), (prevData: { items: Array<ZkEvmL2TxnBatchesItem> } | undefined) => {
const newItems = prevData?.items ? [ ...prevData.items ] : [];
// const newData = prevData ? [ ...prevData ] : []; if (newItems.some((batch => batch.number === payload.batch.number))) {
return { items: newItems };
// if (newData.some((batch => batch.number === payload.batch.number))) { }
// return newData;
// }
// return [ payload.batch, ...newData ].sort((b1, b2) => b2.number - b1.number).slice(0, batchesMaxCount); return { items: [ payload.batch, ...newItems ].sort((b1, b2) => b2.number - b1.number).slice(0, batchesMaxCount) };
// }); });
// }, [ queryClient, batchesMaxCount ]); }, [ queryClient, batchesMaxCount ]);
// const channel = useSocketChannel({ const channel = useSocketChannel({
// topic: 'zkevm_batches:new_zkevm_confirmed_batch', topic: 'zkevm_batches:new_zkevm_confirmed_batch',
// isDisabled: isPlaceholderData || isError, isDisabled: isPlaceholderData || isError,
// }); });
// useSocketMessage({ useSocketMessage({
// channel, channel,
// event: 'new_zkevm_confirmed_batch', event: 'new_zkevm_confirmed_batch',
// handler: handleNewBatchMessage, handler: handleNewBatchMessage,
// }); });
let content; let content;
...@@ -64,7 +62,7 @@ const LatestZkEvmL2Batches = () => { ...@@ -64,7 +62,7 @@ const LatestZkEvmL2Batches = () => {
content = ( content = (
<> <>
<VStack spacing={ 3 } mb={ 4 } overflow="hidden" alignItems="stretch"> <VStack spacing={ 3 } mb={ 4 } overflow="hidden" alignItems="stretch">
{ /* <AnimatePresence initial={ false } > */ } <AnimatePresence initial={ false } >
{ dataToShow.map(((batch, index) => ( { dataToShow.map(((batch, index) => (
<LatestZkevmL2BatchItem <LatestZkevmL2BatchItem
key={ batch.number + (isPlaceholderData ? String(index) : '') } key={ batch.number + (isPlaceholderData ? String(index) : '') }
...@@ -72,7 +70,7 @@ const LatestZkEvmL2Batches = () => { ...@@ -72,7 +70,7 @@ const LatestZkEvmL2Batches = () => {
isLoading={ isPlaceholderData } isLoading={ isPlaceholderData }
/> />
))) } ))) }
{ /* </AnimatePresence> */ } </AnimatePresence>
</VStack> </VStack>
<Flex justifyContent="center"> <Flex justifyContent="center">
<LinkInternal fontSize="sm" href={ route({ pathname: '/zkevm-l2-txn-batches' }) }>View all batches</LinkInternal> <LinkInternal fontSize="sm" href={ route({ pathname: '/zkevm-l2-txn-batches' }) }>View all batches</LinkInternal>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment