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

Update the mobile app's id'ing of number of wallets to match the BX #6278

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading