diff --git a/src/shared/libs/iota/NodesManager.js b/src/shared/libs/iota/NodesManager.js index a83d6d2b3b..6b2d068e95 100644 --- a/src/shared/libs/iota/NodesManager.js +++ b/src/shared/libs/iota/NodesManager.js @@ -2,6 +2,7 @@ import includes from 'lodash/includes'; import isArray from 'lodash/isArray'; import isFunction from 'lodash/isFunction'; import isUndefined from 'lodash/isUndefined'; +import unionBy from 'lodash/unionBy'; import Errors from '../errors'; import { getRandomNodes } from './utils'; import { DEFAULT_RETRIES } from '../../config'; @@ -33,14 +34,11 @@ export default class NodesManager { */ withRetries(failureCallbacks, retryAttempts = DEFAULT_RETRIES) { const { priorityNode, primaryNode, nodeAutoSwitch, nodes, quorum } = this.config; - let attempt = 0; let executedCallback = false; - - const randomNodes = getRandomNodes(nodes, retryAttempts, [primaryNode]); - - const retryNodes = [priorityNode, ...randomNodes]; - + const remotePoW = store.getState().settings.remotePoW; + const randomNodes = getRandomNodes(nodes, retryAttempts, [primaryNode], remotePoW); + const retryNodes = unionBy(remotePoW === priorityNode.pow && [priorityNode], randomNodes, 'url'); // Abort retries on these errors const cancellationErrors = [Errors.LEDGER_CANCELLED, Errors.CANNOT_TRANSITION_ADDRESSES_WITH_ZERO_BALANCE]; diff --git a/src/shared/libs/iota/utils.js b/src/shared/libs/iota/utils.js index d2e6d27af2..1981885060 100644 --- a/src/shared/libs/iota/utils.js +++ b/src/shared/libs/iota/utils.js @@ -8,6 +8,7 @@ import includes from 'lodash/includes'; import isNull from 'lodash/isNull'; import sampleSize from 'lodash/sampleSize'; import size from 'lodash/size'; +import cloneDeep from 'lodash/cloneDeep'; import URL from 'url-parse'; import { BigNumber } from 'bignumber.js'; import { iota } from './index'; @@ -454,11 +455,16 @@ export const fetchRemoteNodes = ( * @param {array} nodes * @param {number} [size] * @param {array} [blacklistedNodes] + * @param {bool} Remote PoW * * @returns {Array} */ -export const getRandomNodes = (nodes, size = 5, blacklistedNodes = []) => { - return sampleSize(filter(nodes, (node) => !find(blacklistedNodes, { url: node.url })), size); +export const getRandomNodes = (nodes, size = 5, blacklistedNodes = [], PoW = false) => { + let nodesToSample = cloneDeep(nodes); + if (PoW) { + nodesToSample = filter(nodes, (node) => node.pow === true); + } + return sampleSize(filter(nodesToSample, (node) => !find(blacklistedNodes, { url: node.url })), size); }; /**