Stop cost info getting into an infinite loop

This commit is contained in:
6ea86b96 2017-06-05 15:37:37 +07:00
parent f97ec7b390
commit c023a41a28
3 changed files with 16 additions and 19 deletions

View file

@ -10,23 +10,9 @@ export function doFetchCostInfoForUri(uri) {
return function(dispatch, getState) {
const state = getState(),
claim = selectClaimsByUri(state)[uri],
isResolving = selectResolvingUris(state).indexOf(uri) !== -1,
isGenerous = selectSettingsIsGenerous(state);
if (claim === null) {
//claim doesn't exist, nothing to fetch a cost for
return;
}
if (!claim) {
setTimeout(() => {
dispatch(doFetchCostInfoForUri(uri));
}, 1000);
if (!isResolving) {
dispatch(doResolveUri(uri));
}
return;
}
if (!claim) return null
function begin() {
dispatch({

View file

@ -4,16 +4,21 @@ import { doFetchCostInfoForUri } from "actions/cost_info";
import {
makeSelectCostInfoForUri,
makeSelectFetchingCostInfoForUri,
} from "selectors/cost_info";
import FilePrice from "./view";
} from 'selectors/cost_info'
import {
makeSelectClaimForUri,
} from 'selectors/claims'
import FilePrice from './view'
const makeSelect = () => {
const selectCostInfoForUri = makeSelectCostInfoForUri();
const selectFetchingCostInfoForUri = makeSelectFetchingCostInfoForUri();
const selectClaim = makeSelectClaimForUri();
const select = (state, props) => ({
costInfo: selectCostInfoForUri(state, props),
fetching: selectFetchingCostInfoForUri(state, props),
claim: selectClaim(state, props),
});
return select;

View file

@ -11,9 +11,15 @@ class FilePrice extends React.Component {
}
fetchCost(props) {
const { costInfo, fetchCostInfo, uri, fetching } = props;
const {
costInfo,
fetchCostInfo,
uri,
fetching,
claim,
} = props;
if (costInfo === undefined && !fetching) {
if (costInfo === undefined && !fetching && claim) {
fetchCostInfo(uri);
}
}