Skip to content

Commit

Permalink
feat(analytics): adding swap create order
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroapfilho committed May 28, 2021
1 parent c7283d6 commit 5b0cf74
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import analytics from 'middleware/analyticsMiddleware/analytics'
import type { PageNamesType } from 'middleware/analyticsMiddleware/types'
import { AnalyticsKey, AnalyticsType } from 'middleware/analyticsMiddleware/types'
import {
getNetworkFee,
getOriginalTimestamp,
simpleBuyOriginDictionary,
simpleBuyPaymentTypeDictionary
} from 'middleware/analyticsMiddleware/utils'

import { getCardTypeByValue } from 'components/Form/CreditCardBox/model'
import { actionTypes as AT } from 'data'
import { convertBaseToStandard } from 'data/components/exchange/services'
import { ModalNamesType } from 'data/types'

const analyticsMiddleware = () => (store) => (next) => (action) => {
Expand Down Expand Up @@ -434,6 +436,19 @@ const analyticsMiddleware = () => (store) => (next) => (action) => {
const outputCurrency = state.form.initSwap.values.COUNTER.coin
const outputType =
state.form.initSwap.values.COUNTER.type === 'CUSTODIAL' ? 'TRADING' : 'USERKEY'
const networkFeeInputAmount =
state.form.initSwap.values.BASE.type === 'CUSTODIAL'
? 0
: Number(
convertBaseToStandard(
state.form.initSwap.values.BASE.coin,
getNetworkFee(state.components.swap.payment.getOrElse(undefined))
)
)
const networkFeeOutputAmount =
state.form.initSwap.values.COUNTER.type === 'CUSTODIAL'
? 0
: state.components.swap.quote.getOrElse({})?.quote.networkFee || 0

analytics.push(AnalyticsKey.SWAP_REQUESTED, {
exchange_rate: exchangeRate,
Expand All @@ -442,10 +457,10 @@ const analyticsMiddleware = () => (store) => (next) => (action) => {
input_currency: inputCurrency,
input_type: inputType,
nabuId,
network_fee_input_amount: 123, // TODO CHANGE
network_fee_input_currency: 'abc', // TODO CHANGE
network_fee_output_amount: 123, // TODO CHANGE
network_fee_output_currency: 'abc', // TODO CHANGE
network_fee_input_amount: networkFeeInputAmount,
network_fee_input_currency: inputCurrency,
network_fee_output_amount: networkFeeOutputAmount,
network_fee_output_currency: outputCurrency,
originalTimestamp: getOriginalTimestamp(),
output_amount: outputAmount,
output_currency: outputCurrency,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as crypto from 'crypto'

import { SBPaymentTypes } from 'core/types'
import { PaymentValue, SBPaymentTypes } from 'core/types'
import { SBShowModalOriginType } from 'data/types'

const simpleBuyOriginDictionary = (rawOrigin: SBShowModalOriginType) => {
Expand Down Expand Up @@ -45,8 +45,17 @@ const generateUniqueUserId = (guid: string) => {
return sha256(guid).toString('base64')
}

const getNetworkFee = (value: PaymentValue | undefined) => {
return value
? value.coin === 'BTC' || value.coin === 'BCH'
? value.selection?.fee
: value.fee
: 0
}

export {
generateUniqueUserId,
getNetworkFee,
getOriginalTimestamp,
simpleBuyOriginDictionary,
simpleBuyPaymentTypeDictionary
Expand Down
11 changes: 2 additions & 9 deletions packages/blockchain-wallet-v4/src/redux/payment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ type IPaymentType = {
) => PaymentType
publish: () => PaymentType
sign: (pw: string) => PaymentType
to: (
addressOrIndex: string | number,
addressType?: AddressTypesType
) => PaymentType
to: (addressOrIndex: string | number, addressType?: AddressTypesType) => PaymentType
}

export type BchPaymentType = IPaymentType & {
Expand Down Expand Up @@ -134,11 +131,7 @@ export type XlmPaymentType = IPaymentType & {
value: () => XlmPaymentValue
}

export type PaymentType =
| BchPaymentType
| BtcPaymentType
| EthPaymentType
| XlmPaymentType
export type PaymentType = BchPaymentType | BtcPaymentType | EthPaymentType | XlmPaymentType

export type PaymentValue = BtcPaymentValue | EthPaymentValue | XlmPaymentValue

Expand Down

0 comments on commit 5b0cf74

Please sign in to comment.