-
Notifications
You must be signed in to change notification settings - Fork 41
/
walletTypes.ts
71 lines (66 loc) · 2.2 KB
/
walletTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { KeychainType } from '~/core/types/keychainTypes';
import { getStatus, getWallets } from '~/entries/popup/handlers/wallet';
import { analytics } from '..';
export const identifyWalletTypes = async () => {
const { unlocked, ready } = await getStatus();
if (!unlocked || !ready) return;
const wallets = await getWallets();
const identify = wallets.reduce(
(result, wallet) => {
switch (wallet.type) {
case KeychainType.HdKeychain:
result.ownedAccounts += wallet.accounts.length;
result.recoveryPhrases += 1;
if (wallet.imported) {
result.importedRecoveryPhrases += 1;
result.hasImported = true;
}
break;
case KeychainType.KeyPairKeychain:
result.ownedAccounts += wallet.accounts.length;
result.privateKeys += 1;
if (wallet.imported) {
result.importedPrivateKeys += 1;
result.hasImported = true;
}
break;
case KeychainType.ReadOnlyKeychain:
result.watchedAccounts += wallet.accounts.length;
break;
case KeychainType.HardwareWalletKeychain:
result.hardwareAccounts += wallet.accounts.length;
if (wallet.vendor === 'Ledger') {
result.ledgerDevices += 1;
} else if (wallet.vendor === 'Trezor') {
result.trezorDevices += 1;
}
break;
}
return result;
},
{
ownedAccounts: 0,
watchedAccounts: 0,
recoveryPhrases: 0,
importedRecoveryPhrases: 0,
privateKeys: 0,
importedPrivateKeys: 0,
hasImported: false,
hardwareAccounts: 0,
ledgerDevices: 0,
trezorDevices: 0,
},
);
analytics.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,
});
};