"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var Spinner_1 = __importDefault(require("./Spinner"));
var getStyleForTopLevelComponent_1 = require("../../core/utils/getStyleForTopLevelComponent");
require("./../styles/assetsItem.sass");
require("./../styles/assetsItemDefault.sass");
var formatCurrency_1 = require("../../core/utils/formatCurrency");
exports.Asset = function (_a) {
    var sdk = _a.sdk, name = _a.name, symbol = _a.symbol, balance = _a.balance, icon = _a.icon, className = _a.className;
    var _b = __read(react_1.useState(''), 2), usdAmount = _b[0], setUsdAmount = _b[1];
    var _c = __read(react_1.useState(''), 2), usdPrice = _c[0], setUsdPrice = _c[1];
    react_1.useEffect(function () {
        var unsubscribe = sdk.subscribeToPrices(function (tokensPrices) {
            var tokenPrice = tokensPrices[symbol] === undefined ? 0 : tokensPrices[symbol]['USD'];
            setUsdPrice(tokenPrice.toString());
        });
        return unsubscribe;
    }, []);
    react_1.useEffect(function () {
        var tokenValue = Number(usdPrice) * Number(balance);
        setUsdAmount(tokenValue.toString());
    }, [usdPrice, balance]);
    return (react_1.default.createElement("div", { key: name, className: "universal-login-assets-item" },
        react_1.default.createElement("div", { className: getStyleForTopLevelComponent_1.getStyleForTopLevelComponent(className) },
            react_1.default.createElement("div", { className: "assets-item" },
                react_1.default.createElement("div", { className: "assets-item-left" },
                    react_1.default.createElement("div", { className: "assets-img-wrapper" },
                        react_1.default.createElement("img", { src: icon, alt: symbol, className: "currency-accordion-img" })),
                    react_1.default.createElement("div", null,
                        react_1.default.createElement("p", { className: "assets-name" }, name),
                        react_1.default.createElement("p", { className: "assets-price" },
                            "1 ",
                            symbol,
                            " = $",
                            usdPrice))),
                react_1.default.createElement("div", { className: "assets-item-right" },
                    balance ? react_1.default.createElement("p", { className: "assets-balance" },
                        " ",
                        balance,
                        " ",
                        symbol) : react_1.default.createElement(Spinner_1.default, null),
                    react_1.default.createElement("div", { className: "assets-balance-converted" },
                        react_1.default.createElement("p", { className: "assets-price-tilde" }, formatCurrency_1.getTildeGivenAmount(usdAmount)),
                        react_1.default.createElement("p", { className: "assets-price" }, formatCurrency_1.formatCurrency(usdAmount))))))));
};
//# sourceMappingURL=Asset.js.map