Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- handleSubmit = () => {
- const typeData = {};
- const currencyData = {};
- const riskRatingData = {};
- getPaintData(Object.values(this.state.portfolio.assets)).map(item => {
- typeData[COLORS_BY_ASSET_TYPE[item.type]] = `${Math.round(
- item.value * 100
- )}% ${ASSET_NAMES_BY_TYPE[item.type]}`;
- });
- getCurrencyData(Object.values(this.state.portfolio.assets)).map(item => {
- currencyData[COLORS_BY_CURRENCY[item.name]] = `${item.name} ${Math.round(
- (item.weight /
- getAssetsWeight(Object.values(this.state.portfolio.assets))) *
- 100
- )}%`;
- });
- getRiskRatingData(Object.values(this.state.portfolio.assets)).map(item => {
- riskRatingData[COLORS_BY_RISK_RATING[item.name]] = `${
- item.name
- } ${Math.round(
- (item.weight /
- getAssetsWeight(Object.values(this.state.portfolio.assets))) *
- 100
- )}%`;
- });
- const summ = {
- RUB: convertCurrency(this.props.summ, 'RUB', this.props.currency),
- USD: convertCurrency(this.props.summ, 'USD', this.props.currency),
- EUR: convertCurrency(this.props.summ, 'EUR', this.props.currency),
- };
- const proposal = {
- assets: Object.values(this.state.portfolio.assets).map(asset => {
- return {
- assetID: asset.asset.id,
- weight: Number.parseFloat(asset.weight * 100).toFixed(2),
- name: asset.asset.name,
- type: asset.asset.type,
- currency: asset.asset.currency,
- expectedProfit: asset.asset.expectedProfit,
- riskRating: asset.asset.riskRating,
- recommendedPeriod: asset.asset.recommendedPeriod,
- downsideRiskInside: asset.asset.yearlyVaR,
- downsideRiskEnd: asset.asset.downsideRisk,
- summDollar: (summ.USD * asset.weight).toFixed(2),
- summEuro: (summ.EUR * asset.weight).toFixed(2),
- summRub: (summ.RUB * asset.weight).toFixed(2),
- };
- }),
- portfolioID: this.props.portfolio.id,
- summ: this.props.summ,
- currency: this.props.currency,
- charts: Array.from(document.querySelectorAll('.recharts-surface')).map(
- e => e.outerHTML.replace(/\r?\n|\r/g, '')
- ),
- legends: [typeData, currencyData, riskRatingData],
- };
- this.props.dispatch(addProposalAction(proposal));
- this.setState({
- isSubmitted: true,
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement