Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
_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)
}
}
})
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;
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,
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;
}
balances.forEach((item, id) => {
try {
let asset = ChainStore.getAsset(id).toJS();
assets = assets.set(id, asset);
} catch (e) {}
});
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}};
}
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;
}
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);
}