<commit_before>import React from "react";
import Immutable from "immutable";
import classNames from "classnames";
import market_utils from "common/market_utils";
import Ps from "perfect-scrollbar";

class OrderBook extends React.Component {
    constructor() {
        super();
        this.state = {
            shouldScrollBottom: false,
            didScrollOnMount: true
        };
    }

    shouldComponentUpdate(nextProps) {
        return (
            !Immutable.is(nextProps.orders, this.props.orders)
            );
    }

    componentDidMount() {
        let bidContainer = React.findDOMNode(this.refs.bidsTbody);
        let askContainer = React.findDOMNode(this.refs.asksTbody);
        bidContainer.scrollTop = bidContainer.scrollHeight;
        Ps.initialize(bidContainer);
        Ps.initialize(askContainer);

        if (bidContainer.scrollTop !== bidContainer.scrollHeight) {
            this.setState({didScrollOnMount: false});
        }
    }

    componentWillReceiveProps() {
        let bidContainer = React.findDOMNode(this.refs.bidsTbody);
        this.setState({shouldScrollBottom: bidContainer.scrollTop + bidContainer.offsetHeight === bidContainer.scrollHeight});
    }

    componentDidUpdate() {
        let askContainer = React.findDOMNode(this.refs.asksTbody);
        let bidContainer = React.findDOMNode(this.refs.bidsTbody);
        if (this.state.shouldScrollBottom !== !this.state.didScrollOnMount) {
            bidContainer.scrollTop = bidContainer.scrollHeight;
            this.setState({didScrollOnMount: true});
        }

        Ps.update(bidContainer);
        Ps.update(askContainer);
    }

    render() {
        let {orders, account, quote, base, quoteSymbol, baseSymbol} = this.props;
        let bids = null, asks = null;
        let high = 0, low = 0;
        
        if(orders.size > 0 && base && quote) {
            // let quotePrecision = utils.get_asset_precision(quote.precision);
            // let basePrecision = utils.get_asset_precision(base.precision);

            bids = orders.filter(a => {
                return a.sell_price.base.asset_id === base.id;
            }).sort((a, b) => {<commit_msg>Fix Orderbook autoscroll to bottom for bids<commit_after>import React from "react";
import Immutable from "immutable";
import classNames from "classnames";
import market_utils from "common/market_utils";
import Ps from "perfect-scrollbar";

class OrderBook extends React.Component {
    constructor() {
        super();
        this.state = {
            shouldScrollBottom: false,
            didScrollOnMount: true
        };
    }

    shouldComponentUpdate(nextProps) {
        return (
            !Immutable.is(nextProps.orders, this.props.orders)
            );
    }

    componentDidMount() {
        let bidContainer = React.findDOMNode(this.refs.bidsTbody);
        let askContainer = React.findDOMNode(this.refs.asksTbody);
        bidContainer.scrollTop = bidContainer.scrollHeight;
        Ps.initialize(bidContainer);
        Ps.initialize(askContainer);

        if (bidContainer.scrollTop !== bidContainer.scrollHeight) {
            this.setState({didScrollOnMount: false});
        }
    }

    componentWillReceiveProps() {
        let bidContainer = React.findDOMNode(this.refs.bidsTbody);
        this.setState({shouldScrollBottom: Math.round(bidContainer.scrollTop + bidContainer.offsetHeight) === bidContainer.scrollHeight});
    }

    componentDidUpdate() {
        let askContainer = React.findDOMNode(this.refs.asksTbody);
        let bidContainer = React.findDOMNode(this.refs.bidsTbody);
        if (this.state.shouldScrollBottom || !this.state.didScrollOnMount) {
            bidContainer.scrollTop = bidContainer.scrollHeight;
            this.setState({didScrollOnMount: true});
        }

        Ps.update(bidContainer);
        Ps.update(askContainer);
    }

    render() {
        let {orders, account, quote, base, quoteSymbol, baseSymbol} = this.props;
        let bids = null, asks = null;
        let high = 0, low = 0;
        
        if(orders.size > 0 && base && quote) {
            // let quotePrecision = utils.get_asset_precision(quote.precision);
            // let basePrecision = utils.get_asset_precision(base.precision);

            bids = orders.filter(a => {
                return a.sell_price.base.asset_id === base.id;
            }).sort((a, b) => {
{'fraction_non_alphanumeric': 0.11093357680894773, 'fraction_numerical': 0.0013695503309746632, 'mean_word_length': 2.545307443365696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3388343', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1204, 'n_words': 228}