2017-06-06 23:19:12 +02:00
|
|
|
import * as types from "constants/action_types";
|
|
|
|
import lbry from "lbry";
|
|
|
|
import lbryio from "lbryio";
|
2017-11-13 22:02:23 +01:00
|
|
|
import { doResolveUri } from "redux/actions/content";
|
|
|
|
import { selectResolvingUris } from "redux/selectors/content";
|
|
|
|
import { selectClaimsByUri } from "redux/selectors/claims";
|
|
|
|
import { selectSettingsIsGenerous } from "redux/selectors/settings";
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
export function doFetchCostInfoForUri(uri) {
|
2017-04-28 17:14:44 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-05-17 23:52:45 +02:00
|
|
|
const state = getState(),
|
2017-06-06 23:19:12 +02:00
|
|
|
claim = selectClaimsByUri(state)[uri],
|
|
|
|
isGenerous = selectSettingsIsGenerous(state);
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2017-06-10 19:17:37 +02:00
|
|
|
if (!claim) return null;
|
2017-05-17 23:52:45 +02:00
|
|
|
|
|
|
|
function begin() {
|
2017-04-28 17:14:44 +02:00
|
|
|
dispatch({
|
2017-05-17 23:52:45 +02:00
|
|
|
type: types.FETCH_COST_INFO_STARTED,
|
2017-04-28 17:14:44 +02:00
|
|
|
data: {
|
|
|
|
uri,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
});
|
2017-05-17 23:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resolve(costInfo) {
|
2017-05-12 01:28:43 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_COST_INFO_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
2017-05-17 23:52:45 +02:00
|
|
|
costInfo,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
});
|
2017-05-17 23:52:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-20 19:20:02 +02:00
|
|
|
/**
|
|
|
|
* "Generous" check below is disabled. We're no longer attempting to include or estimate data fees regardless of settings.
|
|
|
|
*
|
|
|
|
* This should be modified when lbry.stream_cost_estimate is reliable and performant.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
lbry.stream_cost_estimate({ uri }).then(cost => {
|
|
|
|
cacheAndResolve(cost);
|
|
|
|
}, reject);
|
|
|
|
*/
|
|
|
|
|
|
|
|
const fee = claim.value && claim.value.stream && claim.value.stream.metadata
|
|
|
|
? claim.value.stream.metadata.fee
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
if (fee === undefined) {
|
|
|
|
resolve({ cost: 0, includesData: true });
|
|
|
|
} else if (fee.currency == "LBC") {
|
|
|
|
resolve({ cost: fee.amount, includesData: true });
|
2017-05-17 23:52:45 +02:00
|
|
|
} else {
|
2017-09-20 19:20:02 +02:00
|
|
|
// begin();
|
|
|
|
lbryio.getExchangeRates().then(({ lbc_usd }) => {
|
|
|
|
resolve({ cost: fee.amount / lbc_usd, includesData: true });
|
|
|
|
});
|
2017-05-17 23:52:45 +02:00
|
|
|
}
|
2017-09-20 19:20:02 +02:00
|
|
|
|
|
|
|
// if (isGenerous && claim) {
|
|
|
|
// let cost;
|
|
|
|
// const fee = claim.value &&
|
|
|
|
// claim.value.stream &&
|
|
|
|
// claim.value.stream.metadata
|
|
|
|
// ? claim.value.stream.metadata.fee
|
|
|
|
// : undefined;
|
|
|
|
// if (fee === undefined) {
|
|
|
|
// resolve({ cost: 0, includesData: true });
|
|
|
|
// } else if (fee.currency == "LBC") {
|
|
|
|
// resolve({ cost: fee.amount, includesData: true });
|
|
|
|
// } else {
|
|
|
|
// // begin();
|
|
|
|
// lbryio.getExchangeRates().then(({ lbc_usd }) => {
|
|
|
|
// resolve({ cost: fee.amount / lbc_usd, includesData: true });
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// begin();
|
|
|
|
// lbry.getCostInfo(uri).then(resolve);
|
|
|
|
// }
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-28 17:14:44 +02:00
|
|
|
}
|