<commit_before>import React from "react";
import ReactDOM from "react-dom";
import {PropTypes} from "react-router";
import Immutable from "immutable";
import Ps from "perfect-scrollbar";
import utils from "common/utils";
import Translate from "react-translate-component";
import connectToStores from "alt/utils/connectToStores";
import MarketRow from "./MarketRow";
import SettingsStore from "stores/SettingsStore";
import MarketsStore from "stores/MarketsStore";
import AssetStore from "stores/AssetStore";
import ChainTypes from "../Utility/ChainTypes";
import BindToChainState from "../Utility/BindToChainState";
import SettingsActions from "actions/SettingsActions";
import AssetActions from "actions/AssetActions";
import MarketsActions from "actions/MarketsActions";
import cnames from "classnames";
import {debounce} from "lodash";

let lastLookup = new Date();

@BindToChainState()
class MyMarkets extends React.Component {

    static propTypes = {
        core: ChainTypes.ChainAsset.isRequired
    };

    static defaultProps = {
        activeTab: "starred",
        core: "1.3.0"
    };

    static contextTypes = {
        history: PropTypes.history
    };

    constructor(props) {
        super();

        let inputValue = props.viewSettings.get("marketLookupInput");
        let symbols = inputValue ? inputValue.split(":") : [null];
        let quote = symbols[0];
        let base = symbols.length === 2 ? symbols[1] : null;

        this.state = {
            inverseSort: props.viewSettings.get("myMarketsInvert") || true,
            sortBy: props.viewSettings.get("myMarketsSort") || "volume",
            activeTab: props.viewSettings.get("favMarketTab") || "starred",
            lookupQuote: quote,
            lookupBase: base,
            inputValue: inputValue
        };

        this.getAssetList = _.debounce(AssetActions.getAssetList, 150);
    }

    shouldComponentUpdate(nextProps, nextState) {
        return (
            !Immutable.is(nextProps.assets, this.props.assets) ||
            !Immutable.is(nextProps.searchAssets, this.props.searchAssets) ||
            !Immutable.is(nextProps.markets, this.props.markets) ||
            !Immutable.is(nextProps.starredMarkets, this.props.starredMarkets) ||
            !Immutable.is(nextProps.marketStats, this.props.marketStats) ||
            nextState.inverseSort !== this.state.inverseSort ||
            nextState.sortBy !== this.state.sortBy ||
            nextState.activeTab !== this.state.activeTab ||
            nextState.lookupQuote !== this.state.lookupQuote ||
            nextState.lookupBase !== this.state.lookupBase ||
            nextProps.current !== this.props.current
        );
    }

    componentDidMount() {
        let historyContainer = ReactDOM.findDOMNode(this.refs.favorites);
        Ps.initialize(historyContainer);

        if (this.state.activeTab === "all") {
            this._lookupAssets({target: {value: this.state.inputValue}}, true);
        }
    }

    componentDidUpdate() {
        let historyContainer = ReactDOM.findDOMNode(this.refs.favorites);
        Ps.update(historyContainer);
    }

    _inverseSort() {
        SettingsActions.changeViewSetting({
            myMarketsInvert: !this.state.myMarketsInvert
        });
        this.setState({
            inverseSort: !this.state.inverseSort
        });
    }

    _changeSort(type) {
        if (type !== this.state.sortBy) {
            SettingsActions.changeViewSetting({
                myMarketsSort: type
            });
            this.setState({
                sortBy: type
            });
        } else {
            this._inverseSort();
        }
    }

    _goMarkets() {
        this.context.history.pushState(null, "/markets");
    }

    _changeTab(tab) {
        SettingsActions.changeViewSetting({
            favMarketTab: tab
        });
        this.setState({
            activeTab: tab
        });
    }

    _lookupAssets(e, force = false) {
        let now = new Date();

        let symbols = e.target.value.toUpperCase().split(":");
        let quote = symbols[0];<commit_msg>Handle unset market input value in MyMarkets<commit_after>import React from "react";
import ReactDOM from "react-dom";
import {PropTypes} from "react-router";
import Immutable from "immutable";
import Ps from "perfect-scrollbar";
import utils from "common/utils";
import Translate from "react-translate-component";
import connectToStores from "alt/utils/connectToStores";
import MarketRow from "./MarketRow";
import SettingsStore from "stores/SettingsStore";
import MarketsStore from "stores/MarketsStore";
import AssetStore from "stores/AssetStore";
import ChainTypes from "../Utility/ChainTypes";
import BindToChainState from "../Utility/BindToChainState";
import SettingsActions from "actions/SettingsActions";
import AssetActions from "actions/AssetActions";
import MarketsActions from "actions/MarketsActions";
import cnames from "classnames";
import {debounce} from "lodash";

let lastLookup = new Date();

@BindToChainState()
class MyMarkets extends React.Component {

    static propTypes = {
        core: ChainTypes.ChainAsset.isRequired
    };

    static defaultProps = {
        activeTab: "starred",
        core: "1.3.0"
    };

    static contextTypes = {
        history: PropTypes.history
    };

    constructor(props) {
        super();

        let inputValue = props.viewSettings.get("marketLookupInput");
        let symbols = inputValue ? inputValue.split(":") : [null];
        let quote = symbols[0];
        let base = symbols.length === 2 ? symbols[1] : null;

        this.state = {
            inverseSort: props.viewSettings.get("myMarketsInvert") || true,
            sortBy: props.viewSettings.get("myMarketsSort") || "volume",
            activeTab: props.viewSettings.get("favMarketTab") || "starred",
            lookupQuote: quote,
            lookupBase: base,
            inputValue: inputValue
        };

        this.getAssetList = _.debounce(AssetActions.getAssetList, 150);
    }

    shouldComponentUpdate(nextProps, nextState) {
        return (
            !Immutable.is(nextProps.assets, this.props.assets) ||
            !Immutable.is(nextProps.searchAssets, this.props.searchAssets) ||
            !Immutable.is(nextProps.markets, this.props.markets) ||
            !Immutable.is(nextProps.starredMarkets, this.props.starredMarkets) ||
            !Immutable.is(nextProps.marketStats, this.props.marketStats) ||
            nextState.inverseSort !== this.state.inverseSort ||
            nextState.sortBy !== this.state.sortBy ||
            nextState.activeTab !== this.state.activeTab ||
            nextState.lookupQuote !== this.state.lookupQuote ||
            nextState.lookupBase !== this.state.lookupBase ||
            nextProps.current !== this.props.current
        );
    }

    componentDidMount() {
        let historyContainer = ReactDOM.findDOMNode(this.refs.favorites);
        Ps.initialize(historyContainer);

        if (this.state.activeTab === "all" && this.state.inputValue) {
            this._lookupAssets({target: {value: this.state.inputValue}}, true);
        }
    }

    componentDidUpdate() {
        let historyContainer = ReactDOM.findDOMNode(this.refs.favorites);
        Ps.update(historyContainer);
    }

    _inverseSort() {
        SettingsActions.changeViewSetting({
            myMarketsInvert: !this.state.myMarketsInvert
        });
        this.setState({
            inverseSort: !this.state.inverseSort
        });
    }

    _changeSort(type) {
        if (type !== this.state.sortBy) {
            SettingsActions.changeViewSetting({
                myMarketsSort: type
            });
            this.setState({
                sortBy: type
            });
        } else {
            this._inverseSort();
        }
    }

    _goMarkets() {
        this.context.history.pushState(null, "/markets");
    }

    _changeTab(tab) {
        SettingsActions.changeViewSetting({
            favMarketTab: tab
        });
        this.setState({
            activeTab: tab
        });
    }

    _lookupAssets(e, force = false) {
        if (!e.target.value) {
            return;
        }
        let now = new Date();

        let symbols = e.target.value.toUpperCase().split(":");
        let quote = symbols[0];
{'fraction_non_alphanumeric': 0.11923401180296278, 'fraction_numerical': 0.0024087679152113694, 'mean_word_length': 2.494949494949495, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '4727851', 'n_tokens_mistral': 2361, 'n_tokens_neox': 2271, 'n_words': 451}