Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  handleSubmit = () => {
  2.     const typeData = {};
  3.     const currencyData = {};
  4.     const riskRatingData = {};
  5.     getPaintData(Object.values(this.state.portfolio.assets)).map(item => {
  6.       typeData[COLORS_BY_ASSET_TYPE[item.type]] = `${Math.round(
  7.         item.value * 100
  8.       )}% ${ASSET_NAMES_BY_TYPE[item.type]}`;
  9.     });
  10.     getCurrencyData(Object.values(this.state.portfolio.assets)).map(item => {
  11.       currencyData[COLORS_BY_CURRENCY[item.name]] = `${item.name} ${Math.round(
  12.         (item.weight /
  13.           getAssetsWeight(Object.values(this.state.portfolio.assets))) *
  14.           100
  15.       )}%`;
  16.     });
  17.     getRiskRatingData(Object.values(this.state.portfolio.assets)).map(item => {
  18.       riskRatingData[COLORS_BY_RISK_RATING[item.name]] = `${
  19.         item.name
  20.       } ${Math.round(
  21.         (item.weight /
  22.           getAssetsWeight(Object.values(this.state.portfolio.assets))) *
  23.           100
  24.       )}%`;
  25.     });
  26.     const summ = {
  27.       RUB: convertCurrency(this.props.summ, 'RUB', this.props.currency),
  28.       USD: convertCurrency(this.props.summ, 'USD', this.props.currency),
  29.       EUR: convertCurrency(this.props.summ, 'EUR', this.props.currency),
  30.     };
  31.     const proposal = {
  32.       assets: Object.values(this.state.portfolio.assets).map(asset => {
  33.         return {
  34.           assetID: asset.asset.id,
  35.           weight: Number.parseFloat(asset.weight * 100).toFixed(2),
  36.           name: asset.asset.name,
  37.           type: asset.asset.type,
  38.           currency: asset.asset.currency,
  39.           expectedProfit: asset.asset.expectedProfit,
  40.           riskRating: asset.asset.riskRating,
  41.           recommendedPeriod: asset.asset.recommendedPeriod,
  42.           downsideRiskInside: asset.asset.yearlyVaR,
  43.           downsideRiskEnd: asset.asset.downsideRisk,
  44.           summDollar: (summ.USD * asset.weight).toFixed(2),
  45.           summEuro: (summ.EUR * asset.weight).toFixed(2),
  46.           summRub: (summ.RUB * asset.weight).toFixed(2),
  47.         };
  48.       }),
  49.       portfolioID: this.props.portfolio.id,
  50.       summ: this.props.summ,
  51.       currency: this.props.currency,
  52.       charts: Array.from(document.querySelectorAll('.recharts-surface')).map(
  53.         e => e.outerHTML.replace(/\r?\n|\r/g, '')
  54.       ),
  55.       legends: [typeData, currencyData, riskRatingData],
  56.     };
  57.     this.props.dispatch(addProposalAction(proposal));
  58.     this.setState({
  59.       isSubmitted: true,
  60.     });
  61.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement