How to use the @ledgerhq/live-common/lib/countervalues.getCountervalues function in @ledgerhq/live-common

To help you get started, we’ve selected a few @ledgerhq/live-common 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 LedgerHQ / ledger-live-common / tools / src / index.js View on Github external
constructor() {
    super();
    const CounterValues = getCountervalues();
    const store = initStore();

    // quick way to store countervalues with localStorage
    const LS_KEY = "countervalues_intermediary";
    try {
      const json = localStorage.getItem(LS_KEY);
      if (json) {
        store.dispatch(CounterValues.importAction(JSON.parse(json)));
      }
    } catch (e) {
      console.warn(e);
    }
    store.subscribe(() => {
      localStorage.setItem(
        LS_KEY,
        JSON.stringify(CounterValues.exportSelector(store.getState()))
github LedgerHQ / ledger-live-common / tools / src / demos / erc20 / TokenSelect.js View on Github external
// @flow
import React, { useState, useEffect } from "react";
import Select from "react-select";
import { listTokens } from "@ledgerhq/live-common/lib/currencies";
import type { CurrencyToken } from "@ledgerhq/live-common/lib/types";
import { getCountervalues } from "@ledgerhq/live-common/lib/countervalues";

let tickers;
const tickersP = getCountervalues()
  .fetchTickersByMarketcap()
  .then(t => {
    tickers = t;
    return t;
  });

const rank = token => {
  const i = tickers.indexOf(token.ticker);
  if (i === -1) return Infinity;
  return i;
};

const getSortedTokens = () => {
  let tokens = listTokens();
  if (!tickers) return tokens;
  return tokens.slice(0).sort((a, b) => rank(a) - rank(b));
github LedgerHQ / ledger-live-common / tools / src / demos / countervalues / components / ExchangeSelect.js View on Github external
async _load() {
    this._loadId++;
    this.setState({ exchanges: [] });
    const { _loadId } = this;
    const { from, to } = this.props;
    try {
      const exchanges = await getCountervalues().fetchExchangesForPair(
        from,
        to
      );
      if (this._loadId === _loadId) {
        this.setState({ exchanges });
      }
    } catch (error) {
      console.error(error);
      if (this._loadId === _loadId) {
        this.setState({ error });
      }
    }
  }
github LedgerHQ / ledger-live-common / tools / src / store.js View on Github external
export const initStore = () =>
  createStore(
    combineReducers({
      markets,
      countervalues: getCountervalues().reducer
    }),
    composeWithDevTools(applyMiddleware(thunkMiddleware))
  );
github LedgerHQ / ledger-live-common / tools / src / demos / Currencies / index.js View on Github external
async componentDidMount() {
    const tickers = await getCountervalues().fetchTickersByMarketcap();
    this.setState({ tickers });
  }
github LedgerHQ / ledger-live-common / tools / src / demos / countervalues / components / CounterValuesAPIDemo.js View on Github external
render() {
    const { classes, markets, setMarket, addMarket } = this.props;
    const CounterValues = getCountervalues();

    return (
      <div>
        
          
            {polling =&gt; (
              
                
                  CounterValues API demo
                
                </div>
github LedgerHQ / ledger-live-common / tools / src / demos / countervalues / components / PriceGraph.js View on Github external
const mapStateToProps = (state, props: *) =&gt; {
  const data = [];
  let t = Date.now() - props.days * DAY;
  const value = BigNumber(10 ** props.from.units[0].magnitude);
  for (let i = 0; i &lt; props.days; i++) {
    const date = new Date(t);
    const cv = getCountervalues().calculateSelector(state, {
      ...props,
      date,
      value
    });
    data.push({
      date,
      value: cv ? cv.toNumber() : 0
    });
    t += DAY;
  }
  return { data };
};
github LedgerHQ / ledger-live-mobile / src / countervalues.js View on Github external
getAPIBaseURL: () =&gt; LEDGER_COUNTERVALUES_API,
  storeSelector: state =&gt; state.countervalues,
  pairsSelector,
  setExchangePairsAction,
  addExtraPollingHooks,
  network,
  ...(Config.MOCK
    ? {
        getDailyRatesImplementation,
        fetchExchangesForPairImplementation,
        fetchTickersByMarketcapImplementation,
      }
    : {}),
});

const CounterValues = getCountervalues();

type PC = Promise;

let sortCache;
let syncCache = listCryptoCurrencies(true).sort((a, b) =&gt;
  a.name.localeCompare(b.name),
);

export const getFullListSortedCryptoCurrencies: () =&gt; PC = () =&gt; {
  if (!sortCache) {
    sortCache = CounterValues.fetchTickersByMarketcap().then(
      tickers =&gt; {
        const list = listCryptoCurrencies(true).slice(0);
        const prependList = [];
        tickers.forEach(ticker =&gt; {
          const item = list.find(c =&gt; c.ticker === ticker);