<commit_before>import React from "react";
import {PropTypes} from "react";
import {Link} from "react-router";
import Translate from "react-translate-component";
import AssetActions from "actions/AssetActions";
import AssetStore from "stores/AssetStore";
import AccountActions from "actions/AccountActions";
import Trigger from "react-foundation-apps/src/trigger";
import Modal from "react-foundation-apps/src/modal";
import FormattedAsset from "../Utility/FormattedAsset";
import ZfApi from "react-foundation-apps/src/utils/foundation-api";
import notify from "actions/NotificationActions";
import utils from "common/utils";
import AutocompleteInput from "../Forms/AutocompleteInput";
import {debounce} from "lodash";
import AccountInfo from "../Account/AccountInfo";
import LoadingIndicator from "../LoadingIndicator";
// import WalletDb from "stores/WalletDb";
// import WalletUnlockActions from "actions/WalletUnlockActions";
import BlockchainStore from "stores/BlockchainStore";
import validation from "common/validation";
import classnames from "classnames";
import counterpart from "counterpart";
import PrivateKeyStore from "stores/PrivateKeyStore";

class AccountAssets extends React.Component {

    static contextTypes = { router: React.PropTypes.func.isRequired }

    static defaultProps = {
        symbol: "",
        name: "",
        description: "",
        max_supply: 0,
        precision: 0
    }

    static propTypes = {
        symbol: PropTypes.string.isRequired
    }

    constructor(props) {
        super(props);

        this.state = {
            create: {
                symbol: "",
                name: "",
                description: "",
                max_supply: 1000000000000000,
                precision: 4
            },
            issue: {
                amount: 0,
                to: "",
                to_id: "",
                asset_id: "",
                symbol: ""
            },
            errors: {
                symbol: null
            },
            isValid: false,
            searchTerm: "",
            assets: AssetStore.getState().assets
        };

        this._searchAccounts = debounce(this._searchAccounts, 150);
    }

    onAssetsChange(state) {
        this.setState({assets: state.assets});
    }

    componentDidMount() {
        AssetStore.listen(this.onAssetsChange);
        let query_params = this.context.router.getCurrentQuery();
        if(query_params.create_asset) {
            console.log("zf publish create asset");
            ZfApi.publish("create_asset", "open");
        }
    }

    componentWillUnmount() {
        AssetStore.unlisten(this.onAssetsChange);
    }

    _onCreateInput(value, e) {
        let {create} = this.state;
        if (value === "symbol") {
            e.target.value = e.target.value.toUpperCase();
            // console.log(e.target.value, "is valid symbol", validation.is_valid_symbol(e.target.value));
        }
        create[value] = e.target.value;
        this.setState({create: create});
        this._validateCreateFields(create);
    }

    _validateCreateFields( new_state ) {

        let errors = {
            create: null
        };

        errors.create = validation.is_valid_symbol(new_state.symbol) ? null : "Invalid asset symbol";

        let isValid = errors.create === null;

        this.setState({isValid: isValid, errors: errors});
    }

    _onIssueInput(value, e) {
        let key = e.target.id;
        let {issue} = this.state;

        if (key === "to") {
            this._searchAccounts(e.target.value);
            issue.to = e.target.value;
            let account = this.props.searchAccounts.findEntry((name) => {
                return name === e.target.value;
            });

            issue.to_id = account ? account[0] : null;
        } else {
            issue[value] = e.target.value;
        }

        this.setState({issue: issue});
    }

    _createAsset(account_id, e) {
        console.log("account_id:", account_id);
        e.preventDefault();
        ZfApi.publish("create_asset", "close");
        let {create} = this.state;
        AssetActions.createAsset(account_id, create).then(result => {
            if (result) {
                notify.addNotification({
                    message: `Successfully created the asset ${create.symbol}`,//: ${this.state.wallet_public_name}
                    level: "success",
                    autoDismiss: 10
                });
            } else {
                notify.addNotification({
                    message: `Failed to create the asset`,//: ${this.state.wallet_public_name}
                    level: "error",
                    autoDismiss: 10
                });
            }
        });
    }

    _searchAccounts(searchTerm) {
        AccountActions.accountSearch(searchTerm);
    }

    _issueAsset(account_id, e) {
        e.preventDefault();
        ZfApi.publish("issue_asset", "close");
        let {issue} = this.state;
        let asset = this.state.assets.get(issue.asset_id);
        issue.amount *= utils.get_asset_precision(asset.precision);
        AssetActions.issueAsset(account_id, issue).then(result => {
            if (result) {
                notify.addNotification({
                    message: `Successfully issued ${utils.format_asset(issue.amount, this.props.assets.get(issue.asset_id))}`,//: ${this.state.wallet_public_name}
                    level: "success",
                    autoDismiss: 10<commit_msg>"Successfully created the asset" was appearing before transaction dialog was confirmed<commit_after>import React from "react";
import {PropTypes} from "react";
import {Link} from "react-router";
import Translate from "react-translate-component";
import AssetActions from "actions/AssetActions";
import AssetStore from "stores/AssetStore";
import AccountActions from "actions/AccountActions";
import Trigger from "react-foundation-apps/src/trigger";
import Modal from "react-foundation-apps/src/modal";
import FormattedAsset from "../Utility/FormattedAsset";
import ZfApi from "react-foundation-apps/src/utils/foundation-api";
import notify from "actions/NotificationActions";
import utils from "common/utils";
import AutocompleteInput from "../Forms/AutocompleteInput";
import {debounce} from "lodash";
import AccountInfo from "../Account/AccountInfo";
import LoadingIndicator from "../LoadingIndicator";
// import WalletDb from "stores/WalletDb";
// import WalletUnlockActions from "actions/WalletUnlockActions";
import BlockchainStore from "stores/BlockchainStore";
import validation from "common/validation";
import classnames from "classnames";
import counterpart from "counterpart";
import PrivateKeyStore from "stores/PrivateKeyStore";

class AccountAssets extends React.Component {

    static contextTypes = { router: React.PropTypes.func.isRequired }

    static defaultProps = {
        symbol: "",
        name: "",
        description: "",
        max_supply: 0,
        precision: 0
    }

    static propTypes = {
        symbol: PropTypes.string.isRequired
    }

    constructor(props) {
        super(props);

        this.state = {
            create: {
                symbol: "",
                name: "",
                description: "",
                max_supply: 1000000000000000,
                precision: 4
            },
            issue: {
                amount: 0,
                to: "",
                to_id: "",
                asset_id: "",
                symbol: ""
            },
            errors: {
                symbol: null
            },
            isValid: false,
            searchTerm: "",
            assets: AssetStore.getState().assets
        };

        this._searchAccounts = debounce(this._searchAccounts, 150);
    }

    onAssetsChange(state) {
        this.setState({assets: state.assets});
    }

    componentDidMount() {
        AssetStore.listen(this.onAssetsChange);
        let query_params = this.context.router.getCurrentQuery();
        if(query_params.create_asset) {
            console.log("zf publish create asset");
            ZfApi.publish("create_asset", "open");
        }
    }

    componentWillUnmount() {
        AssetStore.unlisten(this.onAssetsChange);
    }

    _onCreateInput(value, e) {
        let {create} = this.state;
        if (value === "symbol") {
            e.target.value = e.target.value.toUpperCase();
            // console.log(e.target.value, "is valid symbol", validation.is_valid_symbol(e.target.value));
        }
        create[value] = e.target.value;
        this.setState({create: create});
        this._validateCreateFields(create);
    }

    _validateCreateFields( new_state ) {

        let errors = {
            create: null
        };

        errors.create = validation.is_valid_symbol(new_state.symbol) ? null : "Invalid asset symbol";

        let isValid = errors.create === null;

        this.setState({isValid: isValid, errors: errors});
    }

    _onIssueInput(value, e) {
        let key = e.target.id;
        let {issue} = this.state;

        if (key === "to") {
            this._searchAccounts(e.target.value);
            issue.to = e.target.value;
            let account = this.props.searchAccounts.findEntry((name) => {
                return name === e.target.value;
            });

            issue.to_id = account ? account[0] : null;
        } else {
            issue[value] = e.target.value;
        }

        this.setState({issue: issue});
    }

    _createAsset(account_id, e) {
        console.log("account_id:", account_id);
        e.preventDefault();
        ZfApi.publish("create_asset", "close");
        let {create} = this.state;
        AssetActions.createAsset(account_id, create).then(result => {
            console.log("... AssetActions.createAsset(account_id, create)", account_id, create)
            // Notify 'Successfully created the asset' was running before transaction dialog confirm
            // if (result) {
            //     notify.addNotification({
            //         message: `Successfully created the asset ${create.symbol}`,//: ${this.state.wallet_public_name}
            //         level: "success",
            //         autoDismiss: 10
            //     });
            // } else {
            //     notify.addNotification({
            //         message: `Failed to create the asset`,//: ${this.state.wallet_public_name}
            //         level: "error",
            //         autoDismiss: 10
            //     });
            // }
        });
    }

    _searchAccounts(searchTerm) {
        AccountActions.accountSearch(searchTerm);
    }

    _issueAsset(account_id, e) {
        e.preventDefault();
        ZfApi.publish("issue_asset", "close");
        let {issue} = this.state;
        let asset = this.state.assets.get(issue.asset_id);
        issue.amount *= utils.get_asset_precision(asset.precision);
        AssetActions.issueAsset(account_id, issue).then(result => {
            if (result) {
                notify.addNotification({
                    message: `Successfully issued ${utils.format_asset(issue.amount, this.props.assets.get(issue.asset_id))}`,//: ${this.state.wallet_public_name}
                    level: "success",
                    autoDismiss: 10
{'fraction_non_alphanumeric': 0.12041559364177248, 'fraction_numerical': 0.005328123612467809, 'mean_word_length': 2.075368651010377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6878972', 'n_tokens_mistral': 3136, 'n_tokens_neox': 2998, 'n_words': 627}