Fix doAbandonClaim (#699)
* 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
This commit is contained in:
parent
ae976c377e
commit
b810e07053
8 changed files with 40 additions and 27 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { doHideModal } from 'redux/actions/app';
|
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 { selectTransactionItems } from 'redux/selectors/wallet';
|
||||||
import { doToast } from 'redux/actions/notifications';
|
import { doToast } from 'redux/actions/notifications';
|
||||||
import ModalRevokeClaim from './view';
|
import ModalRevokeClaim from './view';
|
||||||
|
@ -13,7 +13,6 @@ const perform = (dispatch) => ({
|
||||||
toast: (message, isError) => dispatch(doToast({ message, isError })),
|
toast: (message, isError) => dispatch(doToast({ message, isError })),
|
||||||
closeModal: () => dispatch(doHideModal()),
|
closeModal: () => dispatch(doHideModal()),
|
||||||
abandonTxo: (txo, cb) => dispatch(doAbandonTxo(txo, cb)),
|
abandonTxo: (txo, cb) => dispatch(doAbandonTxo(txo, cb)),
|
||||||
abandonClaim: (txid, nout, cb) => dispatch(doAbandonClaim(txid, nout, cb)),
|
|
||||||
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
|
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ const select = (state, props) => ({
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
closeModal: () => dispatch(doHideModal()),
|
closeModal: () => dispatch(doHideModal()),
|
||||||
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
|
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
|
||||||
deleteFile: (uri, deleteFromComputer, abandonClaim, doGoBack) => {
|
deleteFile: (uri, deleteFromComputer, abandonClaim, doGoBack, claim) => {
|
||||||
dispatch(doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, doGoBack));
|
dispatch(doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, doGoBack, claim));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ type Props = {
|
||||||
claimIsMine: boolean,
|
claimIsMine: boolean,
|
||||||
doResolveUri: (string) => void,
|
doResolveUri: (string) => void,
|
||||||
closeModal: () => void,
|
closeModal: () => void,
|
||||||
deleteFile: (string, boolean, boolean, boolean) => void,
|
deleteFile: (string, boolean, boolean, boolean, any) => void,
|
||||||
doGoBack: boolean,
|
doGoBack: boolean,
|
||||||
title: string,
|
title: string,
|
||||||
fileInfo?: {
|
fileInfo?: {
|
||||||
|
@ -93,7 +93,7 @@ function ModalRemoveFile(props: Props) {
|
||||||
button="primary"
|
button="primary"
|
||||||
label={isAbandoning ? __('Removing...') : __('OK')}
|
label={isAbandoning ? __('Removing...') : __('OK')}
|
||||||
disabled={isAbandoning || !(deleteChecked || abandonChecked)}
|
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} />
|
<Button button="link" label={__('Cancel')} onClick={closeModal} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,7 +13,7 @@ const perform = (dispatch) => ({
|
||||||
toast: (message, isError) => dispatch(doToast({ message, isError })),
|
toast: (message, isError) => dispatch(doToast({ message, isError })),
|
||||||
closeModal: () => dispatch(doHideModal()),
|
closeModal: () => dispatch(doHideModal()),
|
||||||
abandonTxo: (txo, cb) => dispatch(doAbandonTxo(txo, cb)),
|
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)),
|
doResolveUri: (uri) => dispatch(doResolveUri(uri)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ import LbcSymbol from 'component/common/lbc-symbol';
|
||||||
type Props = {
|
type Props = {
|
||||||
closeModal: () => void,
|
closeModal: () => void,
|
||||||
abandonTxo: (Txo, () => void) => void,
|
abandonTxo: (Txo, () => void) => void,
|
||||||
abandonClaim: (string, number, ?() => void) => void,
|
abandonClaim: (Claim, ?() => void) => void,
|
||||||
tx: Txo,
|
tx: Txo,
|
||||||
claim: GenericClaim,
|
claim: Claim,
|
||||||
cb: () => void,
|
cb: () => void,
|
||||||
doResolveUri: (string) => void,
|
doResolveUri: (string) => void,
|
||||||
};
|
};
|
||||||
|
@ -94,7 +94,7 @@ export default function ModalRevokeClaim(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function revokeClaim() {
|
function revokeClaim() {
|
||||||
tx ? abandonTxo(tx, cb) : abandonClaim(claim.txid, claim.nout, cb);
|
tx ? abandonTxo(tx, cb) : abandonClaim(claim, cb);
|
||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
selectClaimsByUri,
|
selectClaimsByUri,
|
||||||
selectMyChannelClaims,
|
selectMyChannelClaims,
|
||||||
selectPendingClaimsById,
|
selectPendingClaimsById,
|
||||||
|
selectClaimIsMine,
|
||||||
} from 'redux/selectors/claims';
|
} from 'redux/selectors/claims';
|
||||||
|
|
||||||
import { doFetchTxoPage } from 'redux/actions/wallet';
|
import { doFetchTxoPage } from 'redux/actions/wallet';
|
||||||
|
@ -263,7 +264,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}`;
|
const outpoint = `${txid}:${nout}`;
|
||||||
|
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch, getState: GetState) => {
|
||||||
|
@ -272,7 +274,8 @@ export function doAbandonClaim(txid: string, nout: number, cb: (string) => void)
|
||||||
const mySupports: { [string]: Support } = selectSupportsByOutpoint(state);
|
const mySupports: { [string]: Support } = selectSupportsByOutpoint(state);
|
||||||
|
|
||||||
// A user could be trying to abandon a support or one of their claims
|
// 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];
|
const supportToAbandon = mySupports[outpoint];
|
||||||
|
|
||||||
if (!claimToAbandon && !supportToAbandon) {
|
if (!claimToAbandon && !supportToAbandon) {
|
||||||
|
|
|
@ -55,9 +55,8 @@ export const doCollectionDelete = (id: string, colKey: ?string = undefined) => (
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (claim && !colKey) {
|
if (claim && !colKey) {
|
||||||
// could support "abandon, but keep" later
|
// could support "abandon collection claim, but keep private collection" later
|
||||||
const { txid, nout } = claim;
|
return dispatch(doAbandonClaim(claim, collectionDelete));
|
||||||
return dispatch(doAbandonClaim(txid, nout, collectionDelete));
|
|
||||||
}
|
}
|
||||||
return collectionDelete();
|
return collectionDelete();
|
||||||
};
|
};
|
||||||
|
|
|
@ -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) => {
|
return (dispatch: Dispatch) => {
|
||||||
if (abandonClaim) {
|
if (abandonClaim) {
|
||||||
const [txid, nout] = outpoint.split(':');
|
dispatch(doAbandonClaim(claim, cb));
|
||||||
dispatch(doAbandonClaim(txid, Number(nout), cb));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
|
@ -65,7 +70,8 @@ export function doDeleteFileAndMaybeGoBack(
|
||||||
uri: string,
|
uri: string,
|
||||||
deleteFromComputer?: boolean,
|
deleteFromComputer?: boolean,
|
||||||
abandonClaim?: boolean,
|
abandonClaim?: boolean,
|
||||||
doGoBack: (any) => void
|
doGoBack: (any) => void,
|
||||||
|
claim: Claim
|
||||||
) {
|
) {
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch, getState: GetState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -80,16 +86,22 @@ export function doDeleteFileAndMaybeGoBack(
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.push(
|
actions.push(
|
||||||
doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim, (abandonState) => {
|
doDeleteFile(
|
||||||
if (abandonState === ABANDON_STATES.DONE) {
|
outpoint || claimOutpoint,
|
||||||
if (abandonClaim) {
|
deleteFromComputer,
|
||||||
if (doGoBack) {
|
abandonClaim,
|
||||||
dispatch(goBack());
|
(abandonState) => {
|
||||||
|
if (abandonState === ABANDON_STATES.DONE) {
|
||||||
|
if (abandonClaim) {
|
||||||
|
if (doGoBack) {
|
||||||
|
dispatch(goBack());
|
||||||
|
}
|
||||||
|
dispatch(doHideModal());
|
||||||
}
|
}
|
||||||
dispatch(doHideModal());
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
claim
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (playingUri && playingUri.uri === uri) {
|
if (playingUri && playingUri.uri === uri) {
|
||||||
|
|
Loading…
Reference in a new issue