Fix doAbandonClaim (#699) (#7422)

* Refactor doAbandonClaim parameters to only claim

- Gets txid and nout by default now, and passing claim allows using more data to verify ownership in case of txid:nout failing again
- Unused on modalRemoveCard
- Edited the comment on doCollectionDelete to explain better

* Fix doAbandonClaim failing to select my claim

Co-authored-by: saltrafael <76502841+saltrafael@users.noreply.github.com>
This commit is contained in:
jessopb 2022-01-19 20:54:01 -05:00 committed by GitHub
parent c7021a08ad
commit 4f6befc0ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 27 deletions

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { doHideModal } from 'redux/actions/app';
import { doAbandonTxo, doAbandonClaim, doResolveUri } from 'redux/actions/claims';
import { doAbandonTxo, doResolveUri } from 'redux/actions/claims';
import { selectTransactionItems } from 'redux/selectors/wallet';
import { doToast } from 'redux/actions/notifications';
import ModalRevokeClaim from './view';
@ -13,7 +13,6 @@ const perform = (dispatch) => ({
toast: (message, isError) => dispatch(doToast({ message, isError })),
closeModal: () => dispatch(doHideModal()),
abandonTxo: (txo, cb) => dispatch(doAbandonTxo(txo, cb)),
abandonClaim: (txid, nout, cb) => dispatch(doAbandonClaim(txid, nout, cb)),
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
});

View file

@ -20,8 +20,8 @@ const select = (state, props) => ({
const perform = (dispatch) => ({
closeModal: () => dispatch(doHideModal()),
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
deleteFile: (uri, deleteFromComputer, abandonClaim, doGoBack) => {
dispatch(doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, doGoBack));
deleteFile: (uri, deleteFromComputer, abandonClaim, doGoBack, claim) => {
dispatch(doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, doGoBack, claim));
},
});

View file

@ -14,7 +14,7 @@ type Props = {
claimIsMine: boolean,
doResolveUri: (string) => void,
closeModal: () => void,
deleteFile: (string, boolean, boolean, boolean) => void,
deleteFile: (string, boolean, boolean, boolean, any) => void,
doGoBack: boolean,
title: string,
fileInfo?: {
@ -93,7 +93,7 @@ function ModalRemoveFile(props: Props) {
button="primary"
label={isAbandoning ? __('Removing...') : __('OK')}
disabled={isAbandoning || !(deleteChecked || abandonChecked)}
onClick={() => deleteFile(uri, deleteChecked, claimIsMine ? abandonChecked : false, doGoBack)}
onClick={() => deleteFile(uri, deleteChecked, claimIsMine ? abandonChecked : false, doGoBack, claim)}
/>
<Button button="link" label={__('Cancel')} onClick={closeModal} />
</div>

View file

@ -13,7 +13,7 @@ const perform = (dispatch) => ({
toast: (message, isError) => dispatch(doToast({ message, isError })),
closeModal: () => dispatch(doHideModal()),
abandonTxo: (txo, cb) => dispatch(doAbandonTxo(txo, cb)),
abandonClaim: (txid, nout, cb) => dispatch(doAbandonClaim(txid, nout, cb)),
abandonClaim: (claim, cb) => dispatch(doAbandonClaim(claim, cb)),
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
});

View file

@ -11,9 +11,9 @@ import LbcSymbol from 'component/common/lbc-symbol';
type Props = {
closeModal: () => void,
abandonTxo: (Txo, () => void) => void,
abandonClaim: (string, number, ?() => void) => void,
abandonClaim: (Claim, ?() => void) => void,
tx: Txo,
claim: GenericClaim,
claim: Claim,
cb: () => void,
doResolveUri: (string) => void,
};
@ -94,7 +94,7 @@ export default function ModalRevokeClaim(props: Props) {
}
function revokeClaim() {
tx ? abandonTxo(tx, cb) : abandonClaim(claim.txid, claim.nout, cb);
tx ? abandonTxo(tx, cb) : abandonClaim(claim, cb);
closeModal();
}

View file

@ -10,6 +10,7 @@ import {
selectClaimsByUri,
selectMyChannelClaims,
selectPendingClaimsById,
selectClaimIsMine,
} from 'redux/selectors/claims';
import { doFetchTxoPage } from 'redux/actions/wallet';
@ -264,7 +265,8 @@ export function doAbandonTxo(txo: Txo, cb: (string) => void) {
};
}
export function doAbandonClaim(txid: string, nout: number, cb: (string) => void) {
export function doAbandonClaim(claim: Claim, cb: (string) => void) {
const { txid, nout } = claim;
const outpoint = `${txid}:${nout}`;
return (dispatch: Dispatch, getState: GetState) => {
@ -273,7 +275,8 @@ export function doAbandonClaim(txid: string, nout: number, cb: (string) => void)
const mySupports: { [string]: Support } = selectSupportsByOutpoint(state);
// A user could be trying to abandon a support or one of their claims
const claimToAbandon = myClaims.find((claim) => claim.txid === txid && claim.nout === nout);
const claimIsMine = selectClaimIsMine(state, claim);
const claimToAbandon = claimIsMine ? claim : myClaims.find((claim) => claim.txid === txid && claim.nout === nout);
const supportToAbandon = mySupports[outpoint];
if (!claimToAbandon && !supportToAbandon) {

View file

@ -55,9 +55,8 @@ export const doCollectionDelete = (id: string, colKey: ?string = undefined) => (
},
});
if (claim && !colKey) {
// could support "abandon, but keep" later
const { txid, nout } = claim;
return dispatch(doAbandonClaim(txid, nout, collectionDelete));
// could support "abandon collection claim, but keep private collection" later
return dispatch(doAbandonClaim(claim, collectionDelete));
}
return collectionDelete();
};

View file

@ -38,11 +38,16 @@ export function doOpenFileInShell(path: string) {
};
}
export function doDeleteFile(outpoint: string, deleteFromComputer?: boolean, abandonClaim?: boolean, cb: any) {
export function doDeleteFile(
outpoint: string,
deleteFromComputer?: boolean,
abandonClaim?: boolean,
cb: any,
claim: Claim
) {
return (dispatch: Dispatch) => {
if (abandonClaim) {
const [txid, nout] = outpoint.split(':');
dispatch(doAbandonClaim(txid, Number(nout), cb));
dispatch(doAbandonClaim(claim, cb));
}
// @if TARGET='app'
@ -65,7 +70,8 @@ export function doDeleteFileAndMaybeGoBack(
uri: string,
deleteFromComputer?: boolean,
abandonClaim?: boolean,
doGoBack: (any) => void
doGoBack: (any) => void,
claim: Claim
) {
return (dispatch: Dispatch, getState: GetState) => {
const state = getState();
@ -80,16 +86,22 @@ export function doDeleteFileAndMaybeGoBack(
}
actions.push(
doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim, (abandonState) => {
if (abandonState === ABANDON_STATES.DONE) {
if (abandonClaim) {
if (doGoBack) {
dispatch(goBack());
doDeleteFile(
outpoint || claimOutpoint,
deleteFromComputer,
abandonClaim,
(abandonState) => {
if (abandonState === ABANDON_STATES.DONE) {
if (abandonClaim) {
if (doGoBack) {
dispatch(goBack());
}
dispatch(doHideModal());
}
dispatch(doHideModal());
}
}
})
},
claim
)
);
if (playingUri && playingUri.uri === uri) {