"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const file_saver_1 = require("file-saver");
const json2csv_1 = require("json2csv");
const types_1 = require("../typing/types");
const lodash_1 = __importDefault(require("lodash"));
exports.delay = (amount) => __awaiter(this, void 0, void 0, function* () {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve();
        }, amount);
    });
});
/**
 * Returns a string hash of a POJO for comparison
 *
 * @param args arguments to hash
 */
function hashObj(args) {
    const sortedKeyArray = lodash_1.default.keys(args).sort();
    return lodash_1.default.join(lodash_1.default.map(sortedKeyArray, key => {
        const val = args[key];
        let result;
        if (types_1.isPojo(val)) {
            result = hashObj(val);
        }
        else {
            result = `${args[key]}`;
        }
        return `${key}:${result}`;
    }), ',');
}
exports.hashObj = hashObj;
exports.toEtherscanUrl = (value, { subdomain, type = 'tx' } = {}) => `https://${subdomain ? subdomain + '.' : ''}etherscan.io/${type}/${value}`;
/**
 * Generates a CSV file from JSON data and triggers a download in the client
 *
 * @param data json2csv data, see https://www.npmjs.com/package/json2csv#javascript-module-examples
 * @param fileName name of the downloaded file
 * @param opts json2csv options, see https://www.npmjs.com/package/json2csv#available-options
 */
exports.downloadCsvFile = (data, fileName, opts) => {
    const csvOutput = json2csv_1.parse(data, opts);
    const blob = new Blob([csvOutput], { type: 'text/csv' });
    const formattedFilename = fileName.endsWith('.csv')
        ? fileName
        : `${fileName}.csv`;
    file_saver_1.saveAs(blob, formattedFilename);
};
// @see https://github.com/ethereumjs/ethereumjs-util/blob/75f529458bc7dc84f85fd0446d0fac92d991c262/index.js#L443
exports.isValidAddress = (address) => {
    return /^0x[0-9a-fA-F]{40}$/i.test(address);
};
//# sourceMappingURL=index.js.map