Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Refactor activePeerSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Gina Contrino committed Oct 12, 2017
1 parent 8cdf096 commit 77a6771
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/actions/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,23 @@ export const activePeerSet = data =>
const reg = /^(?:f|ht)tps?:\/\//i;
return reg.test(url) ? url : `http://${url}`;
};
const config = data.network || {};

const { network } = data;
let config = {};
if (network) {
config = network;
if (network.address) {
const normalizedUrl = new URL(addHttp(network.address));
if (config.address) {
const { hostname, port, protocol } = new URL(addHttp(config.address));

config.node = normalizedUrl.hostname;
config.port = normalizedUrl.port;
config.ssl = normalizedUrl.protocol === 'https';
}
if (config.testnet === undefined && config.port !== undefined) {
config.testnet = config.port === '7000';
}
if (network.custom) {
getNetHash(Lisk.api(config)).then((response) => {
config.nethash = response.nethash;
dispatch(peerSet(data, config));
});
} else {
config.node = hostname;
config.port = port;
config.ssl = protocol === 'https';
}
if (config.testnet === undefined && config.port !== undefined) {
config.testnet = config.port === '7000';
}
if (config.custom) {
getNetHash(Lisk.api(config)).then((response) => {
config.nethash = response.nethash;
dispatch(peerSet(data, config));
}
});
} else {
dispatch(peerSet(data, config));
}
Expand Down

0 comments on commit 77a6771

Please sign in to comment.