Skip to content

Commit

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

Feature/refactor 2.0.0 blockchain
  • Loading branch information
Peterbjx committed Apr 27, 2024
2 parents 9261340 + 18499c7 commit 76f41ae
Show file tree
Hide file tree
Showing 87 changed files with 1,365 additions and 953 deletions.
6 changes: 3 additions & 3 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NEXT_PUBLIC_NETWORK_TYPE = 'TESTNET'
NEXT_PUBLIC_CHAIN_ID = 'AELF'
NEXT_PUBLIC_SYMBOL = 'ELF'
NEXT_PUBLIC_API_URL=http://localhost:4000
NEXT_PUBLIC_REMOTE_URL=http://localhost:3001
NEXT_PUBLIC_CMS_URL=http://192.168.66.62:3200
NEXT_PUBLIC_API_URL = http://localhost:4000
NEXT_PUBLIC_REMOTE_URL = http://localhost:3001
NEXT_PUBLIC_CMS_URL = http://192.168.66.62:3200
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_PUBLIC_NETWORK_TYPE = 'TESTNET'
NEXT_PUBLIC_SYMBOL = 'ELF'
NEXT_PUBLIC_API_URL=http://localhost:4000
NEXT_PUBLIC_API_URL=https://aelfscan.io
NEXT_PUBLIC_REMOTE_URL=http://localhost:3001
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NEXT_PUBLIC_NETWORK_TYPE = 'TESTNET'
NEXT_PUBLIC_CHAIN_ID = 'AELF'
NEXT_PUBLIC_SYMBOL = 'ELF'
NEXT_PUBLIC_API_URL = http://localhost:4000
NEXT_PUBLIC_API_URL = https://aelfscan.io
NEXT_PUBLIC_REMOTE_URL = http://localhost:3001
NEXT_PUBLIC_CMS_URL = http://192.168.66.62:3200
7 changes: 7 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { TChainID } from '@_api/type';

type HashParams = {
hash: string;
chain: TChainID;
};

type ChainId = {
Expand All @@ -20,3 +23,7 @@ type ItemSymbol = {

type NftCollectionPageParams = ChainId & CollectionSymbol;
type Chain = 'AELF' | 'tDVV' | 'tDVW';

type TSearchParamsForTransactionDetail = {
blockHeight: number;
};
101 changes: 54 additions & 47 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,61 @@ const nextConfig = {
ssr: true,
},
},
reactStrictMode: false,
experimental: {
proxyTimeout: 300000,
},
async rewrites() {
return [
{
source: '/home',
destination: '/',
// permanent: false,
},
{
source: '/api/:path*',
destination: 'http://localhost:3001/api/:path*',
// permanent: false,
},
{
source: '/chain/:path*',
destination: 'http://localhost:3001/chain/:path*',
// permanent: false,
},
{
source: '/cms/:path*',
destination: 'http://localhost:3001/cms/:path*',
// permanent: false,
},
{
source: '/new-socket/:path*',
destination: 'http://localhost:3001/new-socket/:path*',
// permanent: false,
},
{
source: '/Portkey_DID/:path*',
destination: 'http://localhost:3001/Portkey_DID/:path*',
// permanent: false,
},
{
source: '/Portkey_V2_DID/:path*',
destination: 'http://localhost:3001/Portkey_V2_DID/:path*',
// permanent: false,
},
{
source: '/v1/api/:path*',
destination: 'http://localhost:3001/v1/api/:path*',
// permanent: false,
},
{
source: '/v2/api/:path*',
destination: 'http://localhost:3001/v2/api/:path*',
// permanent: false,
},
];
return process.env.NODE_ENV === 'production'
? []
: [
{
source: '/home',
destination: '/',
// permanent: false,
},
{
source: '/api/:path*',
destination: 'https://aelfscan.io/api/:path*',
// permanent: false,
basePath: false,
},
{
source: '/chain/:path*',
destination: 'http://localhost:3001/chain/:path*',
// permanent: false,
},
{
source: '/cms/:path*',
destination: 'http://localhost:3001/cms/:path*',
// permanent: false,
},
{
source: '/new-socket/:path*',
destination: 'http://localhost:3001/new-socket/:path*',
// permanent: false,
},
{
source: '/Portkey_DID/:path*',
destination: 'http://localhost:3001/Portkey_DID/:path*',
// permanent: false,
},
{
source: '/Portkey_V2_DID/:path*',
destination: 'http://localhost:3001/Portkey_V2_DID/:path*',
// permanent: false,
},
// {
// source: '/v1/api/:path*',
// destination: 'http://localhost:3001/v1/api/:path*',
// // permanent: false,
// },
// {
// source: '/v2/api/:path*',
// destination: 'http://localhost:3001/v2/api/:path*',
// // permanent: false,
// },
];
},
images: {
remotePatterns: [
Expand Down
47 changes: 47 additions & 0 deletions src/_api/fetchBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import request from '@_api';
import { IBlocksDetailData, IBlocksDetailRequestParams, IBlocksRequestParams, TChainID } from './type';

const defaultTokenList = {
total: 0,
blocks: [],
};

export async function fetchBlocks(params: IBlocksRequestParams) {
const result = await request.block.getBlockList({
params: params,
});
const data = result?.data || defaultTokenList;
return data;
}

export async function fetchLatestBlocksList(params: { chainId: TChainID }) {
const result = await request.block.getLatestBlocksList({
params: params,
});
const data = result?.data || defaultTokenList;
return data;
}

export async function fetchServerBlocks(params: IBlocksRequestParams) {
const result = await request.block.getServerBlockList({
params: params,
});
const data = result?.data || defaultTokenList;
return data;
}

export async function fetchServerBlocksDetail(params: IBlocksDetailRequestParams): Promise<IBlocksDetailData> {
const result = await request.block.getServerBlockDetail({
params: params,
});
const data = result?.data;
return data;
}

export async function fetchBlocksDetail(params: IBlocksDetailRequestParams): Promise<IBlocksDetailData> {
const result = await request.block.getBlockDetail({
params: params,
});
const data = result?.data || {};
return data;
}
3 changes: 1 addition & 2 deletions src/_api/fetchCMS.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import request from '@_api';

export async function fetchCMS() {
const result = await request.cms.getGlobalConfig();
const { data } = result;
const headerMenuList = data.headerMenuList.filter((item) => {
if (item.headerMenu_id.path === 'blockchain') {
item.headerMenu_id.children = item.headerMenu_id.children.filter((child) => {
return child.label === 'Blocks' || child.label === 'Transactions';
return child.label === 'Blocks';
});
}
return item.headerMenu_id?.path === 'blockchain' || item.headerMenu_id?.path === '/tokens';
Expand Down
45 changes: 45 additions & 0 deletions src/_api/fetchTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import request from '@_api';
import {
ITokenHoldersRequestParams,
ITokenTransfersRequestParams,
ITokenDetailRequestParams,
TTokenListRequestParams,
} from './type';
import { IHolderTableData, ITokenDetail, ITokenList, ITransferTableData } from '@app/[chain]/token/[tokenSymbol]/type';

export async function fetchTokenList(params: TTokenListRequestParams): Promise<ITokenList> {
const result = await request.tx.getTransactionDetail({
params: params,
});
const data = result?.data;
return data;
}
export async function fetchServerTokenList(params: TTokenListRequestParams): Promise<ITokenList> {
const result = await request.tx.getTransactionDetail({
params: params,
});
const data = result?.data;
return data;
}
export async function fetchTokenDetail(params: ITokenDetailRequestParams): Promise<ITokenDetail> {
const result = await request.tx.getTransactionDetail({
params: params,
});
const data = result?.data;
return data;
}
export async function fetchTokenDetailTransfers(params: ITokenTransfersRequestParams): Promise<ITransferTableData> {
const result = await request.tx.getTransactionDetail({
params: params,
});
const data = result?.data;
return data;
}

export async function fetchTokenDetailHolders(params: ITokenHoldersRequestParams): Promise<IHolderTableData> {
const result = await request.tx.getTransactionDetail({
params: params,
});
const data = result?.data;
return data;
}
12 changes: 12 additions & 0 deletions src/_api/fetchTransactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import request from '@_api';
import { ITransactionDetailRequestParams, ITransactionDetailDataList } from './type';

export async function fetchTransactionDetails(
params: ITransactionDetailRequestParams,
): Promise<ITransactionDetailDataList> {
const result = await request.tx.getTransactionDetail({
params: params,
});
const data = result?.data;
return data;
}
18 changes: 17 additions & 1 deletion src/_api/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
*/
import { RequestWithParams } from './server';

const BASE_API = '/api'; // server local
const SERVER_BASE_API = `${process.env.NEXT_PUBLIC_API_URL}/api`; // server

const Block_API_List = {
getBlockList: 'https://dummyjson.com/products',
getBlockList: `${BASE_API}/app/blockchain/blocks`,
getLatestBlocksList: `${BASE_API}/app/blockchain/latestBlocks`,
getServerBlockList: `${SERVER_BASE_API}/app/blockchain/blocks`,
getBlockDetail: `${BASE_API}/app/blockchain/blockDetail`,
getServerBlockDetail: `${SERVER_BASE_API}/app/blockchain/blockDetail`,
query: 'https://dummyjson.com/products/search',
};

const Transaction_API_List = {
getTransaction: '',
getTransactionDetail: `${SERVER_BASE_API}/app/blockchain/transactionDetail`,
};

const Token_API_List = {
getTokenList: `api/app/token/list`,
getServerTokenList: `api/app/token/list`,
getTokenDetail: `${SERVER_BASE_API}/app/token/detail`,
getTokenDetailTransfers: `api/app/token/transfers`,
getTokenDetailHolders: `api/app/token/holders`,
};

const Common_API_List = {
Expand Down
6 changes: 4 additions & 2 deletions src/_api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type RequestWithParams = {
params?: any;
} & RequestInit;

const DEFAULT_FETCH_TIMEOUT = 5000;
const DEFAULT_FETCH_TIMEOUT = 300000;
const myServer = new Function();
const timeoutPromise = (delay: number) => {
return new Promise<{ type: string }>((resolve) => {
Expand All @@ -25,7 +25,9 @@ async function service(url: string, options: RequestWithParams) {
const paramsArr: Array<any> = [];
if (Object.keys(params).length > 0) {
for (const item in params) {
paramsArr.push(item + '=' + params[item]);
if (params[item] !== undefined) {
paramsArr.push(item + '=' + params[item]);
}
}
if (url.search(/\?/) === -1) {
url += '?' + paramsArr.join('&');
Expand Down

0 comments on commit 76f41ae

Please sign in to comment.