2021-10-08 05:47:39 +02:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
import { Lbryio } from 'lbryinc';
|
2022-01-30 00:25:40 +01:00
|
|
|
import { selectClaimForUri } from 'redux/selectors/claims';
|
2021-10-08 05:47:39 +02:00
|
|
|
|
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
|
|
export function doFetchCostInfoForUri(uri) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
2022-01-30 00:25:40 +01:00
|
|
|
const claim = selectClaimForUri(state, uri);
|
2021-10-08 05:47:39 +02:00
|
|
|
|
|
|
|
if (!claim) return;
|
|
|
|
|
|
|
|
function resolve(costInfo) {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.FETCH_COST_INFO_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
costInfo,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const fee = claim.value ? claim.value.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 });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|