From 677e77d0ae3f0daf9c5c6d43f73a089c24d60ea6 Mon Sep 17 00:00:00 2001
From: fragosti <francesco.agosti93@gmail.com>
Date: Thu, 14 Jun 2018 10:28:02 -0700
Subject: Add Portal v2 logging

---
 .../website/ts/components/wallet/wrap_ether_item.tsx   | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

(limited to 'packages/website/ts/components/wallet/wrap_ether_item.tsx')

diff --git a/packages/website/ts/components/wallet/wrap_ether_item.tsx b/packages/website/ts/components/wallet/wrap_ether_item.tsx
index f65257142..1651595ca 100644
--- a/packages/website/ts/components/wallet/wrap_ether_item.tsx
+++ b/packages/website/ts/components/wallet/wrap_ether_item.tsx
@@ -1,4 +1,4 @@
-import { Styles } from '@0xproject/react-shared';
+import { constants as sharedConstants, Styles } from '@0xproject/react-shared';
 import { BigNumber, logUtils } from '@0xproject/utils';
 import { Web3Wrapper } from '@0xproject/web3-wrapper';
 import * as _ from 'lodash';
@@ -6,6 +6,7 @@ import FlatButton from 'material-ui/FlatButton';
 import * as React from 'react';
 
 import { Blockchain } from 'ts/blockchain';
+import { analytics } from 'ts/utils/analytics';
 import { EthAmountInput } from 'ts/components/inputs/eth_amount_input';
 import { TokenAmountInput } from 'ts/components/inputs/token_amount_input';
 import { Dispatcher } from 'ts/redux/dispatcher';
@@ -186,6 +187,7 @@ export class WrapEtherItem extends React.Component<WrapEtherItemProps, WrapEther
         this.setState({
             isEthConversionHappening: true,
         });
+        const networkName = sharedConstants.NETWORK_NAME_BY_ID[this.props.networkId];
         try {
             const etherToken = this.props.etherToken;
             const amountToConvert = this.state.currentInputAmount;
@@ -193,10 +195,12 @@ export class WrapEtherItem extends React.Component<WrapEtherItemProps, WrapEther
                 await this.props.blockchain.convertEthToWrappedEthTokensAsync(etherToken.address, amountToConvert);
                 const ethAmount = Web3Wrapper.toUnitAmount(amountToConvert, constants.DECIMAL_PLACES_ETH);
                 this.props.dispatcher.showFlashMessage(`Successfully wrapped ${ethAmount.toString()} ETH to WETH`);
+                analytics.logEvent('Portal', 'Wrap ETH Successfully', networkName);
             } else {
                 await this.props.blockchain.convertWrappedEthTokensToEthAsync(etherToken.address, amountToConvert);
                 const tokenAmount = Web3Wrapper.toUnitAmount(amountToConvert, etherToken.decimals);
                 this.props.dispatcher.showFlashMessage(`Successfully unwrapped ${tokenAmount.toString()} WETH to ETH`);
+                analytics.logEvent('Portal', 'Unwrap WETH Successfully', networkName);
             }
             await this.props.refetchEthTokenStateAsync();
             this.props.onConversionSuccessful();
@@ -207,11 +211,13 @@ export class WrapEtherItem extends React.Component<WrapEtherItemProps, WrapEther
             } else if (!utils.didUserDenyWeb3Request(errMsg)) {
                 logUtils.log(`Unexpected error encountered: ${err}`);
                 logUtils.log(err.stack);
-                const errorMsg =
-                    this.props.direction === Side.Deposit
-                        ? 'Failed to wrap your ETH. Please try again.'
-                        : 'Failed to unwrap your WETH. Please try again.';
-                this.props.dispatcher.showFlashMessage(errorMsg);
+                if (this.props.direction === Side.Deposit) {
+                    this.props.dispatcher.showFlashMessage('Failed to wrap your ETH. Please try again.');
+                    analytics.logEvent('Portal', 'Wrap ETH Failed', networkName);
+                } else {
+                    this.props.dispatcher.showFlashMessage('Failed to unwrap your WETH. Please try again.');
+                    analytics.logEvent('Portal', 'Unwrap WETH Failed', networkName);
+                }
                 await errorReporter.reportAsync(err);
             }
         }
-- 
cgit v1.2.3

