<commit_before>import React from "react";
import Immutable from "immutable";
import DashboardList from "./DashboardList";
import { RecentTransactions } from "../Account/RecentTransactions";
import Translate from "react-translate-component";
import MarketCard from "./MarketCard";
import utils from "common/utils";
import { Apis } from "bitsharesjs-ws";
var logo = require("assets/logo-ico-blue.png");
import LoadingIndicator from "../LoadingIndicator";
import SettingsActions from "actions/SettingsActions";
import WalletUnlockActions from "actions/WalletUnlockActions";

class Dashboard extends React.Component {

    constructor() {
        super();
        let marketsByChain = {
            "4018d784":[
                ["CNY", "OPEN.BTC"],
                ["CNY", "USD"],
                ["CNY", "OPEN.ETH"],
                ["CNY", "BTS"],
                ["BTS", "CNY"],
                ["BTS", "USD"],
                ["BTS", "GOLD"],
                ["BTS", "OPEN.BTC"]
              
            ],
            "39f5e2ed": [
                ["TEST", "PEG.FAKEUSD"],
                ["TEST", "BTWTY"]
            ]
        };
        let chainID = Apis.instance().chain_id;
        if (chainID) chainID = chainID.substr(0, 8);

        this.state = {
            width: null,
            showIgnored: false,
            featuredMarkets: marketsByChain[chainID] || marketsByChain["4018d784"],
            newAssets: [

            ]
        };

        this._setDimensions = this._setDimensions.bind(this);
        // this._sortMarketsByVolume = this._sortMarketsByVolume.bind(this);
    }

    componentDidMount() {
        this._setDimensions();

        window.addEventListener("resize", this._setDimensions, {capture: false, passive: true});
    }

    shouldComponentUpdate(nextProps, nextState) {
        return (
            !utils.are_equal_shallow(nextState.featuredMarkets, this.state.featuredMarkets) ||
            !utils.are_equal_shallow(nextProps.lowVolumeMarkets, this.props.lowVolumeMarkets) ||
            !utils.are_equal_shallow(nextState.newAssets, this.state.newAssets) ||
            nextProps.linkedAccounts !== this.props.linkedAccounts ||
            // nextProps.marketStats !== this.props.marketStats ||
            nextProps.ignoredAccounts !== this.props.ignoredAccounts ||
            nextProps.passwordAccount !== this.props.passwordAccount ||
            nextState.width !== this.state.width ||
            nextProps.accountsReady !== this.props.accountsReady ||
            nextState.showIgnored !== this.state.showIgnored
        );
    }

    componentWillUnmount() {
        window.removeEventListener("resize", this._setDimensions);
    }

    _setDimensions() {
        let width = window.innerWidth;

        if (width !== this.state.width) {
            this.setState({width});
        }
    }

    _onToggleIgnored() {
        this.setState({
            showIgnored: !this.state.showIgnored
        });
    }

    // _sortMarketsByVolume(a, b) {
    //     let idA = a[1] + "_" + a[0];
    //     let idB = b[1] + "_" + b[0];
    //     let statsA = this.props.marketStats.get(idA);
    //     let statsB = this.props.marketStats.get(idB);
    //     if (!statsA || !statsB) return -1;
    //
    //     function getEquivalentVolume(stats, market, marketStats) {
    //         let coreVolume = stats.volumeBaseAsset.asset_id === "1.3.0" ? stats.volumeBaseAsset :
    //            stats.volumeQuoteAsset.asset_id === "1.3.0" ? stats.volumeQuoteAsset : 0;
    //
    //         if (!coreVolume) {
    //             let options = [
    //                 `${market[1]}_BTS`,
    //                 `BTS_${market[1]}`,
    //                 `${market[0]}_BTS`,
    //                 `BTS_${market[0]}`,
    //             ];
    //             let convertUsingStats;
    //             for (var i = 0; i < options.length; i++) {
    //                 convertUsingStats = marketStats.get(options[i]);
    //                 if (convertUsingStats) break;
    //             }
    //
    //             if (convertUsingStats && convertUsingStats.price) {
    //                 if (convertUsingStats.price.base.asset_id === "1.3.0") {
    //                     if (stats.volumeBaseAsset.asset_id === convertUsingStats.price.quote.asset_id) {
    //                         coreVolume = stats.volumeBaseAsset.times(convertUsingStats.price);
    //                     } else if (stats.volumeQuoteAsset.asset_id === convertUsingStats.price.quote.asset_id) {
    //                         coreVolume = stats.volumeQuoteAsset.times(convertUsingStats.price);
    //                     }
    //                 } else if (convertUsingStats.price.quote.asset_id === "1.3.0") {
    //                     if (stats.volumeBaseAsset.asset_id === convertUsingStats.price.base.asset_id) {
    //                         coreVolume = stats.volumeBaseAsset.times(convertUsingStats.price);
    //                     } else if (stats.volumeQuoteAsset.asset_id === convertUsingStats.price.base.asset_id) {
    //                         coreVolume = stats.volumeQuoteAsset.times(convertUsingStats.price);
    //                     }
    //                 }
    //
    //                 console.log(market, "coreVolume", coreVolume && coreVolume.getAmount(), coreVolume && coreVolume.asset_id);
    //
    //             } else {
    //                 console.log(market, "*** Unable to convert price ***");
    //             }
    //         }
    //
    //         return coreVolume;
    //     }
    //
    //     let coreVolumeA = getEquivalentVolume(statsA, a, this.props.marketStats);
    //     let coreVolumeB =  getEquivalentVolume(statsB, b, this.props.marketStats);
    //
    //     if (coreVolumeA && coreVolumeB) {
    //         return coreVolumeB.getAmount() - coreVolumeA.getAmount();
    //     }
    //     return 0;
    // }

    render() {
        let { linkedAccounts, myIgnoredAccounts, accountsReady, passwordAccount } = this.props;
        let {width, showIgnored, featuredMarkets, newAssets} = this.state;

        if (passwordAccount && !linkedAccounts.has(passwordAccount)) {
            linkedAccounts = linkedAccounts.add(passwordAccount);
        }
        let names = linkedAccounts.toArray().sort();
        if (passwordAccount && names.indexOf(passwordAccount) === -1) names.push(passwordAccount);
        let ignored = myIgnoredAccounts.toArray().sort();

        let accountCount = linkedAccounts.size + myIgnoredAccounts.size + (passwordAccount ? 1 : 0);

        if (!accountsReady) {
            return <LoadingIndicator />;
        }

        let validMarkets = 0;
        
        let marketsList = {
            "ico":[
                
                ["CNY", "VEN.WARRANT"],
                ["CNY", "OCT"],
                ["BTS", "OBITS"],
                ["BTS", "ICOO"]
            ],
            "special": [
                
                ["BTS", "BTWTY"],
                ["BTS", "HERO"],
                ["BTS", "GOLD"],
                ["BTS", "EUR"]
            ]
        };
        <commit_msg>vechain<commit_after>import React from "react";
import Immutable from "immutable";
import DashboardList from "./DashboardList";
import { RecentTransactions } from "../Account/RecentTransactions";
import Translate from "react-translate-component";
import MarketCard from "./MarketCard";
import utils from "common/utils";
import { Apis } from "bitsharesjs-ws";
var logo = require("assets/logo-ico-blue.png");
import LoadingIndicator from "../LoadingIndicator";
import SettingsActions from "actions/SettingsActions";
import WalletUnlockActions from "actions/WalletUnlockActions";

class Dashboard extends React.Component {

    constructor() {
        super();
        let marketsByChain = {
            "4018d784":[
                ["CNY", "OPEN.BTC"],
                ["CNY", "USD"],
                ["CNY", "OPEN.ETH"],
                ["CNY", "BTS"],
                ["BTS", "CNY"],
                ["BTS", "USD"],
                ["BTS", "GOLD"],
                ["BTS", "OPEN.BTC"]
              
            ],
            "39f5e2ed": [
                ["TEST", "PEG.FAKEUSD"],
                ["TEST", "BTWTY"]
            ]
        };
        let chainID = Apis.instance().chain_id;
        if (chainID) chainID = chainID.substr(0, 8);

        this.state = {
            width: null,
            showIgnored: false,
            featuredMarkets: marketsByChain[chainID] || marketsByChain["4018d784"],
            newAssets: [

            ]
        };

        this._setDimensions = this._setDimensions.bind(this);
        // this._sortMarketsByVolume = this._sortMarketsByVolume.bind(this);
    }

    componentDidMount() {
        this._setDimensions();

        window.addEventListener("resize", this._setDimensions, {capture: false, passive: true});
    }

    shouldComponentUpdate(nextProps, nextState) {
        return (
            !utils.are_equal_shallow(nextState.featuredMarkets, this.state.featuredMarkets) ||
            !utils.are_equal_shallow(nextProps.lowVolumeMarkets, this.props.lowVolumeMarkets) ||
            !utils.are_equal_shallow(nextState.newAssets, this.state.newAssets) ||
            nextProps.linkedAccounts !== this.props.linkedAccounts ||
            // nextProps.marketStats !== this.props.marketStats ||
            nextProps.ignoredAccounts !== this.props.ignoredAccounts ||
            nextProps.passwordAccount !== this.props.passwordAccount ||
            nextState.width !== this.state.width ||
            nextProps.accountsReady !== this.props.accountsReady ||
            nextState.showIgnored !== this.state.showIgnored
        );
    }

    componentWillUnmount() {
        window.removeEventListener("resize", this._setDimensions);
    }

    _setDimensions() {
        let width = window.innerWidth;

        if (width !== this.state.width) {
            this.setState({width});
        }
    }

    _onToggleIgnored() {
        this.setState({
            showIgnored: !this.state.showIgnored
        });
    }

    // _sortMarketsByVolume(a, b) {
    //     let idA = a[1] + "_" + a[0];
    //     let idB = b[1] + "_" + b[0];
    //     let statsA = this.props.marketStats.get(idA);
    //     let statsB = this.props.marketStats.get(idB);
    //     if (!statsA || !statsB) return -1;
    //
    //     function getEquivalentVolume(stats, market, marketStats) {
    //         let coreVolume = stats.volumeBaseAsset.asset_id === "1.3.0" ? stats.volumeBaseAsset :
    //            stats.volumeQuoteAsset.asset_id === "1.3.0" ? stats.volumeQuoteAsset : 0;
    //
    //         if (!coreVolume) {
    //             let options = [
    //                 `${market[1]}_BTS`,
    //                 `BTS_${market[1]}`,
    //                 `${market[0]}_BTS`,
    //                 `BTS_${market[0]}`,
    //             ];
    //             let convertUsingStats;
    //             for (var i = 0; i < options.length; i++) {
    //                 convertUsingStats = marketStats.get(options[i]);
    //                 if (convertUsingStats) break;
    //             }
    //
    //             if (convertUsingStats && convertUsingStats.price) {
    //                 if (convertUsingStats.price.base.asset_id === "1.3.0") {
    //                     if (stats.volumeBaseAsset.asset_id === convertUsingStats.price.quote.asset_id) {
    //                         coreVolume = stats.volumeBaseAsset.times(convertUsingStats.price);
    //                     } else if (stats.volumeQuoteAsset.asset_id === convertUsingStats.price.quote.asset_id) {
    //                         coreVolume = stats.volumeQuoteAsset.times(convertUsingStats.price);
    //                     }
    //                 } else if (convertUsingStats.price.quote.asset_id === "1.3.0") {
    //                     if (stats.volumeBaseAsset.asset_id === convertUsingStats.price.base.asset_id) {
    //                         coreVolume = stats.volumeBaseAsset.times(convertUsingStats.price);
    //                     } else if (stats.volumeQuoteAsset.asset_id === convertUsingStats.price.base.asset_id) {
    //                         coreVolume = stats.volumeQuoteAsset.times(convertUsingStats.price);
    //                     }
    //                 }
    //
    //                 console.log(market, "coreVolume", coreVolume && coreVolume.getAmount(), coreVolume && coreVolume.asset_id);
    //
    //             } else {
    //                 console.log(market, "*** Unable to convert price ***");
    //             }
    //         }
    //
    //         return coreVolume;
    //     }
    //
    //     let coreVolumeA = getEquivalentVolume(statsA, a, this.props.marketStats);
    //     let coreVolumeB =  getEquivalentVolume(statsB, b, this.props.marketStats);
    //
    //     if (coreVolumeA && coreVolumeB) {
    //         return coreVolumeB.getAmount() - coreVolumeA.getAmount();
    //     }
    //     return 0;
    // }

    render() {
        let { linkedAccounts, myIgnoredAccounts, accountsReady, passwordAccount } = this.props;
        let {width, showIgnored, featuredMarkets, newAssets} = this.state;

        if (passwordAccount && !linkedAccounts.has(passwordAccount)) {
            linkedAccounts = linkedAccounts.add(passwordAccount);
        }
        let names = linkedAccounts.toArray().sort();
        if (passwordAccount && names.indexOf(passwordAccount) === -1) names.push(passwordAccount);
        let ignored = myIgnoredAccounts.toArray().sort();

        let accountCount = linkedAccounts.size + myIgnoredAccounts.size + (passwordAccount ? 1 : 0);

        if (!accountsReady) {
            return <LoadingIndicator />;
        }

        let validMarkets = 0;
        
        let marketsList = {
            "ico":[
                
                ["CNY", "VEN.WARRANT"],
                ["CNY", "VEN"],
                ["BTS", "OBITS"],
                ["BTS", "ICOO"]
            ],
            "special": [
                
                ["BTS", "BTWTY"],
                ["BTS", "HERO"],
                ["BTS", "GOLD"],
                ["BTS", "EUR"]
            ]
        };
        
{'fraction_non_alphanumeric': 0.13882618510158012, 'fraction_numerical': 0.006772009029345372, 'mean_word_length': 1.677431539187913, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 5, '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': '4615648', 'n_tokens_mistral': 4082, 'n_tokens_neox': 3951, 'n_words': 654}