<commit_before>import React, {Component} from "react";
import {Link} from "react-router"
import connectToStores from "alt/utils/connectToStores"
import WalletActions from "actions/WalletActions"
import WalletManagerStore from "stores/WalletManagerStore"
import BalanceClaimByAsset from "components/Wallet/BalanceClaimByAsset"
import Translate from "react-translate-component"
import cname from "classnames"
import counterpart from "counterpart";

class WalletBaseComponent extends Component {

    static getStores() {
        return [WalletManagerStore]
    }

    static getPropsFromStores() {
        var props = WalletManagerStore.getState()
        return props
    }

}

@connectToStores
export default class WalletManager extends WalletBaseComponent {

    getTitle() {

        switch (this.props.location.pathname) {

            case "/wallet/create":
                return "wallet.create_wallet";
                break;

            case "/wallet/backup/create":
                return "wallet.create_backup";
                break;

            case "/wallet/backup/restore":
                return "wallet.restore_backup";
                break;

            case "/wallet/backup/brainkey":
                return "wallet.backup_brainkey";
                break;

            case "/wallet/delete":
                return "wallet.delete_wallet";
                break;

            case "/wallet/change-password":
                return "wallet.change_password";
                break;

            case "/wallet/import-keys":
                return "wallet.import_keys";
                break;


            default:
                return "wallet.console";
                break;
        }
    }

    render() {

        return (
            <div className="grid-block vertical">
                <div className="grid-container" style={{maxWidth: "40rem"}}>
                    <div className="content-block center-content">
                        <div className="page-header">
                            <Translate component="h3" content={this.getTitle()} />
                        </div>
                        <div className="content-block">
                            {this.props.children}
                        </div>
                    </div>
                </div>
            </div>
        )
    }
}

@connectToStores
export class WalletOptions extends WalletBaseComponent {

    render() {
        var has_wallet = !!this.props.current_wallet
        var has_wallets = this.props.wallet_names.size > 1
        var current_wallet = this.props.current_wallet ? this.props.current_wallet.toUpperCase() : ""
        return <span>
            <div className="grid-block">

                <div className="grid-content">
                    <div className="card">
                        <div className="card-content">
                                <label><Translate content="wallet.active_wallet" />:</label>
                                <div>{current_wallet}</div>
                                <br/>
                                {has_wallets ? (
                                    <Link to="/wallet/change">
                                        <div className="button outline success">
                                            <Translate content="wallet.change_wallet" />
                                        </div>
                                    </Link>
                                )
                                :null}
                        </div>
                    </div>
                </div>

                <div className="grid-content">
                    <div className="card">
                        <div className="card-content">
                                <label><Translate content="wallet.import_keys_tool" /></label>
                                <div style={{visibility: "hidden"}}>Dummy</div>
                                <br/>
                                {has_wallet ? (
                                    <Link to="/wallet/import-keys">
                                        <div className="button outline success">
                                            <Translate content="wallet.import_keys" />
                                        </div>
                                    </Link>
                                )
                                :null}
                        </div>
                    </div>
                </div>

                {has_wallet ? <div className="grid-content">
                    <div className="card">
                        <div className="card-content">
                            <label><Translate content="wallet.balance_claims" /></label>
                            <div style={{visibility: "hidden"}}>Dummy</div>
                            <br/>
                            <Link to="wallet/balance-claims">
                                <div className="button outline success">
                                    <Translate content="wallet.balance_claim_lookup" />
                                </div>
                            </Link>
                        {/*<BalanceClaimByAsset>
                            <br/>
                            <div className="button outline success">
                                <Translate content="wallet.balance_claims" /></div>
                        </BalanceClaimByAsset>
                        */}
                        </div>
                    </div>
                </div>:null}

            </div>

            {has_wallet ? <Link to="wallet/backup/create">
            <div className="button outline success"><Translate content="wallet.create_backup" /></div></Link>:null}

            {has_wallet ? <Link to="wallet/backup/brainkey">
            <div className="button outline success"><Translate content="wallet.backup_brainkey" /></div></Link>:null}


            <Link to="wallet/backup/restore">
            <div className="button outline success"><Translate content="wallet.restore_backup" /></div></Link>

            <br/>

            {has_wallet ? <br/> : null}

            <Link to="wallet/create">
            <div className="button outline success"><Translate content="wallet.new_wallet" /></div></Link>

            {has_wallet ? <Link to="wallet/delete">
            <div className="button outline success"><Translate content="wallet.delete_wallet" /></div></Link>:null}

            {has_wallet ? <Link to="wallet/change-password">
            <div className="button outline success"><Translate content="wallet.change_password" /></div></Link>:null}

        </span>
    }

}

@connectToStores
export class ChangeActiveWallet extends WalletBaseComponent {

    constructor() {
        super()
        this.state = { }
    }

    componentWillMount() {
        var current_wallet = this.props.current_wallet
        this.setState({current_wallet})
    }

    render() {
        var state = WalletManagerStore.getState()
        if(state.wallet_names.count() === 1)
            return <label>{this.state.current_wallet}</label>

        var options = []
        state.wallet_names.forEach( wallet_name => {
            options.push(<option key={wallet_name} value={wallet_name}>{wallet_name.toLowerCase()}</option>)
        })

        var is_dirty = this.state.current_wallet !== this.props.current_wallet

        return (
            <div>
                <section className="block-list">
                    <header><Translate content="wallet.active_wallet" />:</header>
                    <ul>
                        <li className="with-dropdown">
                            <select
                                value={this.state.current_wallet}
                                onChange={this.onChange.bind(this)}
                            >
                                    { options }
                            </select>
                        </li>
                    </ul>
                </section>
            { is_dirty ? (
            <div
                className="button outline"
                onClick={this.onConfirm.bind(this)}
            >
                <Translate content="wallet.change" name={this.state.current_wallet} />
            </div>) : null}

            <Link to="wallet/create">
            <div className="button outline"><Translate content="wallet.new_wallet" /></div>
            </Link>

            </div>
        );
    }

    onConfirm() {
        WalletActions.setWallet(this.state.current_wallet);
        if (window.electron) {
            window.location.hash = "";
            window.remote.getCurrentWindow().reload();
        }
        else window.location.href = "/";
    }

    onChange(event) {
        var current_wallet = event.target.value;
        this.setState({current_wallet});
    }

}

@connectToStores
export class WalletDelete extends WalletBaseComponent {

    constructor() {
        super();
        this.state = {
            selected_wallet: null,
            confirm: 0
        };
    }

    _onCancel() {
        this.setState({<commit_msg>Don't reload the page on wallet change<commit_after>import React, {Component} from "react";
import {Link} from "react-router"
import connectToStores from "alt/utils/connectToStores"
import WalletActions from "actions/WalletActions"
import WalletManagerStore from "stores/WalletManagerStore"
import BalanceClaimByAsset from "components/Wallet/BalanceClaimByAsset"
import Translate from "react-translate-component"
import cname from "classnames"
import counterpart from "counterpart";

class WalletBaseComponent extends Component {

    static getStores() {
        return [WalletManagerStore]
    }

    static getPropsFromStores() {
        var props = WalletManagerStore.getState()
        return props
    }

}

@connectToStores
export default class WalletManager extends WalletBaseComponent {

    getTitle() {

        switch (this.props.location.pathname) {

            case "/wallet/create":
                return "wallet.create_wallet";
                break;

            case "/wallet/backup/create":
                return "wallet.create_backup";
                break;

            case "/wallet/backup/restore":
                return "wallet.restore_backup";
                break;

            case "/wallet/backup/brainkey":
                return "wallet.backup_brainkey";
                break;

            case "/wallet/delete":
                return "wallet.delete_wallet";
                break;

            case "/wallet/change-password":
                return "wallet.change_password";
                break;

            case "/wallet/import-keys":
                return "wallet.import_keys";
                break;


            default:
                return "wallet.console";
                break;
        }
    }

    render() {

        return (
            <div className="grid-block vertical">
                <div className="grid-container" style={{maxWidth: "40rem"}}>
                    <div className="content-block center-content">
                        <div className="page-header">
                            <Translate component="h3" content={this.getTitle()} />
                        </div>
                        <div className="content-block">
                            {this.props.children}
                        </div>
                    </div>
                </div>
            </div>
        )
    }
}

@connectToStores
export class WalletOptions extends WalletBaseComponent {

    render() {
        var has_wallet = !!this.props.current_wallet
        var has_wallets = this.props.wallet_names.size > 1
        var current_wallet = this.props.current_wallet ? this.props.current_wallet.toUpperCase() : ""
        return <span>
            <div className="grid-block">

                <div className="grid-content">
                    <div className="card">
                        <div className="card-content">
                                <label><Translate content="wallet.active_wallet" />:</label>
                                <div>{current_wallet}</div>
                                <br/>
                                {has_wallets ? (
                                    <Link to="/wallet/change">
                                        <div className="button outline success">
                                            <Translate content="wallet.change_wallet" />
                                        </div>
                                    </Link>
                                )
                                :null}
                        </div>
                    </div>
                </div>

                <div className="grid-content">
                    <div className="card">
                        <div className="card-content">
                                <label><Translate content="wallet.import_keys_tool" /></label>
                                <div style={{visibility: "hidden"}}>Dummy</div>
                                <br/>
                                {has_wallet ? (
                                    <Link to="/wallet/import-keys">
                                        <div className="button outline success">
                                            <Translate content="wallet.import_keys" />
                                        </div>
                                    </Link>
                                )
                                :null}
                        </div>
                    </div>
                </div>

                {has_wallet ? <div className="grid-content">
                    <div className="card">
                        <div className="card-content">
                            <label><Translate content="wallet.balance_claims" /></label>
                            <div style={{visibility: "hidden"}}>Dummy</div>
                            <br/>
                            <Link to="wallet/balance-claims">
                                <div className="button outline success">
                                    <Translate content="wallet.balance_claim_lookup" />
                                </div>
                            </Link>
                        {/*<BalanceClaimByAsset>
                            <br/>
                            <div className="button outline success">
                                <Translate content="wallet.balance_claims" /></div>
                        </BalanceClaimByAsset>
                        */}
                        </div>
                    </div>
                </div>:null}

            </div>

            {has_wallet ? <Link to="wallet/backup/create">
            <div className="button outline success"><Translate content="wallet.create_backup" /></div></Link>:null}

            {has_wallet ? <Link to="wallet/backup/brainkey">
            <div className="button outline success"><Translate content="wallet.backup_brainkey" /></div></Link>:null}


            <Link to="wallet/backup/restore">
            <div className="button outline success"><Translate content="wallet.restore_backup" /></div></Link>

            <br/>

            {has_wallet ? <br/> : null}

            <Link to="wallet/create">
            <div className="button outline success"><Translate content="wallet.new_wallet" /></div></Link>

            {has_wallet ? <Link to="wallet/delete">
            <div className="button outline success"><Translate content="wallet.delete_wallet" /></div></Link>:null}

            {has_wallet ? <Link to="wallet/change-password">
            <div className="button outline success"><Translate content="wallet.change_password" /></div></Link>:null}

        </span>
    }

}

@connectToStores
export class ChangeActiveWallet extends WalletBaseComponent {

    constructor() {
        super()
        this.state = { }
    }

    componentWillMount() {
        var current_wallet = this.props.current_wallet
        this.setState({current_wallet})
    }

    render() {
        var state = WalletManagerStore.getState()
        if(state.wallet_names.count() === 1)
            return <label>{this.state.current_wallet}</label>

        var options = []
        state.wallet_names.forEach( wallet_name => {
            options.push(<option key={wallet_name} value={wallet_name}>{wallet_name.toLowerCase()}</option>)
        })

        var is_dirty = this.state.current_wallet !== this.props.current_wallet

        return (
            <div>
                <section className="block-list">
                    <header><Translate content="wallet.active_wallet" />:</header>
                    <ul>
                        <li className="with-dropdown">
                            <select
                                value={this.state.current_wallet}
                                onChange={this.onChange.bind(this)}
                            >
                                    { options }
                            </select>
                        </li>
                    </ul>
                </section>
            { is_dirty ? (
            <div
                className="button outline"
                onClick={this.onConfirm.bind(this)}
            >
                <Translate content="wallet.change" name={this.state.current_wallet} />
            </div>) : null}

            <Link to="wallet/create">
            <div className="button outline"><Translate content="wallet.new_wallet" /></div>
            </Link>

            </div>
        );
    }

    onConfirm() {
        WalletActions.setWallet(this.state.current_wallet);
        // if (window.electron) {
        //     window.location.hash = "";
        //     window.remote.getCurrentWindow().reload();
        // }
        // else window.location.href = "/";
    }

    onChange(event) {
        var current_wallet = event.target.value;
        this.setState({current_wallet});
    }

}

@connectToStores
export class WalletDelete extends WalletBaseComponent {

    constructor() {
        super();
        this.state = {
            selected_wallet: null,
            confirm: 0
        };
    }

    _onCancel() {
        this.setState({
{'fraction_non_alphanumeric': 0.1107017157941047, 'fraction_numerical': 0.0006599208095028596, 'mean_word_length': 1.2635051033109286, 'pattern_counts': {'":': 14, '<': 261, '<?xml version=': 0, '>': 265, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923338', 'n_tokens_mistral': 4383, 'n_tokens_neox': 4274, 'n_words': 795}