-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f539ca
commit 95d3d86
Showing
2 changed files
with
0 additions
and
46 deletions.
There are no files selected for viewing
43 changes: 0 additions & 43 deletions
43
src/app/common/hooks/analytics/transactions-analytics.hooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +0,0 @@ | ||
import { useEffect, useMemo } from 'react'; | ||
|
||
import { AccountStxBalanceBigNumber } from '@shared/models/account.model'; | ||
|
||
import { useCurrentStacksAccountUnanchoredBalances } from '@app/query/stacks/balance/stx-balance.hooks'; | ||
import { store } from '@app/store'; | ||
import { analyticsActions } from '@app/store/analytics/analytics.actions'; | ||
import { useAnalyticsHasStxDeposits } from '@app/store/analytics/analytics.selectors'; | ||
import { useCurrentNetworkState } from '@app/store/networks/networks.hooks'; | ||
|
||
import { useAnalytics } from './use-analytics'; | ||
|
||
function useIsFirstDeposit(stxBalance: AccountStxBalanceBigNumber | undefined): boolean { | ||
const currentNetwork = useCurrentNetworkState(); | ||
const { chainId: stxChainId } = currentNetwork.chain.stacks; | ||
const hasStxDeposits = useAnalyticsHasStxDeposits()[stxChainId]; | ||
const hasZeroStx = useMemo( | ||
() => stxBalance?.total_received.amount?.isEqualTo(0) || false, | ||
[stxBalance?.total_received] | ||
); | ||
useEffect(() => { | ||
if (!stxBalance) return; | ||
if (hasZeroStx || !hasStxDeposits) { | ||
store.dispatch( | ||
analyticsActions.hasStxDeposits({ | ||
network: stxChainId, | ||
hasStxDeposits: !hasZeroStx, | ||
}) | ||
); | ||
} | ||
}, [hasZeroStx, hasStxDeposits, stxChainId, stxBalance]); | ||
return !hasStxDeposits && !hasZeroStx; | ||
} | ||
|
||
export function useTrackFirstDeposit() { | ||
const analytics = useAnalytics(); | ||
const { data: balances } = useCurrentStacksAccountUnanchoredBalances(); | ||
const firstDeposit = useIsFirstDeposit(balances?.stx); | ||
useEffect(() => { | ||
if (!firstDeposit || !balances) return; | ||
void analytics.track('deposit_first_stx', { type: 'stx' }); | ||
}, [analytics, balances, firstDeposit]); | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters