Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: changes to use wallet-lib v1.1.0 #252

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,902 changes: 2,606 additions & 2,296 deletions package-lock.json

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
"version": "0.17.0",
"private": true,
"dependencies": {
"@hathor/wallet-lib": "^0.29.0",
"axios": "^0.17.1",
"bootstrap": "^4.0.0",
"d3-selection": "^1.3.2",
"d3-zoom": "^1.7.3",
"font-awesome": "^4.7.0",
"jquery": "^3.2.1",
"lodash": "^4.17.11",
"npm-run-all": "^4.1.2",
"popper.js": "^1.12.9",
"prop-types": "^15.7.2",
"qrcode.react": "^0.8.0",
"react": "^16.12.0",
"react-cookie-consent": "^6.2.4",
"react-copy-to-clipboard": "^5.0.1",
"react-dom": "^16.2.0",
"react-gtm-module": "^2.0.11",
"react-loading": "^1.0.3",
"react-paginate": "^5.0.0",
"react-redux": "^5.0.7",
"@hathor/wallet-lib": "1.1.0",
"axios": "0.17.1",
"bootstrap": "4.6.2",
"d3-selection": "1.4.2",
"d3-zoom": "1.8.3",
"font-awesome": "4.7.0",
"jquery": "3.7.0",
"lodash": "4.17.21",
"npm-run-all": "4.1.5",
"popper.js": "1.16.1",
"prop-types": "15.8.1",
"qrcode.react": "0.8.0",
"react": "16.14.0",
"react-cookie-consent": "6.4.1",
"react-copy-to-clipboard": "5.1.0",
"react-dom": "16.14.0",
"react-gtm-module": "2.0.11",
"react-loading": "1.0.5",
"react-paginate": "5.3.1",
"react-redux": "5.1.2",
"react-router-dom": "4.2.2",
"react-scripts": "^3.2.0",
"redux": "^4.0.0",
"sass": "^1.44.0",
"viz.js": "^2.1.2",
"unleash-proxy-client": "^1.11.0",
"@unleash/proxy-client-react": "^1.0.4"
"react-scripts": "3.4.4",
"redux": "4.2.1",
"sass": "1.64.2",
"viz.js": "2.1.2",
"unleash-proxy-client": "1.11.0",
"@unleash/proxy-client-react": "1.0.4"
},
"scripts": {
"build-css": "sass src:src",
Expand Down
11 changes: 4 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ import { apiLoadErrorUpdate, dashboardUpdate, isVersionAllowedUpdate } from "./a
import { connect } from "react-redux";
import versionApi from './api/version';
import helpers from './utils/helpers';
import hathorLib from '@hathor/wallet-lib';
import { axios as hathorLibAxios, config as hathorLibConfig } from '@hathor/wallet-lib';
import { BASE_URL } from './constants';
import createRequestInstance from './api/customAxiosInstance';

const store = new hathorLib.MemoryStore();
hathorLib.storage.setStore(store);
hathorLib.storage.setItem('wallet:server', BASE_URL);

hathorLibConfig.setServerUrl(BASE_URL);

const mapDispatchToProps = dispatch => {
return {
Expand All @@ -58,11 +55,11 @@ class Root extends React.Component {
componentDidMount() {
WebSocketHandler.on('dashboard', this.handleWebsocket);

hathorLib.axios.registerNewCreateRequestInstance(createRequestInstance);
hathorLibAxios.registerNewCreateRequestInstance(createRequestInstance);
this.props.apiLoadErrorUpdate({apiLoadError: false});

versionApi.getVersion().then((data) => {
hathorLib.network.setNetwork(data.network.split('-')[0]);
hathorLibConfig.setNetwork(data.network.split('-')[0]);
this.props.isVersionAllowedUpdate({allowed: helpers.isVersionAllowed(data.version)});
}, (e) => {
// Error in request
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddressDetailExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ class AddressDetailExplorer extends React.Component {
*/
updateAddress = (address) => {
this.setState({ queryParams: this.pagination.obtainQueryParams() }, () => {
if (hathorLib.transaction.isAddressValid(address)) {
const network = hathorLib.config.getNetwork();
const addressObj = new hathorLib.Address(address, { network });
if (addressObj.isValid()) {
this.setState({
address,
loadingTokens: true,
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddressDetailLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ class AddressDetailLegacy extends React.Component {
*/
updateAddress = (address) => {
this.setState({ queryParams: this.pagination.obtainQueryParams() }, () => {
if (hathorLib.transaction.isAddressValid(address)) {
const network = hathorLib.config.getNetwork();
const addressObj = new hathorLib.Address(address, { network });
if (addressObj.isValid()) {
this.setState({ address, loadingSummary: true, transactions: [], errorMessage: '' }, () => {
const queryParams = this.pagination.obtainQueryParams();
if (queryParams.token !== null) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/AddressHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class AddressHistory extends SortableTable {
*/
isAllAuthority = (tx) => {
for (let txin of tx.inputs) {
if (!hathorLib.wallet.isAuthorityOutput(txin) && txin.decoded.address === this.props.address) {
if (!hathorLib.transactionUtils.isAuthorityOutput(txin) && txin.decoded.address === this.props.address) {
return false;
}
}

for (let txout of tx.outputs) {
if (!hathorLib.wallet.isAuthorityOutput(txout) && txout.decoded.address === this.props.address) {
if (!hathorLib.transactionUtils.isAuthorityOutput(txout) && txout.decoded.address === this.props.address) {
return false;
}
}
Expand Down Expand Up @@ -103,12 +103,12 @@ class AddressHistory extends SortableTable {
}
return (
<tr key={tx.tx_id} className={trClass} onClick={(e) => this.props.onRowClicked(tx.tx_id)}>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.helpers.getTxType(tx)}</td>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.helpers.getShortHash(tx.tx_id)}</td>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.transactionUtils.getTxType(tx)}</td>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.helpersUtils.getShortHash(tx.tx_id)}</td>
<td className="d-none d-lg-table-cell pr-3">{dateFormatter.parseTimestamp(tx.timestamp)}</td>
<td className="state">{statusElement}</td>
<td className="value"><span className="">{prettyValue}</span></td>
<td className="d-lg-none d-table-cell pr-3" colSpan="3">{hathorLib.helpers.getTxType(tx)}<br/>{hathorLib.helpers.getShortHash(tx.tx_id)}<br/>{dateFormatter.parseTimestamp(tx.timestamp)}</td>
<td className="d-lg-none d-table-cell pr-3" colSpan="3">{hathorLib.transactionUtils.getTxType(tx)}<br/>{hathorLib.helpersUtils.getShortHash(tx.tx_id)}<br/>{dateFormatter.parseTimestamp(tx.timestamp)}</td>
</tr>
)
});
Expand Down
14 changes: 7 additions & 7 deletions src/components/AddressHistoryLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class AddressHistory extends React.Component {

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

for (let txout of tx.outputs) {
if (txout.token === token && txout.decoded.address === this.props.address) {
if (!hathorLib.wallet.isAuthorityOutput(txout)) {
if (!hathorLib.transactionUtils.isAuthorityOutput(txout)) {
value += txout.value;
}
}
Expand All @@ -54,13 +54,13 @@ class AddressHistory extends React.Component {
*/
isAllAuthority = (tx) => {
for (let txin of tx.inputs) {
if (!hathorLib.wallet.isAuthorityOutput(txin) && txin.decoded.address === this.props.address) {
if (!hathorLib.transactionUtils.isAuthorityOutput(txin) && txin.decoded.address === this.props.address) {
return false;
}
}

for (let txout of tx.outputs) {
if (!hathorLib.wallet.isAuthorityOutput(txout) && txout.decoded.address === this.props.address) {
if (!hathorLib.transactionUtils.isAuthorityOutput(txout) && txout.decoded.address === this.props.address) {
return false;
}
}
Expand Down Expand Up @@ -165,13 +165,13 @@ class AddressHistory extends React.Component {

return (
<tr key={tx.tx_id} className={trClass} onClick={(e) => this.props.onRowClicked(tx.tx_id)}>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.helpers.getTxType(tx)}</td>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.helpers.getShortHash(tx.tx_id)}</td>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.transactionUtils.getTxType(tx)}</td>
<td className="d-none d-lg-table-cell pr-3">{hathorLib.helpersUtils.getShortHash(tx.tx_id)}</td>
<td className="d-none d-lg-table-cell pr-3">{dateFormatter.parseTimestamp(tx.timestamp)}</td>
<td className={tx.is_voided ? 'voided state' : 'state'}>{statusElement}</td>
<td>{tx.is_voided && <span className="voided-element">Voided</span>}</td>
<td className='value'><span className={tx.is_voided ? 'voided' : ''}>{prettyValue}</span></td>
<td className="d-lg-none d-table-cell pr-3" colSpan="3">{hathorLib.helpers.getTxType(tx)}<br/>{hathorLib.helpers.getShortHash(tx.tx_id)}<br/>{dateFormatter.parseTimestamp(tx.timestamp)}</td>
<td className="d-lg-none d-table-cell pr-3" colSpan="3">{hathorLib.transactionUtils.getTxType(tx)}<br/>{hathorLib.helpersUtils.getShortHash(tx.tx_id)}<br/>{dateFormatter.parseTimestamp(tx.timestamp)}</td>
</tr>
);
});
Expand Down
12 changes: 8 additions & 4 deletions src/components/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ class Navigation extends React.Component {
if (regex.test(text)) {
// It's a valid hash
this.props.history.push(`/transaction/${text}`);
} else if (hathorLib.transaction.isAddressValid(text)) {
// It's a valid address
this.props.history.push(`/address/${text}`);
} else {
this.showError();
const network = hathorLib.config.getNetwork();
const addressObj = new hathorLib.Address(text, { network });
if (addressObj.isValid()) {
// It's a valid address
this.props.history.push(`/address/${text}`);
} else {
this.showError();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/token/TokenConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const TokenConfig = (props) => {

const [token, setToken] = useState(props.token);
const [successMessage, setSuccessMessage] = useState('');
const configurationString = hathorLib.tokens.getConfigurationString(token.uid, token.name, token.symbol);
const configurationString = hathorLib.tokensUtils.getConfigurationString(token.uid, token.name, token.symbol);
const alertSuccess = useRef(null);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/token/TokenRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TokenRow extends React.Component {
render() {
return (
<tr onClick={(e) => this.onRowClicked(this.props.token.uid)}>
<td className="d-lg-table-cell pr-3">{hathorLib.helpers.getShortHash(this.props.token.uid)}</td>
<td className="d-lg-table-cell pr-3">{hathorLib.helpersUtils.getShortHash(this.props.token.uid)}</td>
<td className="d-lg-table-cell pr-3">{this.props.token.name}</td>
<td className="d-lg-table-cell pr-3">{this.props.token.symbol}</td>
<td className="d-lg-table-cell pr-3">{this.props.token.nft ? 'NFT' : 'Custom Token'}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/components/tx/TxRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TxRow extends React.Component {
<tr onClick={(e) => this.handleClickTr(this.props.tx.tx_id)}>
<td className="d-none d-lg-table-cell pr-3">{this.props.tx.tx_id}</td>
<td className="d-none d-lg-table-cell pr-3">{dateFormatter.parseTimestamp(this.props.tx.timestamp)}</td>
<td className="d-lg-none d-table-cell pr-3" colSpan="2">{hathorLib.helpers.getShortHash(this.props.tx.tx_id)} {dateFormatter.parseTimestamp(this.props.tx.timestamp)}</td>
<td className="d-lg-none d-table-cell pr-3" colSpan="2">{hathorLib.helpersUtils.getShortHash(this.props.tx.tx_id)} {dateFormatter.parseTimestamp(this.props.tx.timestamp)}</td>
</tr>
);
}
Expand Down
11 changes: 6 additions & 5 deletions src/screens/DashboardTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import React from 'react';
import TxRow from '../components/tx/TxRow';
import hathorLib from '@hathor/wallet-lib';
import WebSocketHandler from '../WebSocketHandler';
import { DASHBOARD_TX_COUNT, DASHBOARD_BLOCKS_COUNT } from '../constants';
import txApi from '../api/txApi';
import helpers from '../utils/helpers';


/**
Expand All @@ -26,11 +27,11 @@ class DashboardTx extends React.Component {

componentDidMount = () => {
this.getInitialData();
hathorLib.WebSocketHandler.on('network', this.handleWebsocket);
WebSocketHandler.on('network', this.handleWebsocket);
}

componentWillUnmount = () => {
hathorLib.WebSocketHandler.removeListener('network', this.handleWebsocket);
WebSocketHandler.removeListener('network', this.handleWebsocket);
}

/**
Expand Down Expand Up @@ -61,14 +62,14 @@ class DashboardTx extends React.Component {
if (tx.is_block) {
let blocks = this.state.blocks;

blocks = hathorLib.helpers.updateListWs(blocks, tx, DASHBOARD_BLOCKS_COUNT);
blocks = helpers.updateListWs(blocks, tx, DASHBOARD_BLOCKS_COUNT);

// Finally we update the state again
this.setState({ blocks });
} else {
let transactions = this.state.transactions;

transactions = hathorLib.helpers.updateListWs(transactions, tx, DASHBOARD_TX_COUNT);
transactions = helpers.updateListWs(transactions, tx, DASHBOARD_TX_COUNT);

// Finally we update the state again
this.setState({ transactions });
Expand Down
2 changes: 1 addition & 1 deletion src/screens/TransactionDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class TransactionDetail extends React.Component {
updateTxInfo = (id) => {
txApi.getTransaction(id).then((data) => {
this.txReceived(data);
if (data.success && !hathorLib.helpers.isBlock(data.tx)) {
if (data.success && !hathorLib.transactionUtils.isBlock(data.tx)) {
this.getConfirmationData();
}
}, (e) => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const helpers = {
* @inner
*/
isMainnet() {
return hathorLib.network.getNetwork().name === 'mainnet';
return hathorLib.config.getNetwork().name === 'mainnet';
},

/**
Expand Down Expand Up @@ -233,9 +233,9 @@ const helpers = {
*/
renderValue(amount, isInteger) {
if (isInteger) {
return hathorLib.helpersUtils.prettyIntegerValue(amount);
return hathorLib.numberUtils.prettyIntegerValue(amount);
} else {
return hathorLib.helpersUtils.prettyValue(amount);
return hathorLib.numberUtils.prettyValue(amount);
}
},

Expand Down