Skip to content

Commit

Permalink
feat: add MetaMetrics delete on Wallet delete (#9768)
Browse files Browse the repository at this point in the history
## **Description**
This creates a MetaMetrics deletion task when a user deletes their
wallet.

## **Related issues**

Fixes: [1271](MetaMask/mobile-planning#1271)

## **Manual testing steps**

1. Open Flipper Network inspector
2. Go to Settings > Security
3. Delete Wallet
4. Should see Successful call to MM proxy

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**



https://github.com/MetaMask/metamask-mobile/assets/141057783/45472d73-29c8-4e00-ad43-74bb774a51c0



## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
  • Loading branch information
frankvonhoven and legobeat authored May 30, 2024
1 parent 9b33a3e commit f88f38a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/components/UI/DeleteWalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { DeleteWalletModalSelectorsIDs } from '../../../../e2e/selectors/Modals/
import generateTestId from '../../../../wdio/utils/generateTestId';
import { MetaMetricsEvents } from '../../../core/Analytics';
import { useMetrics } from '../../../components/hooks/useMetrics';
import { useDispatch } from 'react-redux';
import { clearHistory } from '../../../actions/browser';
import CookieManager from '@react-native-cookies/cookies';

const DELETE_KEYWORD = 'delete';

Expand All @@ -45,6 +48,7 @@ const DeleteWalletModal = () => {
const [disableButton, setDisableButton] = useState<boolean>(true);

const [resetWalletState, deleteUser] = useDeleteWallet();
const dispatch = useDispatch();

const showConfirmModal = () => {
setShowConfirm(true);
Expand Down Expand Up @@ -85,6 +89,8 @@ const DeleteWalletModal = () => {
};

const deleteWallet = async () => {
await dispatch(clearHistory());
await CookieManager.clearAll(true);
triggerClose();
await resetWalletState();
await deleteUser();
Expand Down
7 changes: 5 additions & 2 deletions app/components/hooks/DeleteWallet/useDeleteWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { EXISTING_USER } from '../../../constants/storage';
import { Authentication } from '../../../core';
import AUTHENTICATION_TYPE from '../../../constants/userProperties';
import { resetVaultBackup } from '../../../core/BackupVault/backupVault';
import { useMetrics } from '../useMetrics';

const useDeleteWallet = () => {
const metrics = useMetrics();
const resetWalletState = useCallback(async () => {
try {
await Authentication.newWalletAndKeychain(`${Date.now()}`, {
Expand All @@ -20,14 +22,15 @@ const useDeleteWallet = () => {
}
}, []);

const deleteUser = useCallback(async () => {
const deleteUser = async () => {
try {
await AsyncStorage.removeItem(EXISTING_USER);
await metrics.createDataDeletionTask();
} catch (error: any) {
const errorMsg = `Failed to remove key: ${EXISTING_USER} from AsyncStorage`;
Logger.log(error, errorMsg);
}
}, []);
};

return [resetWalletState, deleteUser];
};
Expand Down

0 comments on commit f88f38a

Please sign in to comment.