Skip to content

Commit a12db08

Browse files
authored
Merge pull request #4890 from EdgeApp/jon/fix/conversion-tracking
Refactor Conversion Tracking
2 parents e1c70be + 782af1d commit a12db08

16 files changed

+397
-157
lines changed

src/actions/CreateWalletActions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function createAccountTransaction(
128128
// Hack. Keyboard pops up for some reason. Close it
129129
dispatch(
130130
logEvent('Activate_Wallet_Cancel', {
131-
currencyCode: createdWalletCurrencyCode
131+
createdWalletCurrencyCode
132132
})
133133
)
134134
},
@@ -141,7 +141,7 @@ export function createAccountTransaction(
141141
} else if (edgeTransaction) {
142142
dispatch(
143143
logEvent('Activate_Wallet_Done', {
144-
currencyCode: createdWalletCurrencyCode
144+
createdWalletCurrencyCode
145145
})
146146
)
147147
const edgeMetadata: EdgeMetadata = {

src/actions/CryptoExchangeActions.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { convertCurrency } from '../selectors/WalletSelectors'
2424
import { RootState, ThunkAction } from '../types/reduxTypes'
2525
import { NavigationBase } from '../types/routerTypes'
2626
import { GuiCurrencyInfo, GuiSwapInfo } from '../types/types'
27+
import { CryptoAmount } from '../util/CryptoAmount'
2728
import { getCurrencyCode, getWalletTokenId } from '../util/CurrencyInfoHelpers'
2829
import { logActivity } from '../util/logger'
2930
import { bestOfPlugins } from '../util/ReferralHelpers'
@@ -338,13 +339,18 @@ export function shiftCryptoCurrency(navigation: NavigationBase, quote: EdgeSwapQ
338339

339340
await updateSwapCount(state)
340341

341-
const exchangeAmount = await toWallet.nativeToDenomination(toNativeAmount, toCurrencyCode)
342342
dispatch(
343343
logEvent('Exchange_Shift_Success', {
344-
pluginId,
345-
currencyCode: toCurrencyCode,
346-
exchangeAmount,
347-
orderId: result.orderId
344+
conversionValues: {
345+
conversionType: 'crypto',
346+
cryptoAmount: new CryptoAmount({
347+
nativeAmount: toNativeAmount,
348+
currencyCode: toCurrencyCode,
349+
currencyConfig: toWallet.currencyConfig
350+
}),
351+
orderId: result.orderId,
352+
swapProviderId: pluginId
353+
}
348354
})
349355
)
350356
} catch (error: any) {

src/components/scenes/Fio/FioAddressRegisterSelectWalletScene.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { mul, toFixed } from 'biggystring'
21
import { EdgeAccount, EdgeCurrencyConfig, EdgeCurrencyWallet, EdgeDenomination, EdgeTransaction } from 'edge-core-js'
32
import * as React from 'react'
43
import { Alert, Image, View } from 'react-native'
54
import { sprintf } from 'sprintf-js'
65

76
import { FIO_STR } from '../../../constants/WalletAndCurrencyConstants'
87
import { lstrings } from '../../../locales/strings'
9-
import { getExchangeDenomByCurrencyCode, selectDisplayDenom } from '../../../selectors/DenominationSelectors'
8+
import { selectDisplayDenom } from '../../../selectors/DenominationSelectors'
109
import { config } from '../../../theme/appConfig'
1110
import { connect } from '../../../types/reactRedux'
1211
import { EdgeSceneProps } from '../../../types/routerTypes'
1312
import { EdgeAsset } from '../../../types/types'
14-
import { getTokenIdForced } from '../../../util/CurrencyInfoHelpers'
13+
import { CryptoAmount } from '../../../util/CryptoAmount'
1514
import { getWalletName } from '../../../util/CurrencyWalletHelpers'
1615
import { getRegInfo } from '../../../util/FioAddressUtils'
1716
import { logEvent, TrackingEventName, TrackingValues } from '../../../util/tracking'
@@ -30,7 +29,6 @@ interface StateProps {
3029
fioPlugin?: EdgeCurrencyConfig
3130
fioWallets: EdgeCurrencyWallet[]
3231
fioDisplayDenomination: EdgeDenomination
33-
pluginId: string
3432
isConnected: boolean
3533
}
3634

@@ -150,12 +148,16 @@ export class FioAddressRegisterSelectWallet extends React.Component<Props, Local
150148
this.props.onSelectWallet(walletId, paymentCurrencyCode)
151149

152150
const wallet = account.currencyWallets[walletId]
153-
const exchangeDenomination = getExchangeDenomByCurrencyCode(wallet.currencyConfig, paymentCurrencyCode)
154-
const exchangeAmount = allPaymentInfo[paymentCurrencyCode].amount
155-
let nativeAmount = mul(exchangeAmount, exchangeDenomination.multiplier)
156-
nativeAmount = toFixed(nativeAmount, 0, 0)
151+
const { amount: exchangeAmount, address: paymentAddress } = allPaymentInfo[paymentCurrencyCode]
152+
153+
const cryptoAmount = new CryptoAmount({
154+
exchangeAmount,
155+
currencyCode: paymentCurrencyCode,
156+
currencyConfig: wallet.currencyConfig
157+
})
158+
159+
const { tokenId, nativeAmount } = cryptoAmount
157160

158-
const tokenId = getTokenIdForced(account, wallet.currencyInfo.pluginId, paymentCurrencyCode)
159161
const sendParams: SendScene2Params = {
160162
walletId,
161163
tokenId,
@@ -170,7 +172,7 @@ export class FioAddressRegisterSelectWallet extends React.Component<Props, Local
170172
spendTargets: [
171173
{
172174
nativeAmount,
173-
publicAddress: allPaymentInfo[paymentCurrencyCode].address
175+
publicAddress: paymentAddress
174176
}
175177
],
176178
metadata: {
@@ -190,8 +192,12 @@ export class FioAddressRegisterSelectWallet extends React.Component<Props, Local
190192
[{ text: lstrings.string_ok_cap }]
191193
)
192194

193-
const { currencyCode, pluginId } = wallet.currencyInfo
194-
onLogEvent('Fio_Handle_Register', { nativeAmount, pluginId, currencyCode })
195+
onLogEvent('Fio_Handle_Register', {
196+
conversionValues: {
197+
conversionType: 'crypto',
198+
cryptoAmount
199+
}
200+
})
195201
navigation.navigate('homeTab', { screen: 'home' })
196202
}
197203
}
@@ -283,7 +289,6 @@ export const FioAddressRegisterSelectWalletScene = connect<StateProps, DispatchP
283289
fioPlugin: state.core.account.currencyConfig.fio,
284290
fioDisplayDenomination: selectDisplayDenom(state, params.selectedWallet.currencyConfig, null),
285291
defaultFiatCode: state.ui.settings.defaultIsoFiat,
286-
pluginId: params.selectedWallet.currencyInfo.pluginId,
287292
isConnected: state.network.isConnected
288293
}),
289294
dispatch => ({

src/components/scenes/Fio/FioAddressSettingsScene.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { refreshAllFioAddresses } from '../../../actions/FioAddressActions'
66
import { lstrings } from '../../../locales/strings'
77
import { connect } from '../../../types/reactRedux'
88
import { EdgeSceneProps } from '../../../types/routerTypes'
9+
import { CryptoAmount } from '../../../util/CryptoAmount'
910
import { addBundledTxs, getAddBundledTxsFee, getTransferFee } from '../../../util/FioAddressUtils'
1011
import { logEvent, TrackingEventName, TrackingValues } from '../../../util/tracking'
1112
import { SceneWrapper } from '../../common/SceneWrapper'
@@ -104,8 +105,12 @@ export class FioAddressSettingsComponent extends React.Component<Props, LocalSta
104105
}
105106
await addBundledTxs(fioWallet, fioAddressName, fee)
106107

107-
const { currencyCode, pluginId } = fioWallet.currencyInfo
108-
onLogEvent('Fio_Handle_Bundled_Tx', { nativeAmount: String(fee), pluginId, currencyCode })
108+
onLogEvent('Fio_Handle_Bundled_Tx', {
109+
conversionValues: {
110+
conversionType: 'crypto',
111+
cryptoAmount: new CryptoAmount({ nativeAmount: String(fee), currencyConfig: fioWallet.currencyConfig, tokenId: null })
112+
}
113+
})
109114
}
110115

111116
goToTransfer = (params: { fee: number }) => {

src/components/scenes/Fio/FioCreateHandleScene.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@ export const FioCreateHandleScene = (props: Props) => {
130130
await dispatch(refreshAllFioAddresses())
131131
showToast(lstrings.fio_free_handle_complete)
132132

133-
await dispatch(logEvent('Fio_Handle_Register', { dollarValue: 3 }))
133+
await dispatch(
134+
logEvent('Fio_Handle_Register', {
135+
conversionValues: {
136+
conversionType: 'dollar',
137+
dollarConversionValue: 3
138+
}
139+
})
140+
)
134141

135142
navigation.pop()
136143
} catch (e: any) {

src/components/scenes/Fio/FioDomainRegisterSelectWalletScene.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { mul, toFixed } from 'biggystring'
21
import { EdgeAccount, EdgeCurrencyConfig, EdgeCurrencyWallet, EdgeDenomination, EdgeTransaction } from 'edge-core-js'
32
import * as React from 'react'
43
import { View } from 'react-native'
@@ -7,12 +6,12 @@ import { sprintf } from 'sprintf-js'
76

87
import { FIO_STR } from '../../../constants/WalletAndCurrencyConstants'
98
import { lstrings } from '../../../locales/strings'
10-
import { getExchangeDenomByCurrencyCode, selectDisplayDenomByCurrencyCode } from '../../../selectors/DenominationSelectors'
9+
import { selectDisplayDenomByCurrencyCode } from '../../../selectors/DenominationSelectors'
1110
import { config } from '../../../theme/appConfig'
1211
import { connect } from '../../../types/reactRedux'
1312
import { EdgeSceneProps } from '../../../types/routerTypes'
1413
import { EdgeAsset } from '../../../types/types'
15-
import { getTokenIdForced } from '../../../util/CurrencyInfoHelpers'
14+
import { CryptoAmount } from '../../../util/CryptoAmount'
1615
import { getWalletName } from '../../../util/CurrencyWalletHelpers'
1716
import { getDomainRegInfo } from '../../../util/FioAddressUtils'
1817
import { logEvent, TrackingEventName, TrackingValues } from '../../../util/tracking'
@@ -33,7 +32,6 @@ interface StateProps {
3332
fioPlugin?: EdgeCurrencyConfig
3433
fioWallets: EdgeCurrencyWallet[]
3534
fioDisplayDenomination: EdgeDenomination
36-
pluginId: string
3735
isConnected: boolean
3836
}
3937

@@ -121,7 +119,7 @@ class FioDomainRegisterSelectWallet extends React.PureComponent<Props, LocalStat
121119
}
122120

123121
onNextPress = (): void => {
124-
const { account, isConnected, navigation, route, onLogEvent: logEvent } = this.props
122+
const { account, isConnected, navigation, route, onLogEvent } = this.props
125123
const { fioDomain, selectedWallet } = route.params
126124
const { feeValue, paymentInfo: allPaymentInfo, paymentWallet } = this.state
127125

@@ -143,11 +141,16 @@ class FioDomainRegisterSelectWallet extends React.PureComponent<Props, LocalStat
143141
this.props.onSelectWallet(walletId, paymentCurrencyCode)
144142

145143
const wallet = account.currencyWallets[walletId]
146-
const exchangeDenomination = getExchangeDenomByCurrencyCode(wallet.currencyConfig, paymentCurrencyCode)
147-
let nativeAmount = mul(allPaymentInfo[paymentCurrencyCode].amount, exchangeDenomination.multiplier)
148-
nativeAmount = toFixed(nativeAmount, 0, 0)
144+
const { amount: exchangeAmount, address: paymentAddress } = allPaymentInfo[paymentCurrencyCode]
145+
146+
const cryptoAmount = new CryptoAmount({
147+
exchangeAmount,
148+
currencyCode: paymentCurrencyCode,
149+
currencyConfig: wallet.currencyConfig
150+
})
151+
152+
const { tokenId, nativeAmount } = cryptoAmount
149153

150-
const tokenId = getTokenIdForced(account, wallet.currencyInfo.pluginId, paymentCurrencyCode)
151154
const sendParams: SendScene2Params = {
152155
walletId,
153156
tokenId,
@@ -162,7 +165,7 @@ class FioDomainRegisterSelectWallet extends React.PureComponent<Props, LocalStat
162165
spendTargets: [
163166
{
164167
nativeAmount,
165-
publicAddress: allPaymentInfo[paymentCurrencyCode].address
168+
publicAddress: paymentAddress
166169
}
167170
],
168171
metadata: {
@@ -184,7 +187,12 @@ class FioDomainRegisterSelectWallet extends React.PureComponent<Props, LocalStat
184187
buttons={{ ok: { label: lstrings.string_ok_cap } }}
185188
/>
186189
)).catch(err => showError(err))
187-
logEvent('Fio_Domain_Register', { exchangeAmount: String(feeValue), currencyCode: paymentWallet.currencyCode })
190+
onLogEvent('Fio_Domain_Register', {
191+
conversionValues: {
192+
conversionType: 'crypto',
193+
cryptoAmount
194+
}
195+
})
188196
navigation.navigate('homeTab', { screen: 'home' })
189197
}
190198
}
@@ -276,7 +284,6 @@ export const FioDomainRegisterSelectWalletScene = connect<StateProps, DispatchPr
276284
fioWallets: state.ui.wallets.fioWallets,
277285
fioPlugin: state.core.account.currencyConfig.fio,
278286
fioDisplayDenomination: selectDisplayDenomByCurrencyCode(state, params.selectedWallet.currencyConfig, FIO_STR),
279-
pluginId: params.selectedWallet.currencyInfo.pluginId,
280287
isConnected: state.network.isConnected
281288
}),
282289
dispatch => ({

src/components/scenes/Fio/FioDomainSettingsScene.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { formatDate } from '../../../locales/intl'
88
import { lstrings } from '../../../locales/strings'
99
import { connect } from '../../../types/reactRedux'
1010
import { EdgeSceneProps } from '../../../types/routerTypes'
11+
import { CryptoAmount } from '../../../util/CryptoAmount'
1112
import { getDomainSetVisibilityFee, getRenewalFee, getTransferFee, renewFioDomain, setDomainVisibility } from '../../../util/FioAddressUtils'
1213
import { logEvent, TrackingEventName, TrackingValues } from '../../../util/tracking'
1314
import { SceneWrapper } from '../../common/SceneWrapper'
@@ -118,11 +119,11 @@ export class FioDomainSettingsComponent extends React.Component<Props, State> {
118119

119120
await renewFioDomain(fioWallet, fioDomainName, renewalFee)
120121

121-
const { currencyCode, pluginId } = fioWallet.currencyInfo
122122
onLogEvent('Fio_Domain_Renew', {
123-
nativeAmount: String(renewalFee),
124-
currencyCode,
125-
pluginId
123+
conversionValues: {
124+
conversionType: 'crypto',
125+
cryptoAmount: new CryptoAmount({ nativeAmount: String(renewalFee), currencyConfig: fioWallet.currencyConfig, tokenId: null })
126+
}
126127
})
127128
}
128129

src/components/scenes/Fio/FioNameConfirmScene.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { FIO_ADDRESS_DELIMITER } from '../../../constants/WalletAndCurrencyConst
66
import { lstrings } from '../../../locales/strings'
77
import { connect } from '../../../types/reactRedux'
88
import { EdgeSceneProps } from '../../../types/routerTypes'
9+
import { CryptoAmount } from '../../../util/CryptoAmount'
910
import { fioMakeSpend, fioSignAndBroadcast } from '../../../util/FioAddressUtils'
1011
import { logEvent, TrackingEventName, TrackingValues } from '../../../util/tracking'
1112
import { SceneWrapper } from '../../common/SceneWrapper'
@@ -111,16 +112,20 @@ class FioNameConfirm extends React.PureComponent<Props> {
111112
}
112113
} else {
113114
try {
114-
const { currencyCode, pluginId } = paymentWallet.currencyInfo
115115
if (this.isFioAddress()) {
116116
let edgeTx = await fioMakeSpend(paymentWallet, 'registerFioAddress', { fioAddress: fioName })
117117
edgeTx = await fioSignAndBroadcast(paymentWallet, edgeTx)
118118
await paymentWallet.saveTx(edgeTx)
119119

120120
onLogEvent('Fio_Handle_Register', {
121-
nativeAmount: edgeTx.nativeAmount,
122-
currencyCode,
123-
pluginId
121+
conversionValues: {
122+
conversionType: 'crypto',
123+
cryptoAmount: new CryptoAmount({
124+
currencyConfig: paymentWallet.currencyConfig,
125+
nativeAmount: edgeTx.nativeAmount,
126+
tokenId: null
127+
})
128+
}
124129
})
125130

126131
// @ts-expect-error
@@ -136,9 +141,14 @@ class FioNameConfirm extends React.PureComponent<Props> {
136141
const expiration = edgeTx.otherParams?.broadcastResult?.expiration
137142

138143
onLogEvent('Fio_Domain_Register', {
139-
nativeAmount: edgeTx.nativeAmount,
140-
currencyCode,
141-
pluginId
144+
conversionValues: {
145+
conversionType: 'crypto',
146+
cryptoAmount: new CryptoAmount({
147+
currencyConfig: paymentWallet.currencyConfig,
148+
nativeAmount: edgeTx.nativeAmount,
149+
tokenId: null
150+
})
151+
}
142152
})
143153

144154
// @ts-expect-error

src/controllers/edgeProvider/EdgeProviderServer.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Dispatch } from '../../types/reduxTypes'
2828
import { NavigationBase } from '../../types/routerTypes'
2929
import { EdgeAsset, MapObject } from '../../types/types'
3030
import { getCurrencyIconUris } from '../../util/CdnUris'
31+
import { CryptoAmount } from '../../util/CryptoAmount'
3132
import { getTokenIdForced } from '../../util/CurrencyInfoHelpers'
3233
import { getWalletName } from '../../util/CurrencyWalletHelpers'
3334
import { makeCurrencyCodeTable } from '../../util/tokenIdTools'
@@ -410,10 +411,16 @@ export class EdgeProviderServer implements EdgeProviderMethods {
410411
.then(exchangeAmount => {
411412
this._dispatch(
412413
logEvent('EdgeProvider_Conversion_Success', {
413-
pluginId: this._plugin.storeId,
414-
orderId,
415-
currencyCode: transaction.currencyCode,
416-
exchangeAmount: abs(exchangeAmount)
414+
conversionValues: {
415+
conversionType: 'crypto',
416+
cryptoAmount: new CryptoAmount({
417+
currencyConfig: wallet.currencyConfig,
418+
currencyCode: transaction.currencyCode,
419+
exchangeAmount: abs(exchangeAmount)
420+
}),
421+
swapProviderId: this._plugin.storeId,
422+
orderId
423+
}
417424
})
418425
)
419426
})

src/plugins/gui/fiatPlugin.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { HomeAddress, SepaInfo } from '../../types/FormTypes'
1919
import { GuiPlugin } from '../../types/GuiPluginTypes'
2020
import { AppParamList, NavigationBase } from '../../types/routerTypes'
2121
import { getNavigationAbsolutePath } from '../../util/routerUtils'
22-
import { OnLogEvent, TrackingEventName } from '../../util/tracking'
22+
import { OnLogEvent, SellConversionValues, TrackingEventName } from '../../util/tracking'
2323
import {
2424
FiatPaymentType,
2525
FiatPluginAddressFormParams,
@@ -222,19 +222,7 @@ export const executePlugin = async (params: {
222222
showToast: async (message: string, autoHideMs?: number) => {
223223
showToast(message, autoHideMs)
224224
},
225-
trackConversion: async (
226-
event: TrackingEventName,
227-
opts: {
228-
destCurrencyCode: string
229-
destExchangeAmount: string
230-
destPluginId?: string
231-
sourceCurrencyCode: string
232-
sourceExchangeAmount: string
233-
sourcePluginId?: string
234-
pluginId: string
235-
orderId?: string
236-
}
237-
) => {
225+
trackConversion: async (event: TrackingEventName, opts: { conversionValues: SellConversionValues }) => {
238226
onLogEvent(event, opts)
239227
},
240228
exitScene: async () => {

0 commit comments

Comments
 (0)