lbry-desktop/src/renderer/redux/actions/cost_info.js

39 lines
1 KiB
JavaScript
Raw Normal View History

import * as ACTIONS from 'constants/action_types';
import Lbryio from 'lbryio';
import { selectClaimsByUri } from 'redux/selectors/claims';
2017-04-28 17:14:44 +02:00
// eslint-disable-next-line import/prefer-default-export
export function doFetchCostInfoForUri(uri) {
2017-04-28 17:14:44 +02:00
return function(dispatch, getState) {
const state = getState();
const claim = selectClaimsByUri(state)[uri];
if (!claim) return;
function resolve(costInfo) {
2017-05-12 01:28:43 +02:00
dispatch({
type: ACTIONS.FETCH_COST_INFO_COMPLETED,
2017-05-12 01:28:43 +02:00
data: {
uri,
costInfo,
2017-06-06 23:19:12 +02:00
},
});
}
2017-11-21 20:51:12 +01:00
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 {
Lbryio.getExchangeRates().then(({ LBC_USD }) => {
resolve({ cost: fee.amount / LBC_USD, includesData: true });
});
}
2017-06-06 23:19:12 +02:00
};
2017-04-28 17:14:44 +02:00
}