remove the uri from the failed list if the user reattempts getting the same uri #151

Merged
akinwale merged 5 commits from purchase-uri-failures into master 2019-05-27 15:59:21 +02:00
8 changed files with 133 additions and 10 deletions

53
dist/bundle.es.js vendored
View file

@ -119,6 +119,7 @@ const SET_FILE_LIST_SORT = 'SET_FILE_LIST_SORT';
const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED'; const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED';
const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED'; const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED';
const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED'; const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED';
const DELETE_PURCHASED_URI = 'DELETE_PURCHASED_URI';
const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED'; const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED';
const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED'; const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED';
const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED'; const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED';
@ -341,6 +342,7 @@ var action_types = /*#__PURE__*/Object.freeze({
PURCHASE_URI_STARTED: PURCHASE_URI_STARTED, PURCHASE_URI_STARTED: PURCHASE_URI_STARTED,
PURCHASE_URI_COMPLETED: PURCHASE_URI_COMPLETED, PURCHASE_URI_COMPLETED: PURCHASE_URI_COMPLETED,
PURCHASE_URI_FAILED: PURCHASE_URI_FAILED, PURCHASE_URI_FAILED: PURCHASE_URI_FAILED,
DELETE_PURCHASED_URI: DELETE_PURCHASED_URI,
LOADING_FILE_STARTED: LOADING_FILE_STARTED, LOADING_FILE_STARTED: LOADING_FILE_STARTED,
LOADING_FILE_COMPLETED: LOADING_FILE_COMPLETED, LOADING_FILE_COMPLETED: LOADING_FILE_COMPLETED,
LOADING_FILE_FAILED: LOADING_FILE_FAILED, LOADING_FILE_FAILED: LOADING_FILE_FAILED,
@ -2319,6 +2321,8 @@ const selectFileListDownloadedSort = reselect.createSelector(selectState$3, stat
const selectState$4 = state => state.file || {}; const selectState$4 = state => state.file || {};
const selectPurchaseUriErrorMessage = reselect.createSelector(selectState$4, state => state.purchaseUriErrorMessage);
const selectFailedPurchaseUris = reselect.createSelector(selectState$4, state => state.failedPurchaseUris); const selectFailedPurchaseUris = reselect.createSelector(selectState$4, state => state.failedPurchaseUris);
const selectPurchasedUris = reselect.createSelector(selectState$4, state => state.purchasedUris); const selectPurchasedUris = reselect.createSelector(selectState$4, state => state.purchasedUris);
@ -2404,8 +2408,7 @@ function doPurchaseUri(uri, costInfo, saveFile = true) {
} }
const { cost } = costInfo; const { cost } = costInfo;
if (parseFloat(cost) > balance) {
if (cost > balance) {
dispatch({ dispatch({
type: PURCHASE_URI_FAILED, type: PURCHASE_URI_FAILED,
data: { uri, error: 'Insufficient credits' } data: { uri, error: 'Insufficient credits' }
@ -2417,6 +2420,13 @@ function doPurchaseUri(uri, costInfo, saveFile = true) {
}; };
} }
function doDeletePurchasedUri(uri) {
return {
type: DELETE_PURCHASED_URI,
data: { uri }
};
}
function doFetchFileInfo(uri) { function doFetchFileInfo(uri) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
@ -2914,7 +2924,21 @@ const reducers$1 = {};
const defaultState$1 = { const defaultState$1 = {
failedPurchaseUris: [], failedPurchaseUris: [],
purchasedUris: [], purchasedUris: [],
purchasedStreamingUrls: {} purchasedStreamingUrls: {},
purchaseUriErrorMessage: ''
};
reducers$1[PURCHASE_URI_STARTED] = (state, action) => {
const { uri } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.splice(newFailedPurchaseUris.indexOf(uri), 1);
}
return _extends$4({}, state, {
failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: ''
});
}; };
reducers$1[PURCHASE_URI_COMPLETED] = (state, action) => { reducers$1[PURCHASE_URI_COMPLETED] = (state, action) => {
@ -2936,19 +2960,34 @@ reducers$1[PURCHASE_URI_COMPLETED] = (state, action) => {
return _extends$4({}, state, { return _extends$4({}, state, {
failedPurchaseUris: newFailedPurchaseUris, failedPurchaseUris: newFailedPurchaseUris,
purchasedUris: newPurchasedUris, purchasedUris: newPurchasedUris,
purchasedStreamingUrls: newPurchasedStreamingUrls purchasedStreamingUrls: newPurchasedStreamingUrls,
purchaseUriErrorMessage: ''
}); });
}; };
reducers$1[PURCHASE_URI_FAILED] = (state, action) => { reducers$1[PURCHASE_URI_FAILED] = (state, action) => {
const { uri } = action.data; const { uri, error } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice(); const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (!newFailedPurchaseUris.includes(uri)) { if (!newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.push(uri); newFailedPurchaseUris.push(uri);
} }
return _extends$4({}, state, { return _extends$4({}, state, {
failedPurchaseUris: newFailedPurchaseUris failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: error
});
};
reducers$1[DELETE_PURCHASED_URI] = (state, action) => {
const { uri } = action.data;
const newPurchasedUris = state.purchasedUris.slice();
if (newPurchasedUris.includes(uri)) {
newPurchasedUris.splice(newPurchasedUris.indexOf(uri), 1);
}
return _extends$4({}, state, {
purchasedUris: newPurchasedUris
}); });
}; };
@ -3651,6 +3690,7 @@ exports.doBalanceSubscribe = doBalanceSubscribe;
exports.doBlurSearchInput = doBlurSearchInput; exports.doBlurSearchInput = doBlurSearchInput;
exports.doCheckAddressIsMine = doCheckAddressIsMine; exports.doCheckAddressIsMine = doCheckAddressIsMine;
exports.doCreateChannel = doCreateChannel; exports.doCreateChannel = doCreateChannel;
exports.doDeletePurchasedUri = doDeletePurchasedUri;
exports.doDismissError = doDismissError; exports.doDismissError = doDismissError;
exports.doDismissToast = doDismissToast; exports.doDismissToast = doDismissToast;
exports.doError = doError; exports.doError = doError;
@ -3772,6 +3812,7 @@ exports.selectMyClaimsWithoutChannels = selectMyClaimsWithoutChannels;
exports.selectPendingById = selectPendingById; exports.selectPendingById = selectPendingById;
exports.selectPendingClaims = selectPendingClaims; exports.selectPendingClaims = selectPendingClaims;
exports.selectPlayingUri = selectPlayingUri; exports.selectPlayingUri = selectPlayingUri;
exports.selectPurchaseUriErrorMessage = selectPurchaseUriErrorMessage;
exports.selectPurchasedStreamingUrls = selectPurchasedStreamingUrls; exports.selectPurchasedStreamingUrls = selectPurchasedStreamingUrls;
exports.selectPurchasedUris = selectPurchasedUris; exports.selectPurchasedUris = selectPurchasedUris;
exports.selectReceiveAddress = selectReceiveAddress; exports.selectReceiveAddress = selectReceiveAddress;

View file

@ -51,6 +51,22 @@ declare type PurchaseUriCompleted = {
declare type PurchaseUriFailed = { declare type PurchaseUriFailed = {
type: ACTIONS.PURCHASE_URI_FAILED, type: ACTIONS.PURCHASE_URI_FAILED,
data: {
uri: string,
error: any
},
};
declare type PurchaseUriStarted = {
type: ACTIONS.PURCHASE_URI_STARTED,
data: {
uri: string,
streamingUrl: string,
},
};
declare type DeletePurchasedUri = {
type: ACTIONS.DELETE_PURCHASED_URI,
data: { data: {
uri: string uri: string
}, },

16
flow-typed/File.js vendored
View file

@ -51,6 +51,22 @@ declare type PurchaseUriCompleted = {
declare type PurchaseUriFailed = { declare type PurchaseUriFailed = {
type: ACTIONS.PURCHASE_URI_FAILED, type: ACTIONS.PURCHASE_URI_FAILED,
data: {
uri: string,
error: any
},
};
declare type PurchaseUriStarted = {
type: ACTIONS.PURCHASE_URI_STARTED,
data: {
uri: string,
streamingUrl: string,
},
};
declare type DeletePurchasedUri = {
type: ACTIONS.DELETE_PURCHASED_URI,
data: { data: {
uri: string uri: string
}, },

View file

@ -109,6 +109,7 @@ export const SET_FILE_LIST_SORT = 'SET_FILE_LIST_SORT';
export const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED'; export const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED';
export const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED'; export const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED';
export const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED'; export const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED';
export const DELETE_PURCHASED_URI = 'DELETE_PURCHASED_URI';
export const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED'; export const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED';
export const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED'; export const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED';
export const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED'; export const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED';

View file

@ -47,7 +47,7 @@ export {
doCreateChannel, doCreateChannel,
} from 'redux/actions/claims'; } from 'redux/actions/claims';
export { doPurchaseUri, doFileGet } from 'redux/actions/file'; export { doDeletePurchasedUri, doPurchaseUri, doFileGet } from 'redux/actions/file';
export { export {
doFetchFileInfo, doFetchFileInfo,
@ -111,6 +111,7 @@ export {
selectFailedPurchaseUris, selectFailedPurchaseUris,
selectPurchasedUris, selectPurchasedUris,
selectPurchasedStreamingUrls, selectPurchasedStreamingUrls,
selectPurchaseUriErrorMessage,
selectLastPurchasedUri, selectLastPurchasedUri,
makeSelectStreamingUrlForUri, makeSelectStreamingUrlForUri,
} from 'redux/selectors/file'; } from 'redux/selectors/file';

View file

@ -88,8 +88,7 @@ export function doPurchaseUri(uri: string, costInfo: { cost: number }, saveFile:
} }
const { cost } = costInfo; const { cost } = costInfo;
if (parseFloat(cost) > balance) {
if (cost > balance) {
dispatch({ dispatch({
type: ACTIONS.PURCHASE_URI_FAILED, type: ACTIONS.PURCHASE_URI_FAILED,
data: { uri, error: 'Insufficient credits' }, data: { uri, error: 'Insufficient credits' },
@ -102,3 +101,10 @@ export function doPurchaseUri(uri: string, costInfo: { cost: number }, saveFile:
dispatch(doFileGet(uri, saveFile)); dispatch(doFileGet(uri, saveFile));
}; };
} }
export function doDeletePurchasedUri(uri: string) {
return {
type: ACTIONS.DELETE_PURCHASED_URI,
data: { uri },
};
}

View file

@ -6,6 +6,24 @@ const defaultState = {
failedPurchaseUris: [], failedPurchaseUris: [],
purchasedUris: [], purchasedUris: [],
purchasedStreamingUrls: {}, purchasedStreamingUrls: {},
purchaseUriErrorMessage: '',
};
reducers[ACTIONS.PURCHASE_URI_STARTED] = (
state: FileState,
action: PurchaseUriStarted
): FileState => {
const { uri } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.splice(newFailedPurchaseUris.indexOf(uri), 1);
}
return {
...state,
failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: '',
};
}; };
reducers[ACTIONS.PURCHASE_URI_COMPLETED] = ( reducers[ACTIONS.PURCHASE_URI_COMPLETED] = (
@ -32,6 +50,7 @@ reducers[ACTIONS.PURCHASE_URI_COMPLETED] = (
failedPurchaseUris: newFailedPurchaseUris, failedPurchaseUris: newFailedPurchaseUris,
purchasedUris: newPurchasedUris, purchasedUris: newPurchasedUris,
purchasedStreamingUrls: newPurchasedStreamingUrls, purchasedStreamingUrls: newPurchasedStreamingUrls,
purchaseUriErrorMessage: '',
}; };
}; };
@ -39,8 +58,9 @@ reducers[ACTIONS.PURCHASE_URI_FAILED] = (
state: FileState, state: FileState,
action: PurchaseUriFailed action: PurchaseUriFailed
): FileState => { ): FileState => {
const { uri } = action.data; const { uri, error } = action.data;
const newFailedPurchaseUris = state.failedPurchaseUris.slice(); const newFailedPurchaseUris = state.failedPurchaseUris.slice();
if (!newFailedPurchaseUris.includes(uri)) { if (!newFailedPurchaseUris.includes(uri)) {
newFailedPurchaseUris.push(uri); newFailedPurchaseUris.push(uri);
} }
@ -48,6 +68,23 @@ reducers[ACTIONS.PURCHASE_URI_FAILED] = (
return { return {
...state, ...state,
failedPurchaseUris: newFailedPurchaseUris, failedPurchaseUris: newFailedPurchaseUris,
purchaseUriErrorMessage: error,
};
};
reducers[ACTIONS.DELETE_PURCHASED_URI] = (
state: FileState,
action: DeletePurchasedUri
): FileState => {
const { uri } = action.data;
const newPurchasedUris = state.purchasedUris.slice();
if (newPurchasedUris.includes(uri)) {
newPurchasedUris.splice(newPurchasedUris.indexOf(uri), 1);
}
return {
...state,
purchasedUris: newPurchasedUris,
}; };
}; };

View file

@ -5,6 +5,11 @@ type State = { file: FileState };
export const selectState = (state: State): FileState => state.file || {}; export const selectState = (state: State): FileState => state.file || {};
export const selectPurchaseUriErrorMessage: (state: State) => string = createSelector(
selectState,
state => state.purchaseUriErrorMessage
);
export const selectFailedPurchaseUris: (state: State) => Array<string> = createSelector( export const selectFailedPurchaseUris: (state: State) => Array<string> = createSelector(
selectState, selectState,
state => state.failedPurchaseUris state => state.failedPurchaseUris