FIX: Alert the user if notifications deregister failed

This commit is contained in:
Marcos Rodriguez Velez 2025-02-10 09:49:01 -04:00
parent b8a8986a8e
commit 879f4f4081
2 changed files with 63 additions and 27 deletions

View file

@ -493,7 +493,9 @@
"identity_pubkey": "Identity Pubkey",
"xpub_title": "Wallet XPUB",
"manage_wallets_search_placeholder": "Search wallets, memos",
"more_info": "More Info"
"more_info": "More Info",
"details_delete_wallet_error_message": "There was an issue confirming if this wallet was removed from notifications—this could be due to a network issue or poor connection. If you continue, you might still receive notifications for transactions related to this wallet, even after it is deleted.",
"details_delete_anyway": "Delete anyway"
},
"total_balance_view": {
"display_in_bitcoin": "Display in Bitcoin",

View file

@ -1,7 +1,6 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
ActivityIndicator,
Alert,
I18nManager,
InteractionManager,
LayoutAnimation,
@ -42,7 +41,7 @@ import { popToTop } from '../../NavigationService';
import { useFocusEffect, useRoute, RouteProp } from '@react-navigation/native';
import { LightningTransaction, Transaction, TWallet } from '../../class/wallets/types';
import { DetailViewStackParamList } from '../../navigation/DetailViewStackParamList';
import { unsubscribe } from '../../blue_modules/notifications';
import { isNotificationsEnabled, unsubscribe } from '../../blue_modules/notifications';
import HeaderMenuButton from '../../components/HeaderMenuButton';
import { Action } from '../../components/types';
import { CommonToolTipActions } from '../../typings/CommonToolTipActions';
@ -89,25 +88,60 @@ const WalletDetails: React.FC = () => {
}, [wallet]);
const [isMasterFingerPrintVisible, setIsMasterFingerPrintVisible] = useState<boolean>(false);
const navigateToOverviewAndDeleteWallet = useCallback(async () => {
setIsLoading(true);
try {
const externalAddresses = wallet.getAllExternalAddresses();
if (externalAddresses.length > 0) {
await unsubscribe(externalAddresses, [], []);
const handleWalletDeletion = useCallback(
async (forceDelete = false) => {
try {
const isNotificationsSettingsEnabled = await isNotificationsEnabled();
if (isNotificationsSettingsEnabled) {
const externalAddresses = wallet.getAllExternalAddresses();
if (externalAddresses.length > 0) {
await unsubscribe(externalAddresses, [], []);
}
}
deleteWallet(wallet);
saveToDisk(true);
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
popToTop();
} catch (e: unknown) {
console.error(e);
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
if (forceDelete) {
deleteWallet(wallet);
saveToDisk(true);
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
popToTop();
} else {
presentAlert({
title: loc.errors.error,
message: loc.wallets.details_delete_wallet_error_message,
buttons: [
{
text: loc.wallets.details_delete_anyway,
onPress: () => handleWalletDeletion(true),
style: 'destructive',
},
{
text: loc.wallets.list_tryagain,
onPress: () => handleWalletDeletion(),
},
{
text: loc._.cancel,
onPress: () => setIsLoading(false),
style: 'cancel',
},
],
options: { cancelable: false },
});
}
}
deleteWallet(wallet);
saveToDisk(true);
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
popToTop();
} catch (e: unknown) {
console.error(e);
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
presentAlert({ message: (e as Error).message });
setIsLoading(false);
}
}, [deleteWallet, saveToDisk, wallet]);
},
[deleteWallet, saveToDisk, wallet],
);
const navigateToOverviewAndDeleteWallet = useCallback(() => {
setIsLoading(true);
handleWalletDeletion();
}, [handleWalletDeletion]);
const presentWalletHasBalanceAlert = useCallback(async () => {
triggerHapticFeedback(HapticFeedbackTypes.NotificationWarning);
@ -137,10 +171,10 @@ const WalletDetails: React.FC = () => {
const handleDeleteButtonTapped = useCallback(() => {
triggerHapticFeedback(HapticFeedbackTypes.NotificationWarning);
Alert.alert(
loc.wallets.details_delete_wallet,
loc.wallets.details_are_you_sure,
[
presentAlert({
title: loc.wallets.details_delete_wallet,
message: loc.wallets.details_are_you_sure,
buttons: [
{
text: loc.wallets.details_yes_delete,
onPress: async () => {
@ -161,8 +195,8 @@ const WalletDetails: React.FC = () => {
},
{ text: loc.wallets.details_no_cancel, onPress: () => {}, style: 'cancel' },
],
{ cancelable: false },
);
options: { cancelable: false },
});
}, [isBiometricUseCapableAndEnabled, navigateToOverviewAndDeleteWallet, presentWalletHasBalanceAlert, wallet]);
const exportHistoryContent = useCallback(() => {