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 22:14:44 +07:00
// eslint-disable-next-line import/prefer-default-export
export function doFetchCostInfoForUri(uri) {
return (dispatch, getState) => {
const state = getState();
const claim = selectClaimsByUri(state)[uri];
if (!claim) return;
function resolve(costInfo) {
2017-05-11 19:28:43 -04:00
dispatch({
type: ACTIONS.FETCH_COST_INFO_COMPLETED,
2017-05-11 19:28:43 -04:00
data: {
uri,
costInfo,
2017-06-06 17:19:12 -04:00
},
});
}
2017-11-21 16:51:12 -03: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 17:19:12 -04:00
};
2017-04-28 22:14:44 +07:00
}