From a81fa1381ac6c3ef0e8f82ac7335f84b4f27aad0 Mon Sep 17 00:00:00 2001 From: wenzhe Date: Tue, 17 Sep 2019 19:27:17 +0800 Subject: [PATCH] remove service api except sse --- service/index.js | 353 ------------------------------ src/components/SearchBox/index.js | 36 ++- src/index.html | 4 +- src/pages/Account/detail.js | 99 ++++----- src/pages/Block/detail.js | 102 +++++---- src/pages/BlockAndTxn/index.js | 38 +++- src/pages/Epoch/detail.js | 39 ++-- src/pages/Transaction/detail.js | 36 +-- src/pages/Transaction/list.js | 35 +-- src/utils/index.js | 2 +- webpack.config.js | 8 +- 11 files changed, 215 insertions(+), 537 deletions(-) diff --git a/service/index.js b/service/index.js index 96dceb6..44ca57f 100644 --- a/service/index.js +++ b/service/index.js @@ -13,123 +13,6 @@ const start = async () => { await server.register([{ plugin: Susie }]); server.route([ - // 响应接口 - { - method: 'GET', - path: `${SERVER_PREFIX}/ping`, - config: { - cors: true, - handler: async (request, h) => { - return h.response('pong'); - }, - }, - }, - // 获取服务器随机时间 - { - method: 'GET', - path: `${SERVER_PREFIX}/fetch_random_time`, - config: { - cors: true, - handler: async (request, h) => { - const { Readable } = require('stream'); - const rs = Readable(); - // console.log('start') - - rs._read = function() { - rs.pause(); - setTimeout(() => { - rs.resume(); - if (!request.active()) { - // console.log('end'); - return h.close; - } - // 业务逻辑 - rs.push(JSON.stringify({ timestamp: new Date().getTime() })); - }, 1000); - }; - rs.on('data', (chunk) => { - // console.log(chunk.toString()); - }); - - return h.event(rs); - }, - description: '获取服务器随机时间', - tags: ['api', 'sse'], - }, - }, - // 获取 epoch list by epochNum - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchEpochList`, - config: { - cors: true, - handler: async (request, h) => { - const querys = ['block/list'].map((ids) => { - console.log(`${API_HOST}/${ids}`); - return new Promise((resolve, reject) => { - superagent - .get(`${API_HOST}/${ids}`) - .query(request.query) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - if (code == 0) resolve({ [ids]: result.data, ['total_' + ids]: result.total }); - else if (code === 1) resolve({ code }); - else reject([]); - }) - .catch((e) => { - reject([]); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response(payload[0].code === 1 ? { code: 1 } : { code: 0, result: payload }); - }, - description: '初始化获取Block&Tx List', - tags: ['api', 'sse'], - validate: { - query: Joi.object().keys({ - pageNum: Joi.string().required(), - pageSize: Joi.string().required(), - epochNum: Joi.string().required(), - }), - }, - }, - }, - // 获取 block list & tx list 初始化数据 - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchInitBlockandTxList`, - config: { - cors: true, - handler: async (request, h) => { - const querys = ['block/list', 'transaction/list'].map((ids) => { - return new Promise((resolve, reject) => { - superagent - .get(`${API_HOST}/${ids}`) - .query(request.query) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - if (code == 0) resolve({ [ids]: result.data, ['total_' + ids]: result.total }); - else reject([]); - }) - .catch((e) => { - reject([]); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response({ code: 0, result: payload }); - }, - description: '初始化获取Block&Tx List', - tags: ['api', 'sse'], - validate: { - query: Joi.object().keys({ - pageNum: Joi.string().required(), - pageSize: Joi.string().required(), - }), - }, - }, - }, // 获取block list & tx list { method: 'GET', @@ -187,243 +70,7 @@ const start = async () => { }, }, }, - // 获取 tx detail - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchTxDetail`, - config: { - cors: true, - handler: async (request, h) => { - const querys = [`transaction/${request.query.transactionHash}`].map((ids) => { - return new Promise((resolve, reject) => { - superagent - .get(`${API_HOST}/${ids}`) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - console.log(result, message, code); - if (code === 0) resolve({ code, result: result.data, message }); - else if (code === 1 || code === 4) resolve({ code, message }); - else reject({}); - }) - .catch((e) => { - console.log(e.toString()); - reject({}); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response(payload[0]); - }, - description: '获取 tx detail', - tags: ['api'], - validate: { - query: Joi.object().keys({ - transactionHash: Joi.string().required(), - }), - }, - }, - }, // 获取 hash的类型 - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchHashType/{hash}`, - config: { - cors: true, - handler: async (request, h) => { - const querys = [`util/type/${request.params.hash}`].map((ids) => { - return new Promise((resolve, reject) => { - console.log(`${API_HOST}/${ids}`); - superagent - .get(`${API_HOST}/${ids}`) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - if (code == 0) resolve({ code, result: result.data, message }); - else if (code == 1) resolve({ code, message }); - else reject({}); - }) - .catch((e) => { - console.log(e.toString()); - reject({}); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response(payload[0]); - }, - description: '获取 tx detail', - tags: ['api'], - validate: { - params: Joi.object().keys({ - hash: Joi.string().required(), - }), - }, - }, - }, - // 获取 block detail - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchBlockDetail/{blockHash}`, - config: { - cors: true, - handler: async (request, h) => { - const querys = [`block/${request.params.blockHash}`, `block/${request.params.blockHash}/transactionList`].map((ids) => { - return new Promise((resolve, reject) => { - console.log(`${API_HOST}/${ids}`); - superagent - .get(`${API_HOST}/${ids}`) - .query(request.query) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - if (code === 0) resolve({ [ids]: result.data, ['total_' + ids]: result.total }); - else if (code === 1) resolve({ code }); - else reject({}); - }) - .catch((e) => { - console.log(e.toString()); - reject({}); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response(payload[0].code === 1 ? { code: 1 } : { code: 0, result: payload }); - }, - description: '获取 Block detail', - tags: ['api'], - validate: { - query: Joi.object().keys({ - pageNum: Joi.string().required(), - pageSize: Joi.string().required(), - }), - params: Joi.object().keys({ - blockHash: Joi.string().required(), - }), - }, - }, - }, - // 获取 account detail - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchAccountDetail/{address}`, - config: { - cors: true, - handler: async (request, h) => { - const querys = [`account/${request.params.address}`, `account/${request.params.address}/transactionList`].map((ids) => { - return new Promise((resolve, reject) => { - console.log(`${API_HOST}/${ids}`); - superagent - .get(`${API_HOST}/${ids}`) - .query(request.query) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - if (code == 0) resolve({ [ids]: result.data, ['total_' + ids]: result.total }); - else if (code === 1) resolve({ code }); - else reject({}); - }) - .catch((e) => { - console.log(e.toString()); - reject({}); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response(payload[0].code === 1 ? { code: 1 } : { code: 0, result: payload }); - }, - description: '获取 account detail', - tags: ['api'], - validate: { - query: Joi.object().keys({ - pageNum: Joi.string().required(), - pageSize: Joi.string().required(), - startTime: Joi.string(), - endTime: Joi.string(), - txnType: Joi.string(), - }), - params: Joi.object().keys({ - address: Joi.string().required(), - }), - }, - }, - }, - // 获取 MinedBlockList - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchMinedBlockList/{blockHash}`, - config: { - cors: true, - handler: async (request, h) => { - const querys = [`account/${request.params.blockHash}/minedBlockList`].map((ids) => { - return new Promise((resolve, reject) => { - console.log(`${API_HOST}/${ids}`); - superagent - .get(`${API_HOST}/${ids}`) - .query(request.query) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - if (code == 0) resolve({ [ids]: result.data }); - else reject({}); - }) - .catch((e) => { - console.log(e.toString()); - reject({}); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response({ code: 0, result: payload }); - }, - description: '获取 MinedBlockList', - tags: ['api'], - validate: { - query: Joi.object().keys({ - pageNum: Joi.string().required(), - pageSize: Joi.string().required(), - }), - params: Joi.object().keys({ - blockHash: Joi.string().required(), - }), - }, - }, - }, - // 获取 RefereeBlockList - { - method: 'GET', - path: `${SERVER_PREFIX}/fetchRefereeBlockList/{blockHash}`, - config: { - cors: true, - handler: async (request, h) => { - const querys = [`block/${request.params.blockHash}/refereeBlockList`].map((ids) => { - return new Promise((resolve, reject) => { - console.log(`${API_HOST}/${ids}`); - superagent - .get(`${API_HOST}/${ids}`) - .query(request.query) - .then((callback) => { - const { code, result, message } = JSON.parse(callback.text); - if (code == 0) resolve({ [ids]: result.data }); - else reject({}); - }) - .catch((e) => { - console.log(e.toString()); - reject({}); - }); - }); - }); - const payload = await Promise.all(querys); - return h.response({ code: 0, result: payload }); - }, - description: '获取 RefereeBlockList', - tags: ['api'], - validate: { - query: Joi.object().keys({ - pageNum: Joi.string().required(), - pageSize: Joi.string().required(), - }), - params: Joi.object().keys({ - blockHash: Joi.string().required(), - }), - }, - }, - }, ]); await server.start(); diff --git a/src/components/SearchBox/index.js b/src/components/SearchBox/index.js index 5edb657..9653666 100644 --- a/src/components/SearchBox/index.js +++ b/src/components/SearchBox/index.js @@ -134,30 +134,28 @@ class SearchBox extends Component { if (filterValue === 0) { try { - const { code, result } = (await superagent.get(`/proxy/fetchHashType/${value}`)).body; + const { code, result } = (await superagent.get(`/api/util/type/${value}`)).body; if (code !== 0) { history.push(`/search-notfound?searchId=${value}`); hideLoading(); return; } - if (typeof result !== 'undefined') { - switch (result) { - case 0: - history.push(`/blocksdetail/${value}`); - break; - case 1: - history.push(`/transactionsdetail/${value}`); - break; - case 2: - history.push(`/accountdetail/${value}`); - break; - case 3: - history.push(`/epochsdetail/${value}`); - break; - default: - console.log('unknow case'); - break; - } + switch (result.data) { + case 0: + history.push(`/blocksdetail/${value}`); + break; + case 1: + history.push(`/transactionsdetail/${value}`); + break; + case 2: + history.push(`/accountdetail/${value}`); + break; + case 3: + history.push(`/epochsdetail/${value}`); + break; + default: + console.log('unknow case'); + break; } } catch (e) { console.log(e); diff --git a/src/index.html b/src/index.html index fb84881..fb967eb 100755 --- a/src/index.html +++ b/src/index.html @@ -7,9 +7,9 @@ - + <% htmlWebpackPlugin.files.css.forEach((str) => { %> - + <% }); %> diff --git a/src/pages/Account/detail.js b/src/pages/Account/detail.js index dacd761..67d209f 100644 --- a/src/pages/Account/detail.js +++ b/src/pages/Account/detail.js @@ -14,7 +14,7 @@ import DataList from '../../components/DataList'; import Countdown from '../../components/Countdown'; import TableLoading from '../../components/TableLoading'; import EllipsisLine from '../../components/EllipsisLine'; -import { convertToValueorFee, converToGasPrice, i18n } from '../../utils'; +import { convertToValueorFee, converToGasPrice, i18n, sendRequest } from '../../utils'; import CopyButton from '../../components/CopyButton'; import QrcodeButton from '../../components/QrcodeButton'; import * as commonCss from '../../globalStyles/common'; @@ -415,67 +415,60 @@ class Detail extends Component { this.fetchAccountDetail(params.accountid, queries); } - async fetchAccountDetail(accountid, queries) { + fetchAccountDetail(accountid, queries) { const { history } = this.props; this.setState({ isLoading: true, accountid }); - try { - const { code, result } = (await superagent.get(`/proxy/fetchAccountDetail/${accountid}`).query(queries)).body; - if (!code) { - this.setState( - { - accountDetail: result.find((item) => Object.keys(item)[0] === `account/${accountid}`)[`account/${accountid}`], - // TxList: result.find((item) => Object.keys(item)[0] === `account/${accountid}/transactionList`)[ - // `account/${accountid}/transactionList` - // ], - TxList: get( - result.find((item) => Object.keys(item)[0] === `account/${accountid}/transactionList`), - `account/${accountid}/transactionList`, - [] - ), - TxTotalCount: get( - result.find((item) => Object.keys(item)[0] === `account/${accountid}/transactionList`), - `total_account/${accountid}/transactionList`, - [] - ), - minedTotalCount: - get(result.find((item) => Object.keys(item)[0] === `account/${accountid}`), [`account/${accountid}`, 'minedBlocks']) || 0, - }, - () => { - this.setState({ isLoading: false, queries }); - } - ); - } else if (code === 1) { + sendRequest({ + url: `/api/account/${accountid}`, + query: {}, + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + accountDetail: res.body.result.data, + minedTotalCount: res.body.result.data.minedBlocks, + isLoading: false, + }); + } else if (res.body.code === 1) { history.push(`/search-notfound?searchId=${accountid}`); + } else { + this.setState({ + showMaintaining: true, + isLoading: false, + }); } - } catch (e) { + }); + + sendRequest({ + url: `/api/account/${accountid}/transactionList`, + query: { + ...queries, + }, + }).then((res) => { this.setState({ - showMaintaining: true, + TxList: res.body.result.data, + TxTotalCount: res.body.result.total, }); - } - return {}; + }); } - async fetchMinedBlockList(accountid, curMinedPage) { + fetchMinedBlockList(accountid, curMinedPage) { this.setState({ isLoading: true }); - const { code, result } = (await superagent.get(`/proxy/fetchMinedBlockList/${accountid}?pageNum=${curMinedPage}&pageSize=10`)).body; - if (!code) { - this.setState( - { - minedBlockList: result.find((item) => Object.keys(item)[0] === `account/${accountid}/minedBlockList`)[ - `account/${accountid}/minedBlockList` - ], - }, - () => { - this.setState({ - isLoading: false, - curMinedPage, - }); - } - ); - } - this.setState({ isLoading: false }); - return {}; + sendRequest({ + url: `/api/account/${accountid}/minedBlockList`, + query: { + pageNum: curMinedPage, + pageSize: 10, + }, + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + minedBlockList: res.body.result.data, + isLoading: false, + curMinedPage, + }); + } + }); } render() { @@ -579,7 +572,7 @@ class Detail extends Component {
{showMaintaining && (
- {intl.formatMessage({ id: 'system maintaining, please visit after 9/9' })} + {intl.formatMessage({ id: 'system maintaining, please visit later' })}
)} diff --git a/src/pages/Block/detail.js b/src/pages/Block/detail.js index f02bb6f..9999dd0 100644 --- a/src/pages/Block/detail.js +++ b/src/pages/Block/detail.js @@ -10,7 +10,7 @@ import Countdown from '../../components/Countdown'; import TableLoading from '../../components/TableLoading'; import DataList from '../../components/DataList'; import EllipsisLine from '../../components/EllipsisLine'; -import { convertToValueorFee, converToGasPrice, i18n } from '../../utils'; +import { convertToValueorFee, converToGasPrice, i18n, sendRequest } from '../../utils'; import media from '../../globalStyles/media'; import * as commonCss from '../../globalStyles/common'; @@ -268,10 +268,13 @@ const RefColumns = [ ]; class Detail extends Component { - constructor() { - super(); + constructor(...args) { + super(...args); + const { + match: { params }, + } = this.props; this.state = { - blockhash: '', + blockhash: params.blockhash, currentTab: 1, TxTotalCount: 0, refereeBlockList: [], @@ -286,45 +289,65 @@ class Detail extends Component { const { match: { params }, } = this.props; - this.fetchTxDetail(params.blockhash, { activePage: 1 }); + this.fetchBlockDetail(params.blockhash, { activePage: 1 }); + this.fetchReffereBlock(params.blockhash); } - async fetchTxDetail(blockHash, { activePage }) { + fetchBlockDetail(blockHash, { activePage }) { const { history } = this.props; this.setState({ isLoading: true, blockhash: blockHash }); - const { code, result } = (await superagent.get(`/proxy/fetchBlockDetail/${blockHash}?pageNum=${activePage}&pageSize=10`)).body; - if (!code) { - this.setState( - { - blockDetail: result.find((item) => Object.keys(item)[0] === `block/${blockHash}`)[`block/${blockHash}`], - TxList: result.find((item) => Object.keys(item)[0] === `block/${blockHash}/transactionList`)[ - `block/${blockHash}/transactionList` - ], - TxTotalCount: result.find((item) => Object.keys(item)[0] === `block/${blockHash}/transactionList`)[ - `total_block/${blockHash}/transactionList` - ], - }, - () => this.setState({ isLoading: false, curPage: activePage }) - ); - } else if (code === 1) { - history.push(`/search-notfound?searchId=${blockHash}`); - } + + sendRequest({ + url: `/api/block/${blockHash}`, + query: {}, + showError: false, + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + blockDetail: res.body.result.data, + isLoading: false, + }); + } else if (res.body.code === 1) { + history.push(`/search-notfound?searchId=${blockHash}`); + } + }); + + sendRequest({ + url: `/api/block/${blockHash}/transactionList`, + query: { + pageNum: activePage, + pageSize: 10, + }, + showError: false, + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + TxList: res.body.result.data, + TxTotalCount: res.body.result.total, + curPage: activePage, + }); + } + }); } - async fetchReffereBlock(blockHash) { + fetchReffereBlock(blockHash) { this.setState({ isLoading: true }); - const { code, result } = (await superagent.get(`/proxy/fetchRefereeBlockList/${blockHash}?pageNum=1&pageSize=20`)).body; - if (!code) { - this.setState( - { - refereeBlockList: result.find((item) => Object.keys(item)[0] === `block/${blockHash}/refereeBlockList`)[ - `block/${blockHash}/refereeBlockList` - ], - }, - () => this.setState({ isLoading: false }) - ); - } - return {}; + + sendRequest({ + url: `/api/block/${blockHash}/refereeBlockList`, + query: { + pageNum: 1, + pageSize: 20, + }, + showError: false, + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + refereeBlockList: res.body.result.data, + isLoading: false, + }); + } + }); } render() { @@ -334,7 +357,7 @@ class Detail extends Component { } = this.props; if (blockhash !== params.blockhash) { - this.fetchTxDetail(params.blockhash, { activePage: 1 }); + this.fetchBlockDetail(params.blockhash, { activePage: 1 }); } // console.log(refereeBlockList, '===refereeBlockList'); @@ -411,7 +434,6 @@ class Detail extends Component { className={currentTab === 2 ? 'active item' : 'item'} type="button" onClick={() => { - this.fetchReffereBlock(params.blockhash); this.setState({ currentTab: 2 }); }} > @@ -442,7 +464,7 @@ class Detail extends Component { }} onPageChange={(e, data) => { e.preventDefault(); - this.fetchTxDetail(params.blockhash, data); + this.fetchBlockDetail(params.blockhash, data); }} activePage={curPage} totalPages={Math.ceil(TxTotalCount / 10)} @@ -462,7 +484,7 @@ class Detail extends Component { activePage={curPage} onPageChange={(e, data) => { e.preventDefault(); - this.fetchTxDetail(params.blockhash, data); + this.fetchBlockDetail(params.blockhash, data); }} ellipsisItem={null} firstItem={null} diff --git a/src/pages/BlockAndTxn/index.js b/src/pages/BlockAndTxn/index.js index 67e6007..091e8f0 100644 --- a/src/pages/BlockAndTxn/index.js +++ b/src/pages/BlockAndTxn/index.js @@ -131,22 +131,36 @@ class BlockAndTxn extends Component { clearInterval(this.timerId); } - async fetchInitList() { - const { code, result } = (await sendRequest({ - url: '/proxy/fetchInitBlockandTxList', + fetchInitList() { + sendRequest({ + url: '/api/block/list', query: { pageNum: 1, pageSize: 10, }, - })).body; - if (!code) { - this.setState({ - showLoading: false, - BlockList: result.find((item) => Object.keys(item)[0] === 'block/list')['block/list'] || [], - TxList: result.find((item) => Object.keys(item)[0] === 'transaction/list')['transaction/list'] || [], - plusTimeCount: 0, - }); - } + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + showLoading: false, + BlockList: res.body.result.data, + }); + } + }); + + sendRequest({ + url: '/api/transaction/list', + query: { + pageNum: 1, + pageSize: 10, + }, + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + TxList: res.body.result.data, + plusTimeCount: 0, + }); + } + }); } render() { diff --git a/src/pages/Epoch/detail.js b/src/pages/Epoch/detail.js index 1eb0623..2cc91b5 100644 --- a/src/pages/Epoch/detail.js +++ b/src/pages/Epoch/detail.js @@ -10,7 +10,7 @@ import EllipsisLine from '../../components/EllipsisLine'; import Countdown from '../../components/Countdown'; import media from '../../globalStyles/media'; import * as commonCss from '../../globalStyles/common'; -import { i18n } from '../../utils'; +import { i18n, sendRequest } from '../../utils'; const Wrapper = styled.div` max-width: 1200px; @@ -166,28 +166,23 @@ class Detail extends Component { } async fetchInitList({ epochid, curPage }) { - const { history } = this.props; this.setState({ isLoading: true }); - const { code, result } = (await superagent.get(`/proxy/fetchEpochList?pageNum=${curPage}&pageSize=10&epochNum=${epochid}`)).body; - if (!code) { - this.setState( - { - BlockList: result.find((item) => Object.keys(item)[0] === 'block/list')['block/list'], - totalCount: result.find((item) => { - return item['total_block/list']; - })['total_block/list'], - curPage, - }, - () => { - this.setState({ - isLoading: false, - }); - } - ); - } else if (code === 1) { - history.push(`/search-notfound?searchId=${epochid}`); - } - this.setState({ isLoading: false }); + const reqBlockList = sendRequest({ + url: '/api/block/list', + query: { + pageNum: curPage, + pageSize: 10, + epochNum: epochid, + }, + }); + reqBlockList.then((res) => { + this.setState({ + BlockList: res.body.result.data, + totalCount: res.body.result.total, + isLoading: false, + curPage, + }); + }); } render() { diff --git a/src/pages/Transaction/detail.js b/src/pages/Transaction/detail.js index ebb3fe6..0c2f987 100644 --- a/src/pages/Transaction/detail.js +++ b/src/pages/Transaction/detail.js @@ -6,7 +6,7 @@ import superagent from 'superagent'; import moment from 'moment'; import TableLoading from '../../components/TableLoading'; import media from '../../globalStyles/media'; -import { i18n, renderAny } from '../../utils'; +import { i18n, renderAny, sendRequest } from '../../utils'; const Wrapper = styled.div` max-width: 1200px; @@ -94,20 +94,30 @@ class Detail extends Component { this.fetchTxDetail(params.txnhash); } - async fetchTxDetail(txnhash) { + fetchTxDetail(txnhash) { const { history } = this.props; this.setState({ isLoading: true, txnhash }); - const { code, result } = (await superagent.get(`/proxy/fetchTxDetail?transactionHash=${txnhash}`).catch((e) => { - window.location.href = `/notfoundtx?searchId=${txnhash}`; - })).body; - if (!code) { - this.setState({ result }, () => this.setState({ isLoading: false })); - } else if (code === 4) { - history.push(`/notfoundtx?searchId=${txnhash}`); - } else if (code === 1) { - history.push(`/search-notfound?searchId=${txnhash}`); - } - return {}; + return sendRequest({ + url: `/api/transaction/${txnhash}`, + query: {}, + showError: false, + }).then((res) => { + switch (res.body.code) { + case 1: + history.push(`/search-notfound?searchId=${txnhash}`); + break; + case 4: + history.push(`/notfoundtx?searchId=${txnhash}`); + break; + case 0: + default: + this.setState({ + result: res.body.result.data, + isLoading: false, + }); + break; + } + }); } render() { diff --git a/src/pages/Transaction/list.js b/src/pages/Transaction/list.js index fbb5914..5dcbc3c 100644 --- a/src/pages/Transaction/list.js +++ b/src/pages/Transaction/list.js @@ -6,7 +6,7 @@ import DataList from '../../components/DataList'; import Countdown from '../../components/Countdown'; import TableLoading from '../../components/TableLoading'; import EllipsisLine from '../../components/EllipsisLine'; -import { convertToValueorFee, converToGasPrice, i18n } from '../../utils'; +import { convertToValueorFee, converToGasPrice, i18n, sendRequest } from '../../utils'; import media from '../../globalStyles/media'; import ConfirmSimple from '../../components/ConfirmSimple'; import * as commonCss from '../../globalStyles/common'; @@ -164,7 +164,7 @@ class List extends Component { curPageBase = this.state.curPage; } - async fetchTxList({ activePage }) { + fetchTxList({ activePage }) { if (activePage > 10000) { this.setState({ confirmOpen: true, @@ -172,19 +172,24 @@ class List extends Component { return; } this.setState({ isLoading: true }); - const { code, result } = (await superagent.get(`/proxy/fetchInitBlockandTxList?pageNum=${activePage}&pageSize=10`)).body; - if (!code) { - this.setState( - { - TxList: result.find((item) => Object.keys(item)[0] === 'transaction/list')['transaction/list'], - TotalCount: result.find((item) => Object.keys(item)[0] === 'transaction/list')['total_transaction/list'], - }, - () => { - this.setState({ isLoading: false, curPage: activePage }); - document.dispatchEvent(new Event('scroll-to-top')); - } - ); - } + + sendRequest({ + url: '/api/transaction/list', + query: { + pageNum: activePage, + pageSize: 10, + }, + }).then((res) => { + if (res.body.code === 0) { + this.setState({ + TxList: res.body.result.data, + TotalCount: res.body.result.total, + curPage: activePage, + }); + document.dispatchEvent(new Event('scroll-to-top')); + } + this.setState({ isLoading: false }); + }); } render() { diff --git a/src/utils/index.js b/src/utils/index.js index c8b0334..a18301d 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -176,7 +176,7 @@ export const sendRequest = (config) => { }); reqPromise.then((result) => { - if (result.body.code !== 0) { + if (result.body.code !== 0 && config.showError !== false) { let title; switch (result.body.code) { case 1: diff --git a/webpack.config.js b/webpack.config.js index b284608..bb48571 100755 --- a/webpack.config.js +++ b/webpack.config.js @@ -202,13 +202,7 @@ module.exports = { }), ], splitChunks: { - cacheGroups: { - commons: { - name: 'commons', - chunks: 'initial', - minChunks: 2, - }, - }, + chunks: 'all', }, }, };