Skip to content

Commit

Permalink
Merge e522a0c into f8808d8
Browse files Browse the repository at this point in the history
  • Loading branch information
derHowie authored Nov 23, 2024
2 parents f8808d8 + e522a0c commit c581c1f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/analytics/userProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@ type PushNotificationPermissionStatus = 'enabled' | 'disabled' | 'never asked';

// these are all reported seperately so they must be optional
export interface UserProperties {
// number of imported or generated accounts
ownedAccounts?: number;
// number of accounts tied to paired hardware wallets
hardwareAccounts?: number;
// number of watched addresses or ens
watchedAccounts?: number;
// number of imported or generated secret recovery phrases
recoveryPhrases?: number;
// number of imported secret recovery phrases
importedRecoveryPhrases?: number;
// number of unique private keys
privateKeys?: number;
// number of imported unique private keys
importedPrivateKeys?: number;
// number of paired trezor hardware wallets -- unsupported but leaving BX key here
trezorDevices?: number;
// number of paired ledger hardware wallets
ledgerDevices?: number;
// whether a recovery phrase or private key has been imported
hasImported?: boolean;

// settings
currentAddressHash?: string; // NEW
currentAddressHash?: string;
currency?: NativeCurrencyKey;
language?: Language;
enabledTestnets?: boolean;
Expand Down
66 changes: 64 additions & 2 deletions src/screens/WalletScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { AssetList } from '../../components/asset-list';
import { Page } from '../../components/layout';
Expand All @@ -11,6 +11,7 @@ import {
useInitializeWallet,
useLoadAccountLateData,
useLoadGlobalLateData,
useWallets,
useWalletSectionsData,
} from '@/hooks';
import { Toast, ToastPositionContainer } from '@/components/toasts';
Expand All @@ -29,6 +30,7 @@ import { RouteProp, useRoute } from '@react-navigation/native';
import { RootStackParamList } from '@/navigation/types';
import { useNavigation } from '@/navigation';
import Routes from '@/navigation/Routes';
import walletTypes from '@/helpers/walletTypes';

function WalletScreen() {
const { params } = useRoute<RouteProp<RootStackParamList, 'WalletScreen'>>();
Expand All @@ -41,10 +43,69 @@ function WalletScreen() {
const loadAccountLateData = useLoadAccountLateData();
const loadGlobalLateData = useLoadGlobalLateData();
const insets = useSafeAreaInsets();
const { wallets } = useWallets();

const walletReady = useSelector(({ appState: { walletReady } }: AppState) => walletReady);
const { isWalletEthZero, isLoadingUserAssets, isLoadingBalance, briefSectionsData: walletBriefSectionsData } = useWalletSectionsData();

const trackWallets = useCallback(() => {
const identify = Object.values(wallets || {}).reduce(
(result, wallet) => {
switch (wallet.type) {
case walletTypes.mnemonic:
result.ownedAccounts += wallet.addresses.length;
result.recoveryPhrases += 1;
if (wallet.imported) {
result.importedRecoveryPhrases += 1;
result.hasImported = true;
}
break;
case walletTypes.privateKey:
result.ownedAccounts += wallet.addresses.length;
result.privateKeys += 1;
if (wallet.imported) {
result.importedPrivateKeys += 1;
result.hasImported = true;
}
break;
case walletTypes.readOnly:
result.watchedAccounts += wallet.addresses.length;
break;
case walletTypes.bluetooth:
result.hardwareAccounts += wallet.addresses.length;
result.ledgerDevices += 1;
break;
}
return result;
},
{
ownedAccounts: 0,
watchedAccounts: 0,
recoveryPhrases: 0,
importedRecoveryPhrases: 0,
privateKeys: 0,
importedPrivateKeys: 0,
hasImported: false,
hardwareAccounts: 0,
ledgerDevices: 0,
trezorDevices: 0,
}
);

analyticsV2.identify({
ownedAccounts: identify.ownedAccounts,
hardwareAccounts: identify.hardwareAccounts,
watchedAccounts: identify.watchedAccounts,
recoveryPhrases: identify.recoveryPhrases,
importedRecoveryPhrases: identify.importedRecoveryPhrases,
privateKeys: identify.privateKeys,
importedPrivateKeys: identify.importedPrivateKeys,
ledgerDevices: identify.ledgerDevices,
trezorDevices: identify.trezorDevices,
hasImported: identify.hasImported,
});
}, [wallets]);

useEffect(() => {
// This is the fix for Android wallet creation problem.
// We need to remove the welcome screen from the stack.
Expand All @@ -63,13 +124,14 @@ function WalletScreen() {
await initializeWallet(null, null, null, !params?.emptyWallet);
setInitialized(true);
setParams({ emptyWallet: false });
trackWallets();
};

if (!initialized || (params?.emptyWallet && initialized)) {
// We run the migrations only once on app launch
initializeAndSetParams();
}
}, [initializeWallet, initialized, params, setParams]);
}, [initializeWallet, initialized, params, setParams, trackWallets]);

useEffect(() => {
if (walletReady) {
Expand Down

0 comments on commit c581c1f

Please sign in to comment.