Skip to content

Commit

Permalink
Account deletion - minor fixes (#2963)
Browse files Browse the repository at this point in the history
* 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 <sauce47@posteo.net>
  • Loading branch information
keikari and miko authored Sep 10, 2023
1 parent 74820ff commit 312570c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ui/modal/modalRemoveAccount/thunk.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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());
}

Expand Down
8 changes: 6 additions & 2 deletions ui/redux/actions/memberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};

Expand Down
6 changes: 5 additions & 1 deletion ui/redux/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 312570c

Please sign in to comment.