How to use @ledgerhq/currencies - 10 common examples

To help you get started, weā€™ve selected a few @ledgerhq/currencies 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-mobile / src / screens / Dashboard.js View on Github external
render() {
    const { accounts, calculateCounterValue } = this.props;
    const fiatUnit = getFiatUnit("USD"); // FIXME no more hardcoded
    const data = getBalanceHistorySum(
      accounts,
      30,
      fiatUnit,
      calculateCounterValue
    );
    return (
github LedgerHQ / ledger-live-mobile / src / screens / Dashboard.js View on Github external
render() {
    const { accounts, calculateCounterValue } = this.props;
    const { opCount, refreshing } = this.state;
    const fiatUnit = getFiatUnit("USD");
    const data = groupAccountsOperationsByDay(accounts, opCount);
    const totalBalance = accounts.reduce(
      // FIXME pick from last graph point? (no need to compute it again)
      (sum, account) =>
        sum +
        calculateCounterValue(account.currency, fiatUnit)(account.balance),
      0
    );
    return accounts.length === 0 ? (
      
    ) : (
github LedgerHQ / ledger-live-mobile / src / components / CurrencyUnitInput.js View on Github external
const initialValueStringFromProps = props =>
  props.value === 0
    ? "" // empty string because we want to fallback on displaying the placeholder
    : formatCurrencyUnit(props.unit, props.value, {
        locale: props.locale,
        disableRounding: true
        // useGrouping: false // FIXME should we disable grouping?
      });
github LedgerHQ / ledger-live-mobile / src / components / CurrencyUnitInput.js View on Github external
onChangeText = (valueString: string) => {
    const { unit, onChange } = this.props;
    const value = parseCurrencyUnit(unit, valueString);
    // TODO polish: valueString needs to be cleaned if there are more digits than required
    // TODO polish: we need to MAX the field if value is higher than threshold
    this.setState({ value, valueString });
    if (!isNaN(value)) {
      onChange(value);
    }
  };
github LedgerHQ / ledger-live-mobile / src / screens / ImportAccounts.js View on Github external
const [, , name, coinType] = accTuple;
        const existingAccount = nextProps.accounts.find(a => a.id === id);
        if (existingAccount) {
          // only the name is supposed to change. rest is never changing
          if (existingAccount.name === name) {
            return {
              account: existingAccount,
              mode: "id"
            };
          }
          return {
            account: { ...existingAccount, name },
            mode: "patch"
          };
        }
        const currency = getCurrencyByCoinType(coinType);
        const account = {
          id,
          name,
          coinType,
          currency,
          // these fields will be completed as we will sync
          address: "",
          balance: 0,
          operations: [],
          archived: false,
          unit: currency.units[0]
        };
        pendingImportingAccounts[id] = true;
        return { account, mode: "create" };
      })
      .sort(
github LedgerHQ / ledger-live-mobile / src / screens / Settings / SelectFiatUnit.js View on Github external
/* @flow */
import { connect } from "react-redux";
import { listFiats } from "@ledgerhq/currencies";
import { saveSettings } from "../../actions/settings";
import type { State } from "../../reducers";
import makeGenericSelectScreen from "../makeGenericSelectScreen";
import { withCounterValuePolling } from "../../context/CounterValuePolling";

const items = listFiats()
  .map(cur => ({ value: cur.code, label: `${cur.name} (${cur.code})` }))
  .sort((a, b) => a.label.localeCompare(b.label));

const mapStateToProps = (state: State) => ({
  selectedKey: state.settings.counterValue,
  items
});

const mapDispatchToProps = (dispatch: *, props: *) => ({
  onValueChange: ({ value }: *) => {
    dispatch(saveSettings({ counterValue: value }));
    props.counterValuePolling.poll();
    props.counterValuePolling.flush();
  }
});
github LedgerHQ / ledger-live-mobile / src / screens / Settings / FiatUnitSection.js View on Github external
/* @flow */
import React, { PureComponent } from "react";
import { StyleSheet, Image } from "react-native";
import { listFiats } from "@ledgerhq/currencies";
import LText from "../../components/LText";
import SectionEntry from "../../components/SectionEntry";
import { withCounterValuePolling } from "../../context/CounterValuePolling";

const fiatList = listFiats()
  .map(cur => ({ value: cur.code, label: `${cur.name} (${cur.code})` }))
  .sort((a, b) => a.label.localeCompare(b.label));

class FiatUnitSection extends PureComponent<*> {
  render() {
    const { navigation, saveSettings, value, counterValuePolling } = this.props;
    const arrowRight = require("../../images/arrow_right.png");

    const callback = item => {
      saveSettings({ counterValue: item.value });
      counterValuePolling.poll();
      counterValuePolling.flush();
    };

    return (
github LedgerHQ / ledger-live-desktop / src / components / modals / AddAccount / index.js View on Github external
if (currency && data && data.finish) {
        const { accountIndex, finish, ...account } = data
        addAccount({
          ...account,
          // As data is passed inside electron event system,
          // dates are converted to their string equivalent
          //
          // so, quick & dirty way to put back Date objects
          operations: account.operations.map(op => ({
            ...op,
            date: new Date(op.date),
          })),
          name: `Account ${accountIndex + 1}`,
          archived: true,
          currency,
          unit: getDefaultUnitByCoinType(currency.coinType),
        })
      }
    }

    if (type === 'wallet.getAccounts.success') {
      this.setState({
        selectedAccounts: Object.keys(accountsImport).map(k => accountsImport[k].id),
        stepIndex: 3,
      })
    }
  }
github LedgerHQ / ledger-live-mobile / src / mock / account.js View on Github external
// @flow
import { listCurrencies } from "@ledgerhq/currencies";
import type { Currency } from "@ledgerhq/currencies";
import type { Account } from "../types/common";

const currencies = listCurrencies();

export function genBalanceDataNext(data: *, dateIncrement: number) {
  function mix(a, b, m) {
    return (1 - m) * a + m * b;
  }
  return {
    date: new Date(data[data.length - 1].date.getTime() + dateIncrement),
    value: mix(
      data[data.length - 1].value,
      Math.floor(6000000 * Math.random()),
      0.5
    )
  };
}

export function genBalanceData(n: number, dateIncrement: number) {
github LedgerHQ / ledger-live-mobile / src / screens / Dashboard.js View on Github external
(sum, account) =>
        sum +
        calculateCounterValue(account.currency, getFiatUnit("USD"))(
          account.balance
        ),
      0