11'use strict'
22
33const logger = require ( 'electron-log' )
4+ const analytics = require ( './../../../analytics' )
45
56const {
67 getAuctionGasLimit
@@ -25,10 +26,19 @@ function createApi ({ ethWallet, tokens }) {
2526 logger . verbose ( 'Buying MET in auction' , {
2627 from, value, address, gasLimit, gasPrice
2728 } )
29+ analytics . event ( { ec : 'Buy' , ea : 'Buy MET in auction initiated' } )
2830
2931 return ethWallet . sendTransaction ( {
3032 password, from, to : address , value, gasLimit, gasPrice
3133 } )
34+ . then ( function ( response ) {
35+ analytics . event ( { ec : 'Buy' , ea : 'Buy MET in auction succeeded' } )
36+ return response
37+ } )
38+ . catch ( function ( err ) {
39+ analytics . event ( { ec : 'Buy' , ea : 'Buy MET in auction failed' } )
40+ throw err
41+ } )
3242 }
3343
3444 function onConvertEthToMtn ( { password, from, value, minReturn, gasLimit, gasPrice } ) {
@@ -37,6 +47,7 @@ function createApi ({ ethWallet, tokens }) {
3747 const data = encodeConvertEthToMtn ( { web3, address, value, minReturn } )
3848
3949 logger . verbose ( 'Converting ETH to MET' , { from, value, address } )
50+ analytics . event ( { ec : 'Convert' , ea : 'Convert ETH to MET initiated' } )
4051
4152 return ethWallet . sendTransaction ( {
4253 password,
@@ -47,12 +58,22 @@ function createApi ({ ethWallet, tokens }) {
4758 gasLimit,
4859 gasPrice
4960 } )
61+ . then ( function ( response ) {
62+ analytics . event ( { ec : 'Convert' , ea : 'Convert ETH to MET succeeded' } )
63+ return response
64+ } )
65+ . catch ( function ( err ) {
66+ analytics . event ( { ec : 'Convert' , ea : 'Convert ETH to MET failed' } )
67+ throw err
68+ } )
5069 }
5170
5271 function onConvertMtnToEth ( { password, from, value, minReturn, gasPrice, gasLimit } ) {
5372 const token = getTokenAddress ( )
5473 const address = getConverterAddress ( )
5574
75+ analytics . event ( { ec : 'Convert' , ea : 'Convert MET to ETH initiated' } )
76+
5677 return tokens . getAllowance ( { token, from, to : address } )
5778 . then ( function ( allowance ) {
5879 logger . debug ( 'Current allowance' , allowance )
@@ -85,6 +106,10 @@ function createApi ({ ethWallet, tokens }) {
85106 return ethWallet . sendTransaction ( {
86107 password, from, to : address , data, gasPrice, gasLimit
87108 } )
109+ . then ( function ( response ) {
110+ analytics . event ( { ec : 'Convert' , ea : 'Convert MET to ETH succeeded' } )
111+ return response
112+ } )
88113 } )
89114 . catch ( function ( err ) {
90115 logger . warn ( 'Conversion failed - removing approval' )
@@ -103,6 +128,7 @@ function createApi ({ ethWallet, tokens }) {
103128 } )
104129 } )
105130 . catch ( function ( err ) {
131+ analytics . event ( { ec : 'Convert' , ea : 'Convert MET to ETH failed' } )
106132 throw err
107133 } )
108134 }
0 commit comments