Skip to content

Commit

Permalink
updates nodeStorageActions.js and nodeNetworkActions.js
Browse files Browse the repository at this point in the history
  • Loading branch information
comountainclimber committed Nov 12, 2018
1 parent d383e1b commit fc7eaaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
21 changes: 13 additions & 8 deletions app/actions/nodeNetworkActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,27 @@ export default createActions(
let nodes
switch (networkId) {
case MAIN_NETWORK_ID:
nodes = NODES_MAIN_NET
nodes = NODES_MAIN_NET.filter(
data =>
!NODE_EXLUSION_CRITERIA.some(criteria =>
data.url.includes(criteria)
)
)
break
case TEST_NETWORK_ID:
nodes = NODES_TEST_NET
// eslint-disable-next-line
totalDisplayed = NODES_TEST_NET.length
break
default:
nodes = NODES_MAIN_NET
nodes = NODES_MAIN_NET.filter(
data =>
!NODE_EXLUSION_CRITERIA.some(criteria =>
data.url.includes(criteria)
)
)
}
const promises = nodes
.filter(
data =>
!NODE_EXLUSION_CRITERIA.some(criteria => data.url.includes(criteria))
)
.map(node => getBlockCount(node))
const promises = [...nodes].map(node => getBlockCount(node))
const result = await raceNodePromises(totalDisplayed, promises)
return result
}
Expand Down
18 changes: 11 additions & 7 deletions app/actions/nodeStorageActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import { createActions } from 'spunky'
import { isEmpty, random } from 'lodash-es'
import { rpc } from 'neon-js'
import { rpc, api } from 'neon-js'

import { getStorage, setStorage } from '../core/storage'
import {
Expand Down Expand Up @@ -40,7 +40,7 @@ export const getRPCEndpoint = async (
default:
nodeList = NODES_MAIN_NET
}
const data = nodeList
const data = [...nodeList]
.filter(
data => !excludeCritera.some(criteria => data.url.includes(criteria))
)
Expand All @@ -62,14 +62,18 @@ export const getRPCEndpoint = async (
n => n.client.lastSeenHeight >= heightThreshold
)
const randomlySelectedRPCUrl =
goodNodes[random(goodNodes.length)].client.net
goodNodes[random(goodNodes.length) - 1].client.net
cachedRPCUrl[net] = randomlySelectedRPCUrl
return randomlySelectedRPCUrl
} catch (error) {
console.log('An error occurred attempting to obtain RPC endpoint', {
error
})
return ''
console.warn(
'An error occurred attempting to obtain RPC endpoint defaulting to neon-js getRPCEndpointFrom()',
{
error
}
)
const endpoint = await api.getRPCEndpointFrom({ net }, api.neoscan)
return endpoint
}
}

Expand Down

0 comments on commit fc7eaaf

Please sign in to comment.