From 312570c47bb1de6f8239f23ba493aa12dc6444d6 Mon Sep 17 00:00:00 2001 From: miko <34790748+keikari@users.noreply.github.com> Date: Sun, 10 Sep 2023 15:29:00 +0300 Subject: [PATCH] Account deletion - minor fixes (#2963) * Consider 'this subscription is no longer active' error as a successful membership cancellation This seems to happen if membership subscription has cancelled itself due to issues with payments. (Those are still returned by `selectMyActiveMembershipsById`) * Consider 'a delete operation is already in progress' response as a successful accoutn deletion * Update balance before `doSendCreditsToOdysee` --------- Co-authored-by: miko --- ui/modal/modalRemoveAccount/thunk.js | 3 ++- ui/redux/actions/memberships.js | 8 ++++++-- ui/redux/actions/user.js | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ui/modal/modalRemoveAccount/thunk.js b/ui/modal/modalRemoveAccount/thunk.js index 8900c0266f..b954850ae1 100644 --- a/ui/modal/modalRemoveAccount/thunk.js +++ b/ui/modal/modalRemoveAccount/thunk.js @@ -1,6 +1,6 @@ // @flow import analytics from 'analytics'; -import { doSpendEverything, doSendCreditsToOdysee } from 'redux/actions/wallet'; +import { doUpdateBalance, doSpendEverything, doSendCreditsToOdysee } from 'redux/actions/wallet'; import { doUserFetch, doUserDeleteAccount } from 'redux/actions/user'; import { selectTotalBalance } from 'redux/selectors/wallet'; import { selectMyActiveMembershipsById } from 'redux/selectors/memberships'; @@ -54,6 +54,7 @@ export function doRemoveAccountSequence() { if (!isWalletEmpty) { await dispatch(doSpendEverything()); await new Promise((res) => setTimeout(res, 5000)); // Hoping the timeout helps to avoid using outputs already spend in txo_spend + await dispatch(doUpdateBalance()); await dispatch(doSendCreditsToOdysee()); } diff --git a/ui/redux/actions/memberships.js b/ui/redux/actions/memberships.js index 6270eac188..b1d6b029b6 100644 --- a/ui/redux/actions/memberships.js +++ b/ui/redux/actions/memberships.js @@ -181,8 +181,12 @@ export const doMembershipCancelForMembershipId = (membershipId: number) => async return response; }) .catch((e) => { - dispatch({ type: ACTIONS.SET_MEMBERSHIP_CANCEL_FAILED, data: membershipId }); - throw new Error(e); + if (e.message === 'this subscription is no longer active') { + dispatch({ type: ACTIONS.SET_MEMBERSHIP_CANCEL_SUCCESFUL, data: membershipId }); + } else { + dispatch({ type: ACTIONS.SET_MEMBERSHIP_CANCEL_FAILED, data: membershipId }); + throw new Error(e); + } }); }; diff --git a/ui/redux/actions/user.js b/ui/redux/actions/user.js index b1430127d9..bd5f2bae89 100644 --- a/ui/redux/actions/user.js +++ b/ui/redux/actions/user.js @@ -526,7 +526,11 @@ export function doUserDeleteAccount() { dispatch({ type: ACTIONS.USER_DELETION_COMPLETED, }); - throw error; + if (error.message === 'a delete operation is already in progress') { + // Don't throw error + } else { + throw error; + } }; await Lbryio.call('user', 'delete', {}, 'post').then(success, failure);