Skip to content

Commit

Permalink
feat: add all possible performance timers for now
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-deriv committed Apr 8, 2024
1 parent ce12402 commit ce017b2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/components/TotalAssets/TotalAssets.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { twMerge } from 'tailwind-merge';

import { Text } from '@deriv-com/ui';
import { Text, useDevice } from '@deriv-com/ui';

import { useActiveDerivTradingAccount } from '@/hooks';
import { setPerformanceValue } from '@/utils';

import { TotalAssetsLoader } from '../Loaders';

const TotalAssets = () => {
const { data: activeDerivTradingAccount } = useActiveDerivTradingAccount();
const { data: activeDerivTradingAccount, isFetching } = useActiveDerivTradingAccount();
const { isMobile } = useDevice();

// need to add more conditions to show the loader
if (isFetching) {
return <TotalAssetsLoader />;
}

setPerformanceValue('login_time', isMobile);
setPerformanceValue('redirect_from_deriv_com_time', isMobile);
setPerformanceValue('switch_currency_accounts_time', isMobile);
setPerformanceValue('switch_from_demo_to_real_time', isMobile);
setPerformanceValue('switch_from_real_to_demo_time', isMobile);

return (
<div className='relative lg:inline-block text-center lg:text-right w-full lg:w-auto flex justify-center mt-24 lg:mt-0'>
Expand Down
2 changes: 2 additions & 0 deletions src/components/TradingAccountsList/TradingAccountsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Text } from '@deriv-com/ui';
import { IconComponent } from '@/components';
import { IconToCurrencyMapper } from '@/constants';
import { useActiveDerivTradingAccount, useDerivTradingAccountsList, useQueryParams, useRegulationFlags } from '@/hooks';
import { startPerformanceEventTimer } from '@/utils';

export const TradingAccountsList = () => {
const { data: tradingAccountsList } = useDerivTradingAccountsList();
Expand All @@ -15,6 +16,7 @@ export const TradingAccountsList = () => {
const { closeModal } = useQueryParams();

const handleSwitchAccount = (loginid: string) => {
startPerformanceEventTimer('switch_currency_accounts_time');
switchAccount(loginid);
closeModal();
};
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useAccountSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAuthData } from '@deriv-com/api-hooks';

import { Regulation } from '@/constants';
import { useUIContext } from '@/providers';
import { startPerformanceEventTimer } from '@/utils';

import {
useActiveDerivTradingAccount,
Expand Down Expand Up @@ -66,6 +67,9 @@ export const useAccountSwitcher = () => {

const loginId = account.value === accountTypes[0].value ? demoLoginId : firstRealLoginId;
if (loginId) {
if (account.value === accountTypes[0].value)
startPerformanceEventTimer('switch_from_real_to_demo_time');
else startPerformanceEventTimer('switch_from_demo_to_real_time');
switchAccount(loginId);
}

Expand Down
9 changes: 9 additions & 0 deletions src/pages/signup/signup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Link } from 'react-router-dom';

import { useDevice } from '@deriv-com/ui';

import { setPerformanceValue } from '@/utils';

export const Signup = () => {
const { isMobile } = useDevice();

// leave it here for now
setPerformanceValue('signup_time', isMobile);

return (
<>
<h1>Signup</h1>
Expand Down
4 changes: 2 additions & 2 deletions src/utils/performance-metrics-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const startPerformanceEventTimer = (action: keyof typeof Window.prototype
window.performance_metrics[action] = Date.now();
};

export const setPerformanceValue = (action: keyof typeof Window.prototype.performance_metrics) => {
export const setPerformanceValue = (action: keyof typeof Window.prototype.performance_metrics, isMobile = false) => {
if (window.performance_metrics?.[action]) {
const value = (Date.now() - window.performance_metrics[action]) / 1000;
window.performance_metrics[action] = 0;
Expand All @@ -51,7 +51,7 @@ export const setPerformanceValue = (action: keyof typeof Window.prototype.perfor
Analytics.trackEvent(event_name, {
action,
value,
device: true ? 'mobile' : 'desktop',
device: isMobile ? 'mobile' : 'desktop',
});
}
};
Expand Down

0 comments on commit ce017b2

Please sign in to comment.