<commit_before>import React from "react";
import {Link} from "react-router/es";
import Icon from "../Icon/Icon";
import AssetName from "../Utility/AssetName";
import MarketsActions from "actions/MarketsActions";
import SettingsActions from "actions/SettingsActions";
import PriceStatWithLabel from "./PriceStatWithLabel";
import Translate from "react-translate-component";
import counterpart from "counterpart";
import {ChainStore} from "bitsharesjs/es";
import ExchangeHeaderCollateral from "./ExchangeHeaderCollateral";

export default class ExchangeHeader extends React.Component {

    constructor() {
        super();

        this.state = {
            volumeShowQuote: true
        };
    }

    shouldComponentUpdate(nextProps) {
        if (!nextProps.marketReady)
            return false;
        return true;
    }

    _addMarket(quote, base) {
        let marketID = `${quote}_${base}`;
        if (!this.props.starredMarkets.has(marketID)) {
            SettingsActions.addStarMarket(quote, base);
        } else {
            SettingsActions.removeStarMarket(quote, base);
        }
    }

    changeVolumeBase() {
        this.setState({
            volumeShowQuote: !this.state.volumeShowQuote
        });
    }

    render() {
        const {quoteAsset, baseAsset, starredMarkets, hasPrediction, feedPrice,
            showCallLimit, lowestCallPrice, marketReady, latestPrice,
            marketStats, showDepthChart, account} = this.props;

        const baseSymbol = baseAsset.get("symbol");
        const quoteSymbol = quoteAsset.get("symbol");

        // Favorite star
        const marketID = `${quoteSymbol}_${baseSymbol}`;
        const starClass = starredMarkets.has(marketID) ? "gold-star" : "grey-star";

        // Market stats
        const dayChange = marketStats.get("change");

        const dayChangeClass = parseFloat(dayChange) === 0 ? "" : parseFloat(dayChange) < 0 ? "negative" : "positive";
        const volumeBase = marketStats.get("volumeBase");
        const volumeQuote = marketStats.get("volumeQuote");
        const dayChangeWithSign = (dayChange > 0) ? "+" + dayChange : dayChange;

        const volume24h = this.state.volumeShowQuote ? volumeQuote : volumeBase;
        const volume24hAsset = this.state.volumeShowQuote ? quoteAsset : baseAsset;

        let showCollateralRatio = false;

        const quoteId = quoteAsset.get("id");
        const baseId = baseAsset.get("id");

        const lookForBitAsset = (quoteId === "1.3.0") ? baseId : (baseId === "1.3.0" ? quoteId : null);
        const possibleBitAsset = lookForBitAsset ? ChainStore.getAsset(lookForBitAsset) : null;
        const isBitAsset = possibleBitAsset ? !!possibleBitAsset.get("bitasset") : false;
        let collOrderObject = "";
        let settlePrice = null;

        if (isBitAsset) {

            if (account.toJS && account.has("call_orders")) {

                const call_orders = account.get("call_orders").toJS();

                for (let i = 0; i < call_orders.length; i++) {

                    let callID = call_orders[i];

                    let position = ChainStore.getObject(callID);
                    let debtAsset = position.getIn(["call_price", "quote", "asset_id"]);

                    if (debtAsset === lookForBitAsset) {
                        collOrderObject = callID;
                        showCollateralRatio = true;
                        break;
                    }
                };
            }

            /* Settlment Offset */
            let settleAsset = baseAsset.get("id") == "1.3.0" ? quoteAsset : quoteAsset.get("id") == "1.3.0" ? baseAsset : null;

            if(settleAsset) {
                let offset_percent = settleAsset.getIn(["bitasset", "options"]).toJS().force_settlement_offset_percent;
                settlePrice = baseAsset.get("id") == "1.3.0" ? feedPrice.toReal()/(1 + (offset_percent / 10000)) : feedPrice.toReal()*(1 + (offset_percent / 10000))
            }
        }

        const translator = require("counterpart");

        return (
                <div className="grid-block shrink no-padding overflow-visible top-bar">
                    <div className="grid-block overflow-visible">
                        <div className="grid-block shrink">
                            <div style={{padding: "10px"}}>
                                {!hasPrediction ? (
                                    <div style={{padding: "0 5px", fontSize: "18px", marginTop: "1px"}}>
                                        <Link to={`/asset/${quoteSymbol}`} className="asset-prefix"><AssetName name={quoteSymbol} replace={true} /></Link><commit_msg>Fix #1219: Incorrect feed prices break the exchange page<commit_after>import React from "react";
import {Link} from "react-router/es";
import Icon from "../Icon/Icon";
import AssetName from "../Utility/AssetName";
import MarketsActions from "actions/MarketsActions";
import SettingsActions from "actions/SettingsActions";
import PriceStatWithLabel from "./PriceStatWithLabel";
import Translate from "react-translate-component";
import counterpart from "counterpart";
import {ChainStore} from "bitsharesjs/es";
import ExchangeHeaderCollateral from "./ExchangeHeaderCollateral";

export default class ExchangeHeader extends React.Component {

    constructor() {
        super();

        this.state = {
            volumeShowQuote: true
        };
    }

    shouldComponentUpdate(nextProps) {
        if (!nextProps.marketReady)
            return false;
        return true;
    }

    _addMarket(quote, base) {
        let marketID = `${quote}_${base}`;
        if (!this.props.starredMarkets.has(marketID)) {
            SettingsActions.addStarMarket(quote, base);
        } else {
            SettingsActions.removeStarMarket(quote, base);
        }
    }

    changeVolumeBase() {
        this.setState({
            volumeShowQuote: !this.state.volumeShowQuote
        });
    }

    render() {
        const {quoteAsset, baseAsset, starredMarkets, hasPrediction, feedPrice,
            showCallLimit, lowestCallPrice, marketReady, latestPrice,
            marketStats, showDepthChart, account} = this.props;

        const baseSymbol = baseAsset.get("symbol");
        const quoteSymbol = quoteAsset.get("symbol");

        // Favorite star
        const marketID = `${quoteSymbol}_${baseSymbol}`;
        const starClass = starredMarkets.has(marketID) ? "gold-star" : "grey-star";

        // Market stats
        const dayChange = marketStats.get("change");

        const dayChangeClass = parseFloat(dayChange) === 0 ? "" : parseFloat(dayChange) < 0 ? "negative" : "positive";
        const volumeBase = marketStats.get("volumeBase");
        const volumeQuote = marketStats.get("volumeQuote");
        const dayChangeWithSign = (dayChange > 0) ? "+" + dayChange : dayChange;

        const volume24h = this.state.volumeShowQuote ? volumeQuote : volumeBase;
        const volume24hAsset = this.state.volumeShowQuote ? quoteAsset : baseAsset;

        let showCollateralRatio = false;

        const quoteId = quoteAsset.get("id");
        const baseId = baseAsset.get("id");

        const lookForBitAsset = (quoteId === "1.3.0") ? baseId : (baseId === "1.3.0" ? quoteId : null);
        const possibleBitAsset = lookForBitAsset ? ChainStore.getAsset(lookForBitAsset) : null;
        const isBitAsset = possibleBitAsset ? !!possibleBitAsset.get("bitasset") : false;
        let collOrderObject = "";
        let settlePrice = null;

        if (isBitAsset) {

            if (account.toJS && account.has("call_orders")) {

                const call_orders = account.get("call_orders").toJS();

                for (let i = 0; i < call_orders.length; i++) {

                    let callID = call_orders[i];

                    let position = ChainStore.getObject(callID);
                    let debtAsset = position.getIn(["call_price", "quote", "asset_id"]);

                    if (debtAsset === lookForBitAsset) {
                        collOrderObject = callID;
                        showCollateralRatio = true;
                        break;
                    }
                };
            }

            /* Settlment Offset */
            let settleAsset = baseAsset.get("id") == "1.3.0" ? quoteAsset : quoteAsset.get("id") == "1.3.0" ? baseAsset : null;

            if(settleAsset && feedPrice) {
                let offset_percent = settleAsset.getIn(["bitasset", "options"]).toJS().force_settlement_offset_percent;
                settlePrice = baseAsset.get("id") == "1.3.0" ? feedPrice.toReal()/(1 + (offset_percent / 10000)) : feedPrice.toReal()*(1 + (offset_percent / 10000));
            }
        }

        const translator = require("counterpart");

        return (
                <div className="grid-block shrink no-padding overflow-visible top-bar">
                    <div className="grid-block overflow-visible">
                        <div className="grid-block shrink">
                            <div style={{padding: "10px"}}>
                                {!hasPrediction ? (
                                    <div style={{padding: "0 5px", fontSize: "18px", marginTop: "1px"}}>
                                        <Link to={`/asset/${quoteSymbol}`} className="asset-prefix"><AssetName name={quoteSymbol} replace={true} /></Link>
{'fraction_non_alphanumeric': 0.12319073657124477, 'fraction_numerical': 0.009434973732175405, 'mean_word_length': 2.2355185570586196, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4811963', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2439, 'n_words': 548}