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

Replace account id on rudderstack with hash id #3089

Merged
merged 4 commits into from
Aug 1, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MAINNET, TESTNET } from '../../utils/constants';
import { wallet } from '../../utils/wallet';
import LoadingDots from '../common/loader/LoadingDots';
import { MigrationModal, ButtonsContainer, StyledButton, Container } from './CommonComponents';
import { resetUserState, initAnalytics, recordWalletMigrationEvent, recordWalletMigrationState, rudderAnalyticsReady } from './metrics';
import { resetUserState, initAnalytics, recordWalletMigrationEvent, recordWalletMigrationState, rudderAnalyticsReady, accountIdToHash } from './metrics';
import CleanKeysCompleteModal from './modals/CleanKeysCompleteModal/CleanKeyCompleteModal';
import CleanKeysModal from './modals/CleanKeysModal/CleanKeysModal';
import Disable2FAModal from './modals/Disable2faModal/Disable2FA';
Expand Down Expand Up @@ -94,7 +94,7 @@ const WalletMigration = ({ open, onClose }) => {

const navigateToRedirect = ({ accounts, walletName }) => {
recordWalletMigrationEvent(`${WALLET_MIGRATION_VIEWS.MIGRATE_ACCOUNTS} COMPLETED`, {
listOfAccounts: accounts.join(', '),
listOfAccounts: accounts.map((accountId) => accountIdToHash(accountId)).join(', '),
selectedWallet: walletName,
});
setMigrationStep(WALLET_MIGRATION_VIEWS.VERIFYING);
Expand Down Expand Up @@ -130,7 +130,7 @@ const WalletMigration = ({ open, onClose }) => {
await account.deleteKey(publicKey);
await wallet.removeWalletAccount(accountId);
} catch {
failedAccounts.push(accountId);
failedAccounts.push(accountIdToHash(accountId));
}
}
setIsLoggingOut(false);
Expand All @@ -141,12 +141,11 @@ const WalletMigration = ({ open, onClose }) => {
errorMessage: `fail to delete keys for account(s) ${failedAccounts.join(', ')}`,
}));
} else {
// On success, update segment with first accountId as reference
// Due to .deleteKey above, we have to explicity pass fallbackAcountId to recordWalletMigrationState
recordWalletMigrationState({ state: 'migration completed' }, availableAccounts[0]);
const hashId = accountIdToHash(availableAccounts[0]);
recordWalletMigrationState({ state: 'migration completed' }, hashId);
resetUserState();
onClose();
deleteMigrationStep();
deleteMigrationStep();
location.reload();
}
};
Expand Down
13 changes: 11 additions & 2 deletions packages/frontend/src/components/wallet-migration/metrics.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sha256 from 'js-sha256';
import * as rudderanalytics from 'rudder-sdk-js';

import Environments from '../../../../../features/environments.json';
Expand Down Expand Up @@ -57,7 +58,8 @@ export const recordWalletMigrationEvent = (eventLabel, properties = {}) => {

try {
const accountId = localStorage.getItem(KEY_ACTIVE_ACCOUNT_ID);
rudderanalytics.track(eventLabel, { ...properties, userId: accountId });
const hashId = accountIdToHash(accountId);
rudderanalytics.track(eventLabel, { ...properties, userId: hashId });
} catch (e) {
console.error(e);
}
Expand All @@ -70,8 +72,9 @@ export const recordWalletMigrationState = (traits = {}, fallBackAccountId) => {

try {
const accountId = localStorage.getItem(KEY_ACTIVE_ACCOUNT_ID) || fallBackAccountId;
const hashId = accountIdToHash(accountId);
rudderanalytics.identify(
accountId,
hashId,
{
...traits,
userAgent: navigator?.userAgent || 'Unknown',
Expand All @@ -88,3 +91,9 @@ export const resetUserState = () => {
}
return rudderanalytics.reset();
};

export function accountIdToHash(accountId) {
const hash = sha256.create();
hash.update(accountId);
return hash.hex();
};
andy-haynes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IMPORT_STATUS } from '../../../accounts/batch_import_accounts';
import sequentialAccountImportReducer, { ACTIONS } from '../../../accounts/batch_import_accounts/sequentialAccountImportReducer';
import LoadingDots from '../../../common/loader/LoadingDots';
import { MigrationModal, Container, IconBackground } from '../../CommonComponents';
import { recordWalletMigrationEvent } from '../../metrics';
import { accountIdToHash, recordWalletMigrationEvent } from '../../metrics';
import { WALLET_MIGRATION_VIEWS } from '../../WalletMigration';
import AccessKeyList from './AccessKeyList';
import AccountKeyCleanup from './AccountKeyCleanup';
Expand Down Expand Up @@ -209,7 +209,7 @@ const CleanKeysModal = ({ accounts, handleSetActiveView, onNext, onClose, rotate
setKeysAreDeleting(false);
recordWalletMigrationEvent(`${WALLET_MIGRATION_VIEWS.CLEAN_KEYS} COMPLETED`, {
numberOfFAKDeleted: keysToRemove.length,
accountId: currentAccount.accountId,
accountId: accountIdToHash(currentAccount.accountId),
});
}
setShowConfirmSeedphraseModal(false);
Expand Down