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;
};
import React, { useState, useEffect } from 'react';
import Spinner from './Spinner';
import { getStyleForTopLevelComponent } from '../../core/utils/getStyleForTopLevelComponent';
import './../styles/assetsItem.sass';
import './../styles/assetsItemDefault.sass';
import { getTildeGivenAmount, formatCurrency } from '../../core/utils/formatCurrency';
export var 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(useState(''), 2), usdAmount = _b[0], setUsdAmount = _b[1];
    var _c = __read(useState(''), 2), usdPrice = _c[0], setUsdPrice = _c[1];
    useEffect(function () {
        var unsubscribe = sdk.subscribeToPrices(function (tokensPrices) {
            var tokenPrice = tokensPrices[symbol] === undefined ? 0 : tokensPrices[symbol]['USD'];
            setUsdPrice(tokenPrice.toString());
        });
        return unsubscribe;
    }, []);
    useEffect(function () {
        var tokenValue = Number(usdPrice) * Number(balance);
        setUsdAmount(tokenValue.toString());
    }, [usdPrice, balance]);
    return (React.createElement("div", { key: name, className: "universal-login-assets-item" },
        React.createElement("div", { className: getStyleForTopLevelComponent(className) },
            React.createElement("div", { className: "assets-item" },
                React.createElement("div", { className: "assets-item-left" },
                    React.createElement("div", { className: "assets-img-wrapper" },
                        React.createElement("img", { src: icon, alt: symbol, className: "currency-accordion-img" })),
                    React.createElement("div", null,
                        React.createElement("p", { className: "assets-name" }, name),
                        React.createElement("p", { className: "assets-price" },
                            "1 ",
                            symbol,
                            " = $",
                            usdPrice))),
                React.createElement("div", { className: "assets-item-right" },
                    balance ? React.createElement("p", { className: "assets-balance" },
                        " ",
                        balance,
                        " ",
                        symbol) : React.createElement(Spinner, null),
                    React.createElement("div", { className: "assets-balance-converted" },
                        React.createElement("p", { className: "assets-price-tilde" }, getTildeGivenAmount(usdAmount)),
                        React.createElement("p", { className: "assets-price" }, formatCurrency(usdAmount))))))));
};
//# sourceMappingURL=Asset.js.map