How to use the bitsharesjs/es.ChainStore.getAsset function in bitsharesjs

To help you get started, we’ve selected a few bitsharesjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitshares / bitshares-ui / web / app / components / Utility / EquivalentValueComponent.jsx View on Github external
render() {
        let {amount, toAsset, fromAsset, fullPrecision, marketStats} = this.props;
        let coreAsset = ChainStore.getAsset("1.3.0");
        let toStats, fromStats;

        let toID = toAsset.get("id");
        let toSymbol = toAsset.get("symbol");
        let fromID = fromAsset.get("id");
        let fromSymbol = fromAsset.get("symbol");

        if (!fullPrecision) {
            amount = utils.get_asset_amount(amount, fromAsset);
        }

        // console.log("marketStats:", marketStats.toJS());
        if (coreAsset && marketStats) {
            let coreSymbol = coreAsset.get("symbol");
            toStats = marketStats.get(toSymbol + "_" + coreSymbol);
            fromStats = marketStats.get(fromSymbol + "_" + coreSymbol);
github bitshares / bitshares-ui / web / app / components / Utility / TotalBalanceValue.jsx View on Github external
_startUpdates(props) {
        let coreAsset = ChainStore.getAsset("1.3.0");
        let {fromAssets} = props;

        if (coreAsset) {
            // From assets
            fromAssets.forEach(asset => {
                if (asset) {

                    if (asset.get("id") !== coreAsset.get("id")) {
                        setTimeout(() => {
                            MarketsActions.getMarketStats(coreAsset, asset);
                            this.fromStatsIntervals[asset.get("id")] = setInterval(MarketsActions.getMarketStats.bind(this, coreAsset, asset), 10 * 60 * 1000);
                        }, 50)
                    }
                }
            })
github bitshares / bitshares-ui / app / lib / common / account_utils.js View on Github external
accountBalances.forEach((balanceID, assetID) => {
            let balanceObject = ChainStore.getObject(balanceID);
            let balance = balanceObject
                ? parseInt(balanceObject.get("balance"), 10)
                : 0;
            let hasBalance = false,
                eqFee;

            if (assetID === "1.3.0" && balance >= fee) {
                hasBalance = true;
            } else if (balance && ChainStore.getAsset(assetID)) {
                let asset = ChainStore.getAsset(assetID);
                let price = utils.convertPrice(
                    core,
                    asset.getIn(["options", "core_exchange_rate"]).toJS(),
                    null,
                    asset.get("id")
                );

                eqFee = parseInt(
                    utils.convertValue(price, fee, core, asset),
                    10
                );
                if (parseInt(eqFee, 10) !== eqFee) {
                    eqFee += 1; // Add 1 to round up;
                }
                if (balance >= eqFee && this.checkFeePool(asset, eqFee)) {
                    hasBalance = true;
github bitshares / bitshares-ui / web / app / api / ApplicationApi.js View on Github external
return new Promise((resolve, reject) => {
            let tr = new TransactionBuilder();
            console.log("ops:", ops["worker_initializer"], ops["vesting_balance_worker_initializer"].toObject(undefined));
            const core = ChainStore.getAsset("1.3.0");
            if (!core) reject(new Error("Can't find core asset, please try again"));
            let precision = Math.pow(10, core.get("precision"));

            const owner = ChainStore.getAccount(account).get("id");
            if (!owner) reject(new Error("Can't find the owner account, please try again"));
            
            try {
                tr.add_type_operation("worker_create", {
                    fee: {
                        amount: 0,
                        asset_id: 0
                    },
                    owner,
                    work_begin_date: options.start,
                    work_end_date: options.end,
                    daily_pay: options.pay * precision,
github bitshares / bitshares-ui / web / app / components / Transfer / Transfer.jsx View on Github external
shouldComponentUpdate(np, ns) {
        let { asset_types: current_types } = this._getAvailableAssets();
        let { asset_types } = this._getAvailableAssets(ns);

        if (asset_types.length === 1) {
            let asset = ChainStore.getAsset(asset_types[0]);
            if (current_types.length !== 1) {
                this.onAmountChanged({amount: ns.amount, asset});
            }

            if (asset_types[0] !== this.state.fee_asset_id) {
                if (asset && this.state.fee_asset_id !== asset_types[0]) {
                    this.setState({
                        feeAsset: asset,
                        fee_asset_id: asset_types[0]
                    });
                }
            }
        }
        return true;
    }
github bitshares / bitshares-ui / app / components / Modal / WithdrawModalNew.jsx View on Github external
balances.forEach((item, id) => {
            try {
                let asset = ChainStore.getAsset(id).toJS();
                assets = assets.set(id, asset);
            } catch (e) {}
        });
github bitshares / bitshares-ui / web / lib / common / account_utils.js View on Github external
static getPossibleFees(account, operation) {
        let core = ChainStore.getAsset("1.3.0");
        account = !account || account.toJS ? account : ChainStore.getAccount(account);

        if (!account || !core) {
            return {assets: ["1.3.0"], fees: {"1.3.0": 0}};
        }

        let assets = [], fees = {};

        let globalObject = ChainStore.getObject("2.0.0");

        let fee = utils.estimateFee(operation, null, globalObject);

        let accountBalances = account.get("balances");
        if (!accountBalances) {
            return {assets: ["1.3.0"], fees: {"1.3.0": 0}};
        }
github bitshares / bitshares-ui / app / lib / common / account_utils.js View on Github external
static checkFeePool(asset, fee) {
        asset = asset.toJS ? asset : ChainStore.getAsset(asset);
        if (!asset) return undefined;

        const dynamicObject = ChainStore.getObject(
            asset.get("dynamic_asset_data_id")
        );
        if (!dynamicObject) return undefined;

        let feePool = parseInt(dynamicObject.get("fee_pool"), 10);

        return feePool >= fee;
    }
github bitshares / bitshares-ui / web / app / components / Transfer / Transfer.jsx View on Github external
super(props);
        this.state = Transfer.getInitialState();
        let {query} = this.props.location;

        if(query.from) {
            this.state.from_name = query.from;
            ChainStore.getAccount(query.from);
        }
        if(query.to) {
            this.state.to_name = query.to;
            ChainStore.getAccount(query.to);
        }
        if(query.amount) this.state.amount = query.amount;
        if(query.asset) {
            this.state.asset_id = query.asset;
            this.state.asset = ChainStore.getAsset(query.asset);
        }
        if(query.memo) this.state.memo = query.memo;
        let currentAccount = AccountStore.getState().currentAccount;
        if (!this.state.from_name) this.state.from_name = currentAccount;
        this.onTrxIncluded = this.onTrxIncluded.bind(this);
    }