Skip to content

Commit

Permalink
style: Automatic lint fixes and formatting (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliomir authored Aug 16, 2024
1 parent e600939 commit b61769d
Show file tree
Hide file tree
Showing 87 changed files with 3,010 additions and 2,062 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ jobs:
- name: Build
run: |
make build site=testnet
- name: Format
run: |
npm run format:check
94 changes: 59 additions & 35 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ import VersionError from './screens/VersionError';
import WebSocketHandler from './WebSocketHandler';
import NanoContractDetail from './screens/nano/NanoContractDetail';
import BlueprintDetail from './screens/nano/BlueprintDetail';
import { apiLoadErrorUpdate, dashboardUpdate, isVersionAllowedUpdate, updateServerInfo } from "./actions/index";
import { connect } from "react-redux";
import {
apiLoadErrorUpdate,
dashboardUpdate,
isVersionAllowedUpdate,
updateServerInfo,
} from './actions/index';
import { connect } from 'react-redux';
import versionApi from './api/version';
import helpers from './utils/helpers';
import { axios as hathorLibAxios, config as hathorLibConfig } from '@hathor/wallet-lib';
Expand All @@ -48,47 +53,48 @@ const mapDispatchToProps = dispatch => {
};
};


const mapStateToProps = (state) => {
const mapStateToProps = state => {
return { isVersionAllowed: state.isVersionAllowed, apiLoadError: state.apiLoadError };
};


class Root extends React.Component {
componentDidMount() {
WebSocketHandler.on('dashboard', this.handleWebsocket);

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

versionApi.getVersion().then((data) => {
let network = data.network;
if (data.network.includes('testnet')) {
network = 'testnet';
this.props.apiLoadErrorUpdate({ apiLoadError: false });

versionApi.getVersion().then(
data => {
let network = data.network;
if (data.network.includes('testnet')) {
network = 'testnet';
}
hathorLibConfig.setNetwork(network);
this.props.updateServerInfo(data);
this.props.isVersionAllowedUpdate({ allowed: helpers.isVersionAllowed(data.version) });
},
e => {
// Error in request
console.log(e);
this.props.apiLoadErrorUpdate({ apiLoadError: true });
}
hathorLibConfig.setNetwork(network);
this.props.updateServerInfo(data);
this.props.isVersionAllowedUpdate({allowed: helpers.isVersionAllowed(data.version)});
}, (e) => {
// Error in request
console.log(e);
this.props.apiLoadErrorUpdate({apiLoadError: true});
});
);
}

componentWillUnmount() {
WebSocketHandler.removeListener('dashboard', this.handleWebsocket);
}

handleWebsocket = (wsData) => {
handleWebsocket = wsData => {
if (wsData.type === 'dashboard:metrics') {
this.updateWithWs(wsData);
}
}
};

updateWithWs = (data) => {
updateWithWs = data => {
this.props.dashboardUpdate({ ...data });
}
};

render() {
if (this.props.isVersionAllowed === undefined) {
Expand All @@ -97,14 +103,18 @@ class Root extends React.Component {
<Router>
<>
<Navigation />
{ this.props.apiLoadError ?
{this.props.apiLoadError ? (
<div className="content-wrapper">
<h3 className="text-danger">Error loading the explorer. Please reload the page to try again.</h3>
<h3 className="text-danger">
Error loading the explorer. Please reload the page to try again.
</h3>
</div>
: <Loading /> }
) : (
<Loading />
)}
</>
</Router>);

</Router>
);
} else if (!this.props.isVersionAllowed) {
return <VersionError />;
} else {
Expand All @@ -125,22 +135,36 @@ class Root extends React.Component {
<NavigationRoute exact path="/statistics" component={Dashboard} />
<NavigationRoute exact path="/token_detail/:tokenUID" component={TokenDetail} />
<NavigationRoute exact path="/address/:address" component={AddressDetail} />
<NavigationRoute exact path="/nano_contract/detail/:nc_id" component={NanoContractDetail} />
<NavigationRoute exact path="/blueprint/detail/:blueprint_id" component={BlueprintDetail} />
<NavigationRoute
exact
path="/nano_contract/detail/:nc_id"
component={NanoContractDetail}
/>
<NavigationRoute
exact
path="/blueprint/detail/:blueprint_id"
component={BlueprintDetail}
/>
<NavigationRoute exact path="" component={DashboardTx} />
</Switch>
</Router>
<GDPRConsent />
</>
)
);
}
}
}

const NavigationRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={(props) => (
<div><Navigation {...props}/><Component {...props} /></div>
)} />
)
<Route
{...rest}
render={props => (
<div>
<Navigation {...props} />
<Component {...props} />
</div>
)}
/>
);

export default connect(mapStateToProps, mapDispatchToProps)(Root);
34 changes: 16 additions & 18 deletions src/WebSocketHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import EventEmitter from 'events';
import { WS_URL } from './constants';

const HEARTBEAT_TMO = 30000; // 30s

const HEARTBEAT_TMO = 30000; // 30s

class WS extends EventEmitter {
constructor(){
constructor() {
if (!WS.instance) {
super();
this.connected = false;
Expand All @@ -33,45 +32,44 @@ class WS extends EventEmitter {
this.ws.onmessage = this.onMessage;
this.ws.onerror = this.onError;
this.ws.onclose = this.onClose;
}
};

onMessage = evt => {
const message = JSON.parse(evt.data)
const _type = message.type.split(':')[0]
this.emit(_type, message)
}
const message = JSON.parse(evt.data);
const _type = message.type.split(':')[0];
this.emit(_type, message);
};

onOpen = () => {
this.connected = true;
console.log('ws connection established');
this.heartbeat = setInterval(this.sendPing, HEARTBEAT_TMO);
}
};

onClose = () => {
this.connected = false;
setTimeout(this.setup, 500);
clearInterval(this.heartbeat);
console.log('ws connection closed');
}
};

onError = evt => {
console.log('ws error', evt);
}
};

sendMessage = (msg) => {
sendMessage = msg => {
if (!this.connected) {
console.log('ws not connected, cannot send message');
return;
}

this.ws.send(msg);
}
};

sendPing = () => {
const msg = JSON.stringify({'type': 'ping'})
this.sendMessage(msg)
}

const msg = JSON.stringify({ type: 'ping' });
this.sendMessage(msg);
};
}

const instance = new WS();
Expand Down
7 changes: 5 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

export const dashboardUpdate = data => ({ type: "dashboard_update", payload: data });
export const dashboardUpdate = data => ({ type: 'dashboard_update', payload: data });

export const isVersionAllowedUpdate = data => ({ type: "is_version_allowed_update", payload: data });
export const isVersionAllowedUpdate = data => ({
type: 'is_version_allowed_update',
payload: data,
});

export const apiLoadErrorUpdate = data => ({ type: 'api_load_error_update', payload: data });

Expand Down
34 changes: 18 additions & 16 deletions src/api/addressApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@ const addressApi = {
offset (optional): int -> offset this many transactions before fetching
*/

const data = {address};
const data = { address };
if (limit) {
data['limit'] = limit;
data.limit = limit;
}
if (offset) {
data['offset'] = offset;
data.offset = offset;
}

return requestExplorerServiceV1.get(`address/tokens`, {params: data}).then((res) => {
return requestExplorerServiceV1.get(`address/tokens`, { params: data }).then(res => {
if (res && res.data) {
return res.data
return res.data;
}
});
},

getBalance(address, token) {
return requestExplorerServiceV1.get(`address/balance`, {params: {address, token}}).then((res) => {
if (res && res.data) {
return res.data
}
});
return requestExplorerServiceV1
.get(`address/balance`, { params: { address, token } })
.then(res => {
if (res && res.data) {
return res.data;
}
});
},

getHistory(address, token, limit, lastTx, lastTs) {
Expand All @@ -47,22 +49,22 @@ const addressApi = {
lastTs (optional): int -> last timestamp of the page, so we can retrieve the next page
*/

const data = {address, token};
const data = { address, token };
if (limit) {
data['limit'] = limit;
data.limit = limit;
}

if (lastTx) {
data['last_tx'] = lastTx;
data.last_tx = lastTx;
}

if (lastTs) {
data['last_ts'] = lastTs;
data.last_ts = lastTs;
}

return requestExplorerServiceV1.get(`address/history`, {params: data}).then((res) => {
return requestExplorerServiceV1.get(`address/history`, { params: data }).then(res => {
if (res && res.data) {
return res.data
return res.data;
}
});
},
Expand Down
44 changes: 25 additions & 19 deletions src/api/addressApiLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import requestExplorerServiceV1 from './axiosInstance';

const addressApi = {
getBalance(address) {
return requestExplorerServiceV1.get(`node_api/address_balance`, {params: {address}}).then((res) => {
if (res && res.data) {
return res.data
}
}).catch((error) => {
// something wrong with request
});
return requestExplorerServiceV1
.get(`node_api/address_balance`, { params: { address } })
.then(res => {
if (res && res.data) {
return res.data;
}
})
.catch(error => {
// something wrong with request
});
},

search(address, count, hash, page, token) {
Expand All @@ -27,23 +30,26 @@ const addressApi = {
if 'next', we get the objects after the hash reference
token (optional): str -> only fetch txs related to this token uid
*/
const data = {address, count};

const data = { address, count };
if (hash) {
data['hash'] = hash;
data['page'] = page;
data.hash = hash;
data.page = page;
}
if (token) {
data['token'] = token;
data.token = token;
}

return requestExplorerServiceV1.get(`node_api/address_search`, {params: data}).then((res) => {
if (res && res.data) {
return res.data
}
}).catch((error) => {
// something wrong with request
});
return requestExplorerServiceV1
.get(`node_api/address_search`, { params: data })
.then(res => {
if (res && res.data) {
return res.data;
}
})
.catch(error => {
// something wrong with request
});
},
};

Expand Down
Loading

0 comments on commit b61769d

Please sign in to comment.