<commit_before>import Ractive from 'lib/ractive';
import emitter from 'lib/emitter';
import { getWallet, getWalletById } from 'lib/wallet';
import crypto from 'lib/crypto';
import changelly from 'lib/changelly';
import { showError } from 'widgets/modals/flash';
import details from 'lib/wallet/details';
import showMecto from 'widgets/modals/mecto';
import qrcode from 'lib/qrcode';
import { validateSend } from 'lib/wallet/validator';
import showConfirmation from 'widgets/modals/confirm-send';
import { toAtom, toUnitString } from 'lib/convert';
import { translate } from 'lib/i18n';
import _ from 'lodash';
import template from './index.ract';
import footer from '../footer.ract';
import loader from 'partials/loader/loader.ract';

export default function(el) {
  const ractive = new Ractive({
    el,
    template,
    data: {
      isLoading: true,
      isLoadingEstimate: true,
      isFirstEstimate: true,
      fromCryptoId: null,
      fromCrypto: null,
      minAmount: '',
      toCryptoId: null,
      toCrypto: null,
      toAmount: '',
      toAddress: '',
      toCryptoSupported: false,
      usedOwnToAddress: false,
      rate: '',
      coins: [],
      qrScannerAvailable: qrcode.isScanAvailable,
    },
    partials: {
      loader,
      footer,
    },
  });

  let _maxAmount;
  let _fromAmount = '1';

  const fromCryptoIdObserver = ractive.observe('fromCryptoId', (id, old) => {
    if (!old) return;
    ractive.set('fromCrypto', ractive.get('coins').find((item) => item._id === id));
    if (id === ractive.get('toCryptoId')) {
      return ractive.set('toCryptoId', old);
    }
    return estimate();
  });

  ractive.observe('toCryptoId', (id, old) => {
    if (!old) return;
    ractive.set('toCrypto', ractive.get('coins').find((item) => item._id === id));
    if (id === ractive.get('fromCryptoId')) {
      return ractive.set('fromCryptoId', old);
    }
    return estimate();
  });

  ractive.on('input-from-amount', () => {
    const fromAmount = ractive.find('#changelly_from_amount').value;
    if (fromAmount === _fromAmount) return;
    _fromAmount = fromAmount;
    estimate();
  });

  ractive.on('before-show', (context) => {
    if (context.isBack) {
      return true;
    }

    ractive.set('isLoading', true);
    ractive.set('isLoadingEstimate', true);
    ractive.set('isFirstEstimate', true);

    crypto.getCryptos().then((cryptos) => {<commit_msg>fix(app): exchange to address input<commit_after>import Ractive from 'lib/ractive';
import emitter from 'lib/emitter';
import { getWallet, getWalletById } from 'lib/wallet';
import crypto from 'lib/crypto';
import changelly from 'lib/changelly';
import { showError } from 'widgets/modals/flash';
import details from 'lib/wallet/details';
import showMecto from 'widgets/modals/mecto';
import qrcode from 'lib/qrcode';
import { validateSend } from 'lib/wallet/validator';
import showConfirmation from 'widgets/modals/confirm-send';
import { toAtom, toUnitString } from 'lib/convert';
import { translate } from 'lib/i18n';
import _ from 'lodash';
import template from './index.ract';
import footer from '../footer.ract';
import loader from 'partials/loader/loader.ract';

export default function(el) {
  const ractive = new Ractive({
    el,
    template,
    data: {
      isLoading: true,
      isLoadingEstimate: true,
      isFirstEstimate: true,
      fromCryptoId: null,
      fromCrypto: null,
      minAmount: '',
      toCryptoId: null,
      toCrypto: null,
      toAmount: '',
      toAddress: '',
      toCryptoSupported: false,
      usedOwnToAddress: false,
      rate: '',
      coins: [],
      qrScannerAvailable: qrcode.isScanAvailable,
    },
    partials: {
      loader,
      footer,
    },
  });

  let _maxAmount;
  let _fromAmount = '1';

  const fromCryptoIdObserver = ractive.observe('fromCryptoId', (id, old) => {
    if (!old) return;
    ractive.set('fromCrypto', ractive.get('coins').find((item) => item._id === id));
    if (id === ractive.get('toCryptoId')) {
      return ractive.set('toCryptoId', old);
    }
    return estimate();
  });

  ractive.observe('toCryptoId', (id, old) => {
    if (!old) return;
    const toCrypto = ractive.get('coins').find((item) => item._id === id);
    ractive.set('toCrypto', toCrypto);
    ractive.set('toCryptoSupported', toCrypto.supported && !!getWalletById(toCrypto._id));
    if (ractive.get('toCryptoSupported')) {
      ractive.set('toAddress', getWalletById(toCrypto._id).getNextAddress());
      ractive.set('usedOwnToAddress', true);
    } else {
      ractive.set('toAddress', '');
      ractive.set('usedOwnToAddress', false);
    }
    if (id === ractive.get('fromCryptoId')) {
      return ractive.set('fromCryptoId', old);
    }
    return estimate();
  });

  ractive.on('input-from-amount', () => {
    const fromAmount = ractive.find('#changelly_from_amount').value;
    if (fromAmount === _fromAmount) return;
    _fromAmount = fromAmount;
    estimate();
  });

  ractive.on('before-show', (context) => {
    if (context.isBack) {
      return true;
    }

    ractive.set('isLoading', true);
    ractive.set('isLoadingEstimate', true);
    ractive.set('isFirstEstimate', true);

    crypto.getCryptos().then((cryptos) => {
{'fraction_non_alphanumeric': 0.15566218809980806, 'fraction_numerical': 0.0011516314779270633, 'mean_word_length': 3.5, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038389', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1672, 'n_words': 368}