<commit_before>import React, {PropTypes, Component} from "react";
import {Link} from "react-router/es";
import {FormattedDate} from "react-intl";
import { connect } from "alt-react";
import WalletActions from "actions/WalletActions";
import WalletManagerStore from "stores/WalletManagerStore";
import BackupStore from "stores/BackupStore";
import WalletDb from "stores/WalletDb";
import BackupActions, {backup, decryptWalletBackup} from "actions/BackupActions";
import notify from "actions/NotificationActions";
import {saveAs} from "file-saver";
import cname from "classnames";
import Translate from "react-translate-component";
import {ChainConfig} from "bitsharesjs-ws";
import {PrivateKey} from "bitsharesjs/es";
import SettingsActions from "actions/SettingsActions";

const connectObject = {
    listenTo() {
        return [WalletManagerStore, BackupStore];
    },
    getProps() {
        let wallet = WalletManagerStore.getState();
        let backup = BackupStore.getState();
        return { wallet, backup };
    }
};

//The default component is WalletManager.jsx
class BackupCreate extends Component {
    render() {
        return (
            <div style={{maxWidth: "40rem"}}>
            <Create noText={this.props.noText} newAccount={this.props.location ? this.props.location.query.newAccount : null}>
                <NameSizeModified/>
                {this.props.noText ? null : <Sha1/>}
                <Download downloadCb={this.props.downloadCb}/>
            </Create>

        </div>
    );
    }
}
BackupCreate = connect(BackupCreate, connectObject);

// layout is a small project
// class WalletObjectInspector extends Component {
//     static propTypes={ walletObject: PropTypes.object }
//     render() {
//         return <div style={{overflowY:'auto'}}>
//             <Inspector
//                 data={ this.props.walletObject || {} }
//                 search={false}/>
//         </div>
//     }
// }

class BackupRestore extends Component {

    constructor() {
        super()
        this.state = {
            newWalletName: null
        }
    }

    componentWillMount() {
        BackupActions.reset();
    }

    render() {
        let new_wallet = this.props.wallet.new_wallet
        let has_new_wallet = this.props.wallet.wallet_names.has(new_wallet)
        let restored = has_new_wallet

        return (
            <div>
                <Translate style={{textAlign: "left", maxWidth: "30rem"}} component="p" content="wallet.import_backup_choose" />
                {(new FileReader).readAsBinaryString ? null : <p className="error">Warning! You browser doesn't support some some file operations required to restore backup, we recommend you to use Chrome or Firefox browsers to restore your backup.</p>}
                <Upload>
                    <NameSizeModified/>
                    <DecryptBackup saveWalletObject={true}>
                        <NewWalletName>
                            <Restore/>
                        </NewWalletName>
                    </DecryptBackup>
                </Upload>
                <br />
                <Link to="/"><button className="blue"><Translate content="wallet.back" /></button></Link>
            </div>
        );
    }
}

BackupRestore = connect(BackupRestore, connectObject);

class Restore extends Component {

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

    isRestored() {
        let new_wallet = this.props.wallet.new_wallet;
        let has_new_wallet = this.props.wallet.wallet_names.has(new_wallet);
        return has_new_wallet;
    }

    render() {
        let new_wallet = this.props.wallet.new_wallet
        let has_new_wallet = this.isRestored()

        if(has_new_wallet)
            return <span>
                <h5><Translate content="wallet.restore_success" name={new_wallet.toUpperCase()} /></h5>
                <Link to="/dashboard">
                    <div className="button outline">
                        <Translate component="span" content="header.dashboard" />
                    </div>
                </Link>
                <div>{this.props.children}</div>
            </span>

        return <span>
            <h3><Translate content="wallet.ready_to_restore" /></h3>
            <div className="button outline"
                onClick={this.onRestore.bind(this)}><Translate content="wallet.restore_wallet_of" name={new_wallet} /></div>
        </span>
    }

    onRestore() {
        WalletActions.restore(
            this.props.wallet.new_wallet,
            this.props.backup.wallet_object
        );
        SettingsActions.changeSetting({
            setting: "passwordLogin",
            value: false
        });
    }

}
Restore = connect(Restore, connectObject);

class NewWalletName extends Component {

    constructor() {
        super()
        this.state = {
            new_wallet: null,
            accept: false
        }
    }

    componentWillMount() {
        let has_current_wallet = !!this.props.wallet.current_wallet
        if( ! has_current_wallet) {
            let walletName = "default";
            if (this.props.backup.name) {
                walletName = this.props.backup.name.match(/[a-z0-9_-]*/)[0]
            }
            WalletManagerStore.setNewWallet(walletName)
            this.setState({accept: true})
        }
        if( has_current_wallet && this.props.backup.name && ! this.state.new_wallet) {
            // begning of the file name might make a good wallet name
            let new_wallet = this.props.backup.name.match(/[a-z0-9_-]*/)[0]
            if( new_wallet )
                this.setState({new_wallet})
        }
    }

    render() {
        if(this.state.accept)
            return <span>{this.props.children}</span>

        let has_wallet_name = !!this.state.new_wallet
        let has_wallet_name_conflict = has_wallet_name ?
            this.props.wallet.wallet_names.has(this.state.new_wallet) : false
        let name_ready = ! has_wallet_name_conflict && has_wallet_name

        return (
        <form onSubmit={this.onAccept.bind(this)}>
            <h5><Translate content="wallet.new_wallet_name" /></h5>
            <input
                type="text"
                id="new_wallet"
                onChange={this.formChange.bind(this)}
                value={this.state.new_wallet}
            />
            <p>{ has_wallet_name_conflict ? <Translate content="wallet.wallet_exist" /> : null}</p>
            <div onClick={ this.onAccept.bind(this) } type="submit" className={cname("button outline", {disabled: ! name_ready})}>
                <Translate content="wallet.accept" />
            </div>
        </form>);
    }
<commit_msg>Fix #1147: Make sure backup filename is converted to lowercase<commit_after>import React, {PropTypes, Component} from "react";
import {Link} from "react-router/es";
import {FormattedDate} from "react-intl";
import { connect } from "alt-react";
import WalletActions from "actions/WalletActions";
import WalletManagerStore from "stores/WalletManagerStore";
import BackupStore from "stores/BackupStore";
import WalletDb from "stores/WalletDb";
import BackupActions, {backup, decryptWalletBackup} from "actions/BackupActions";
import notify from "actions/NotificationActions";
import {saveAs} from "file-saver";
import cname from "classnames";
import Translate from "react-translate-component";
import {ChainConfig} from "bitsharesjs-ws";
import {PrivateKey} from "bitsharesjs/es";
import SettingsActions from "actions/SettingsActions";

const connectObject = {
    listenTo() {
        return [WalletManagerStore, BackupStore];
    },
    getProps() {
        let wallet = WalletManagerStore.getState();
        let backup = BackupStore.getState();
        return { wallet, backup };
    }
};

//The default component is WalletManager.jsx
class BackupCreate extends Component {
    render() {
        return (
            <div style={{maxWidth: "40rem"}}>
            <Create noText={this.props.noText} newAccount={this.props.location ? this.props.location.query.newAccount : null}>
                <NameSizeModified/>
                {this.props.noText ? null : <Sha1/>}
                <Download downloadCb={this.props.downloadCb}/>
            </Create>

        </div>
    );
    }
}
BackupCreate = connect(BackupCreate, connectObject);

// layout is a small project
// class WalletObjectInspector extends Component {
//     static propTypes={ walletObject: PropTypes.object }
//     render() {
//         return <div style={{overflowY:'auto'}}>
//             <Inspector
//                 data={ this.props.walletObject || {} }
//                 search={false}/>
//         </div>
//     }
// }

class BackupRestore extends Component {

    constructor() {
        super()
        this.state = {
            newWalletName: null
        }
    }

    componentWillMount() {
        BackupActions.reset();
    }

    render() {
        let new_wallet = this.props.wallet.new_wallet
        let has_new_wallet = this.props.wallet.wallet_names.has(new_wallet)
        let restored = has_new_wallet

        return (
            <div>
                <Translate style={{textAlign: "left", maxWidth: "30rem"}} component="p" content="wallet.import_backup_choose" />
                {(new FileReader).readAsBinaryString ? null : <p className="error">Warning! You browser doesn't support some some file operations required to restore backup, we recommend you to use Chrome or Firefox browsers to restore your backup.</p>}
                <Upload>
                    <NameSizeModified/>
                    <DecryptBackup saveWalletObject={true}>
                        <NewWalletName>
                            <Restore/>
                        </NewWalletName>
                    </DecryptBackup>
                </Upload>
                <br />
                <Link to="/"><button className="blue"><Translate content="wallet.back" /></button></Link>
            </div>
        );
    }
}

BackupRestore = connect(BackupRestore, connectObject);

class Restore extends Component {

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

    isRestored() {
        let new_wallet = this.props.wallet.new_wallet;
        let has_new_wallet = this.props.wallet.wallet_names.has(new_wallet);
        return has_new_wallet;
    }

    render() {
        let new_wallet = this.props.wallet.new_wallet
        let has_new_wallet = this.isRestored()

        if(has_new_wallet)
            return <span>
                <h5><Translate content="wallet.restore_success" name={new_wallet.toUpperCase()} /></h5>
                <Link to="/dashboard">
                    <div className="button outline">
                        <Translate component="span" content="header.dashboard" />
                    </div>
                </Link>
                <div>{this.props.children}</div>
            </span>

        return <span>
            <h3><Translate content="wallet.ready_to_restore" /></h3>
            <div className="button outline"
                onClick={this.onRestore.bind(this)}><Translate content="wallet.restore_wallet_of" name={new_wallet} /></div>
        </span>
    }

    onRestore() {
        WalletActions.restore(
            this.props.wallet.new_wallet,
            this.props.backup.wallet_object
        );
        SettingsActions.changeSetting({
            setting: "passwordLogin",
            value: false
        });
    }

}
Restore = connect(Restore, connectObject);

class NewWalletName extends Component {

    constructor() {
        super()
        this.state = {
            new_wallet: null,
            accept: false
        }
    }

    componentWillMount() {
        let has_current_wallet = !!this.props.wallet.current_wallet
        if( ! has_current_wallet) {
            let walletName = "default";
            if (this.props.backup.name) {
                walletName = this.props.backup.name.match(/[a-z0-9_-]*/)[0]
            }
            WalletManagerStore.setNewWallet(walletName)
            this.setState({accept: true})
        }
        if( has_current_wallet && this.props.backup.name && ! this.state.new_wallet) {
            // begning of the file name might make a good wallet name
            let new_wallet = this.props.backup.name.toLowerCase().match(/[a-z0-9_-]*/)[0];
            if( new_wallet )
                this.setState({new_wallet})
        }
    }

    render() {
        if(this.state.accept)
            return <span>{this.props.children}</span>

        let has_wallet_name = !!this.state.new_wallet
        let has_wallet_name_conflict = has_wallet_name ?
            this.props.wallet.wallet_names.has(this.state.new_wallet) : false
        let name_ready = ! has_wallet_name_conflict && has_wallet_name

        return (
        <form onSubmit={this.onAccept.bind(this)}>
            <h5><Translate content="wallet.new_wallet_name" /></h5>
            <input
                type="text"
                id="new_wallet"
                onChange={this.formChange.bind(this)}
                value={this.state.new_wallet}
            />
            <p>{ has_wallet_name_conflict ? <Translate content="wallet.wallet_exist" /> : null}</p>
            <div onClick={ this.onAccept.bind(this) } type="submit" className={cname("button outline", {disabled: ! name_ready})}>
                <Translate content="wallet.accept" />
            </div>
        </form>);
    }

{'fraction_non_alphanumeric': 0.12092330603127327, 'fraction_numerical': 0.002829486224869695, 'mean_word_length': 2.0783864313545726, 'pattern_counts': {'":': 0, '<': 129, '<?xml version=': 0, '>': 129, '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': '6937379', 'n_tokens_mistral': 3760, 'n_tokens_neox': 3831, 'n_words': 757}