<commit_before>import React, {Component} from "react";
import counterpart from "counterpart";
import Translate from "react-translate-component";
import {Button, Card, Steps, Tooltip} from "bitshares-ui-style-guide";
import debounceRender from "react-debounce-render";
import AssetWrapper from "../Utility/AssetWrapper";
import {connect} from "alt-react";
import {ChainStore} from "bitsharesjs";
import WalletUnlockActions from "actions/WalletUnlockActions";

import BorrowModal from "../Modal/BorrowModal";
import AccountStore from "../../stores/AccountStore";
import Icon from "../Icon/Icon";
import AssetSelect from "../Utility/AssetSelect";
import * as ReactDOM from "react-dom";

class Borrow extends Component {
    constructor() {
        super();
        this.state = {
            isBorrowBaseModalVisible: false,
            selectedAsset: null,
            step: 0
        };
        this.steps = [
            {
                key: "introduction",
                icon: "borrow"
            },
            {
                key: "concept",
                has_legend: true
            },
            {
                key: "setup",
                has_legend: true
            },
            {
                key: "benefits",
                has_legend: true
            },
            {
                key: "risks",
                has_legend: true
            }
        ];
        this.showBorrowModal = this.showBorrowModal.bind(this);
        this.hideBorrowModal = this.hideBorrowModal.bind(this);
    }

    showBorrowModal() {
        // needs a known account
        if (!this.props.currentAccount) {
            WalletUnlockActions.unlock()
                .then(() => {
                    this.setState({
                        isBorrowBaseModalVisible: true
                    });
                })
                .catch(() => {});
        } else {
            this.setState({
                isBorrowBaseModalVisible: true
            });
        }
    }

    hideBorrowModal() {
        this.setState({
            isBorrowBaseModalVisible: false
        });
    }

    next() {
        let step = this.state.step + 1;
        if (step >= this.steps.length) step = this.steps.length;
        this.setState({step});
    }

    prev() {
        let step = this.state.step - 1;
        if (step < 0) step = 0;
        this.setState({step});
    }

    onAssetChange(selected_asset) {
        this.setState({
            selectedAsset: selected_asset
        });
    }

    render() {
        let currentAccount = ChainStore.getAccount(this.props.currentAccount);
        let accountLoaded = !(
            !currentAccount || typeof currentAccount === "string"
        );
        const current = this.state.step;
        const tinyScreen = window.innerWidth <= 800;
        const started = this.state.step > 0;

        const selectedAssetObject = ChainStore.getAsset(
            this.state.selectedAsset
        );
        let steps = this.steps;
        let legend = null;
        if (current < steps.length) {
            try {
                if (steps[current].has_legend) {
                    legend = counterpart.translate(
                        "showcases.borrow.steps_" +
                            steps[current].key +
                            ".text_legend"
                    );
                    legend = legend.split("\n").map(item => {
                        return item.split(":");
                    });
                }
            } catch (err) {
                legend = counterpart.translate(
                    "showcases.borrow.steps_" +
                        steps[current].key +
                        ".text_legend"
                );
            }
        }

        let finishedCard = null;
        if (current >= steps.length) {
            finishedCard = (
                <Card>
                    <div className={"center-content"}>
                        <Translate
                            content={"showcases.borrow.choose"}
                            component={"h4"}
                        />
                    </div>
                    <div
                        style={{
                            display: "flex",
                            justifyContent: "center"
                        }}
                    >
                        <div>
                            <AssetSelect
                                style={{
                                    width: "12rem",
                                    marginBottom: "1rem"
                                }}
                                assets={[
                                    "1.3.113",
                                    "1.3.120",
                                    "1.3.121",
                                    "1.3.1325",
                                    "1.3.105",
                                    "1.3.106",
                                    "1.3.103"
                                ]}
                                onChange={this.onAssetChange.bind(this)}<commit_msg>#2926. resolve issue with empty borrowed asset<commit_after>import React, {Component} from "react";
import counterpart from "counterpart";
import Translate from "react-translate-component";
import {Button, Card, Steps, Tooltip} from "bitshares-ui-style-guide";
import debounceRender from "react-debounce-render";
import AssetWrapper from "../Utility/AssetWrapper";
import {connect} from "alt-react";
import {ChainStore} from "bitsharesjs";
import WalletUnlockActions from "actions/WalletUnlockActions";

import BorrowModal from "../Modal/BorrowModal";
import AccountStore from "../../stores/AccountStore";
import Icon from "../Icon/Icon";
import AssetSelect from "../Utility/AssetSelect";
import * as ReactDOM from "react-dom";

class Borrow extends Component {
    constructor() {
        super();
        this.state = {
            isBorrowBaseModalVisible: false,
            selectedAsset: null,
            step: 0
        };
        this.steps = [
            {
                key: "introduction",
                icon: "borrow"
            },
            {
                key: "concept",
                has_legend: true
            },
            {
                key: "setup",
                has_legend: true
            },
            {
                key: "benefits",
                has_legend: true
            },
            {
                key: "risks",
                has_legend: true
            }
        ];
        this.showBorrowModal = this.showBorrowModal.bind(this);
        this.hideBorrowModal = this.hideBorrowModal.bind(this);
    }

    showBorrowModal() {
        // needs a known account
        if (!this.props.currentAccount) {
            WalletUnlockActions.unlock()
                .then(() => {
                    this.setState({
                        isBorrowBaseModalVisible: true
                    });
                })
                .catch(() => {});
        } else {
            this.setState({
                isBorrowBaseModalVisible: true
            });
        }
    }

    hideBorrowModal() {
        this.setState({
            isBorrowBaseModalVisible: false
        });
    }

    next() {
        let step = this.state.step + 1;
        if (step >= this.steps.length) step = this.steps.length;
        this.setState({step});
    }

    prev() {
        let step = this.state.step - 1;
        if (step < 0) step = 0;
        this.setState({step});
    }

    onAssetChange(selected_asset) {
        this.setState({
            selectedAsset: selected_asset
        });
    }

    render() {
        let currentAccount = ChainStore.getAccount(this.props.currentAccount);
        let accountLoaded = !(
            !currentAccount || typeof currentAccount === "string"
        );
        const current = this.state.step;
        const tinyScreen = window.innerWidth <= 800;
        const started = this.state.step > 0;

        const selectedAssetObject = ChainStore.getAsset(
            this.state.selectedAsset
        );
        let steps = this.steps;
        let legend = null;
        if (current < steps.length) {
            try {
                if (steps[current].has_legend) {
                    legend = counterpart.translate(
                        "showcases.borrow.steps_" +
                            steps[current].key +
                            ".text_legend"
                    );
                    legend = legend.split("\n").map(item => {
                        return item.split(":");
                    });
                }
            } catch (err) {
                legend = counterpart.translate(
                    "showcases.borrow.steps_" +
                        steps[current].key +
                        ".text_legend"
                );
            }
        }

        let finishedCard = null;
        if (current >= steps.length) {
            finishedCard = (
                <Card>
                    <div className={"center-content"}>
                        <Translate
                            content={"showcases.borrow.choose"}
                            component={"h4"}
                        />
                    </div>
                    <div
                        style={{
                            display: "flex",
                            justifyContent: "center"
                        }}
                    >
                        <div>
                            <AssetSelect
                                style={{
                                    width: "12rem",
                                    marginBottom: "1rem"
                                }}
                                assets={[
                                    "1.3.113",
                                    "1.3.120",
                                    "1.3.121",
                                    "1.3.1325",
                                    "1.3.105",
                                    "1.3.106",
                                    "1.3.103"
                                ]}
                                value={this.state.selectedAsset}
                                onChange={this.onAssetChange.bind(this)}
{'fraction_non_alphanumeric': 0.10324916813466432, 'fraction_numerical': 0.009982384028185555, 'mean_word_length': 1.0088460782386475, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4421753', 'n_tokens_mistral': 2564, 'n_tokens_neox': 2373, 'n_words': 476}