From 28c1d256717787f23e2cd9cdee0edc673749085a Mon Sep 17 00:00:00 2001 From: Victor Kirov Date: Mon, 24 Jun 2024 09:34:20 +0300 Subject: [PATCH] Change setup to use the master pubkey hash as the identifier (#359) --- src/app/hooks/useWalletReducer.ts | 18 ++++++++++++++++- src/app/screens/legal/index.tsx | 20 +++---------------- .../settings/privacyPreferences/index.tsx | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/app/hooks/useWalletReducer.ts b/src/app/hooks/useWalletReducer.ts index e400ae23d..9ba722ddf 100644 --- a/src/app/hooks/useWalletReducer.ts +++ b/src/app/hooks/useWalletReducer.ts @@ -28,7 +28,12 @@ import { } from '@stores/wallet/actions/actionCreators'; import { useQueryClient } from '@tanstack/react-query'; import { generatePasswordHash } from '@utils/encryptionUtils'; -import { resetMixPanel, trackMixPanel } from '@utils/mixpanel'; +import { + hasOptedInMixPanelTracking, + optInMixPanel, + resetMixPanel, + trackMixPanel, +} from '@utils/mixpanel'; import { useCallback } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import useSeedVault from './useSeedVault'; @@ -275,6 +280,17 @@ const useWalletReducer = () => { if (showDataCollectionAlert !== null && showDataCollectionAlert !== undefined) { changeShowDataCollectionAlert(!showDataCollectionAlert); changeShowDataCollectionAlert(showDataCollectionAlert); + + // reinitialise with masterpubkey hash now that we have it + if (hasOptedInMixPanelTracking()) { + const seed = await seedVault.getSeed(); + const wallet = await walletFromSeedPhrase({ + mnemonic: seed, + index: 0n, + network: 'Mainnet', + }); + optInMixPanel(wallet.masterPubKey); + } } localStorage.setItem('migrated', 'true'); setSessionStartTime(); diff --git a/src/app/screens/legal/index.tsx b/src/app/screens/legal/index.tsx index 5113fdda3..f4496a08e 100644 --- a/src/app/screens/legal/index.tsx +++ b/src/app/screens/legal/index.tsx @@ -1,9 +1,7 @@ import LinkIcon from '@assets/img/linkIcon.svg'; import Separator from '@components/separator'; -import useSeedVault from '@hooks/useSeedVault'; import useWalletReducer from '@hooks/useWalletReducer'; import { CustomSwitch } from '@screens/ledger/importLedgerAccount/steps/index.styled'; -import { walletFromSeedPhrase } from '@secretkeylabs/xverse-core'; import Button from '@ui-library/button'; import { PRIVACY_POLICY_LINK, TERMS_LINK } from '@utils/constants'; import { saveIsTermsAccepted } from '@utils/localStorage'; @@ -76,7 +74,6 @@ function Legal() { const { t } = useTranslation('translation', { keyPrefix: 'LEGAL_SCREEN' }); const navigate = useNavigate(); const { changeShowDataCollectionAlert } = useWalletReducer(); - const seedVault = useSeedVault(); const [searchParams] = useSearchParams(); const theme = useTheme(); const [isToggleEnabled, setIsToggleEnabled] = useState(true); @@ -85,23 +82,12 @@ function Legal() { const handleLegalAccept = async () => { if (isToggleEnabled) { - try { - const seed = await seedVault.getSeed(); - const wallet = await walletFromSeedPhrase({ - mnemonic: seed, - index: 0n, - network: 'Mainnet', - }); - optInMixPanel(wallet.masterPubKey); - changeShowDataCollectionAlert(); - } catch (e) { - console.error(e); - // if this fails, user will be shown the data collection alert again on first start - } + optInMixPanel(); } else { optOutMixPanel(); - changeShowDataCollectionAlert(); } + + changeShowDataCollectionAlert(); saveIsTermsAccepted(true); const isRestore = !!searchParams.get('restore'); if (isRestore) { diff --git a/src/app/screens/settings/privacyPreferences/index.tsx b/src/app/screens/settings/privacyPreferences/index.tsx index 7f46b745e..c1608cfc8 100644 --- a/src/app/screens/settings/privacyPreferences/index.tsx +++ b/src/app/screens/settings/privacyPreferences/index.tsx @@ -56,7 +56,7 @@ function PrivacyPreferencesScreen() { setIsEnabled(checked); if (checked) { - optInMixPanel(selectedAccount?.masterPubKey); + optInMixPanel(selectedAccount.masterPubKey); } else { optOutMixPanel(); }