How to use the @ledgerhq/live-common/lib/currencies.getCryptoCurrencyById 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-desktop / src / api / Ripple.js View on Github external
// @flow
import logger from 'logger'
import { BigNumber } from 'bignumber.js'
import { RippleAPI } from 'ripple-lib'
import {
  parseCurrencyUnit,
  getCryptoCurrencyById,
  formatCurrencyUnit,
} from '@ledgerhq/live-common/lib/currencies'

const rippleUnit = getCryptoCurrencyById('ripple').units[0]

export const defaultEndpoint = 'wss://s2.ripple.com'

export const apiForEndpointConfig = (endpointConfig: ?string = null) => {
  const server = endpointConfig || defaultEndpoint
  const api = new RippleAPI({ server })
  api.on('error', (errorCode, errorMessage) => {
    logger.warn(`Ripple API error: ${errorCode}: ${errorMessage}`)
  })
  return api
}

export const parseAPIValue = (value: string) => parseCurrencyUnit(rippleUnit, value)

export const parseAPICurrencyObject = ({
  currency,
github LedgerHQ / ledger-live-common / demo / src / demos / countervalue-intermediary / reducers / app.js View on Github external
currency: getCryptoCurrencyById("bitcoin"),
      exchange: null,
      value: 0.5
    },
    {
      currency: getCryptoCurrencyById("litecoin"),
      exchange: "BINANCE",
      value: 2
    },
    {
      currency: getCryptoCurrencyById("ethereum"),
      exchange: "BINANCE",
      value: 1
    },
    {
      currency: getCryptoCurrencyById("zencash"),
      exchange: "BINANCE",
      value: 10
    }
  ]
};

const reducers: { [_: string]: (State, *) => State } = {
  SET_COUNTERVALUE_CURRENCY: (state, { currency }) => ({
    ...state,
    countervalueCurrency: currency
  }),

  SET_COUNTERVALUE_EXCHANGE: (state, { exchange }) => ({
    ...state,
    countervalueExchange: exchange
  }),
github LedgerHQ / ledger-live-desktop / src / components / ManagerV2Page / AppsList / Item.js View on Github external
const notEnoughMemoryToInstall = useMemo(
      () => isOutOfMemoryState(predictOptimisticState(reducer(state, { type: 'install', name }))),
      [name, state],
    )

    const isLiveSupported =
      app.currencyId && isCurrencySupported(getCryptoCurrencyById(app.currencyId))

    return (
      
        
          <img height="{40}" width="{40}" src="{manager.getIconUrl(app.icon)}" alt="">
          
            
            
          
        
        
          {formatSize(
            ((installed &amp;&amp; installed.blocks) || 0) * deviceModel.deviceSize || app.bytes || 0,
          )}
        
        
          {isLiveSupported ? (
            }&gt;
              
github LedgerHQ / ledger-live-mobile / src / libcore / signAndBroadcast.js View on Github external
Observable.create(o => {
    let unsubscribed = false;
    const currency = getCryptoCurrencyById(currencyId);
    const isCancelled = () => unsubscribed;
    doSignAndBroadcast({
      accountId,
      currency,
      blockHeight,
      derivationMode,
      seedIdentifier,
      xpub,
      index,
      transaction,
      deviceId,
      isCancelled,
      onSigning: () => {
        o.next({ type: "signing" });
      },
      onSigned: () => {
github LedgerHQ / ledger-live-desktop / src / components / modals / Debug.js View on Github external
const before = window.performance.now()
      const res = await job()
      const after = window.performance.now()
      this.log(
        `benchmark: ${Math.round((after - before) * 100) / 100}ms: ${name} => ${String(res)}`,
      )
    }

    await run('ping process', () => ping.send().toPromise())
    await run('libcore version', () =>
      libcoreGetVersion
        .send()
        .toPromise()
        .then(o => o.stringVersion),
    )
    const currency = getCryptoCurrencyById('bitcoin')
    const derivationScheme = getDerivationScheme({
      currency,
      derivationMode: 'segwit',
    })
    const obj = {
      path: runDerivationScheme(derivationScheme, currency),
      currencyId: currency.id,
      devicePath: device.path,
      derivationMode: 'segwit',
    }
    await run('getAddress', () =>
      getAddress
        .send(obj)
        .toPromise()
        .then(o => o.address),
    )
github LedgerHQ / ledger-live-desktop / src / reducers / settings.js View on Github external
getCryptoCurrencyById,
  getFiatCurrencyByTicker,
} from '@ledgerhq/live-common/lib/currencies'
import { getLanguages } from 'config/languages'
import { createSelector } from 'reselect'
import type { InputSelector as Selector } from 'reselect'
import type { CryptoCurrency, Currency } from '@ledgerhq/live-common/lib/types'
import { getEnv } from '@ledgerhq/live-common/lib/env'
import { currencySettingsDefaults } from 'helpers/SettingsDefaults'
import { getSystemLocale } from 'helpers/systemLocale'

import type { CurrencySettings } from 'types/common'
import type { State } from 'reducers'

const bitcoin = getCryptoCurrencyById('bitcoin')
const ethereum = getCryptoCurrencyById('ethereum')
export const possibleIntermediaries = [bitcoin, ethereum]
export const intermediaryCurrency = (from: Currency, _to: Currency) =&gt; {
  if (from === ethereum || from.type === 'TokenCurrency') return ethereum
  return bitcoin
}

export const timeRangeDaysByKey = {
  week: 7,
  month: 30,
  year: 365,
}

export type TimeRange = $Keys

export type { CurrencySettings }
github LedgerHQ / ledger-live-desktop / src / commands / libcoreScanFromXPUB.js View on Github external
({ currencyId, xpub, derivationMode, seedIdentifier }) =&gt; {
    const currency = getCryptoCurrencyById(currencyId)
    const freshAddress = ''
    const freshAddressPath = runDerivationScheme(derivationMode, getCryptoCurrencyById(currencyId))
    const account: $Exact = {
      type: 'Account',
      name: `(DEV) ${currencyId}`,
      xpub,
      seedIdentifier,
      id: encodeAccountId({
        type: 'libcore_dev',
        version: '1',
        currencyId,
        xpubOrAddress: xpub,
        derivationMode,
      }),
      derivationMode,
      currency,
github LedgerHQ / ledger-live-common / demo / src / demos / countervalue-intermediary / reducers / app.js View on Github external
countervalueCurrency: getFiatCurrencyByTicker("USD"),
  countervalueExchange: "Kraken",
  intermediaryCurrency: getCryptoCurrencyById("bitcoin"),
  rows: [
    {
      currency: getCryptoCurrencyById("bitcoin"),
      exchange: null,
      value: 0.5
    },
    {
      currency: getCryptoCurrencyById("litecoin"),
      exchange: "BINANCE",
      value: 2
    },
    {
      currency: getCryptoCurrencyById("ethereum"),
      exchange: "BINANCE",
      value: 1
    },
    {
      currency: getCryptoCurrencyById("zencash"),
      exchange: "BINANCE",
      value: 10
    }
  ]
};

const reducers: { [_: string]: (State, *) => State } = {
  SET_COUNTERVALUE_CURRENCY: (state, { currency }) => ({
    ...state,
    countervalueCurrency: currency
  }),
github LedgerHQ / ledger-live-desktop / src / __mocks__ / storybook-state.js View on Github external
import { genStoreState } from '@ledgerhq/live-common/lib/countervalues/mock'
import {
  getCryptoCurrencyById,
  getFiatCurrencyByTicker,
} from '@ledgerhq/live-common/lib/currencies'

export default {
  countervalues: genStoreState([
    {
      from: getCryptoCurrencyById('bitcoin'),
      to: getFiatCurrencyByTicker('USD'),
      exchange: 'KRAKEN',
      dateFrom: new Date(2015, 1, 1),
      dateTo: new Date(),
      rate: d => 0.007 + 0.003 * Math.max(0, (d / 1e12 + Math.sin(d / 1e9)) / 2),
    },
  ]),
}
github LedgerHQ / ledger-live-mobile / src / families / bitcoin / ScreenEditFeePerByte / CustomFeesRow.js View on Github external
TextInput,
  Platform,
} from "react-native";
import { BigNumber } from "bignumber.js";
import {
  sanitizeValueString,
  getCryptoCurrencyById,
} from "@ledgerhq/live-common/lib/currencies";

import LText from "../../../components/LText/index";

import Check from "../../../icons/Check";
import colors from "../../../colors";
import { CUSTOM_FEES_CAP } from "../../../constants";

const bitcoinCurrency = getCryptoCurrencyById("bitcoin");
const satoshiUnit = bitcoinCurrency.units[bitcoinCurrency.units.length - 1];

type Props = {
  title: React$Node,
  last?: boolean,
  initialValue: ?BigNumber,
  onPress: BigNumber =&gt; void,
  isSelected: boolean,
  isValid?: boolean,
};

type State = {
  fees: ?string,
};

class FeesRow extends Component {