Skip to content
This repository has been archived by the owner on Aug 12, 2021. It is now read-only.

Commit

Permalink
fix: Simplify DB paginations (especially for Txs of old chains) (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youngjoon Lee authored Mar 15, 2021
1 parent 038a313 commit ee61e61
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const endpoint = 'localhost';

MediBloc Explorer Client is using Webpack.

If you want to watch all the changes of the code in real time, run the following command. It will run the MediBloc Explorer on the port 3000(<http://localhost:3000>).
If you want to watch all the changes of the code in real time, run the following command. It will run the MediBloc Explorer on the port 8080(<http://localhost:8080>).

`yarn start`

Expand Down
3 changes: 1 addition & 2 deletions client/src/components/AccountList/AccountList.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class AccountList extends Component {
const props = nextProps || this.props;
const { location: { search } } = props;
const { page = 1 } = qs.parse(search);
const { medState: { numAccount } } = props;
const { from, to } = ranger(page, numAccount, contentsInPage);
const { from, to } = ranger(page, contentsInPage);
w.loader(BlockchainActions.getAccounts({ from, to }));
}

Expand Down
3 changes: 1 addition & 2 deletions client/src/components/BPList/BPList.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class BPList extends Component {
const props = nextProps || this.props;
const { location: { search } } = props;
const { page = 1 } = qs.parse(search);
const { medState: { numCandidate } } = props;
const { from, to } = ranger(page, numCandidate, bpsInPage);
const { from, to } = ranger(page, bpsInPage);
w.loader(BlockchainActions.getBPs({ from, to }));
}

Expand Down
3 changes: 1 addition & 2 deletions client/src/components/BlockList/BlockList.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class BlockList extends Component {
const props = nextProps || this.props;
const { location: { search } } = props;
const { page = 1 } = qs.parse(search);
const { medState: { height } } = props;
const { from, to } = ranger(page, height, contentsInPage);
const { from, to } = ranger(page, contentsInPage);
w.loader(
BlockchainActions
.getBlocks({ from, to }),
Expand Down
10 changes: 4 additions & 6 deletions client/src/components/TxList/TxList.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class TxList extends Component {
}

getTxs() {
const { page, medState: { numTx } } = this.props;
const { from, to } = ranger(page, numTx, contentsInPage);
const { page } = this.props;
const { from, to } = ranger(page, contentsInPage);
w.loader(BlockchainActions.getTxs({ from, to }));
}

getAccTxs() {
const { account, page } = this.props;
const { from, to } = ranger(page, account.totalTxs, contentsInPage);
const { from, to } = ranger(page, contentsInPage);
w.loader(BlockchainActions.getAccountDetail({
address: account.address,
from,
Expand All @@ -61,7 +61,7 @@ class TxList extends Component {
} = this.props;
const titles = txTitleList[type];
const spaces = txSpaceList[type];
const { from, to } = ranger(page, txs.length, contentsInPage);
const { from, to } = ranger(page, contentsInPage);

return (
<div className="txList">
Expand Down Expand Up @@ -119,7 +119,6 @@ class TxList extends Component {

TxList.propTypes = {
account: PropTypes.object,
medState: PropTypes.object,
txList: PropTypes.array.isRequired,
txs: PropTypes.array.isRequired,

Expand All @@ -131,7 +130,6 @@ TxList.propTypes = {

TxList.defaultProps = {
account: {},
medState: {},
};

export default TxList;
2 changes: 1 addition & 1 deletion client/src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// export const NODE_ENDPOINT = '/api/v1';
export const NODE_ENDPOINT = 'http://localhost:3000/api/v1';
export const NODE_ENDPOINT = 'http://localhost:8080/api/v1';



Expand Down
3 changes: 1 addition & 2 deletions client/src/lib/ranger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ranger = (page, amount, contentsInPage) => {
if (amount < contentsInPage) return { from: 0, to: amount };
const ranger = (page, contentsInPage) => {
let from = (page - 1) * contentsInPage;
let to = (page * contentsInPage) - 1;
if (from < 0) from = 0;
Expand Down

0 comments on commit ee61e61

Please sign in to comment.