How to use the @cityofzion/neon-js.settings.timeout function in @cityofzion/neon-js

To help you get started, we’ve selected a few @cityofzion/neon-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CityOfZion / neon-wallet / app / actions / nodeStorageActions.js View on Github external
import { createActions } from 'spunky'
import { random, get, compact } from 'lodash-es'
import { rpc, api, settings } from '@cityofzion/neon-js'

import { getStorage, setStorage } from '../core/storage'
import {
  MAIN_NETWORK_ID,
  TEST_NETWORK_ID,
  NODES_MAIN_NET,
  NODES_TEST_NET,
  NODE_EXLUSION_CRITERIA,
} from '../core/constants'
import { findNetworkByLabel } from '../core/networks'

const PING_TIMEOUT_OVERRIDE = 1000
const DEFAULT_PING_TIMEOUT = settings.timeout.ping

const ID = 'nodeStorage'
const STORAGE_KEY = 'selectedNode'
const CACHE_EXPIRATION =
  15 /* minutes */ * 60 /* seconds */ * 1000 /* milliseconds */
const cachedRPCUrl = {}

type Net = NetworkLabelTypes

type Props = {
  url: string,
  net: Net,
}

export const determineIfCacheIsExpired = (
  timestamp: number,
github CityOfZion / neon-wallet / app / modules / transactions.js View on Github external
import { getNode, getRPCEndpoint } from '../actions/nodeStorageActions'
import { addPendingTransaction } from '../actions/pendingTransactionActions'

const { reverseHex, ab2hexstring } = u

const MAX_FREE_TX_SIZE = 1024
const FEE_PER_EXTRA_BYTE = 0.00001
const LOW_PRIORITY_THRESHOLD_GAS_AMOUNT = 0.001
const RPC_TIMEOUT_OVERRIDE = 60000
const FEE_OPTIONS = {
  LOW: 0.001,
  MEDIUM: 0.05,
  HIGH: 0.1,
}

settings.timeout.rpc = RPC_TIMEOUT_OVERRIDE

const extractTokens = (sendEntries: Array) =>
  sendEntries.filter(({ symbol }) => isToken(symbol))

const extractAssets = (sendEntries: Array) =>
  sendEntries.filter(({ symbol }) => !isToken(symbol))

const buildIntents = (sendEntries: Array) => {
  const assetEntries = extractAssets(sendEntries)
  // $FlowFixMe
  return flatMap(assetEntries, ({ address, amount, symbol }) =>
    api.makeIntent({ [symbol]: toNumber(amount) }, address),
  )
}

const buildTransferScript = (
github CityOfZion / neon-wallet / app / actions / nodeNetworkActions.js View on Github external
const defaultCase = () =>
    NODES_MAIN_NET.filter(
      data =>
        !NODE_EXLUSION_CRITERIA.some(criteria => data.url.includes(criteria)),
    )
  switch (networkId) {
    case MAIN_NETWORK_ID:
      nodes = defaultCase()
      break
    case TEST_NETWORK_ID:
      nodes = NODES_TEST_NET
      break
    default:
      nodes = defaultCase()
  }
  settings.timeout.ping = PING_TIMEOUT_OVERRIDE
  const results = await pingNodes(nodes)
  settings.timeout.ping = DEFAULT_PING_TIMEOUT
  // filter out the undefined results that did not meet the max time alloted
  return results.filter(node => node)
})
github CityOfZion / neon-wallet / app / actions / nodeNetworkActions.js View on Github external
// @flow
import { rpc, settings } from '@cityofzion/neon-js'
import { createActions } from 'spunky'

import {
  NODES_MAIN_NET,
  NODES_TEST_NET,
  MAIN_NETWORK_ID,
  TEST_NETWORK_ID,
  NODE_EXLUSION_CRITERIA,
} from '../core/constants'
import { raceAll } from '../util/promiseUtils'

const ID = 'nodeNetwork'
const PING_TIMEOUT_OVERRIDE = 5000
const DEFAULT_PING_TIMEOUT = settings.timeout.ping

const pingNode = ({ url }) =>
  new Promise(resolve => {
    const client = new rpc.RPCClient(url)
    client.ping().then(latency => {
      if (client.lastSeenHeight !== 0) {
        resolve({
          url,
          blockCount: client.lastSeenHeight,
          latency,
        })
      }
    })
  })

const pingNodes = (nodes: Array) =>
github CityOfZion / neon-wallet / app / actions / nodeStorageActions.js View on Github external
export const getRPCEndpoint = async (
  net: Net,
  excludeCritera: Array = NODE_EXLUSION_CRITERIA,
) => {
  settings.timeout.ping = PING_TIMEOUT_OVERRIDE
  try {
    if (
      cachedRPCUrl[net] &&
      !determineIfCacheIsExpired(cachedRPCUrl[net].timestamp)
    ) {
      return cachedRPCUrl[net].node
    }
    const NETWORK = findNetworkByLabel(net)
    let nodeList
    switch (NETWORK.id) {
      case MAIN_NETWORK_ID:
        nodeList = NODES_MAIN_NET
        break
      case TEST_NETWORK_ID:
        nodeList = NODES_TEST_NET
        break
github nos / client / src / common / util / getRPCEndpoint.js View on Github external
return new rpc.RPCClient(cachedRPC).ping().then((num) => {
      if (num <= settings.timeout.ping) return cachedRPC;
      cachedRPC = null;
      return getRPCEndpoint(net);
    });
  }