Skip to content

Commit

Permalink
Fix: Eslint parsing (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliomir authored Nov 5, 2024
1 parent 7e684ac commit 3c2d1e7
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 196 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
node: true,
},
extends: ['airbnb-base', 'plugin:react/recommended', 'plugin:prettier/recommended'],
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
jsx: true,
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ jobs:
- name: Format
run: |
npm run format:check
- name: Linting
run: |
npm run lint
75 changes: 37 additions & 38 deletions src/components/AddressDetailLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/

import React from 'react';
import hathorLib from '@hathor/wallet-lib';
import ReactLoading from 'react-loading';
import { isEqual } from 'lodash';
import AddressSummaryLegacy from './AddressSummaryLegacy';
import AddressHistoryLegacy from './AddressHistoryLegacy';
import PaginationURL from '../utils/pagination';
import hathorLib from '@hathor/wallet-lib';
import ReactLoading from 'react-loading';
import colors from '../index.scss';
import WebSocketHandler from '../WebSocketHandler';
import { TX_COUNT } from '../constants';
import { isEqual } from 'lodash';
import helpers from '../utils/helpers';
import metadataApi from '../api/metadataApi';
import addressApiLegacy from '../api/addressApiLegacy';
Expand Down Expand Up @@ -130,8 +130,8 @@ class AddressDetailLegacy extends React.Component {
// We only add new tx/blocks if it's the first page
if (!this.state.hasBefore) {
if (this.shouldUpdate(tx, true)) {
let transactions = this.state.transactions;
let hasAfter = this.state.hasAfter || transactions.length === TX_COUNT;
let { transactions } = this.state;
const hasAfter = this.state.hasAfter || transactions.length === TX_COUNT;
transactions = helpers.updateListWs(transactions, tx, TX_COUNT);

const newNumberOfTransactions = this.state.numberOfTransactions + 1;
Expand Down Expand Up @@ -252,7 +252,7 @@ class AddressDetailLegacy extends React.Component {
this.setState({ loadingSummary: false });
return;
}
selectedToken = keys[0];
[selectedToken] = keys;
}
}

Expand Down Expand Up @@ -316,7 +316,7 @@ class AddressDetailLegacy extends React.Component {
*/
shouldUpdate = (tx, checkToken) => {
const arr = [...tx.outputs, ...tx.inputs];
const token = this.pagination.obtainQueryParams().token;
const { token } = this.pagination.obtainQueryParams();

for (const element of arr) {
if (element.decoded.address === this.state.address) {
Expand Down Expand Up @@ -374,39 +374,38 @@ class AddressDetailLegacy extends React.Component {
const renderData = () => {
if (this.state.errorMessage) {
return <p className="text-danger mt-3">{this.state.errorMessage}</p>;
} else if (this.state.address === null) {
}
if (this.state.address === null) {
return null;
} else {
if (this.state.loadingSummary || this.state.loadingHistory) {
return <ReactLoading type="spin" color={colors.purpleHathor} delay={500} />;
} else {
return (
<div>
{renderWarningAlert()}
<AddressSummaryLegacy
address={this.state.address}
balance={this.state.balance}
selectedToken={this.state.selectedToken}
numberOfTransactions={this.state.numberOfTransactions}
tokenSelectChanged={this.onTokenSelectChanged}
isNFT={isNFT()}
metadataLoaded={this.state.metadataLoaded}
/>
<AddressHistoryLegacy
address={this.state.address}
onRowClicked={this.onRowClicked}
pagination={this.pagination}
selectedToken={this.state.selectedToken}
transactions={this.state.transactions}
hasAfter={this.state.hasAfter}
hasBefore={this.state.hasBefore}
isNFT={isNFT()}
metadataLoaded={this.state.metadataLoaded}
/>
</div>
);
}
}
if (this.state.loadingSummary || this.state.loadingHistory) {
return <ReactLoading type="spin" color={colors.purpleHathor} delay={500} />;
}
return (
<div>
{renderWarningAlert()}
<AddressSummaryLegacy
address={this.state.address}
balance={this.state.balance}
selectedToken={this.state.selectedToken}
numberOfTransactions={this.state.numberOfTransactions}
tokenSelectChanged={this.onTokenSelectChanged}
isNFT={isNFT()}
metadataLoaded={this.state.metadataLoaded}
/>
<AddressHistoryLegacy
address={this.state.address}
onRowClicked={this.onRowClicked}
pagination={this.pagination}
selectedToken={this.state.selectedToken}
transactions={this.state.transactions}
hasAfter={this.state.hasAfter}
hasBefore={this.state.hasBefore}
isNFT={isNFT()}
metadataLoaded={this.state.metadataLoaded}
/>
</div>
);
};

return <div className="content-wrapper">{renderData()}</div>;
Expand Down
30 changes: 13 additions & 17 deletions src/components/AddressHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import React from 'react';
import { connect } from 'react-redux';
import dateFormatter from '../utils/date';
import hathorLib from '@hathor/wallet-lib';
import PropTypes from 'prop-types';
import dateFormatter from '../utils/date';
import PaginationURL from '../utils/pagination';
import SortableTable from './SortableTable';
import EllipsiCell from './EllipsiCell';
Expand All @@ -30,7 +30,7 @@ class AddressHistory extends SortableTable {
* @return {boolean} If the tx has only authority in the search address
*/
isAllAuthority = tx => {
for (let txin of tx.inputs) {
for (const txin of tx.inputs) {
if (
!hathorLib.transactionUtils.isAuthorityOutput(txin) &&
txin.decoded.address === this.props.address
Expand All @@ -39,7 +39,7 @@ class AddressHistory extends SortableTable {
}
}

for (let txout of tx.outputs) {
for (const txout of tx.outputs) {
if (
!hathorLib.transactionUtils.isAuthorityOutput(txout) &&
txout.decoded.address === this.props.address
Expand Down Expand Up @@ -135,12 +135,10 @@ class AddressHistory extends SortableTable {
);
}
trClass = 'input-tr';
} else {
if (this.props.txCache[tx.tx_id]) {
if (this.isAllAuthority(this.props.txCache[tx.tx_id])) {
statusElement = <span>Authority</span>;
prettyValue = '--';
}
} else if (this.props.txCache[tx.tx_id]) {
if (this.isAllAuthority(this.props.txCache[tx.tx_id])) {
statusElement = <span>Authority</span>;
prettyValue = '--';
}
}

Expand All @@ -149,7 +147,7 @@ class AddressHistory extends SortableTable {
trClass = '';
}
return (
<tr key={tx.tx_id} className={trClass} onClick={e => this.props.onRowClicked(tx.tx_id)}>
<tr key={tx.tx_id} className={trClass} onClick={_e => this.props.onRowClicked(tx.tx_id)}>
<td className="d-none d-lg-table-cell pe-3">
{hathorLib.transactionUtils.getTxType(tx)}
</td>
Expand Down Expand Up @@ -211,12 +209,10 @@ class AddressHistory extends SortableTable {
);
}
trClass = 'input-tr';
} else {
if (this.props.txCache[tx.tx_id]) {
if (this.isAllAuthority(this.props.txCache[tx.tx_id])) {
statusElement = <span>Authority</span>;
prettyValue = '--';
}
} else if (this.props.txCache[tx.tx_id]) {
if (this.isAllAuthority(this.props.txCache[tx.tx_id])) {
statusElement = <span>Authority</span>;
prettyValue = '--';
}
}

Expand All @@ -225,7 +221,7 @@ class AddressHistory extends SortableTable {
trClass = '';
}
return (
<tr key={tx.tx_id} className={trClass} onClick={e => this.props.onRowClicked(tx.tx_id)}>
<tr key={tx.tx_id} className={trClass} onClick={_e => this.props.onRowClicked(tx.tx_id)}>
<td className="pe-3">{hathorLib.transactionUtils.getTxType(tx)}</td>
<td className="pe-3">
<EllipsiCell id={tx.tx_id} />
Expand Down
82 changes: 38 additions & 44 deletions src/components/AddressHistoryLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import React from 'react';
import { Link } from 'react-router-dom';
import dateFormatter from '../utils/date';
import hathorLib, { numberUtils } from '@hathor/wallet-lib';
import PropTypes from 'prop-types';
import PaginationURL from '../utils/pagination';
import { connect } from 'react-redux';
import PaginationURL from '../utils/pagination';
import dateFormatter from '../utils/date';

const mapStateToProps = state => ({
decimalPlaces: state.serverInfo.decimal_places,
Expand All @@ -29,15 +29,15 @@ class AddressHistory extends React.Component {
const token = this.props.selectedToken;
let value = 0;

for (let txin of tx.inputs) {
for (const txin of tx.inputs) {
if (txin.token === token && txin.decoded.address === this.props.address) {
if (!hathorLib.transactionUtils.isAuthorityOutput(txin)) {
value -= txin.value;
}
}
}

for (let txout of tx.outputs) {
for (const txout of tx.outputs) {
if (txout.token === token && txout.decoded.address === this.props.address) {
if (!hathorLib.transactionUtils.isAuthorityOutput(txout)) {
value += txout.value;
Expand All @@ -56,7 +56,7 @@ class AddressHistory extends React.Component {
* @return {boolean} If the tx has only authority in the search address
*/
isAllAuthority = tx => {
for (let txin of tx.inputs) {
for (const txin of tx.inputs) {
if (
!hathorLib.transactionUtils.isAuthorityOutput(txin) &&
txin.decoded.address === this.props.address
Expand All @@ -65,7 +65,7 @@ class AddressHistory extends React.Component {
}
}

for (let txout of tx.outputs) {
for (const txout of tx.outputs) {
if (
!hathorLib.transactionUtils.isAuthorityOutput(txout) &&
txout.decoded.address === this.props.address
Expand Down Expand Up @@ -93,39 +93,35 @@ class AddressHistory extends React.Component {
const loadPagination = () => {
if (this.props.transactions.length === 0) {
return null;
} else {
return (
<nav aria-label="Tx pagination" className="d-flex justify-content-center">
<ul className="pagination">
<li
ref="txPrevious"
className={!this.props.hasBefore ? 'page-item me-3 disabled' : 'page-item me-3'}
}
return (
<nav aria-label="Tx pagination" className="d-flex justify-content-center">
<ul className="pagination">
<li
ref="txPrevious"
className={!this.props.hasBefore ? 'page-item me-3 disabled' : 'page-item me-3'}
>
<Link
className="page-link"
to={this.props.pagination.setURLParameters({
hash: getFirstHash(),
page: 'previous',
})}
>
<Link
className="page-link"
to={this.props.pagination.setURLParameters({
hash: getFirstHash(),
page: 'previous',
})}
>
Previous
</Link>
</li>
<li
ref="txNext"
className={!this.props.hasAfter ? 'page-item disabled' : 'page-item'}
Previous
</Link>
</li>
<li ref="txNext" className={!this.props.hasAfter ? 'page-item disabled' : 'page-item'}>
<Link
className="page-link"
to={this.props.pagination.setURLParameters({ hash: getLastHash(), page: 'next' })}
>
<Link
className="page-link"
to={this.props.pagination.setURLParameters({ hash: getLastHash(), page: 'next' })}
>
Next
</Link>
</li>
</ul>
</nav>
);
}
Next
</Link>
</li>
</ul>
</nav>
);
};

const loadTable = () => {
Expand Down Expand Up @@ -164,7 +160,7 @@ class AddressHistory extends React.Component {
};

const loadTableBody = () => {
return this.props.transactions.map((tx, idx) => {
return this.props.transactions.map((tx, _idx) => {
const value = this.calculateAddressBalance(tx);
let statusElement = '';
let trClass = '';
Expand Down Expand Up @@ -199,11 +195,9 @@ class AddressHistory extends React.Component {
);
}
trClass = 'input-tr';
} else {
if (this.isAllAuthority(tx)) {
statusElement = <span>Authority</span>;
prettyValue = '--';
}
} else if (this.isAllAuthority(tx)) {
statusElement = <span>Authority</span>;
prettyValue = '--';
}

if (!this.props.metadataLoaded) {
Expand All @@ -212,7 +206,7 @@ class AddressHistory extends React.Component {
}

return (
<tr key={tx.tx_id} className={trClass} onClick={e => this.props.onRowClicked(tx.tx_id)}>
<tr key={tx.tx_id} className={trClass} onClick={_e => this.props.onRowClicked(tx.tx_id)}>
<td className="d-none d-lg-table-cell pe-3">
{hathorLib.transactionUtils.getTxType(tx)}
</td>
Expand Down
Loading

0 comments on commit 3c2d1e7

Please sign in to comment.