Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: useTracking #160

Merged
merged 38 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e0eec84
refactor
dan-ziv Apr 7, 2022
e53d5f3
more
dan-ziv Apr 7, 2022
b007f3e
fix(Terms): add notes (#144)
CarmitKl Apr 11, 2022
1e0a94b
prerelease: v1.2.0-dev.2
semantic-release-bot Apr 11, 2022
445f20b
Merge branch 'dev' of github.com:starkware-libs/starknet-bridge into …
dan-ziv Apr 11, 2022
01c7b45
fixes
dan-ziv Apr 11, 2022
0f85949
fixes
dan-ziv Apr 11, 2022
67f50f7
fix(Faq): update question 8 (#149)
CarmitKl Apr 12, 2022
4e604bd
ci: add nginx configuration file for app routing (#150)
guyvelleman Apr 12, 2022
125061d
prerelease: v1.2.0-dev.3
semantic-release-bot Apr 12, 2022
d431033
fix
dan-ziv Apr 12, 2022
10c7a27
move unsupported chain id txt to strings
dan-ziv Apr 12, 2022
ddcdfdb
Merge branch 'fix/unsupported-chain-id' of github.com:starkware-libs/…
dan-ziv Apr 12, 2022
c47af5d
fix lint
dan-ziv Apr 12, 2022
732734d
remove packages
dan-ziv Apr 12, 2022
8d2171f
add event
dan-ziv Apr 12, 2022
50199b5
Merge branch 'dev' of github.com:starkware-libs/starknet-bridge into …
dan-ziv Apr 12, 2022
913dea1
fixes
dan-ziv Apr 12, 2022
d1d9c43
fix
dan-ziv Apr 12, 2022
f3205e6
Merge branch 'fix/unsupported-chain-id' of github.com:starkware-libs/…
dan-ziv Apr 12, 2022
470a9a6
delete
dan-ziv Apr 12, 2022
836c4d7
Merge branch 'dev' of github.com:starkware-libs/starknet-bridge into …
dan-ziv Apr 18, 2022
84a1e74
usetranslaction
dan-ziv Apr 18, 2022
465f45a
open in new tab
dan-ziv Apr 18, 2022
9a7ef76
lint fix in link- add 'noreferrer'
Apr 18, 2022
4c76a1f
Merge branch 'dev' of github.com:starkware-libs/starknet-bridge into …
dan-ziv Apr 18, 2022
ba4c2c5
remove notes
dan-ziv Apr 18, 2022
a452bca
fix modal sent text
dan-ziv Apr 18, 2022
e14d3c6
refactor
dan-ziv Apr 18, 2022
e3abf0d
fix useCallback
dan-ziv Apr 18, 2022
0e709f3
fix useCallback
dan-ziv Apr 18, 2022
3cee73c
Merge branch 'dev' of github.com:starkware-libs/starknet-bridge into …
dan-ziv Apr 18, 2022
ab54f66
fix typo
Apr 18, 2022
01de3e9
fix a missing import
Apr 18, 2022
0fcfd8c
Merge branch 'dev' into refactor/useTracking
dan-ziv Apr 18, 2022
344287a
fix menu tracking
dan-ziv Apr 21, 2022
21d4a38
Merge branch 'refactor/useTracking' of github.com:starkware-libs/star…
dan-ziv Apr 21, 2022
110e349
fixes
dan-ziv Apr 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/analytics/track-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ export const TrackEvent = {
TRANSFER: {
SWAP_NETWORK: 'TRANSFER_MENU/swap_network',
MAX_CLICK: 'TRANSFER_MENU/max_click',
TRANSFER_TO_L2_INITIATED: 'TRANSFER_MENU/transfer_to_l2_initiated',
TRANSFER_TO_L2_SUCCESS: 'TRANSFER_MENU/transfer_to_l2_success',
TRANSFER_TO_L2_REJECT: 'TRANSFER_MENU/transfer_to_l2_reject',
TRANSFER_TO_L2_ERROR: 'TRANSFER_MENU/transfer_to_l2_error',
TRANSFER_TO_L1_INITIATED: 'TRANSFER_MENU/transfer_to_l1_initiated',
TRANSFER_TO_L1_SUCCESS: 'TRANSFER_MENU/transfer_to_l1_success',
TRANSFER_TO_L1_REJECT: 'TRANSFER_MENU/transfer_to_l1_reject',
TRANSFER_TO_L1_ERROR: 'TRANSFER_MENU/transfer_to_l1_error',
COMPLETE_TRANSFER_TO_L1_INITIATED: 'TRANSFER_MENU/complete_transfer_to_l1_initiated',
COMPLETE_TRANSFER_TO_L1_SUCCESS: 'TRANSFER_MENU/complete_transfer_to_l1_success',
COMPLETE_TRANSFER_TO_L1_REJECT: 'TRANSFER_MENU/complete_transfer_to_l1_reject',
COMPLETE_TRANSFER_TO_L1_ERROR: 'TRANSFER_MENU/complete_transfer_to_l1_error'
TRANSFER_TO_L2: {
INITIATED: 'TRANSFER_MENU/transfer_to_l2_initiated',
SUCCESS: 'TRANSFER_MENU/transfer_to_l2_success',
ERROR: 'TRANSFER_MENU/transfer_to_l2_error',
REJECT: 'TRANSFER_MENU/transfer_to_l2_reject'
},
TRANSFER_TO_L1: {
INITIATED: 'TRANSFER_MENU/transfer_to_l1_initiated',
SUCCESS: 'TRANSFER_MENU/transfer_to_l1_success',
ERROR: 'TRANSFER_MENU/transfer_to_l1_error',
REJECT: 'TRANSFER_MENU/transfer_to_l1_reject'
},
COMPLETE_TRANSFER_TO_L1: {
INITIATED: 'TRANSFER_MENU/complete_transfer_to_l1_initiated',
SUCCESS: 'TRANSFER_MENU/complete_transfer_to_l1_success',
ERROR: 'TRANSFER_MENU/complete_transfer_to_l1_error',
REJECT: 'TRANSFER_MENU/complete_transfer_to_l1_reject'
}
},

/**
Expand Down
7 changes: 4 additions & 3 deletions src/components/Containers/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react';
import {useLocation, useNavigate} from 'react-router-dom';
import useBreakpoint from 'use-breakpoint';

import {track} from '../../../analytics';
import {TrackEvent} from '../../../analytics';
import {ReactComponent as StarkGateLogo} from '../../../assets/img/starkgate.svg';
import {Breakpoint} from '../../../enums';
import {useColors, useConstants, useEnvs, useTranslation} from '../../../hooks';
import {useColors, useConstants, useEnvs, useTracking, useTranslation} from '../../../hooks';
import {useLogin} from '../../../providers/AppProvider';
import {useMenu} from '../../../providers/MenuProvider';
import {useIsL1, useIsL2} from '../../../providers/TransferProvider';
Expand All @@ -16,6 +16,7 @@ import styles from './Header.module.scss';

export const Header = () => {
const {DISCORD_LINK_URL} = useConstants();
const [trackDiscordClick] = useTracking(TrackEvent.DISCORD_TAB_CLICK);
const {env} = useEnvs();
const {tabDiscordTxt, tabFaqTxt, tabTermsTxt, chainTxt} = useTranslation('containers.header');
const navigate = useNavigate();
Expand Down Expand Up @@ -59,7 +60,7 @@ export const Header = () => {
};

const onTabDiscordClick = () => {
track(TrackEvent.DISCORD_TAB_CLICK);
trackDiscordClick();
utils.browser.openInNewTab(DISCORD_LINK_URL);
};

Expand Down
44 changes: 20 additions & 24 deletions src/components/Features/Account/Account.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import PropTypes from 'prop-types';
import React from 'react';

import {track, TrackEvent} from '../../../analytics';
import {useCompleteTransferToL1, useConstants, useEnvs, useTranslation} from '../../../hooks';
import {
useAccountTracking,
useCompleteTransferToL1,
useConstants,
useEnvs,
useTranslation
} from '../../../hooks';
import {useMenu} from '../../../providers/MenuProvider';
import {useTransfer} from '../../../providers/TransferProvider';
import {useAccountTransfersLog} from '../../../providers/TransfersLogProvider';
Expand All @@ -21,6 +26,13 @@ import {TransferLog} from '../TransferLog/TransferLog';

export const Account = ({transferId}) => {
const {titleTxt} = useTranslation('menus.account');
const [
trackTxLinkClick,
trackAccountLinkClick,
trackViewTransfersLog,
trackCompleteTransferClick,
trackAddressCopied
] = useAccountTracking();
const {etherscanAccountUrl, voyagerAccountUrl} = useEnvs();
const {ETHERSCAN, VOYAGER} = useConstants();
const {showTransferMenu} = useMenu();
Expand All @@ -36,56 +48,40 @@ export const Account = ({transferId}) => {
key={index}
transfer={transfer}
onCompleteTransferClick={() => onCompleteTransferClick(transfer)}
onTxClick={onTxClick}
onTxClick={trackTxLinkClick}
/>
))
: null;
};

const onTxClick = () => {
track(TrackEvent.ACCOUNT.TX_LINK_CLICK);
};

const onCompleteTransferClick = transfer => {
track(TrackEvent.ACCOUNT.COMPLETE_TRANSFER_CLICK);
trackCompleteTransferClick();
completeTransferToL1(transfer);
};

const onAccountLinkClick = () => {
track(TrackEvent.ACCOUNT.ACCOUNT_LINK_CLICK);
};

const onShowTransfers = () => {
track(TrackEvent.ACCOUNT.VIEW_TRANSFERS_LOG);
};

const onAccountAddressClick = () => {
track(TrackEvent.ACCOUNT.ADDRESS_COPIED);
};

return (
<Menu>
<div>
<BackButton onClick={() => showTransferMenu()} />
<MenuTitle text={utils.object.evaluate(titleTxt, {network: fromNetwork.name})} />
<AccountAddress address={account} onClick={onAccountAddressClick} />
<AccountAddress address={account} onClick={trackAddressCopied} />
{isL1 && (
<LinkButton
text={ETHERSCAN}
url={etherscanAccountUrl(account)}
onClick={onAccountLinkClick}
onClick={trackAccountLinkClick}
/>
)}
{isL2 && (
<LinkButton
text={VOYAGER}
url={voyagerAccountUrl(account)}
onClick={onAccountLinkClick}
onClick={trackAccountLinkClick}
/>
)}
<TransferLogContainer
transferIndex={utils.object.findIndexById(transfers, transferId)}
onShowTransfers={onShowTransfers}
onShowTransfers={trackViewTransfersLog}
>
{renderTransfers()}
</TransferLogContainer>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Features/SelectToken/SelectToken.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React, {useEffect, useState} from 'react';

import {track, TrackEvent} from '../../../analytics';
import L1Logo from '../../../assets/svg/tokens/eth.svg';
import L2Logo from '../../../assets/svg/tokens/starknet.svg';
import {useColors, useTranslation} from '../../../hooks';
import {useColors, useTranslation, useSelectTokenTracking} from '../../../hooks';
import {useMenu} from '../../../providers/MenuProvider';
import {useTokens} from '../../../providers/TokensProvider';
import {useTransfer} from '../../../providers/TransferProvider';
import {BackButton, Menu, MenuTitle, RefreshIcon, SearchToken, SelectTokenList} from '../../UI';
import styles from './SelectToken.module.scss';

export const SelectToken = () => {
const [trackSelectToken] = useSelectTokenTracking();
const {titleTxt} = useTranslation('menus.selectToken');
const {tokens, updateTokenBalance} = useTokens();
const {colorBeta} = useColors();
Expand All @@ -25,7 +25,7 @@ export const SelectToken = () => {

const onTokenSelect = tokenData => {
const {symbol} = tokenData;
track(TrackEvent.SELECT_TOKEN.TOKEN_SELECTED, {symbol});
trackSelectToken(symbol);
selectToken(symbol);
showTransferMenu();
};
Expand Down
14 changes: 10 additions & 4 deletions src/components/Features/Transfer/Transfer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React, {useEffect, useState} from 'react';

import {track, TrackEvent} from '../../../analytics';
import {ActionType, NetworkType} from '../../../enums';
import {useMaxDeposit, useTransferToL1, useTransferToL2, useTranslation} from '../../../hooks';
import {
useMaxDeposit,
useTransferToL1,
useTransferToL2,
useTransferTracking,
useTranslation
} from '../../../hooks';
import {useMenu} from '../../../providers/MenuProvider';
import {useL1Token, useL2Token, useTokens} from '../../../providers/TokensProvider';
import {useAmount, useIsL1, useIsL2, useTransfer} from '../../../providers/TransferProvider';
Expand All @@ -26,6 +31,7 @@ export const Transfer = () => {
tooManyDigitsErrorMsg,
negativeValueErrorMsg
} = useTranslation('menus.transfer');
const [trackMaxClick, trackSwapNetworks] = useTransferTracking();
const [isL1, swapToL1] = useIsL1();
const [isL2, swapToL2] = useIsL2();
const [amount, setAmount] = useAmount();
Expand Down Expand Up @@ -82,7 +88,7 @@ export const Transfer = () => {

const onMaxClick = () => {
try {
track(TrackEvent.TRANSFER.MAX_CLICK);
trackMaxClick();
setAmount(String(Math.min(selectedToken.balance, isL1 ? Number(maxDeposit) : Infinity)));
} catch (ex) {
setAmount(selectedToken.balance);
Expand All @@ -94,7 +100,7 @@ export const Transfer = () => {
};

const onSwapClick = () => {
track(TrackEvent.TRANSFER.SWAP_NETWORK);
trackSwapNetworks();
isL2 ? swapToL1() : swapToL2();
};

Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './useTransferProgress';
export * from './useTokenConstant';
export * from './useConstants';
export * from './useTranslation';
export * from './useTracking';
69 changes: 69 additions & 0 deletions src/hooks/useTracking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {useCallback} from 'react';

import {track, TrackEvent} from '../analytics';
import {MenuType} from '../enums';

export const useTracking = events => {
if (typeof events === 'string') {
events = [events];
}

const trackEvent = useCallback(event => data => track(event, data), []);

return events.map(trackEvent, [events]);
};

export const useMenuTracking = () => {
const [trackAccountMenu, trackTransferMenu, trackSelectTokenMenu] = useTracking([
TrackEvent.ACCOUNT_MENU,
TrackEvent.TRANSFER_MENU,
TrackEvent.SELECT_TOKEN_MENU
]);

return useCallback(menu => {
switch (menu) {
case MenuType.ACCOUNT:
trackAccountMenu();
break;
case MenuType.SELECT_TOKEN:
trackSelectTokenMenu();
break;
case MenuType.TRANSFER:
default:
trackTransferMenu();
break;
}
}, []);
};

export const useLoginTracking = () => {
return useTracking([TrackEvent.LOGIN_SCREEN, ...Object.values(TrackEvent.LOGIN)]);
};

export const useTermsTracking = () => {
return useTracking([TrackEvent.TERMS_SCREEN, ...Object.values(TrackEvent.TERMS)]);
};

export const useTransferTracking = () => {
return useTracking([TrackEvent.TRANSFER.MAX_CLICK, TrackEvent.TRANSFER.SWAP_NETWORK]);
};

export const useTransferToL1Tracking = () => {
return useTracking([...Object.values(TrackEvent.TRANSFER.TRANSFER_TO_L1)]);
};

export const useTransferToL2Tracking = () => {
return useTracking([...Object.values(TrackEvent.TRANSFER.TRANSFER_TO_L2)]);
};

export const useCompleteTransferToL1Tracking = () => {
return useTracking([...Object.values(TrackEvent.TRANSFER.COMPLETE_TRANSFER_TO_L1)]);
};

export const useAccountTracking = () => {
return useTracking([...Object.values(TrackEvent.ACCOUNT)]);
};

export const useSelectTokenTracking = () => {
return useTracking([...Object.values(TrackEvent.SELECT_TOKEN)]);
};
Loading