Skip to content

Commit

Permalink
Merge pull request #319 from AElfProject/feature/refactor-2.0.0-Block…
Browse files Browse the repository at this point in the history
…chain

feat: delete blocks request store
  • Loading branch information
Peterbjx authored Apr 28, 2024
2 parents 63b6d75 + 2d5bd0d commit 208f5db
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/_api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function service(url: string, options: RequestWithParams) {
}
}

console.log(url, 'url-----------');
console.log(url, options, 'url-----------');

try {
const response = await fetch(url, options);
Expand Down
18 changes: 9 additions & 9 deletions src/_api/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface IFromInfo {
isProducer: boolean;
}

export interface ITransactionsRequestParams {
export interface ITransactionsRequestParams extends RequestInit {
chainId: TChainID;
transactionId: string;
blockHeight: number;
Expand All @@ -62,13 +62,13 @@ export interface ITransactionsResponse {
transactions: ITransactionsResponseItem[];
}

export interface ITransactionDetailRequestParams {
export interface ITransactionDetailRequestParams extends RequestInit {
chainId: TChainID;
transactionId: string;
blockHeight: number;
}

export interface IBlocksRequestParams {
export interface IBlocksRequestParams extends RequestInit {
chainId: TChainID;
blockHeight?: number;
maxResultCount: number;
Expand All @@ -90,7 +90,7 @@ export interface IBlocksResponse {
blocks: IBlocksResponseItem[];
}

export interface IBlocksDetailRequestParams {
export interface IBlocksDetailRequestParams extends RequestInit {
chainId: TChainID;
blockHeight: number;
}
Expand Down Expand Up @@ -190,31 +190,31 @@ export interface ITransactionDetailDataList {
list: ITransactionDetailData[];
}

export interface ITokenHoldersRequestParams {
export interface ITokenHoldersRequestParams extends RequestInit {
chainId: TChainID;
symbol: string;
skipCount: number;
maxResultCount: number;
// search: string;
}

export interface ITokenTransfersRequestParams {
export interface ITokenTransfersRequestParams extends RequestInit {
chainId: TChainID;
skipCount: number;
maxResultCount: number;
symbol: string;
search: string;
}

export interface ITokenDetailRequestParams {
export interface ITokenDetailRequestParams extends RequestInit {
chainId: TChainID;
symbol: string;
}

export interface TTokenListRequestParams {
export interface TTokenListRequestParams extends RequestInit {
chainId: TChainID;
skipCount: number;
maxResultCount: number;
sort: SortEnum;
sortBy: number;
sortBy: string;
}
2 changes: 1 addition & 1 deletion src/_style/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ html{
@apply h-full w-full;
}
body {
@apply lg:min-w-[768px] bg-F7 select-none relative h-full w-full overflow-x-hidden overflow-y-auto;
@apply lg:min-w-[768px] bg-F7 relative h-full w-full overflow-x-hidden overflow-y-auto;
.explorer-dropdown-menu{
.explorer-dropdown-menu-item{
@apply !text-xs !leading-20 !text-base-100 !px-2 !py-[6px];
Expand Down
4 changes: 2 additions & 2 deletions src/_types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export enum AddressType {
}

export enum SortEnum {
asc,
desc,
asc = 'Asc',
desc = 'Desc',
}
4 changes: 2 additions & 2 deletions src/_utils/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export const addSymbol = (str: string | number) => {
return `${str} ${process.env.NEXT_PUBLIC_SYMBOL}`;
};

export const divDecimals = (num: number | string, decimals = 8e10) => {
export const divDecimals = (num: number | string, decimals = 1e10) => {
const bigNumber = new BigNumber(num);
return bigNumber.dividedBy(decimals || 8e10).toNumber();
return bigNumber.dividedBy(decimals || 1e10).toNumber();
};

export const getPageNumber = (page: number, pageSize: number): number => {
Expand Down
1 change: 0 additions & 1 deletion src/_utils/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export function getPathnameFirstSlash(pathname: string) {
}
export default function addressFormat(address: string, chainId?: string, prefix?: string) {
const defaultChainId = store.getState().getChainId.defaultChain;
console.log(defaultChainId, 'defaultChainId');
if (!address) return '';
return `${prefix || SYMBOL}_${address}_${chainId || defaultChainId}`;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/[chain]/block/[hash]/_components/baseinfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { useParams } from 'next/navigation';
export default function BaseInfo({ data }) {
const router = useRouter();
const { chain } = useParams();
const isFirst = data.preBlockHeight === 0;
const isLast = data.nextBlockHeight === 0;
const isFirst = data?.preBlockHeight === 0;
const isLast = data?.nextBlockHeight === 0;
const jump = useCallback(
(type: JumpTypes) => {
switch (type) {
Expand Down
10 changes: 5 additions & 5 deletions src/app/[chain]/block/[hash]/_components/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Detail({ SSRData }) {
const [showMore, setShowMore] = useState<boolean>(false);
const [currentPage, setCurrentPage] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(25);
const [total] = useState<number>(SSRData.transactions.length);
const [total] = useState<number>(SSRData?.transactions?.length);
const [timeFormat, setTimeFormat] = useState<string>('Age');

const { chain } = useParams();
Expand All @@ -41,7 +41,7 @@ export default function Detail({ SSRData }) {
},
chainId: chain as string,
});
}, [timeFormat]);
}, [chain, timeFormat]);

const multiTitle = `More than > ${total} transactions found`;

Expand All @@ -57,9 +57,9 @@ export default function Detail({ SSRData }) {
};

const tableData = useMemo(() => {
const transactions = detailData.transactions || [];
const transactions = detailData?.transactions || [];
return transactions.slice((currentPage - 1) * pageSize, currentPage * pageSize);
}, [currentPage, detailData.transactions, pageSize]);
}, [currentPage, detailData?.transactions, pageSize]);

const moreChange = useCallback(() => {
setShowMore(!showMore);
Expand Down Expand Up @@ -104,7 +104,7 @@ export default function Detail({ SSRData }) {
return (
<div className={clsx('token-detail-container')}>
<HeadTitle content="Blocks">
<span className="ml-2 block text-xs leading-5 text-base-200">#{detailData.blockHeight}</span>
<span className="ml-2 block text-xs leading-5 text-base-200">#{detailData?.blockHeight}</span>
</HeadTitle>

<div className="detail-table">
Expand Down
6 changes: 5 additions & 1 deletion src/app/[chain]/block/[hash]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { fetchServerBlocksDetail } from '@_api/fetchBlocks';
import Detail from './_components/detail';
import { TChainID } from '@_api/type';
export default async function Block({ params }: { params: { hash: string; chain: TChainID } }) {
const data = await fetchServerBlocksDetail({ blockHeight: Number(params.hash), chainId: params.chain });
const data = await fetchServerBlocksDetail({
blockHeight: Number(params.hash),
chainId: params.chain,
cache: 'no-store',
});
console.log(data, 'data');
return <Detail SSRData={data} />;
}
3 changes: 2 additions & 1 deletion src/app/[chain]/blocks/blockList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface IBlocksData {
}

export default function BlockList({ SSRData }) {
console.log(SSRData, ' SSRData');
const { isMobile } = useMobileAll();
const [currentPage, setCurrentPage] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(25);
Expand Down Expand Up @@ -79,7 +80,7 @@ export default function BlockList({ SSRData }) {
},
chianId: chain,
});
}, [timeFormat]);
}, [chain, timeFormat]);

const pageMaxBlock = data[0]?.blockHeight;
const pageMinBlock = data[data.length - 1]?.blockHeight;
Expand Down
1 change: 1 addition & 0 deletions src/app/[chain]/blocks/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default async function BlocksPage({ params }) {
const data = await fetchServerBlocks({
chainId: params.chain || 'AELF',
maxResultCount: 25,
cache: 'no-store',
});
return <BlockList SSRData={data} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const TokenDetailItems: IOverviewItem[] = [
render: (text, record) => <NumberPercentGroup number={text} percent={record['holderPercentChange24H']} />,
},
{
key: 'totalTransfers',
key: 'transferCount',
label: 'TOTAL TRANSFERS',
format: thousandsNumber,
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/[chain]/token/[tokenSymbol]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function TokenSymbol({
tokenSymbol: string;
};
}) {
const tokenDetail = await fetchTokenDetail({ chainId: chain as TChainID, symbol: tokenSymbol });
const tokenDetail = await fetchTokenDetail({ chainId: chain as TChainID, symbol: tokenSymbol, cache: 'no-store' });
console.log(tokenDetail, 'tokenDetail');
return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[chain]/token/[tokenSymbol]/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface ITokenDetail {
circulatingSupply: string;
holders: number;
holderPercentChange24h: number;
totalTransfers: string;
transferCount: number;
priceInUsd: number;
pricePercentChange24h: number;
contractAddress: string;
Expand Down
6 changes: 4 additions & 2 deletions src/app/[chain]/tokens/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import { ChainId } from 'global';
import TokensList from './tokensList';
import { fetchServerTokenList } from '@_api/fetchTokens';
import { TChainID } from '@_api/type';
import { SortEnum } from '@_types/common';

export default async function TokensPage({ params }: { params: ChainId }) {
const data = await fetchServerTokenList({
skipCount: 0,
maxResultCount: 50,
chainId: params.chain as TChainID,
sortBy: 2,
sort: 1,
sortBy: 'HolderCount',
sort: SortEnum.desc,
cache: 'no-store',
});
return <TokensList SSRData={data} />;
}
2 changes: 1 addition & 1 deletion src/app/[chain]/tokens/tokensList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function TokensList({ SSRData }: TokensListProps) {
maxResultCount: 50,
chainId: chain as TChainID,
sort,
sortBy: 2,
sortBy: 'HolderCount',
};
setLoading(true);
const data = await fetchTokenList(params);
Expand Down

0 comments on commit 208f5db

Please sign in to comment.