Skip to content

Commit 982ad7b

Browse files
authored
Merge pull request #169 from oasisprotocol/ml/wrap/fix-analytics-events-values
move: Send tracking event values in cent amount
2 parents df3e591 + b2a43c2 commit 982ad7b

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

move/src/useDeposit.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import { useAccount, useBalance } from 'wagmi'
33
import { depositToSapphireStep1, depositToSapphireStep2 } from './deposit/depositToSapphire'
44
import { ConsensusAccount, useGenerateConsensusAccount } from './deposit/useGenerateConsensusAccount'
55
import { usePrevious } from './hooks/usePrevious.ts'
6-
import { getSapphireBalance, waitForConsensusBalance, waitForSapphireBalance } from './utils/getBalances'
6+
import {
7+
fromBaseUnitsToTrackEventCents,
8+
getSapphireBalance,
9+
waitForConsensusBalance,
10+
waitForSapphireBalance,
11+
} from './utils/getBalances'
712
import { useBlockNavigatingAway } from './utils/useBlockNavigatingAway'
813
import { trackEvent } from 'fathom-client'
14+
import { consensusConfig } from './utils/oasisConfig.ts'
915

1016
/** any consensus -> generatedConsensusAccount -> sapphireAddress */
1117
export function useDeposit() {
@@ -36,7 +42,7 @@ export function useDeposit() {
3642
const amountToDeposit = await waitForConsensusBalance(consensusAccount.address, 0n)
3743

3844
trackEvent('deposit flow started', {
39-
_value: Number(amountToDeposit.formatted),
45+
_value: fromBaseUnitsToTrackEventCents(amountToDeposit.raw, consensusConfig.decimals),
4046
})
4147

4248
setProgress({ percentage: 0.25, message: 'ROSE transfer initiated' })
@@ -65,7 +71,7 @@ export function useDeposit() {
6571
})
6672

6773
trackEvent('deposit flow finished', {
68-
_value: Number(amountToDeposit.formatted),
74+
_value: fromBaseUnitsToTrackEventCents(amountToDeposit.raw, consensusConfig.decimals),
6975
})
7076

7177
allowNavigatingAway() // Stop blocking unless new transfer comes in

move/src/useWithdraw.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { useState } from 'react'
22
import { useAccount, useBalance, useSendTransaction } from 'wagmi'
33
import { usePrevious } from './hooks/usePrevious.ts'
4-
import { getConsensusBalance, waitForConsensusBalance, waitForSapphireBalance } from './utils/getBalances'
4+
import {
5+
fromBaseUnitsToTrackEventCents,
6+
getConsensusBalance,
7+
waitForConsensusBalance,
8+
waitForSapphireBalance,
9+
} from './utils/getBalances'
510
import { useBlockNavigatingAway } from './utils/useBlockNavigatingAway'
611
import { transferToConsensus } from './withdraw/transferToConsensus'
712
import { useGenerateSapphireAccount } from './withdraw/useGenerateSapphireAccount'
813
import { minimalWithdrawableAmount, withdrawToConsensus } from './withdraw/withdrawToConsensus'
914
import { trackEvent } from 'fathom-client'
15+
import { consensusConfig } from './utils/oasisConfig.ts'
1016

1117
// Use global variable here, due to step4 using different context(not in sync with react hooks)
1218
let isInputModeGlobal = true
@@ -82,7 +88,7 @@ export function useWithdraw() {
8288
const amountToWithdraw2 = await waitForConsensusBalance(generatedConsensusAccount.address, 0n)
8389

8490
trackEvent('withdrawal flow started', {
85-
_value: Number(amountToWithdraw2.formatted),
91+
_value: fromBaseUnitsToTrackEventCents(amountToWithdraw2.raw, consensusConfig.decimals),
8692
})
8793

8894
const preWithdrawConsensusBalance = await getConsensusBalance(consensusAddress)
@@ -99,7 +105,7 @@ export function useWithdraw() {
99105
})
100106

101107
trackEvent('withdrawal flow finished', {
102-
_value: Number(amountToWithdraw2.formatted),
108+
_value: fromBaseUnitsToTrackEventCents(amountToWithdraw2.raw, consensusConfig.decimals),
103109
})
104110

105111
allowNavigatingAway() // Stop blocking unless new transfer comes in

move/src/utils/getBalances.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ function fromBaseUnits(valueInBaseUnits: bigint, decimals: number): string {
8181
return value.toFixed()
8282
}
8383

84+
export function fromBaseUnitsToTrackEventCents(valueInBaseUnits: bigint, decimals: number): number {
85+
const value = fromBaseUnits(valueInBaseUnits, decimals)
86+
return BigNumber(value).multipliedBy(100).integerValue().toNumber()
87+
}
88+
8489
export function getValidOasisAddress(addr: string): `oasis1${string}` | null {
8590
try {
8691
staking.addressFromBech32(addr)

0 commit comments

Comments
 (0)