import loadTemplate from '../utils/loadTemplate';
import baseVw from './baseVw';
import { getExchangeRate } from '../utils/currency';
import app from '../app';

const RATE_EXPIRY_S = '300';

export default class extends baseVw {
  constructor(options = {}) {
    super(options);
    this.listenTo(app.settings, 'change:localCurrency', this.updatePrice);
  }

  className() {
    return 'btcTicker';
  }

  get localCurrency() {
    return app.settings.get('localCurrency');
  }

  getCurrentPrice() {
    return getExchangeRate(this.localCurrency);
  }

  updatePrice() {
    const latestPrice = this.getCurrentPrice();
    if (latestPrice !== this.currentBTCPrice) {
      this.currentBTCPrice = latestPrice;
      this.render();
    }
  }

  remove() {
    clearInterval(this.refreshCode);
    super.remove();
  }

  render() {
    if (this.refreshCode == null) {
      this.refreshCode = setInterval(() => this.updatePrice(), RATE_EXPIRY_S * 1000);
    }

    if (this.currentBTCPrice == null) {
      this.currentBTCPrice = this.getCurrentPrice();
    }

    loadTemplate('btcTicker.html', (t) => {
      this.$el.html(t({
        currentBTCPrice: this.currentBTCPrice,
        localCurrency: this.localCurrency,
      }));
    });

    return this;
  }
}


@@ -504,16 +504,79 @@
   return
+ %5B'BTC', 'TBTC'%5D.indexOf(this.localCurrency) !== -1 ?%0A      1 :
  getExch

tweak to the BTCTicker to not get exchange rate data for BTC