Skip to content

Commit

Permalink
add tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Oct 12, 2023
1 parent c2a09be commit 0ab97c9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/swapv2/LimitOrder/EditOrderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default function EditOrderModal({
onDismiss={onDismiss}
onClickGaslessCancel={onClickGaslessCancel}
onClickHardCancel={onClickHardCancel}
order={order}
buttonInfo={{
orderSupportGasless: supportGasLessCancel,
chainSupportGasless,
Expand Down
25 changes: 21 additions & 4 deletions src/components/swapv2/LimitOrder/Modals/CancelButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { GasStation } from 'components/Icons'
import { MouseoverTooltip } from 'components/Tooltip'
import { CancelStatus } from 'components/swapv2/LimitOrder/Modals/CancelOrderModal'
import { DOCS_LINKS } from 'components/swapv2/LimitOrder/const'
import { CancelOrderType } from 'components/swapv2/LimitOrder/type'
import { getPayloadTracking } from 'components/swapv2/LimitOrder/helpers'
import { CancelOrderType, LimitOrder } from 'components/swapv2/LimitOrder/type'
import { useActiveWeb3React } from 'hooks'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import useTheme from 'hooks/useTheme'
import { ExternalLink } from 'theme'
import { formatDisplayNumber } from 'utils/numbers'
Expand Down Expand Up @@ -94,6 +97,7 @@ const CancelButtons = ({
confirmOnly = false,
cancelType,
setCancelType,
order,
buttonInfo: {
orderSupportGasless,
chainSupportGasless,
Expand All @@ -116,13 +120,26 @@ const CancelButtons = ({
cancelType: CancelOrderType
setCancelType: (v: CancelOrderType) => void
buttonInfo: ButtonInfo
order: LimitOrder | undefined
}) => {
const theme = useTheme()
const isWaiting = cancelStatus === CancelStatus.WAITING
const isCountDown = cancelStatus === CancelStatus.COUNTDOWN
const isTimeout = cancelStatus === CancelStatus.TIMEOUT
const isCancelDone = cancelStatus === CancelStatus.CANCEL_DONE
console.log(123, orderSupportGasless, chainSupportGasless)
const { mixpanelHandler } = useMixpanel()
const { networkInfo } = useActiveWeb3React()

const onSetType = (type: CancelOrderType) => {
setCancelType(type)
if (!order) return
mixpanelHandler(
isEdit ? MIXPANEL_TYPE.LO_CLICK_UPDATE_TYPE : MIXPANEL_TYPE.LO_CLICK_CANCEL_TYPE,
getPayloadTracking(order, networkInfo.name, {
[isEdit ? 'edit_type' : 'cancel_type']: type === CancelOrderType.GAS_LESS_CANCEL ? 'Gasless' : 'Hard',
}),
)
}

const gasAmountDisplay = estimateGas
? `~${formatDisplayNumber(estimateGas + '', {
Expand Down Expand Up @@ -200,7 +217,7 @@ const CancelButtons = ({
>
<ButtonOutlined
{...propsGasless}
onClick={() => setCancelType(CancelOrderType.GAS_LESS_CANCEL)}
onClick={() => onSetType(CancelOrderType.GAS_LESS_CANCEL)}
$disabled={disabledGasLessCancel}
disabled={disabledGasLessCancel}
>
Expand All @@ -213,7 +230,7 @@ const CancelButtons = ({
buttonHardEdit={
<ButtonOutlined
{...propsHardCancel}
onClick={() => setCancelType(CancelOrderType.HARD_CANCEL)}
onClick={() => onSetType(CancelOrderType.HARD_CANCEL)}
color={cancelType === CancelOrderType.HARD_CANCEL ? theme.primary : undefined}
>
<GasStation size={20} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function CancelOrderModal({
flowState={flowState}
/>
<CancelButtons
order={order}
cancelType={cancelType}
setCancelType={setCancelType}
estimateGas={estimateGas}
Expand Down
3 changes: 2 additions & 1 deletion src/components/swapv2/LimitOrder/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ export const getPayloadCreateOrder = (params: CreateOrderParam) => {
}
}

export const getPayloadTracking = (order: LimitOrder, networkName: string) => {
export const getPayloadTracking = (order: LimitOrder, networkName: string, payload = {}) => {
const { makerAssetSymbol, takerAssetSymbol, makingAmount, makerAssetDecimals, id } = order
return {
...payload,
from_token: makerAssetSymbol,
to_token: takerAssetSymbol,
from_network: networkName,
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/useMixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export enum MIXPANEL_TYPE {
LO_CLICK_EDIT_ORDER,
LO_DISPLAY_SETTING_CLICK,
LO_CLICK_SUBSCRIBE_BTN,
LO_CLICK_CANCEL_TYPE,
LO_CLICK_UPDATE_TYPE,

// Wallet UI
WUI_WALLET_CLICK,
Expand Down Expand Up @@ -1115,6 +1117,14 @@ export default function useMixpanel(currencies?: { [field in Field]?: Currency }
mixpanel.track('Limit Order - User click to Subscribe button')
break
}
case MIXPANEL_TYPE.LO_CLICK_CANCEL_TYPE: {
mixpanel.track('Limit Order - Cancel Order Double Signature Click', payload)
break
}
case MIXPANEL_TYPE.LO_CLICK_UPDATE_TYPE: {
mixpanel.track('Limit Order - Update Order Double Signature Click', payload)
break
}

case MIXPANEL_TYPE.WUI_WALLET_CLICK: {
mixpanel.track('Wallet UI - Wallet Click')
Expand Down

0 comments on commit 0ab97c9

Please sign in to comment.