{"size": 1785, "ext": "js", "max_stars_repo_path": "app/scripts/directives/dexns-token-registration.js", "max_stars_repo_name": "antoshek/ClassicEtherWallet", "max_stars_repo_stars_event_min_datetime": "2016-08-17T16:28:59.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-22T12:18:02.000Z", "max_issues_repo_path": "app/scripts/directives/dexns-token-registration.js", "max_issues_repo_name": "antoshek/ClassicEtherWallet", "max_issues_repo_issues_event_min_datetime": "2018-02-05T14:25:18.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-03T16:25:06.000Z", "max_forks_repo_path": "app/scripts/directives/dexns-token-registration.js", "max_forks_repo_name": "antoshek/ClassicEtherWallet", "max_forks_repo_forks_event_min_datetime": "2016-08-19T08:53:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-03T14:15:13.000Z"}
{"max_stars_count": 47, "max_issues_count": 158, "max_forks_count": 41, "avg_line_length": 30.2542372881, "max_line_length": 80, "alphanum_fraction": 0.4196078431}
"use strict";

module.exports = function dexnsTokenRegistrationForm() {
    return {
        require: "form",
        restrict: "A",
        template: require("./dexns-token-registration.html"),
        link: function linkToken(scope, elem, attrs, form) {
            form.tokenName.$asyncValidators.tokenName = async function(_val) {
                let result = false;
                if (_val) {
                    const { available } = await scope.checkDexNSName(_val);

                    result = available;
                }
                if (result) {
                    return Promise.resolve(result);
                }
                return Promise.reject(result);
            };

            form.abi.$validators.abi = function(_val) {
                if (!_val) return true;

                try {
                    return JSON.parse(_val);
                } catch (e) {
                    return false;
                }
            };

            form.tokenNetwork.$validators.tokenNetwork = val => {
                const found = Object.values(nodes.nodeList).find(
                    node => node.type === val
                );

                return Boolean(found);
            };

            form.destination.$validators.destination = Validator.isValidAddress;

            scope.resetForm = function() {
                Object.assign(scope.input, {
                    abi: "",
                    link: "",
                    sourceCode: "",
                    info: "",
                    tokenName: "",
                    tokenNetwork: ajaxReq.type,
                    owner: "",
                    destination: "",
                    hideOwner: false,
                    assign: false
                });
            };
        }
    };
};
