Merge pull request #2696 from BlueWallet/deletefix

FIX: Wallet delete would cause crash
This commit is contained in:
GLaDOS 2021-02-25 01:39:00 +00:00 committed by GitHub
commit 74a0018acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View File

@ -21,11 +21,17 @@ function WatchConnectivity() {
useEffect(() => {
if (isInstalled && isReachable && walletsInitialized) {
sendWalletsToWatch();
watchEvents.on('message', handleMessages);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletsInitialized, wallets, preferredFiatCurrency, isReachable, isInstalled]);
}, [walletsInitialized, isReachable, isInstalled]);
useEffect(() => {
if (isInstalled && isReachable && walletsInitialized) {
sendWalletsToWatch();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletsInitialized, wallets, isReachable, isInstalled]);
useEffect(() => {
if (isInstalled && isReachable && walletsInitialized && preferredFiatCurrency) {
@ -33,11 +39,13 @@ function WatchConnectivity() {
transferCurrentComplicationUserInfo({
preferredFiatCurrency: JSON.parse(preferredFiatCurrency).endPointKey,
});
sendWalletsToWatch();
} catch (e) {
console.log('WatchConnectivity useEffect preferredFiatCurrency error');
console.log(e);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [preferredFiatCurrency, walletsInitialized, isReachable, isInstalled]);
const handleMessages = (message, reply) => {

View File

@ -168,6 +168,15 @@ const WalletDetails = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletID]);
const navigateToOverviewAndDeleteWallet = () => {
setIsLoading(true);
Notifications.unsubscribe(wallet.getAllExternalAddresses(), [], []);
popToTop();
deleteWallet(wallet);
saveToDisk();
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
};
const presentWalletHasBalanceAlert = useCallback(async () => {
ReactNativeHapticFeedback.trigger('notificationWarning', { ignoreAndroidSystemSettings: false });
try {
@ -178,12 +187,7 @@ const WalletDetails = () => {
'plain-text',
);
if (Number(walletBalanceConfirmation) === wallet.getBalance()) {
setIsLoading(true);
Notifications.unsubscribe(wallet.getAllExternalAddresses(), [], []);
deleteWallet(wallet);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
await saveToDisk();
popToTop();
navigateToOverviewAndDeleteWallet();
} else {
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
setIsLoading(false);
@ -191,7 +195,7 @@ const WalletDetails = () => {
}
} catch (_) {}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [popToTop, wallet]);
}, []);
const navigateToWalletExport = () => {
navigate('WalletExportRoot', {
@ -374,12 +378,7 @@ const WalletDetails = () => {
if (wallet.getBalance() > 0 && wallet.allowSend()) {
presentWalletHasBalanceAlert();
} else {
setIsLoading(true);
Notifications.unsubscribe(wallet.getAllExternalAddresses(), [], []);
popToTop();
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
deleteWallet(wallet);
saveToDisk();
navigateToOverviewAndDeleteWallet();
}
},
style: 'destructive',